Skip to content

Commit

Permalink
add variable completions for launch and tasks.json
Browse files Browse the repository at this point in the history
fixes #8370
  • Loading branch information
isidorn committed May 9, 2018
1 parent 4729ed8 commit 64520d5
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions extensions/configuration-editing/src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ export function activate(context: vscode.ExtensionContext): void {
//extensions suggestions
context.subscriptions.push(...registerExtensionsCompletions());

// launch.json variable suggestions
context.subscriptions.push(registerVariableCompletions('**/launch.json'));

// task.json variable suggestions
context.subscriptions.push(registerVariableCompletions('**/task.json'));

// launch.json decorations
context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(editor => updateLaunchJsonDecorations(editor), null, context.subscriptions));
context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(event => {
Expand Down Expand Up @@ -108,6 +114,27 @@ function registerSettingsCompletions(): vscode.Disposable {
});
}

function registerVariableCompletions(pattern: string): vscode.Disposable {
return vscode.languages.registerCompletionItemProvider({ language: 'jsonc', pattern }, {
provideCompletionItems(document, position, token) {
const location = getLocation(document.getText(), document.offsetAt(position));
if (!location.isAtPropertyKey && location.previousNode && location.previousNode.type === 'string') {
return [{ label: 'workspaceFolder', detail: localize('workspaceFolder', "The path of the folder opened in VS Code") }, { label: 'workspaceFolderBasename', detail: localize('workspaceFolderBasename', "The name of the folder opened in VS Code without any slashes (/)") },
{ label: 'relativeFile', detail: localize('relativeFile', "The current opened file relative to ${workspaceFolder}") }, { label: 'file', detail: localize('file', "The current opened file") }, { label: 'cwd', detail: localize('cwd', "The task runner's current working directory on startup") },
{ label: 'lineNumber', detail: localize('lineNumber', "The current selected line number in the active file") }, { label: 'selectedText', detail: localize('selectedText', "The current selected text in the active file") },
{ label: 'fileDirname', detail: localize('fileDirname', "The current opened file's dirname") }, { label: 'fileExtname', detail: localize('fileExtname', "The current opened file's extension") }, { label: 'fileBasename', detail: localize('fileBasename', "The current opened file's basename") },
{ label: 'fileBasenameNoExtension', detail: localize('fileBasenameNoExtension', "The current opened file's basename with no file extension") }].map(variable => ({
label: '${' + variable.label + '}',
range: new vscode.Range(position, position),
detail: variable.detail
}));
}

return [];
}
});
}

interface IExtensionsContent {
recommendations: string[];
}
Expand Down

0 comments on commit 64520d5

Please sign in to comment.