Skip to content

Commit

Permalink
Add configuration for REPL / dynamic diagram
Browse files Browse the repository at this point in the history
  • Loading branch information
fdodino committed Sep 24, 2023
1 parent 5f4b6e5 commit 9a9b697
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 39 deletions.
19 changes: 15 additions & 4 deletions client/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,24 @@ const getCurrentFileName = (document: vscode.TextDocument | undefined) =>
const getFiles = (document: vscode.TextDocument | undefined) =>
document ? [fsToShell(document.uri.fsPath)] : []

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

export const startRepl = (): Task => {
const currentDocument = window.activeTextEditor?.document
const cliCommands = [`repl`, ...getFiles(currentDocument), '--skipValidations']
const replTask = wollokCLITask('repl', `Wollok Repl: ${getCurrentFileName(currentDocument)}`, cliCommands)
setTimeout(() => {
vscode.commands.executeCommand('simpleBrowser.show', 'http://localhost:3000/')
}, 1000)

const openDynamicDiagram = workspace.getConfiguration('wollokLSP').get('openDynamicDiagramOnRepl') as boolean
if (openDynamicDiagram) {
setTimeout(() => {
const openInternalDynamicDiagram = workspace.getConfiguration('wollokLSP').get('openInternalDynamicDiagram') as boolean
if (openInternalDynamicDiagram) {
vscode.commands.executeCommand('simpleBrowser.show', DYNAMIC_DIAGRAM_URI)
} else {
vscode.env.openExternal(vscode.Uri.parse(DYNAMIC_DIAGRAM_URI))
}
}, 1000)
}
return replTask
}

Expand All @@ -80,7 +91,7 @@ const registerCLICommand = (

const wollokCLITask = (task: string, name: string, cliCommands: string[]) => {
const wollokCli = unknownToShell(
workspace.getConfiguration('wollokLinter').get('cli-path'),
workspace.getConfiguration('wollokLSP').get('cli-path'),
)
const folder = workspace.workspaceFolders[0]
const shellCommand = [
Expand Down
42 changes: 30 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,13 @@
"type": "object",
"title": "Wollok LSP IDE",
"properties": {
"wollokLinter.cli-path": {
"wollokLSP.cli-path": {
"scope": "resource",
"type": "string",
"description": "Path to Wollok-CLI."
"description": "Path to Wollok-CLI.",
"order": 0
},
"wollokLinter.maxNumberOfProblems": {
"scope": "resource",
"type": "number",
"default": 100,
"description": "Controls the maximum number of problems produced by the server."
},
"wollokLinter.language": {
"wollokLSP.language": {
"scope": "resource",
"type": "string",
"enum": [
Expand All @@ -76,9 +71,31 @@
"Based on Local Environment"
],
"default": "Based on Local Environment",
"description": "Language used while reporting linter errors and warnings."
"description": "Language used while reporting linter errors and warnings.",
"order": 1
},
"wollokLSP.maxNumberOfProblems": {
"scope": "resource",
"type": "number",
"default": 100,
"description": "Controls the maximum number of problems produced by the server.",
"order": 2
},
"wollokLSP.openDynamicDiagramOnRepl": {
"scope": "resource",
"type": "boolean",
"default": true,
"description": "Opens the dynamic diagram when running the REPL.",
"order": 3
},
"wollokLSP.openInternalDynamicDiagram": {
"scope": "resource",
"type": "boolean",
"default": true,
"description": "If true, opens an internal dynamic diagram inside Wollok IDE. If false, it will open a new external browser.",
"order": 4
},
"wollokLinter.trace.server": {
"wollokLSP.trace.server": {
"scope": "window",
"type": "string",
"enum": [
Expand All @@ -87,7 +104,8 @@
"verbose"
],
"default": "off",
"description": "Traces the communication between VS Code and the language server."
"description": "Traces the communication between VS Code and the language server.",
"order": 5
}
}
},
Expand Down
19 changes: 2 additions & 17 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {
validateTextDocument,
workspaceSymbols,
} from './linter'
import { initializeSettings, WollokLinterSettings } from './settings'
import { initializeSettings, WollokLSPSettings } from './settings'
import { templates } from './functionalities/autocomplete/templates'
import { EnvironmentProvider } from './utils/vm/environment-provider'

Expand Down Expand Up @@ -77,28 +77,13 @@ connection.onInitialized(() => {
})

// Cache the settings of all open documents
const documentSettings: Map<string, Thenable<WollokLinterSettings>> = new Map()
const documentSettings: Map<string, Thenable<WollokLSPSettings>> = new Map()

connection.onDidChangeConfiguration(() => {
// Revalidate all open text documents
documents.all().forEach(validateTextDocument(connection, documents.all()))
})

// function getDocumentSettings(resource: string): Thenable<ExampleSettings> {
// if (!hasConfigurationCapability) {
// return Promise.resolve(globalSettings)
// }
// let result = documentSettings.get(resource)
// if (!result) {
// result = connection.workspace.getConfiguration({
// scopeUri: resource,
// section: 'languageServerExample',
// })
// documentSettings.set(resource, result)
// }
// return result
// }

// Only keep settings for open documents
documents.onDidClose((e) => {
documentSettings.delete(e.document.uri)
Expand Down
16 changes: 10 additions & 6 deletions server/src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Connection } from 'vscode-languageserver/node'

export interface WollokLinterSettings {
export interface WollokLSPSettings {
maxNumberOfProblems: number
language: string
language: string,
openDynamicDiagramOnRepl: boolean,
openInternalDynamicDiagram: boolean,
}

// ══════════════════════════════════════════════════════════════════════════════════════════════════════════════════
Expand All @@ -18,12 +20,14 @@ const envLang = () => {
return fullLanguage ? fullLanguage.substring(0, 2) : SPANISH
}

const defaultSettings: WollokLinterSettings = {
const defaultSettings: WollokLSPSettings = {
maxNumberOfProblems: 1000,
language: envLang(),
openDynamicDiagramOnRepl: true,
openInternalDynamicDiagram: true,
}

let globalSettings: WollokLinterSettings = defaultSettings
let globalSettings: WollokLSPSettings = defaultSettings

const languageDescription: { [key: string]: string } = {
Spanish: SPANISH,
Expand All @@ -38,8 +42,8 @@ export const updateDocumentSettings = async (
): Promise<void> => {
globalSettings =
((await connection.workspace.getConfiguration({
section: 'wollokLinter',
})) as WollokLinterSettings) || defaultSettings
section: 'wollokLSP',
})) as WollokLSPSettings) || defaultSettings
}

export const initializeSettings = async (
Expand Down

0 comments on commit 9a9b697

Please sign in to comment.