Skip to content

Commit

Permalink
Using shared-definitions preinstall + rebasing from Ivo's PR
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Mar 24, 2024
1 parent 98dc23c commit 43669d7
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 56 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ yalc.lock
.DS_Store
coverage
.nyc_output
wollok.log
wollok.log
./client/src/shared-definitions.ts
2 changes: 1 addition & 1 deletion client/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
fsToShell,
unknownToShell,
} from './platform-string-utils'
import { COMMAND_RUN_ALL_TESTS, COMMAND_RUN_GAME, COMMAND_RUN_PROGRAM, COMMAND_RUN_TEST, COMMAND_START_REPL, wollokLSPExtensionCode } from './constants'
import { COMMAND_RUN_ALL_TESTS, COMMAND_RUN_GAME, COMMAND_RUN_PROGRAM, COMMAND_RUN_TEST, COMMAND_START_REPL, wollokLSPExtensionCode } from './shared-definitions'

export const subscribeWollokCommands = (context: ExtensionContext): void => {
context.subscriptions.push(registerCLICommand(COMMAND_START_REPL, startRepl))
Expand Down
2 changes: 1 addition & 1 deletion client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
} from 'vscode-languageclient/node'
import { subscribeWollokCommands } from './commands'
import { allWollokFiles } from './utils'
import { wollokLSPExtensionId } from './constants'
import { wollokLSPExtensionId } from './shared-definitions'

let client: LanguageClient

Expand Down
File renamed without changes.
46 changes: 12 additions & 34 deletions client/src/test/code-lens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,44 +57,22 @@ suite('Should do code lenses', () => {

test('Shows test code lenses for Wollok Definition file', async () => {
await testCodeLenses(getDocumentURI('pepita.wlk'), [
new CodeLens(
new Range(new Position(0, 0), new Position(4, 0)),
{
range : {
c : {
c : 0,
e : 0,
},
e : {
c : 4,
e : 0,
},
},
command : {
arguments : [
'pepita.Pepita',
],
command : 'wollok.start.repl',
title : 'Run in REPL',
},
title : 'Run in REPL',
command : 'wollok.start.repl',
arguments : ['pepita.Pepita'],
},
),
new CodeLens(
new Range(new Position(4, 0), new Position(6, 0)),
{
range: {
c : {
c : 4,
e : 0,
},
e : {
c : 6,
e : 0,
},
},
command: {
arguments: [
'pepita.a',
],
command: 'wollok.start.repl',
title: 'Run in REPL',
},
title: 'Run in REPL',
command: 'wollok.start.repl',
arguments: ['pepita.a'],
},
),
])
})
})
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
]
},
"scripts": {
"preinstall": "ln ./server/src/shared-definitions.ts ./client/src",
"vscode:prepublish": "npm run compile",
"compile": "tsc -b",
"watch": "tsc -b -w",
Expand Down
35 changes: 17 additions & 18 deletions server/src/functionalities/code-lens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CodeLens, CodeLensParams, Position, Range } from 'vscode-languageserver
import { Describe, Node, Package, Test, Program, Environment, is, PROGRAM_FILE_EXTENSION, TEST_FILE_EXTENSION, WOLLOK_FILE_EXTENSION, Class, Singleton, Entity } from 'wollok-ts'
import { getWollokFileExtension, packageFromURI, toVSCRange } from '../utils/text-documents'
import { removeQuotes } from '../utils/strings'
import { COMMAND_RUN_GAME, COMMAND_RUN_PROGRAM, COMMAND_RUN_TEST, COMMAND_START_REPL } from '../constants'
import { COMMAND_RUN_GAME, COMMAND_RUN_PROGRAM, COMMAND_RUN_TEST, COMMAND_START_REPL } from '../shared-definitions'

export const codeLenses = (environment: Environment) => (params: CodeLensParams): CodeLens[] | null => {
const fileExtension = getWollokFileExtension(params.textDocument.uri)
Expand Down Expand Up @@ -41,7 +41,22 @@ export const getTestCodeLenses = (file: Package): CodeLens[] => {
]
}

const buildRunAllTestsCodeLens = (file: Package): CodeLens =>
export const getWollokFileCodeLenses = (file: Package): CodeLens[] =>
file.members.filter(isWollokDefinition).flatMap(definition => [
buildLens(definition, COMMAND_START_REPL, 'Run in REPL'),
])

/************************************************************************************************/
/* HELPER FUNCTIONS
/************************************************************************************************/

const isTesteable = (node: Node): node is Test | Describe =>
node.is(Test) || node.is(Describe)

const isWollokDefinition = (node: Node): node is Class | Singleton =>
node.is(Class) || node.is(Singleton)

const buildRunAllTestsCodeLens = (file: Package): CodeLens =>
buildTestsCodeLens(
Range.create(Position.create(0, 0), Position.create(0, 0)),
'wollok.run.test',
Expand Down Expand Up @@ -76,22 +91,6 @@ const buildTestsCodeLens = (range: Range, command: string, title: string, args:
},
})

export const getWollokFileCodeLenses = (file: Package): CodeLens[] =>
file.members.filter(isWollokDefinition).flatMap(definition => [
buildLens(definition, COMMAND_START_REPL, 'Run in REPL'),
])

/************************************************************************************************/
/* HELPER FUNCTIONS
/************************************************************************************************/

const isTesteable = (node: Node): node is Test | Describe =>
node.is(Test) || node.is(Describe)

const isWollokDefinition = (node: Node): node is Class | Singleton =>
node.is(Class) || node.is(Singleton)


const buildLens = (node: Entity, command: string, title: string) => (
{
range: toVSCRange(node.sourceMap!),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export const COMMAND_START_REPL = 'wollok.start.repl'
export const COMMAND_RUN_GAME = 'wollok.run.game'
export const COMMAND_RUN_PROGRAM = 'wollok.run.program'
export const COMMAND_RUN_ALL_TESTS = 'wollok.run.allTests'
export const COMMAND_RUN_TEST = 'wollok.run.tests'
export const COMMAND_RUN_TEST = 'wollok.run.test'

0 comments on commit 43669d7

Please sign in to comment.