Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 28 additions & 3 deletions src/sourcekit-lsp/LanguageClientConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -41,6 +39,26 @@ 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`
peekLocation: true, // allow SourceKit-LSP to send `Location` instead of `DocumentUri` for the locations to peek.
},
"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.
Expand All @@ -57,7 +75,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
Expand Down
6 changes: 3 additions & 3 deletions src/sourcekit-lsp/extensions/PeekDocumentsRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// We use namespaces to store request information just like vscode-languageclient
/* eslint-disable @typescript-eslint/no-namespace */

import { DocumentUri, Position, MessageDirection, RequestType } from "vscode-languageclient";
import { DocumentUri, Position, Location, MessageDirection, RequestType } from "vscode-languageclient";

/** Parameters used to make a {@link PeekDocumentsRequest}. */
export interface PeekDocumentsParams {
Expand All @@ -30,9 +30,9 @@ export interface PeekDocumentsParams {
position: Position;

/**
* An array `DocumentUri` of the documents to appear inside the "peeked" editor
* An array `DocumentUri` or `Location` of the documents to appear inside the "peeked" editor
*/
locations: DocumentUri[];
locations: DocumentUri[] | Location[];
}

/** Response to indicate the `success` of the {@link PeekDocumentsRequest}. */
Expand Down
15 changes: 10 additions & 5 deletions src/sourcekit-lsp/peekDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,16 @@ export function activatePeekDocuments(client: langclient.LanguageClient): vscode
);

const peekLocations = params.locations.map(
location =>
new vscode.Location(
client.protocol2CodeConverter.asUri(location),
new vscode.Position(0, 0)
)
location => {
if (typeof location === "string") { // DocumentUri is a typedef of `string`, so effectively we are checking for DocumentUri here
return new vscode.Location(
client.protocol2CodeConverter.asUri(location),
new vscode.Position(0, 0)
)
} else {
return client.protocol2CodeConverter.asLocation(location)
}
}
);

await openPeekedEditorIn(peekURI, peekPosition, peekLocations);
Expand Down
Loading