From 1af4fb86f728bccf4d7acce46e5b3eab7914845c Mon Sep 17 00:00:00 2001 From: Alex Hoppen Date: Mon, 14 Jul 2025 16:45:18 +0200 Subject: [PATCH] When running against SourceKit-LSP 6.3, use a dictionary to communicate experimental client capabilities Companion of https://github.com/swiftlang/sourcekit-lsp/pull/2204 --- .../LanguageClientConfiguration.ts | 30 +++++++++++++++++-- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/sourcekit-lsp/LanguageClientConfiguration.ts b/src/sourcekit-lsp/LanguageClientConfiguration.ts index a4659268b..a083bf01b 100644 --- a/src/sourcekit-lsp/LanguageClientConfiguration.ts +++ b/src/sourcekit-lsp/LanguageClientConfiguration.ts @@ -31,8 +31,6 @@ import { SourceKitLSPErrorHandler } from "./LanguageClientManager"; /* eslint-disable @typescript-eslint/no-explicit-any */ function initializationOptions(swiftVersion: Version): any { let options: any = { - "workspace/peekDocuments": true, // workaround for client capability to handle `PeekDocumentsRequest` - "workspace/getReferenceDocument": true, // the client can handle URIs with scheme `sourcekit-lsp:` "textDocument/codeLens": { supportedCommands: { "swift.run": "swift.run", @@ -41,6 +39,25 @@ function initializationOptions(swiftVersion: Version): any { }, }; + // Swift 6.3 changed the value to enable experimental client capabilities from `true` to `{ "supported": true }` + // (https://github.com/swiftlang/sourcekit-lsp/pull/2204) + if (swiftVersion.isGreaterThanOrEqual(new Version(6, 3, 0))) { + options = { + "workspace/peekDocuments": { + supported: true, // workaround for client capability to handle `PeekDocumentsRequest` + }, + "workspace/getReferenceDocument": { + supported: true, // the client can handle URIs with scheme `sourcekit-lsp:` + }, + }; + } else { + options = { + ...options, + "workspace/peekDocuments": true, // workaround for client capability to handle `PeekDocumentsRequest` + "workspace/getReferenceDocument": true, // the client can handle URIs with scheme `sourcekit-lsp:` + }; + } + // Swift 6.0.0 and later supports background indexing. // In 6.0.0 it is experimental so only "true" enables it. // In 6.1.0 it is no longer experimental, and so "auto" or "true" enables it. @@ -57,7 +74,14 @@ function initializationOptions(swiftVersion: Version): any { }; } - if (swiftVersion.isGreaterThanOrEqual(new Version(6, 1, 0))) { + if (swiftVersion.isGreaterThanOrEqual(new Version(6, 3, 0))) { + options = { + ...options, + "window/didChangeActiveDocument": { + supported: true, // the client can send `window/didChangeActiveDocument` notifications + }, + }; + } else if (swiftVersion.isGreaterThanOrEqual(new Version(6, 1, 0))) { options = { ...options, "window/didChangeActiveDocument": true, // the client can send `window/didChangeActiveDocument` notifications