From ef055619d3b682dec4c859ddc7860d0aeaef8cc9 Mon Sep 17 00:00:00 2001 From: Patrick Desaulniers Date: Tue, 12 Dec 2023 19:05:02 -0500 Subject: [PATCH] Bring back teal.compilerPath setting Should fix https://github.com/teal-language/vscode-teal/issues/66 --- package.json | 9 ++------- server/diagnostics.ts | 4 ++-- server/server.ts | 32 ++++++++++++++++++++++---------- server/teal.ts | 14 +++++++------- 4 files changed, 33 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index af5fb72..08313cf 100644 --- a/package.json +++ b/package.json @@ -24,15 +24,10 @@ "configuration": { "title": "Teal", "properties": { - "teal.compilerPath.unix": { + "teal.compilerPath": { "type": "string", "default": "tl", - "description": "The path of the tl compiler on Unix-like platforms." - }, - "teal.compilerPath.window": { - "type": "string", - "default": "tl.bat", - "description": "The path of the tl compiler on Windows." + "description": "The path of the tl compiler." } } }, diff --git a/server/diagnostics.ts b/server/diagnostics.ts index 8adde96..a060673 100644 --- a/server/diagnostics.ts +++ b/server/diagnostics.ts @@ -6,10 +6,10 @@ import { TreeSitterDocument } from "./tree-sitter-document"; import { EOL } from "os"; export namespace TealLS { - export async function validateTextDocument(textDocument: TreeSitterDocument): Promise> { + export async function validateTextDocument(textDocument: TreeSitterDocument, compilerPath: string): Promise> { const projectRoot = await textDocument.getProjectRoot(); - const checkResult = await Teal.runCommandOnText(Teal.TLCommand.Check, textDocument.getText(), projectRoot); + const checkResult = await Teal.runCommandOnText(Teal.TLCommand.Check, compilerPath, textDocument.getText(), projectRoot); const crashPattern = /stack traceback:/m; diff --git a/server/server.ts b/server/server.ts index ae41f89..58070f3 100644 --- a/server/server.ts +++ b/server/server.ts @@ -83,20 +83,28 @@ connection.onInitialized(() => { } }); -interface TealServerSettings { }; +interface TealServerSettings { + compilerPath: string +}; -const defaultSettings: TealServerSettings = {}; +const defaultSettings: TealServerSettings = { + compilerPath: "tl" +}; let globalSettings: TealServerSettings = defaultSettings; +function getCompilerPath() { + return globalSettings.compilerPath; +} + // Cache the settings of all open documents let settingsCache: Map = new Map(); // Cache "tl types" queries of all open documents let typesCommandCache: Map = new Map(); -async function verifyMinimumTLVersion(): Promise { - const tlVersion = await Teal.getVersion(); +async function verifyMinimumTLVersion(compilerPath: string): Promise { + const tlVersion = await Teal.getVersion(compilerPath); if (tlVersion !== null) { const targetVersion = new MajorMinorPatch(0, 12, 0); @@ -123,6 +131,8 @@ connection.onDidChangeConfiguration((change) => { // Reset all cached document settings settingsCache.clear(); } else { + console.log("onDidChangeConfiguration", change.settings); + globalSettings = ( (change.settings.teal || defaultSettings) ); @@ -130,7 +140,7 @@ connection.onDidChangeConfiguration((change) => { // Revalidate all open text documents documents.forEach(async function (x: TreeSitterDocument) { - const validVersion = await verifyMinimumTLVersion(); + const validVersion = await verifyMinimumTLVersion(globalSettings.compilerPath); if (validVersion) { validateTextDocument(x.uri); @@ -140,7 +150,7 @@ connection.onDidChangeConfiguration((change) => { typesCommandCache.clear(); }); -async function getDocumentSettings(uri: string): Promise { +async function getDocumentSettings(uri: string): Promise { if (!hasConfigurationCapability) { return Promise.resolve(globalSettings); } @@ -154,7 +164,7 @@ async function getDocumentSettings(uri: string): Promise { - const validVersion = await verifyMinimumTLVersion(); + const settings = await getDocumentSettings(params.textDocument.uri); + + const validVersion = await verifyMinimumTLVersion(settings.compilerPath); if (!validVersion) { return; @@ -346,7 +358,7 @@ async function _validateTextDocument(uri: string): Promise { let settings = await getDocumentSettings(textDocument.uri); try { - const diagnosticsByPath = await TealLS.validateTextDocument(textDocument); + const diagnosticsByPath = await TealLS.validateTextDocument(textDocument, settings.compilerPath); for (let [uri, diagnostics] of diagnosticsByPath.entries()) { connection.sendDiagnostics({ uri: uri, diagnostics: diagnostics }); diff --git a/server/teal.ts b/server/teal.ts index c0a6146..f4099d6 100644 --- a/server/teal.ts +++ b/server/teal.ts @@ -148,13 +148,13 @@ export namespace Teal { * @param text The text. * @param projectRoot The directory which contains the tlconfig.lua file to use for running the command. */ - export async function runCommandOnText(command: TLCommand, text: string, projectRoot?: string): Promise { + export async function runCommandOnText(command: TLCommand, compilerPath: string, text: string, projectRoot?: string): Promise { try { return await withFile(async ({ path, fd }) => { await writeFile(fd, text); try { - let result = await runCommand(command, path, projectRoot); + let result = await runCommand(command, compilerPath, path, projectRoot); return result; } catch (error) { throw error; @@ -165,9 +165,9 @@ export namespace Teal { } } - export const tlNotFoundErrorMessage = "Could not find the tl executable. Please make sure that it is available in the PATH."; + export const tlNotFoundErrorMessage = "Could not find the tl executable or one of its dependencies. Please make sure that they are available in the PATH."; - export async function runCommand(command: TLCommand, filePath?: string, cwd?: string): Promise { + export async function runCommand(command: TLCommand, compilerPath: string, filePath?: string, cwd?: string): Promise { let child: any; let isWindows = process.platform == "win32"; @@ -182,7 +182,7 @@ export namespace Teal { args.push(filePath); } - child = spawn("tl", args, { + child = spawn(compilerPath, args, { shell: isWindows, cwd: cwd }); @@ -213,11 +213,11 @@ export namespace Teal { }); } - export async function getVersion(): Promise { + export async function getVersion(compilerPath: string): Promise { let commandResult: TLCommandIOInfo; try { - commandResult = await Teal.runCommand(Teal.TLCommand.Version); + commandResult = await Teal.runCommand(Teal.TLCommand.Version, compilerPath); } catch (e) { return null; }