Skip to content

Commit cc68315

Browse files
committed
Log message when overriding client's document selector
1 parent dadd73f commit cc68315

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

client-node-tests/src/integration.test.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,16 @@ suite ('Client Features', () => {
140140

141141
test('Document Selector - Client and server', () => {
142142
const client = createClient(documentSelector);
143+
const capabilitySelector = { documentSelector: [{ scheme: 'file', language: 'test' }] } as any;
144+
145+
client.info = (message, data) => {
146+
assert.strictEqual(message, 'Overriding client document selector');
147+
assert.deepStrictEqual(data, capabilitySelector);
148+
};
143149

144150
const feature = client.getFeature(lsclient.FoldingRangeRequest.method) as unknown as FoldingRangeTestFeature;
145151
{
146-
const [, options] = feature.getRegistration(documentSelector, { documentSelector: [{ scheme: 'file', language: 'test' }] });
152+
const [, options] = feature.getRegistration(documentSelector, capabilitySelector);
147153
isDefined(options);
148154
const filter = options.documentSelector[0] as lsclient.TextDocumentFilter;
149155
assert.strictEqual(filter.scheme, 'file');
@@ -153,7 +159,7 @@ suite ('Client Features', () => {
153159
{
154160
// Note that the old registration spec has no support for providing a document selector.
155161
// So ensure that even if we pass one in we will not honor it.
156-
const options = feature.getRegistrationOptions(documentSelector, { documentSelector: [{ scheme: 'file', language: 'test' }] } as any);
162+
const options = feature.getRegistrationOptions(documentSelector, capabilitySelector);
157163
isDefined(options);
158164
const filter = options.documentSelector[0] as lsclient.TextDocumentFilter;
159165
assert.strictEqual(filter.scheme, 'lsptests');

client/src/common/features.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,11 @@ export abstract class TextDocumentLanguageFeature<PO, RO extends TextDocumentReg
552552
if (!documentSelector || !capability) {
553553
return undefined;
554554
}
555+
556+
if (documentSelector && capability) {
557+
this._client.info('Overriding client document selector', capability);
558+
}
559+
555560
return (Is.boolean(capability) && capability === true ? { documentSelector } : Object.assign({}, capability, { documentSelector })) as RO & { documentSelector: DocumentSelector };
556561
}
557562

@@ -756,4 +761,4 @@ export interface FeatureClient<M, CO = object> {
756761
getFeature(request: typeof NotebookDocumentSyncRegistrationType.method): DynamicFeature<NotebookDocumentSyncRegistrationOptions> & NotebookDocumentProviderShape;
757762
getFeature(request: typeof InlineCompletionRequest.method): (DynamicFeature<InlineCompletionRegistrationOptions> & TextDocumentProviderFeature<InlineCompletionItemProvider>) | undefined;
758763
getFeature(request: typeof ExecuteCommandRequest.method): DynamicFeature<ExecuteCommandOptions>;
759-
}
764+
}

0 commit comments

Comments
 (0)