Skip to content

Allow VS Code to recognise files with "sourcekit-lsp" scheme to provide Semantic Functionality through SourceKitLSP #990

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
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
5 changes: 4 additions & 1 deletion src/WorkspaceContext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,10 @@ export class WorkspaceContext implements vscode.Disposable {
async focusUri(uri?: vscode.Uri) {
this.currentDocument = uri ?? null;
this.updateContextKeysForFile();
if (this.currentDocument?.scheme === "file") {
if (
this.currentDocument?.scheme === "file" ||
this.currentDocument?.scheme === "sourcekit-lsp"
) {
await this.focusPackageUri(this.currentDocument);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/sourcekit-lsp/LanguageClientManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ export class LanguageClientManager {

// document selector used by language client
static appleLangDocumentSelector = [
{ scheme: "sourcekit-lsp", language: "swift" },
{ scheme: "file", language: "swift" },
{ scheme: "untitled", language: "swift" },
{ scheme: "file", language: "objective-c" },
Expand Down
2 changes: 1 addition & 1 deletion src/sourcekit-lsp/getReferenceDocument.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export function activateGetReferenceDocument(client: langclient.LanguageClient):
{
provideTextDocumentContent: async (uri, token) => {
const params: GetReferenceDocumentParams = {
uri: uri.toString(true),
uri: client.code2ProtocolConverter.asUri(uri),
};

const result = await client.sendRequest(GetReferenceDocumentRequest, params, token);
Expand Down
8 changes: 2 additions & 6 deletions src/sourcekit-lsp/peekDocuments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@ export function activatePeekDocuments(client: langclient.LanguageClient): vscode
PeekDocumentsRequest.method,
async (params: PeekDocumentsParams) => {
const locations = params.locations.map(uri => {
const url = new URL(uri);
const location = new vscode.Location(
vscode.Uri.parse(url.href, true),
client.protocol2CodeConverter.asUri(uri),
new vscode.Position(0, 0)
);

Expand All @@ -32,10 +31,7 @@ export function activatePeekDocuments(client: langclient.LanguageClient): vscode

await vscode.commands.executeCommand(
"editor.action.peekLocations",
vscode.Uri.from({
scheme: "file",
path: new URL(params.uri).pathname,
}),
client.protocol2CodeConverter.asUri(params.uri),
new vscode.Position(params.position.line, params.position.character),
locations,
"peek"
Expand Down