Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add launch/task variable completions to workspace file #165842

Merged
merged 1 commit into from Nov 8, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions extensions/configuration-editing/src/configurationEditingMain.ts
Expand Up @@ -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());
}
Expand All @@ -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);
Expand Down Expand Up @@ -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[];
}
Expand Down