From 1695f45b05ebdc08b04dc01403e979edf8f2b6fd Mon Sep 17 00:00:00 2001 From: Fernando Dodino Date: Mon, 7 Oct 2024 20:51:11 -0300 Subject: [PATCH] Fix #186 --- package.json | 7 +++++++ packages/client/src/commands.ts | 7 ++++--- packages/server/src/settings.ts | 4 ++++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 8a8401a..87ff156 100644 --- a/package.json +++ b/package.json @@ -223,6 +223,13 @@ "description": "Traces the communication between VS Code and the language server.", "order": 20 }, + "wollokLSP.repl.portNumber": { + "scope": "resource", + "type": "number", + "default": 3000, + "description": "Port number that will be used when running the REPL.", + "order": 25 + }, "wollokLSP.dynamicDiagram.openDynamicDiagramOnRepl": { "scope": "resource", "type": "boolean", diff --git a/packages/client/src/commands.ts b/packages/client/src/commands.ts index f5d188d..6005608 100644 --- a/packages/client/src/commands.ts +++ b/packages/client/src/commands.ts @@ -14,6 +14,7 @@ import { fsToShell, } from './platform-string-utils' import { COMMAND_RUN_ALL_TESTS, COMMAND_RUN_GAME, COMMAND_RUN_PROGRAM, COMMAND_RUN_TEST, COMMAND_START_REPL, wollokLSPExtensionCode } from './shared-definitions' +import { DEFAULT_PORT } from '../../server/src/settings' export const subscribeWollokCommands = (context: ExtensionContext): void => { context.subscriptions.push(registerCLICommand(COMMAND_START_REPL, startRepl)) @@ -66,16 +67,16 @@ const getCurrentFileName = (document: vscode.TextDocument | undefined) => const getFiles = (document: vscode.TextDocument | undefined): [ReturnType] | [] => 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('repl.portNumber') as number ?? DEFAULT_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) diff --git a/packages/server/src/settings.ts b/packages/server/src/settings.ts index 3673326..bca4198 100644 --- a/packages/server/src/settings.ts +++ b/packages/server/src/settings.ts @@ -2,9 +2,12 @@ import { Connection } from 'vscode-languageserver/node' import { wollokLSPExtensionCode } from './shared-definitions' import { LANGUAGES } from 'wollok-ts' +export const DEFAULT_PORT = 3000 + export interface WollokLSPSettings { maxNumberOfProblems: number language: LANGUAGES, + portNumber: number, openDynamicDiagramOnRepl: boolean, openInternalDynamicDiagram: boolean, dynamicDiagramDarkMode: boolean, @@ -25,6 +28,7 @@ const envLang = () => { const defaultSettings: WollokLSPSettings = { maxNumberOfProblems: 1000, language: envLang(), + portNumber: DEFAULT_PORT, openDynamicDiagramOnRepl: true, openInternalDynamicDiagram: true, dynamicDiagramDarkMode: true,