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

Add TextDocumentContentResult #1538

Merged
merged 1 commit into from
Aug 9, 2024
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
2 changes: 1 addition & 1 deletion client-node-tests/src/servers/testServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ connection.languages.inlineCompletion.on((_params) => {
});

connection.workspace.textDocumentContent.on((_params) => {
return 'Some test content';
return { text: 'Some test content' };
});

connection.onRequest(
Expand Down
2 changes: 1 addition & 1 deletion client/src/common/textDocumentContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export class TextDocumentContentFeature extends WorkspaceFeature<TextDocumentCon
if (token.isCancellationRequested) {
return null;
}
return result;
return result.text;
}, (error) => {
return client.handleFailedRequest(TextDocumentContentRequest.type, token, error, null);
});
Expand Down
20 changes: 18 additions & 2 deletions protocol/src/common/protocol.textDocumentContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@ export interface TextDocumentContentParams {
uri: DocumentUri;
}

/**
* Result of the `workspace/textDocumentContent` request.
*
* @since 3.18.0
* @proposed
*/
export interface TextDocumentContentResult {
/**
* The text content of the text document. Please note, that the content of
* any subsequent open notifications for the text document might differ
* from the returned content due to whitespace and line ending
* normalizations done on the client
*/
text: string;
}

/**
* The `workspace/textDocumentContent` request is sent from the client to the
* server to request the content of a text document.
Expand All @@ -66,8 +82,8 @@ export interface TextDocumentContentParams {
export namespace TextDocumentContentRequest {
export const method: 'workspace/textDocumentContent' = 'workspace/textDocumentContent';
export const messageDirection: MessageDirection = MessageDirection.clientToServer;
export const type = new ProtocolRequestType<TextDocumentContentParams, string, void, void, TextDocumentContentRegistrationOptions>(method);
export type HandlerSignature = RequestHandler<TextDocumentContentParams, string, void>;
export const type = new ProtocolRequestType<TextDocumentContentParams, TextDocumentContentResult, void, void, TextDocumentContentRegistrationOptions>(method);
export type HandlerSignature = RequestHandler<TextDocumentContentParams, TextDocumentContentResult, void>;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions protocol/src/common/protocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ import {
} from './protocol.inlineCompletion';

import {
TextDocumentContentClientCapabilities, TextDocumentContentOptions, TextDocumentContentRegistrationOptions, TextDocumentContentParams,
TextDocumentContentClientCapabilities, TextDocumentContentOptions, TextDocumentContentRegistrationOptions, TextDocumentContentParams, TextDocumentContentResult,
TextDocumentContentRequest, TextDocumentContentRefreshParams, TextDocumentContentRefreshRequest
} from './protocol.textDocumentContent';

Expand Down Expand Up @@ -4310,8 +4310,8 @@ export {
// Inline Completions
InlineCompletionClientCapabilities, InlineCompletionOptions, InlineCompletionParams, InlineCompletionRegistrationOptions, InlineCompletionRequest,
// Text Document Content
TextDocumentContentClientCapabilities, TextDocumentContentOptions, TextDocumentContentRegistrationOptions, TextDocumentContentParams, TextDocumentContentRequest,
TextDocumentContentRefreshParams, TextDocumentContentRefreshRequest
TextDocumentContentClientCapabilities, TextDocumentContentOptions, TextDocumentContentRegistrationOptions, TextDocumentContentParams, TextDocumentContentResult,
TextDocumentContentRequest, TextDocumentContentRefreshParams, TextDocumentContentRefreshRequest
};

// To be backwards compatible
Expand Down
6 changes: 3 additions & 3 deletions server/src/common/textDocumentContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
* ------------------------------------------------------------------------------------------ */

import { TextDocumentContentRefreshRequest, TextDocumentContentRequest, type Disposable, type DocumentUri, type RequestHandler, type TextDocumentContentParams } from 'vscode-languageserver-protocol';
import { TextDocumentContentRefreshRequest, TextDocumentContentRequest, type Disposable, type DocumentUri, type RequestHandler, type TextDocumentContentParams, type TextDocumentContentResult } from 'vscode-languageserver-protocol';

import type { Feature, _RemoteWorkspace } from './server';

Expand All @@ -16,7 +16,7 @@ import type { Feature, _RemoteWorkspace } from './server';
export interface TextDocumentContentFeatureShape {
textDocumentContent: {
refresh(uri: DocumentUri): Promise<void>;
on(handler: RequestHandler<TextDocumentContentParams, string | null, void>): Disposable;
on(handler: RequestHandler<TextDocumentContentParams, TextDocumentContentResult | null, void>): Disposable;
};
}

Expand All @@ -27,7 +27,7 @@ export const TextDocumentContentFeature: Feature<_RemoteWorkspace, TextDocumentC
refresh: (uri: DocumentUri): Promise<void> => {
return this.connection.sendRequest(TextDocumentContentRefreshRequest.type, { uri });
},
on: (handler: RequestHandler<TextDocumentContentParams, string | null, void>): Disposable => {
on: (handler: RequestHandler<TextDocumentContentParams, TextDocumentContentResult | null, void>): Disposable => {
return this.connection.onRequest(TextDocumentContentRequest.type, (params, cancel) => {
return handler(params, cancel);
});
Expand Down
2 changes: 1 addition & 1 deletion testbed/server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ connection.languages.semanticTokens.onRange((params) => {

let counter = 0;
connection.workspace.textDocumentContent.on((_param) => {
return `Text content version ${counter++}`;
return { text: `Text content version ${counter++}` };
});

const refreshNotification: NotificationType<string> = new NotificationType<string>('testbed/refreshContent');
Expand Down