Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove messages and definitions #190

Merged
merged 12 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<!-- DO NOT REMOVE - contributor_list:data:start:["ivojawer", "fdodino", "PalumboN", "npasserini", "FerRomMu", "dependabot[bot]"]:end -->
<!-- DO NOT REMOVE - contributor_list:data:start:["ivojawer", "fdodino", "PalumboN", "npasserini", "Miranda-03", "FerRomMu", "dependabot[bot]"]:end -->


# Wollok IDE
Expand Down Expand Up @@ -41,6 +41,6 @@ Do you want to contribute? Great, you are always welcome!
<!-- DO NOT REMOVE - contributor_list:start -->
## 👥 Contributors

<img src="https://avatars.githubusercontent.com/u/18614957?v=4" height="40" width="40" alt="ivojawer" title="ivojawer" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/4549002?v=4" height="40" width="40" alt="fdodino" title="fdodino" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/4098184?v=4" height="40" width="40" alt="PalumboN" title="PalumboN" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/4633913?v=4" height="40" width="40" alt="npasserini" title="npasserini" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/70177008?v=4" height="40" width="40" alt="FerRomMu" title="FerRomMu" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/in/29110?v=4" height="40" width="40" alt="dependabot[bot]" title="dependabot[bot]" class="avatar circle"/>&nbsp;
<img src="https://avatars.githubusercontent.com/u/18614957?v=4" height="40" width="40" alt="ivojawer" title="ivojawer" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/4549002?v=4" height="40" width="40" alt="fdodino" title="fdodino" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/4098184?v=4" height="40" width="40" alt="PalumboN" title="PalumboN" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/4633913?v=4" height="40" width="40" alt="npasserini" title="npasserini" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/72475370?v=4" height="40" width="40" alt="Miranda-03" title="Miranda-03" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/u/70177008?v=4" height="40" width="40" alt="FerRomMu" title="FerRomMu" class="avatar circle"/>&nbsp;<img src="https://avatars.githubusercontent.com/in/29110?v=4" height="40" width="40" alt="dependabot[bot]" title="dependabot[bot]" class="avatar circle"/>&nbsp;
<!-- DO NOT REMOVE - contributor_list:end -->
<!-- prettier-ignore-end -->
17 changes: 16 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@
"scope": "resource",
"type": "string",
"description": "Path to Wollok-CLI.",
"default": "wollok",
"order": 10
},
"wollokLSP.language": {
Expand Down Expand Up @@ -222,6 +223,20 @@
"description": "Traces the communication between VS Code and the language server.",
"order": 20
},
"wollokLSP.replPortNumber": {
"scope": "resource",
"type": "number",
"default": 3000,
"description": "Port number that will be used when running the REPL.",
"order": 25
},
"wollokLSP.gamePortNumber": {
"scope": "resource",
"type": "number",
"default": 4200,
"description": "Port number that will be used when running a game.",
"order": 26
},
"wollokLSP.dynamicDiagram.openDynamicDiagramOnRepl": {
"scope": "resource",
"type": "boolean",
Expand Down Expand Up @@ -328,7 +343,7 @@
"lint-staged": "lint-staged"
},
"dependencies": {
"wollok-ts": "4.1.6"
"wollok-ts": "4.1.8"
},
"devDependencies": {
"@istanbuljs/nyc-config-typescript": "^1.0.2",
Expand Down
19 changes: 12 additions & 7 deletions packages/client/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,13 @@
window,
workspace,
} from 'vscode'
import { DEFAULT_GAME_PORT, DEFAULT_REPL_PORT } from '../../server/src/settings'
import {
asShellString,
fsToShell,
} from './platform-string-utils'
import { COMMAND_RUN_ALL_TESTS, COMMAND_RUN_GAME, COMMAND_RUN_PROGRAM, COMMAND_RUN_TEST, COMMAND_START_REPL, wollokLSPExtensionCode, COMMAND_INIT_PROJECT } from './shared-definitions'
import { getLSPMessage } from './messages'

export const subscribeWollokCommands = (context: ExtensionContext): void => {
context.subscriptions.push(registerCLICommand(COMMAND_START_REPL, startRepl))
Expand All @@ -37,11 +39,14 @@
*/

export const runProgram = (isGame = false) => ([fqn]: [string]): Task => {
const wollokLSPConfiguration = workspace.getConfiguration(wollokLSPExtensionCode)
const portNumber = wollokLSPConfiguration.get('gamePortNumber') as number ?? DEFAULT_GAME_PORT

// Terminate previous terminal session
vscode.commands.executeCommand('workbench.action.terminal.killAll')
return wollokCLITask('run program', `Wollok run ${isGame ? 'game' : 'program'}`, [
'run',
...isGame ? ['-g'] : [],
...isGame ? ['-g', '--port', portNumber.toString()] : [],
asShellString(fqn),
'--skipValidations',
])
Expand Down Expand Up @@ -74,16 +79,16 @@
const getFiles = (document: vscode.TextDocument | undefined): [ReturnType<typeof fsToShell>] | [] =>
document ? [fsToShell(document.uri.fsPath)] : []

const DYNAMIC_DIAGRAM_URI = 'http://localhost:3000/'

export const startRepl = (): Task => {
const currentDocument = window.activeTextEditor?.document
const wollokLSPConfiguration = workspace.getConfiguration(wollokLSPExtensionCode)
const dynamicDiagramDarkMode = wollokLSPConfiguration.get('dynamicDiagram.dynamicDiagramDarkMode') as boolean
const openDynamicDiagram = wollokLSPConfiguration.get('dynamicDiagram.openDynamicDiagramOnRepl') as boolean
const millisecondsToOpenDynamicDiagram = wollokLSPConfiguration.get('dynamicDiagram.millisecondsToOpenDynamicDiagram') as number
const portNumber = wollokLSPConfiguration.get('replPortNumber') as number ?? DEFAULT_REPL_PORT
const DYNAMIC_DIAGRAM_URI = `http://localhost:${portNumber}/`

const cliCommands = [`repl`, ...getFiles(currentDocument), '--skipValidations', dynamicDiagramDarkMode ? '--darkMode' : '', openDynamicDiagram ? '': '--skipDiagram']
const cliCommands = [`repl`, ...getFiles(currentDocument), '--skipValidations', '--port', portNumber.toString(), dynamicDiagramDarkMode ? '--darkMode' : '', openDynamicDiagram ? '': '--skipDiagram']
// Terminate previous tasks
vscode.commands.executeCommand('workbench.action.terminal.killAll')
const replTask = wollokCLITask('repl', `Wollok Repl: ${getCurrentFileName(currentDocument)}`, cliCommands)
Expand Down Expand Up @@ -114,11 +119,11 @@
)

const wollokCLITask = (task: string, name: string, cliCommands: Array<string | vscode.ShellQuotedString>) => {
const wollokCliPath: string = workspace.getConfiguration(wollokLSPExtensionCode).get('cli-path')
// TODO: i18n - but it's in the server
const wollokLSPConfiguration = workspace.getConfiguration(wollokLSPExtensionCode)
const wollokCliPath: string = wollokLSPConfiguration.get('cli-path')
if (!wollokCliPath) {
vscode.commands.executeCommand('workbench.action.openSettings', wollokLSPExtensionCode)
throw new Error('Missing configuration WollokLSP/cli-path. Set the path where wollok-ts-cli is located in order to run Wollok tasks')
throw new Error(getLSPMessage('missingWollokCliPath'))

Check warning on line 126 in packages/client/src/commands.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/src/commands.ts#L126

Added line #L126 was not covered by tests
}

const folder = workspace.workspaceFolders[0]
Expand Down
5 changes: 3 additions & 2 deletions packages/client/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ import {
TransportKind,
WorkDoneProgress,
} from 'vscode-languageclient/node'
import { WollokDebugAdapterFactory, WollokDebugConfigurationProvider } from '../../debug-adapter/src/index'
import { subscribeWollokCommands } from './commands'
import { getLSPMessage } from './messages'
import { wollokLSPExtensionId } from './shared-definitions'
import { allWollokFiles } from './utils'
import { WollokDebugAdapterFactory, WollokDebugConfigurationProvider } from '../../debug-adapter/src/index'

let client: LanguageClient

Expand Down Expand Up @@ -81,7 +82,7 @@ export function activate(context: ExtensionContext): void {

client.onProgress(WorkDoneProgress.type, 'wollok-build', (progress) => {
if (progress.kind === 'begin' || progress.kind === 'report') {
statusBarItem.text = '$(loading~spin) Wollok Building...'
statusBarItem.text = '$(loading~spin) ' + getLSPMessage('wollokBuilding')
statusBarItem.show()
} else {
statusBarItem.hide()
Expand Down
23 changes: 23 additions & 0 deletions packages/client/src/messages.ts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jajajaj ATR

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { getMessage, LANGUAGES, Messages } from 'wollok-ts'
import { wollokLSPExtensionCode } from './shared-definitions'
import { workspace } from 'vscode'

export const languageDescription: { [key: string]: LANGUAGES } = {
Spanish: LANGUAGES.SPANISH,
English: LANGUAGES.ENGLISH,
}

export const lang = (selectedLanguage: string): LANGUAGES => languageDescription[selectedLanguage] ?? LANGUAGES.ENGLISH

export const lspClientMessages: Messages = {
[LANGUAGES.ENGLISH]: {
missingWollokCliPath: 'Missing configuration WollokLSP/cli-path. Set the path where wollok-ts-cli is located in order to run Wollok tasks',
wollokBuilding: 'Wollok Building...',
},
[LANGUAGES.SPANISH]: {
missingWollokCliPath: 'Falta configurar la ruta donde está instalado wollok-ts-cli. Este paso es necesario para ejecutar cualquier comando de Wollok.',
wollokBuilding: 'Generando Wollok...',
},
}

export const getLSPMessage = (message: string): string => getMessage({ message, language: lang(workspace.getConfiguration(wollokLSPExtensionCode).get('language')), customMessages: lspClientMessages })
15 changes: 14 additions & 1 deletion packages/client/src/test/commands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,23 @@ import * as sinon from 'sinon'
import { ShellExecution, ShellQuotedString, ShellQuoting, Task, Uri, workspace } from 'vscode'
import { initProject, runAllTests, runProgram, runTest, startRepl } from '../commands'
import { activate, getDocumentURI, getFolderURI } from './helper'
import { DEFAULT_GAME_PORT, DEFAULT_REPL_PORT } from '../../../server/src/settings'

suite('Should run commands', () => {
const folderURI = getFolderURI()
const pepitaURI = getDocumentURI('pepita.wlk')

const configuration = {
gamePortNumber: DEFAULT_GAME_PORT,
replPortNumber: DEFAULT_REPL_PORT,
'cli-path': '/usr/bin/wollok-ts-cli',
'dynamicDiagram.dynamicDiagramDarkMode': true,
'dynamicDiagram.openDynamicDiagramOnRepl': true,
}

beforeEach(() => {
sinon.stub(workspace, 'getConfiguration').value((_configuration: string) => ({
get: (_value: string) => '/usr/bin/wollok-ts-cli',
get: (_value: string) => configuration[_value],
}))
})

Expand Down Expand Up @@ -40,6 +49,8 @@ suite('Should run commands', () => {
[
'run',
'-g',
'--port',
DEFAULT_GAME_PORT.toString(),
quoted('file.program'),
'--skipValidations',
'-p',
Expand Down Expand Up @@ -91,6 +102,8 @@ suite('Should run commands', () => {
'repl',
quoted(pepitaURI.fsPath),
'--skipValidations',
'--port',
DEFAULT_REPL_PORT.toString(),
'--darkMode',
'', // do not open dynamic diagram
'-p',
Expand Down
5 changes: 4 additions & 1 deletion packages/debug-adapter/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"@types/node": "^18.14.1",
"@types/vscode": "^1.92.0",
"@vscode/debugadapter-testsupport": "^1.67.0",
"mocha": "^10.7.3"
"mocha": "^10.7.3",
"nyc": "^17.0.0",
"ts-mocha": "^10.0.0",
"wollok-ts": "4.1.6"
}
}
48 changes: 12 additions & 36 deletions packages/server/src/functionalities/definition.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Location, TextDocumentPositionParams } from 'vscode-languageserver'
import { Environment, Method, Module, Node, Reference, Self, Send, Super, is, match, sendDefinitions, when } from 'wollok-ts'
import { getNodesByPosition, nodeToLocation } from '../utils/text-documents'
import { Environment, getNodeDefinition, Method, Node, Send, sendDefinitions } from 'wollok-ts'
import { logger } from '../utils/logger'
import { getNodesByPosition, nodeToLocation } from '../utils/text-documents'

export const definition = (environment: Environment) => (
textDocumentPosition: TextDocumentPositionParams
Expand All @@ -13,42 +13,18 @@ export const definition = (environment: Environment) => (

export const getDefinition = (environment: Environment) => (node: Node): Node[] => {
try {
if (node.is(Send)) {
// TODO: migrate to wollok-ts
const getDefinitionFromSyntheticMethod = (method: Method) => {
return method.parent.allFields.find((field) => field.name === method.name && field.isProperty)
}

const definitions = sendDefinitions(environment)(node)
return definitions.map((method: Method) => method.isSynthetic ? getDefinitionFromSyntheticMethod(method) : method)
}
return getNodeDefinition(environment)(node)
} catch (error) {
logger.error(`✘ Error in getDefinition: ${error}`, error)
return [node]
}
}

// TODO: terminar de migrar a wollok-ts estas 4 definiciones
export const getNodeDefinition = (environment: Environment) => (node: Node): Node[] => {
try {
return match(node)(
when(Reference)(node => definedOrEmpty(node.target)),
when(Send)(node => mapSyntheticMethods(environment, node)),
when(Super)(node => definedOrEmpty(superMethodDefinition(node))),
when(Self)(node => definedOrEmpty(getParentModule(node)))
)
} catch {
return [node]
}
}

const mapSyntheticMethods = (environment: Environment, node: Send) => {
const definitions = sendDefinitions(environment)(node)
return definitions.map((method: Method) => method.isSynthetic ? getDefinitionFromSyntheticMethod(method) : method)
}

const getDefinitionFromSyntheticMethod = (method: Method) => {
return method.parent.allFields.find((field) => field.name === method.name && field.isProperty)
}

const superMethodDefinition = (superNode: Super): Method | undefined => {
const currentMethod = superNode.ancestors.find(is(Method))!
const module = getParentModule(superNode)
return module ? module.lookupMethod(currentMethod.name, superNode.args.length, { lookupStartFQN: module.fullyQualifiedName }) : undefined
}

const getParentModule = (node: Node) => node.ancestors.find(is(Module))

const definedOrEmpty = <T>(value: T | undefined): T[] => value ? [value] : []
}
Loading
Loading