Skip to content

Commit a3c53e1

Browse files
authored
make sure vscode.executeDocumentHighlights return an array (#200113)
re #200056
1 parent 6d33f51 commit a3c53e1

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/vs/editor/contrib/wordHighlighter/browser/wordHighlighter.ts

+3-2
Original file line numberDiff line numberDiff line change
@@ -253,9 +253,10 @@ function computeOccurencesMultiModel(registry: LanguageFeatureRegistry<MultiDocu
253253
return new TextualOccurenceRequest(model, selection, word, wordSeparators, otherModels);
254254
}
255255

256-
registerModelAndPositionCommand('_executeDocumentHighlights', (accessor, model, position) => {
256+
registerModelAndPositionCommand('_executeDocumentHighlights', async (accessor, model, position) => {
257257
const languageFeaturesService = accessor.get(ILanguageFeaturesService);
258-
return getOccurrencesAtPosition(languageFeaturesService.documentHighlightProvider, model, position, CancellationToken.None);
258+
const map = await getOccurrencesAtPosition(languageFeaturesService.documentHighlightProvider, model, position, CancellationToken.None);
259+
return map?.get(model.uri);
259260
});
260261

261262
class WordHighlighter {

src/vs/workbench/api/test/browser/extHostApiCommands.test.ts

+27
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,33 @@ suite('ExtHostLanguageFeatureCommands', function () {
681681
});
682682
});
683683

684+
// --- document highlights
685+
686+
test('"vscode.executeDocumentHighlights" API has stopped returning DocumentHighlight[]#200056', async function () {
687+
688+
689+
disposables.push(extHost.registerDocumentHighlightProvider(nullExtensionDescription, defaultSelector, <vscode.DocumentHighlightProvider>{
690+
provideDocumentHighlights() {
691+
return [
692+
new types.DocumentHighlight(new types.Range(0, 17, 0, 25), types.DocumentHighlightKind.Read)
693+
];
694+
}
695+
}));
696+
697+
await rpcProtocol.sync();
698+
699+
return commands.executeCommand<vscode.DocumentHighlight[]>('vscode.executeDocumentHighlights', model.uri, new types.Position(0, 0)).then(values => {
700+
assert.ok(Array.isArray(values));
701+
assert.strictEqual(values.length, 1);
702+
const [first] = values;
703+
assert.strictEqual(first.range.start.line, 0);
704+
assert.strictEqual(first.range.start.character, 17);
705+
assert.strictEqual(first.range.end.line, 0);
706+
assert.strictEqual(first.range.end.character, 25);
707+
});
708+
709+
});
710+
684711
// --- outline
685712

686713
test('Outline, back and forth', function () {

0 commit comments

Comments
 (0)