mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-26 03:29:00 +01:00
Add launch/task variable completions to workspace file (#165842)
Fix #164728
This commit is contained in:
@@ -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[];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user