diff options
author | cos <cos> | 2024-10-15 17:01:32 +0200 |
---|---|---|
committer | cos <cos> | 2024-10-15 17:01:36 +0200 |
commit | 7505ee134320457269f3376de8eae978ad6acb2a (patch) | |
tree | b0318f8d25df0f5b6fbb5870dceb7a1f87dc7c4e | |
parent | de1344a97c883698d5630b01d8299a17a9d95148 (diff) | |
download | PerlNavigator-7505ee134320457269f3376de8eae978ad6acb2a.zip |
Workaround broken workspaceFolders capability handlingworkaround/broken_rooturi
According to [language server specification][spec] clients not
announcing the workspaceFolders capability should fallback. Primarily to
rootUri, and further to rootPath when needed.
This commit works around the buggy behaviour with vim-ale. Since I have
never ever seen typescript code prior to today, attempting to fix this
properly seems a bit too challenging for me.
[spec]: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/
-rw-r--r-- | server/src/server.ts | 33 |
1 files changed, 27 insertions, 6 deletions
diff --git a/server/src/server.ts b/server/src/server.ts index de62214..4be7e27 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -51,6 +51,7 @@ const documents: TextDocuments<TextDocument> = new TextDocuments(TextDocument); let hasConfigurationCapability = false; let hasWorkspaceFolderCapability = false; +let rootUri = ''; connection.onInitialize(async (params: InitializeParams) => { const capabilities = params.capabilities; @@ -87,6 +88,11 @@ connection.onInitialize(async (params: InitializeParams) => { supported: true, }, }; + } else { + process.stderr.write("No hasWorkspaceFolderCapability in onInitialize().\n"); + if (params.rootUri!=null) { + rootUri = params.rootUri; + } } await getPerlAssetsPath(); // Ensures assets are unpacked. Should this be in onInitialized? return result; @@ -183,15 +189,30 @@ async function dispatchForMods(textDocument: TextDocument) { } async function getWorkspaceFoldersSafe(): Promise<WorkspaceFolder[]> { - try { - const workspaceFolders = await connection.workspace.getWorkspaceFolders(); - if (!workspaceFolders) { + process.stderr.write("Now in getWorkspaceFoldersSafe().\n"); + if (hasWorkspaceFolderCapability) { + process.stderr.write("getWorkspaceFoldersSafe() has hasWorkspaceFolderCapability.\n"); + try { + const workspaceFolders = await connection.workspace.getWorkspaceFolders(); + if (!workspaceFolders) { + return []; + } else { + return workspaceFolders; + } + } catch (error) { return []; + } + } else { + process.stderr.write("No hasWorkspaceFolderCapability in getWorkspaceFoldersSafe() .\n"); + if (rootUri!=null) { + const dummyFolder: WorkspaceFolder = { + uri: rootUri, + name: rootUri, + } + return [dummyFolder]; } else { - return workspaceFolders; + return []; } - } catch (error) { - return []; } } |