Skip to content
Open
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
10 changes: 8 additions & 2 deletions client-node-tests/src/integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,10 +140,16 @@ suite ('Client Features', () => {

test('Document Selector - Client and server', () => {
const client = createClient(documentSelector);
const capabilitySelector = { documentSelector: [{ scheme: 'file', language: 'test' }] } as any;

client.info = (message, data) => {
assert.strictEqual(message, `Overriding client document selector for ${lsclient.FoldingRangeRequest.method}`);
assert.deepStrictEqual(data, capabilitySelector);
};

const feature = client.getFeature(lsclient.FoldingRangeRequest.method) as unknown as FoldingRangeTestFeature;
{
const [, options] = feature.getRegistration(documentSelector, { documentSelector: [{ scheme: 'file', language: 'test' }] });
const [, options] = feature.getRegistration(documentSelector, capabilitySelector);
isDefined(options);
const filter = options.documentSelector[0] as lsclient.TextDocumentFilter;
assert.strictEqual(filter.scheme, 'file');
Expand All @@ -153,7 +159,7 @@ suite ('Client Features', () => {
{
// Note that the old registration spec has no support for providing a document selector.
// So ensure that even if we pass one in we will not honor it.
const options = feature.getRegistrationOptions(documentSelector, { documentSelector: [{ scheme: 'file', language: 'test' }] } as any);
const options = feature.getRegistrationOptions(documentSelector, capabilitySelector);
isDefined(options);
const filter = options.documentSelector[0] as lsclient.TextDocumentFilter;
assert.strictEqual(filter.scheme, 'lsptests');
Expand Down
8 changes: 7 additions & 1 deletion client/src/common/features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,12 @@ export abstract class TextDocumentLanguageFeature<PO, RO extends TextDocumentReg
if (!documentSelector || !capability) {
return undefined;
}

const capabilitySelector = capability ?? (capability as any).documentSelector;
if (documentSelector && capabilitySelector && JSON.stringify(documentSelector) !== JSON.stringify(capabilitySelector)) {
this._client.info(`Overriding client document selector for ${this._registrationType.method}`, capability);
}

return (Is.boolean(capability) && capability === true ? { documentSelector } : Object.assign({}, capability, { documentSelector })) as RO & { documentSelector: DocumentSelector };
}

Expand Down Expand Up @@ -756,4 +762,4 @@ export interface FeatureClient<M, CO = object> {
getFeature(request: typeof NotebookDocumentSyncRegistrationType.method): DynamicFeature<NotebookDocumentSyncRegistrationOptions> & NotebookDocumentProviderShape;
getFeature(request: typeof InlineCompletionRequest.method): (DynamicFeature<InlineCompletionRegistrationOptions> & TextDocumentProviderFeature<InlineCompletionItemProvider>) | undefined;
getFeature(request: typeof ExecuteCommandRequest.method): DynamicFeature<ExecuteCommandOptions>;
}
}