From 0e736b1016b08599b826d1203be04b752966d4c6 Mon Sep 17 00:00:00 2001 From: palumbon Date: Sun, 16 Oct 2022 18:20:52 +0200 Subject: [PATCH 1/5] REPL integration with CLI --- client/package-lock.json | 2 +- client/src/extension.ts | 26 +++++++++++++++++++++++--- package.json | 9 ++++++++- 3 files changed, 32 insertions(+), 5 deletions(-) diff --git a/client/package-lock.json b/client/package-lock.json index 8ed37577..f579365e 100644 --- a/client/package-lock.json +++ b/client/package-lock.json @@ -16,7 +16,7 @@ "vscode-languageclient": "^8.0.2" }, "engines": { - "vscode": "^1.67.0" + "vscode": "^1.71.0" } }, "node_modules/@tootallnate/once": { diff --git a/client/src/extension.ts b/client/src/extension.ts index f934cf4f..a56c341f 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -4,11 +4,13 @@ * ------------------------------------------------------------------------------------------ */ import * as path from 'path' -import { workspace, ExtensionContext } from 'vscode' -import { LanguageClient, +import { commands, ExtensionContext, ShellExecution, Task, tasks, window, workspace } from 'vscode' +import { + LanguageClient, LanguageClientOptions, ServerOptions, - TransportKind } from 'vscode-languageclient/node' + TransportKind +} from 'vscode-languageclient/node' let client: LanguageClient @@ -43,6 +45,24 @@ export function activate(context: ExtensionContext): void { }, } + context.subscriptions.push( + commands.registerCommand('wollok.start.repl', () => { + + const currentDocument = window.activeTextEditor.document + const folder = workspace.workspaceFolders[0] + const currentFileName = currentDocument.uri.path.replace(`${folder.uri.path}/`, '') + + tasks.executeTask(new Task( + { type: 'wollok', task: 'repl' }, + folder, + `Wollok Repl: ${currentFileName}`, + 'wollok', + new ShellExecution(`wollok repl ${currentDocument.fileName}`) + )) + }) + ); + + // Create the language client and start the client. client = new LanguageClient( 'wollok-lsp-ide', diff --git a/package.json b/package.json index 9788e1e7..4e743a1d 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,14 @@ "description": "Traces the communication between VS Code and the language server." } } - } + }, + "commands": [ + { + "command": "wollok.start.repl", + "title": "Start a new REPL session", + "category": "Wollok" + } + ] }, "scripts": { "vscode:prepublish": "npm run compile", From ef797116ce0e3538419ee43def051589634fd423 Mon Sep 17 00:00:00 2001 From: palumbon Date: Sun, 16 Oct 2022 19:08:28 +0200 Subject: [PATCH 2/5] Configure and use Wollok-CLI path --- client/src/extension.ts | 5 +++-- package.json | 5 +++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/client/src/extension.ts b/client/src/extension.ts index a56c341f..5452df48 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -47,17 +47,18 @@ export function activate(context: ExtensionContext): void { context.subscriptions.push( commands.registerCommand('wollok.start.repl', () => { + const wollokCli = workspace.getConfiguration('wollokLinter').get('cli-path') const currentDocument = window.activeTextEditor.document const folder = workspace.workspaceFolders[0] - const currentFileName = currentDocument.uri.path.replace(`${folder.uri.path}/`, '') + const currentFileName = path.basename(currentDocument.uri.path) tasks.executeTask(new Task( { type: 'wollok', task: 'repl' }, folder, `Wollok Repl: ${currentFileName}`, 'wollok', - new ShellExecution(`wollok repl ${currentDocument.fileName}`) + new ShellExecution(`${wollokCli} repl ${currentDocument.fileName}`) )) }) ); diff --git a/package.json b/package.json index 4e743a1d..39a73757 100644 --- a/package.json +++ b/package.json @@ -46,6 +46,11 @@ "type": "object", "title": "Wollok LSP IDE", "properties": { + "wollokLinter.cli-path": { + "scope": "resource", + "type": "string", + "description": "Path to Wollok-CLI." + }, "wollokLinter.maxNumberOfProblems": { "scope": "resource", "type": "number", From 7c0fda8d07dab3209c3de31f24d4b1badd6ffb5b Mon Sep 17 00:00:00 2001 From: palumbon Date: Sun, 16 Oct 2022 21:40:48 +0200 Subject: [PATCH 3/5] CLI integration: run all tests --- client/src/extension.ts | 15 +++++++++++++++ package.json | 6 ++++++ 2 files changed, 21 insertions(+) diff --git a/client/src/extension.ts b/client/src/extension.ts index 5452df48..9716156b 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -63,6 +63,21 @@ export function activate(context: ExtensionContext): void { }) ); + context.subscriptions.push( + commands.registerCommand('wollok.run.allTests', () => { + const wollokCli = workspace.getConfiguration('wollokLinter').get('cli-path') + const folder = workspace.workspaceFolders[0] + + tasks.executeTask(new Task( + { type: 'wollok', task: 'run tests' }, + folder, + `Wollok run all tests`, + 'wollok', + new ShellExecution(`${wollokCli} test`) + )) + }) + ); + // Create the language client and start the client. client = new LanguageClient( diff --git a/package.json b/package.json index 39a73757..83143533 100644 --- a/package.json +++ b/package.json @@ -86,6 +86,12 @@ "command": "wollok.start.repl", "title": "Start a new REPL session", "category": "Wollok" + }, + { + "command": "wollok.run.allTests", + "title": "Run all tests", + "when": "resourceExtname == .wtest", + "category": "Wollok" } ] }, From c477b60e75829f23f4633328084f1de021b1b8f9 Mon Sep 17 00:00:00 2001 From: palumbon Date: Mon, 17 Oct 2022 05:46:05 +0200 Subject: [PATCH 4/5] Moving commands code to new file --- client/src/commands.ts | 41 ++++++++++++++++++++++++++++++++++++++++ client/src/completion.ts | 0 client/src/extension.ts | 37 ++++-------------------------------- 3 files changed, 45 insertions(+), 33 deletions(-) create mode 100644 client/src/commands.ts delete mode 100644 client/src/completion.ts diff --git a/client/src/commands.ts b/client/src/commands.ts new file mode 100644 index 00000000..8ffb5b86 --- /dev/null +++ b/client/src/commands.ts @@ -0,0 +1,41 @@ +import * as path from 'path' +import { commands, ExtensionContext, ShellExecution, Task, tasks, window, workspace } from 'vscode' + + +export const subscribeWollokCommands = (context: ExtensionContext) => { + context.subscriptions.push(registerCLICommand('wollok.start.repl', startRepl)) + context.subscriptions.push(registerCLICommand('wollok.run.allTests', runAllTests)) +} + +/** + * CLI Commands + */ + +const runAllTests = () => wollokCLITask('run tests', `Wollok run all tests`, ['test']) + +const startRepl = () => { + const currentDocument = window.activeTextEditor.document + const currentFileName = path.basename(currentDocument.uri.path) + return wollokCLITask('repl', `Wollok Repl: ${currentFileName}`, ['repl', currentDocument.fileName]) +} + +/** + * Helpers + */ + +const registerCLICommand = (command: string, taskBuilder: () => Task) => + commands.registerCommand(command, () => tasks.executeTask(taskBuilder())) + +const wollokCLITask = (task: string, name: string, cliCommands: string[]) => { + const wollokCli = workspace.getConfiguration('wollokLinter').get('cli-path') + const folder = workspace.workspaceFolders[0] + const shellCommand = [wollokCli, ...cliCommands].join(' ') + + return new Task( + { type: 'wollok', task }, + folder, + name, + 'wollok', + new ShellExecution(shellCommand) + ) +} \ No newline at end of file diff --git a/client/src/completion.ts b/client/src/completion.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/client/src/extension.ts b/client/src/extension.ts index 9716156b..aa58f3a5 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -4,13 +4,14 @@ * ------------------------------------------------------------------------------------------ */ import * as path from 'path' -import { commands, ExtensionContext, ShellExecution, Task, tasks, window, workspace } from 'vscode' +import { ExtensionContext, workspace } from 'vscode' import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient/node' +import { subscribeWollokCommands } from './commands' let client: LanguageClient @@ -45,38 +46,8 @@ export function activate(context: ExtensionContext): void { }, } - context.subscriptions.push( - commands.registerCommand('wollok.start.repl', () => { - const wollokCli = workspace.getConfiguration('wollokLinter').get('cli-path') - - const currentDocument = window.activeTextEditor.document - const folder = workspace.workspaceFolders[0] - const currentFileName = path.basename(currentDocument.uri.path) - - tasks.executeTask(new Task( - { type: 'wollok', task: 'repl' }, - folder, - `Wollok Repl: ${currentFileName}`, - 'wollok', - new ShellExecution(`${wollokCli} repl ${currentDocument.fileName}`) - )) - }) - ); - - context.subscriptions.push( - commands.registerCommand('wollok.run.allTests', () => { - const wollokCli = workspace.getConfiguration('wollokLinter').get('cli-path') - const folder = workspace.workspaceFolders[0] - - tasks.executeTask(new Task( - { type: 'wollok', task: 'run tests' }, - folder, - `Wollok run all tests`, - 'wollok', - new ShellExecution(`${wollokCli} test`) - )) - }) - ); + // Subscribe Wollok Commands + subscribeWollokCommands(context) // Create the language client and start the client. From 8978f05777f4deedfa0c25cd5128f74a8ca478fb Mon Sep 17 00:00:00 2001 From: palumbon Date: Mon, 17 Oct 2022 05:57:16 +0200 Subject: [PATCH 5/5] Fix eslint --- client/src/commands.ts | 4 ++-- client/src/extension.ts | 6 ++---- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/client/src/commands.ts b/client/src/commands.ts index 8ffb5b86..a03aeb9c 100644 --- a/client/src/commands.ts +++ b/client/src/commands.ts @@ -2,7 +2,7 @@ import * as path from 'path' import { commands, ExtensionContext, ShellExecution, Task, tasks, window, workspace } from 'vscode' -export const subscribeWollokCommands = (context: ExtensionContext) => { +export const subscribeWollokCommands = (context: ExtensionContext): void => { context.subscriptions.push(registerCLICommand('wollok.start.repl', startRepl)) context.subscriptions.push(registerCLICommand('wollok.run.allTests', runAllTests)) } @@ -11,7 +11,7 @@ export const subscribeWollokCommands = (context: ExtensionContext) => { * CLI Commands */ -const runAllTests = () => wollokCLITask('run tests', `Wollok run all tests`, ['test']) +const runAllTests = () => wollokCLITask('run tests', 'Wollok run all tests', ['test']) const startRepl = () => { const currentDocument = window.activeTextEditor.document diff --git a/client/src/extension.ts b/client/src/extension.ts index aa58f3a5..6cba4cb1 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -5,12 +5,10 @@ import * as path from 'path' import { ExtensionContext, workspace } from 'vscode' -import { - LanguageClient, +import { LanguageClient, LanguageClientOptions, ServerOptions, - TransportKind -} from 'vscode-languageclient/node' + TransportKind } from 'vscode-languageclient/node' import { subscribeWollokCommands } from './commands' let client: LanguageClient