Skip to content

Commit

Permalink
add game port number configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Oct 8, 2024
1 parent 1695f45 commit 6c0b779
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
9 changes: 8 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,20 @@
"description": "Traces the communication between VS Code and the language server.",
"order": 20
},
"wollokLSP.repl.portNumber": {
"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
9 changes: 6 additions & 3 deletions packages/client/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +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'
import { DEFAULT_REPL_PORT, DEFAULT_GAME_PORT } from '../../server/src/settings'

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

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 @@ -73,7 +76,7 @@ export const startRepl = (): Task => {
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 portNumber = wollokLSPConfiguration.get('replPortNumber') as number ?? DEFAULT_REPL_PORT
const DYNAMIC_DIAGRAM_URI = `http://localhost:${portNumber}/`

const cliCommands = [`repl`, ...getFiles(currentDocument), '--skipValidations', '--port', portNumber.toString(), dynamicDiagramDarkMode ? '--darkMode' : '', openDynamicDiagram ? '': '--skipDiagram']
Expand Down
9 changes: 6 additions & 3 deletions packages/server/src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ import { Connection } from 'vscode-languageserver/node'
import { wollokLSPExtensionCode } from './shared-definitions'
import { LANGUAGES } from 'wollok-ts'

Check failure on line 3 in packages/server/src/settings.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, lts/hydrogen)

Module '"wollok-ts"' has no exported member 'LANGUAGES'.

Check failure on line 3 in packages/server/src/settings.ts

View workflow job for this annotation

GitHub Actions / test (macos-latest, lts/hydrogen)

Module '"wollok-ts"' has no exported member 'LANGUAGES'.

export const DEFAULT_PORT = 3000
export const DEFAULT_REPL_PORT = 3000
export const DEFAULT_GAME_PORT = 4200

export interface WollokLSPSettings {
maxNumberOfProblems: number
language: LANGUAGES,
portNumber: number,
replPortNumber: number,
gamePortNumber: number,
openDynamicDiagramOnRepl: boolean,
openInternalDynamicDiagram: boolean,
dynamicDiagramDarkMode: boolean,
Expand All @@ -28,7 +30,8 @@ const envLang = () => {
const defaultSettings: WollokLSPSettings = {
maxNumberOfProblems: 1000,
language: envLang(),
portNumber: DEFAULT_PORT,
replPortNumber: DEFAULT_REPL_PORT,
gamePortNumber: DEFAULT_GAME_PORT,
openDynamicDiagramOnRepl: true,
openInternalDynamicDiagram: true,
dynamicDiagramDarkMode: true,
Expand Down

0 comments on commit 6c0b779

Please sign in to comment.