Skip to content
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

Rename workspace/getReferenceDocument to workspace/textDocumentContent #1050

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
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
16 changes: 8 additions & 8 deletions src/sourcekit-lsp/LanguageClientManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import { DiagnosticsManager } from "../DiagnosticsManager";
import { LSPLogger, LSPOutputChannel } from "./LSPOutputChannel";
import { SwiftOutputChannel } from "../ui/SwiftOutputChannel";
import { promptForDiagnostics } from "../commands/captureDiagnostics";
import { activateGetReferenceDocument } from "./getReferenceDocument";
import { activateTextDocumentContent } from "./textDocumentContent";

interface SourceKitLogMessageParams extends langclient.LogMessageParams {
logName?: string;
Expand Down Expand Up @@ -113,7 +113,7 @@ export class LanguageClientManager {
private cancellationToken?: vscode.CancellationTokenSource;
private legacyInlayHints?: vscode.Disposable;
private peekDocuments?: vscode.Disposable;
private getReferenceDocument?: vscode.Disposable;
private textDocumentContent?: vscode.Disposable;
private restartedPromise?: Promise<void>;
private currentWorkspaceFolder?: vscode.Uri;
private waitingOnRestartCount: number;
Expand Down Expand Up @@ -251,7 +251,7 @@ export class LanguageClientManager {
this.cancellationToken?.dispose();
this.legacyInlayHints?.dispose();
this.peekDocuments?.dispose();
this.getReferenceDocument?.dispose();
this.textDocumentContent?.dispose();
this.subscriptions.forEach(item => item.dispose());
this.languageClient?.stop();
this.namedOutputChannels.forEach(channel => channel.dispose());
Expand Down Expand Up @@ -402,8 +402,8 @@ export class LanguageClientManager {
this.legacyInlayHints = undefined;
this.peekDocuments?.dispose();
this.peekDocuments = undefined;
this.getReferenceDocument?.dispose();
this.getReferenceDocument = undefined;
this.textDocumentContent?.dispose();
this.textDocumentContent = undefined;
if (client) {
this.cancellationToken?.cancel();
this.cancellationToken?.dispose();
Expand Down Expand Up @@ -596,7 +596,7 @@ export class LanguageClientManager {
private initializationOptions(): 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:`
"workspace/textDocumentContent": true, // the client can handle URIs with scheme `sourcekit-lsp:`
"textDocument/codeLens": {
supportedCommands: {
"swift.run": "swift.run",
Expand Down Expand Up @@ -659,8 +659,8 @@ export class LanguageClientManager {
}

this.peekDocuments = activatePeekDocuments(client);
this.getReferenceDocument = activateGetReferenceDocument(client);
this.workspaceContext.subscriptions.push(this.getReferenceDocument);
this.textDocumentContent = activateTextDocumentContent(client);
this.workspaceContext.subscriptions.push(this.textDocumentContent);
})
.catch(reason => {
this.workspaceContext.outputChannel.log(`${reason}`);
Expand Down
16 changes: 8 additions & 8 deletions src/sourcekit-lsp/lspExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,29 +57,29 @@ export const PeekDocumentsRequest = new langclient.RequestType<
>("workspace/peekDocuments");

// Get Reference Document
export interface GetReferenceDocumentParams {
export interface TextDocumentContentParams {
/**
* The `DocumentUri` of the custom scheme url for which content is required
*/
uri: langclient.DocumentUri;
}

/**
* Response containing `content` of `GetReferenceDocumentRequest`
* Response containing `content` of `TextDocumentContentRequest`
*/
export interface GetReferenceDocumentResult {
content: string;
export interface TextDocumentContentResult {
text: string;
}

/**
* Request from the client to the server asking for contents of a URI having a custom scheme
* For example: "sourcekit-lsp:"
*/
export const GetReferenceDocumentRequest = new langclient.RequestType<
GetReferenceDocumentParams,
GetReferenceDocumentResult,
export const TextDocumentContentRequest = new langclient.RequestType<
TextDocumentContentParams,
TextDocumentContentResult,
unknown
>("workspace/getReferenceDocument");
>("workspace/textDocumentContent");

// Inlay Hints (pre Swift 5.6)
export interface LegacyInlayHintsParams {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@

import * as vscode from "vscode";
import * as langclient from "vscode-languageclient/node";
import { GetReferenceDocumentParams, GetReferenceDocumentRequest } from "./lspExtensions";
import { TextDocumentContentParams, TextDocumentContentRequest } from "./lspExtensions";

export function activateGetReferenceDocument(client: langclient.LanguageClient): vscode.Disposable {
const getReferenceDocument = vscode.workspace.registerTextDocumentContentProvider(
export function activateTextDocumentContent(client: langclient.LanguageClient): vscode.Disposable {
const textDocumentContent = vscode.workspace.registerTextDocumentContentProvider(
"sourcekit-lsp",
{
provideTextDocumentContent: async (uri, token) => {
const params: GetReferenceDocumentParams = {
const params: TextDocumentContentParams = {
uri: client.code2ProtocolConverter.asUri(uri),
};

const result = await client.sendRequest(GetReferenceDocumentRequest, params, token);
const result = await client.sendRequest(TextDocumentContentRequest, params, token);

if (result) {
return result.content;
return result.text;
} else {
return "Unable to retrieve reference document";
}
},
}
);

return getReferenceDocument;
return textDocumentContent;
}