Skip to content

Commit 6aa5ca4

Browse files
authored
Add launch/task variable completions to workspace file (microsoft#165842)
Fix microsoft#164728
1 parent cee2f8d commit 6aa5ca4

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

extensions/configuration-editing/src/configurationEditingMain.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export function activate(context: vscode.ExtensionContext): void {
2121
// task.json variable suggestions
2222
context.subscriptions.push(registerVariableCompletions('**/tasks.json'));
2323

24+
// Workspace file launch/tasks variable completions
25+
context.subscriptions.push(registerVariableCompletions('**/*.code-workspace'));
26+
2427
// keybindings.json/package.json context key suggestions
2528
context.subscriptions.push(registerContextKeyCompletions());
2629
}
@@ -38,6 +41,10 @@ function registerVariableCompletions(pattern: string): vscode.Disposable {
3841
provideCompletionItems(document, position, _token) {
3942
const location = getLocation(document.getText(), document.offsetAt(position));
4043
if (isCompletingInsidePropertyStringValue(document, location, position)) {
44+
if (document.fileName.endsWith('.code-workspace') && !isLocationInsideTopLevelProperty(location, ['launch', 'tasks'])) {
45+
return [];
46+
}
47+
4148
let range = document.getWordRangeAtPosition(position, /\$\{[^"\}]*\}?/);
4249
if (!range || range.start.isEqual(position) || range.end.isEqual(position) && document.getText(range).endsWith('}')) {
4350
range = new vscode.Range(position, position);
@@ -84,6 +91,10 @@ function isCompletingInsidePropertyStringValue(document: vscode.TextDocument, lo
8491
return false;
8592
}
8693

94+
function isLocationInsideTopLevelProperty(location: Location, values: string[]) {
95+
return values.includes(location.path[0] as string);
96+
}
97+
8798
interface IExtensionsContent {
8899
recommendations: string[];
89100
}

0 commit comments

Comments
 (0)