refine completion provider for context keys, https://github.com/microsoft/vscode/issues/9303

This commit is contained in:
Johannes Rieken 2021-02-17 15:21:18 +01:00
parent 29f80fb60f
commit 79f90304be

View file

@ -147,17 +147,22 @@ function registerContextKeyCompletions(): vscode.Disposable {
{
async provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken) {
const replacing = document.getWordRangeAtPosition(position, /[\w.-\d]/);
const inserting = replacing?.with(undefined, position);
if (!replacing || !inserting) {
const location = getLocation(document.getText(), document.offsetAt(position));
if (location.isAtPropertyKey) {
return;
}
const location = getLocation(document.getText(), document.offsetAt(position));
if (!location.matches(['*', 'when']) && !location.matches(['contributes', 'menus', '*', '*', 'when'])) {
return;
}
const replacing = document.getWordRangeAtPosition(position, /[^"\s]+/);
if (!replacing) {
return;
}
const inserting = replacing.with(undefined, position);
const data = await vscode.commands.executeCommand<ContextKeyInfo[]>('getContextKeyInfo');
if (token.isCancellationRequested || !data) {
return;