Skip to content

Commit

Permalink
make sure vscode.executeDocumentHighlights return an array (#200113)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken authored Dec 6, 2023
1 parent 6d33f51 commit a3c53e1
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,10 @@ function computeOccurencesMultiModel(registry: LanguageFeatureRegistry<MultiDocu
return new TextualOccurenceRequest(model, selection, word, wordSeparators, otherModels);
}

registerModelAndPositionCommand('_executeDocumentHighlights', (accessor, model, position) => {
registerModelAndPositionCommand('_executeDocumentHighlights', async (accessor, model, position) => {
const languageFeaturesService = accessor.get(ILanguageFeaturesService);
return getOccurrencesAtPosition(languageFeaturesService.documentHighlightProvider, model, position, CancellationToken.None);
const map = await getOccurrencesAtPosition(languageFeaturesService.documentHighlightProvider, model, position, CancellationToken.None);
return map?.get(model.uri);
});

class WordHighlighter {
Expand Down
27 changes: 27 additions & 0 deletions src/vs/workbench/api/test/browser/extHostApiCommands.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -681,6 +681,33 @@ suite('ExtHostLanguageFeatureCommands', function () {
});
});

// --- document highlights

test('"vscode.executeDocumentHighlights" API has stopped returning DocumentHighlight[]#200056', async function () {


disposables.push(extHost.registerDocumentHighlightProvider(nullExtensionDescription, defaultSelector, <vscode.DocumentHighlightProvider>{
provideDocumentHighlights() {
return [
new types.DocumentHighlight(new types.Range(0, 17, 0, 25), types.DocumentHighlightKind.Read)
];
}
}));

await rpcProtocol.sync();

return commands.executeCommand<vscode.DocumentHighlight[]>('vscode.executeDocumentHighlights', model.uri, new types.Position(0, 0)).then(values => {
assert.ok(Array.isArray(values));
assert.strictEqual(values.length, 1);
const [first] = values;
assert.strictEqual(first.range.start.line, 0);
assert.strictEqual(first.range.start.character, 17);
assert.strictEqual(first.range.end.line, 0);
assert.strictEqual(first.range.end.character, 25);
});

});

// --- outline

test('Outline, back and forth', function () {
Expand Down

0 comments on commit a3c53e1

Please sign in to comment.