diff --git a/src/lsp/api.ts b/src/lsp/api.ts index 66fbb780d..6f9a4fc97 100644 --- a/src/lsp/api.ts +++ b/src/lsp/api.ts @@ -13,6 +13,15 @@ export const clientIsAlive = (client: defs.LspClient) => { return [defs.LspStatus.Starting, defs.LspStatus.Running].includes(client.status); }; +/** + * Checks if a given path is the root of the filesystem in a platform agnostic manner (this should + * work identically on POSIX and Windows) + */ +const isRoot = (dir: string) => { + const normalized = path.normalize(dir); + return path.dirname(normalized) === normalized; +}; + /** * Find the closest, active clojure-lsp client to a given URI. This works by traversing up the path component of the * provided URI until a client at the same level is found. This works because clients in the LspClientStore use their @@ -23,13 +32,13 @@ export const clientIsAlive = (client: defs.LspClient) => { * must be explicitly referenced. */ export const getActiveClientForUri = (clients: defs.LspClientStore, uri: vscode.Uri) => { - let current = uri.path; - while (current !== '/') { + let current = uri.fsPath; + while (!isRoot(current)) { const client = clients.get(current); if (client && clientIsAlive(client)) { return client; } - current = path.resolve(current, '..'); + current = path.join(current, '..'); } const fallback_client = clients.get(FALLBACK_CLIENT_ID); if (fallback_client && clientIsAlive(fallback_client)) { diff --git a/src/lsp/commands/vscode-commands.ts b/src/lsp/commands/vscode-commands.ts index c069d616a..1442e2785 100644 --- a/src/lsp/commands/vscode-commands.ts +++ b/src/lsp/commands/vscode-commands.ts @@ -11,7 +11,7 @@ export const filterOutRootsWithClients = ( clients: defs.LspClientStore ) => { return uris.filter((root) => { - const client = clients.get(root.uri.path); + const client = clients.get(root.uri.fsPath); return !client || !api.clientIsAlive(client); }); }; diff --git a/src/lsp/provider.ts b/src/lsp/provider.ts index 7043d30eb..8d72a3ab6 100644 --- a/src/lsp/provider.ts +++ b/src/lsp/provider.ts @@ -101,7 +101,7 @@ export const createClientProvider = (params: CreateClientProviderParams) => { }; let lsp_server_path: Promise | undefined = undefined; - const provisionClient = async (uri: vscode.Uri, id = uri.path) => { + const provisionClient = async (uri: vscode.Uri, id = uri.fsPath) => { if (lsp_server_path === undefined) { lsp_server_path = lsp_client.ensureLSPServer(params.context).catch((err) => { console.error('Failed to download lsp server', err);