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/commands.ts b/client/src/commands.ts new file mode 100644 index 00000000..a03aeb9c --- /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): void => { + 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 f934cf4f..6cba4cb1 100644 --- a/client/src/extension.ts +++ b/client/src/extension.ts @@ -4,11 +4,12 @@ * ------------------------------------------------------------------------------------------ */ import * as path from 'path' -import { workspace, ExtensionContext } from 'vscode' +import { ExtensionContext, workspace } from 'vscode' import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind } from 'vscode-languageclient/node' +import { subscribeWollokCommands } from './commands' let client: LanguageClient @@ -43,6 +44,10 @@ export function activate(context: ExtensionContext): void { }, } + // Subscribe Wollok Commands + subscribeWollokCommands(context) + + // Create the language client and start the client. client = new LanguageClient( 'wollok-lsp-ide', diff --git a/package.json b/package.json index 9788e1e7..83143533 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", @@ -75,7 +80,20 @@ "description": "Traces the communication between VS Code and the language server." } } - } + }, + "commands": [ + { + "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" + } + ] }, "scripts": { "vscode:prepublish": "npm run compile",