Add launch/task variable completions to workspace file (#165842)

Fix #164728
This commit is contained in:
Rob Lourens 2022-11-08 10:05:55 -08:00 committed by GitHub
parent cee2f8d673
commit 6aa5ca4c28
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -21,6 +21,9 @@ export function activate(context: vscode.ExtensionContext): void {
// task.json variable suggestions
context.subscriptions.push(registerVariableCompletions('**/tasks.json'));
// Workspace file launch/tasks variable completions
context.subscriptions.push(registerVariableCompletions('**/*.code-workspace'));
// keybindings.json/package.json context key suggestions
context.subscriptions.push(registerContextKeyCompletions());
}
@ -38,6 +41,10 @@ function registerVariableCompletions(pattern: string): vscode.Disposable {
provideCompletionItems(document, position, _token) {
const location = getLocation(document.getText(), document.offsetAt(position));
if (isCompletingInsidePropertyStringValue(document, location, position)) {
if (document.fileName.endsWith('.code-workspace') && !isLocationInsideTopLevelProperty(location, ['launch', 'tasks'])) {
return [];
}
let range = document.getWordRangeAtPosition(position, /\$\{[^"\}]*\}?/);
if (!range || range.start.isEqual(position) || range.end.isEqual(position) && document.getText(range).endsWith('}')) {
range = new vscode.Range(position, position);
@ -84,6 +91,10 @@ function isCompletingInsidePropertyStringValue(document: vscode.TextDocument, lo
return false;
}
function isLocationInsideTopLevelProperty(location: Location, values: string[]) {
return values.includes(location.path[0] as string);
}
interface IExtensionsContent {
recommendations: string[];
}