diff --git a/extensions/configuration-editing/src/extension.ts b/extensions/configuration-editing/src/extension.ts index e338cd3d42a..a264c339051 100644 --- a/extensions/configuration-editing/src/extension.ts +++ b/extensions/configuration-editing/src/extension.ts @@ -7,12 +7,27 @@ import * as vscode from 'vscode'; import { getLocation } from 'jsonc-parser'; +import * as path from 'path'; + +const decoration = vscode.window.createTextEditorDecorationType({ + color: '#b1b1b1', + isWholeLine: true +}); export function activate(context) { //keybindings.json command-suggestions context.subscriptions.push(registerKeybindingsCompletions()); + // launch.json decorations + context.subscriptions.push(vscode.window.onDidChangeActiveTextEditor(editor => updateLaunchJsonDecorations(editor), null, context.subscriptions)); + context.subscriptions.push(vscode.workspace.onDidChangeTextDocument(event => { + if (vscode.window.activeTextEditor && event.document === vscode.window.activeTextEditor.document) { + console.log('hello there'); + updateLaunchJsonDecorations(vscode.window.activeTextEditor); + } + }, null, context.subscriptions)); + updateLaunchJsonDecorations(vscode.window.activeTextEditor); } function registerKeybindingsCompletions(): vscode.Disposable { @@ -31,6 +46,22 @@ function registerKeybindingsCompletions(): vscode.Disposable { }); } +function updateLaunchJsonDecorations(editor: vscode.TextEditor) { + if (!editor || path.basename(editor.document.fileName) !== 'launch.json') { + return; + } + + const ranges = []; + for (let i = 0; i < editor.document.lineCount; i++) { + const line = editor.document.lineAt(i); + if (line.text.indexOf('\"version\"') >= 0 || line.text.indexOf('\"type\"') >= 0 || line.text.indexOf('\"request\"') >= 0) { + ranges.push(new vscode.Range(line.range.start, line.range.start)); + } + } + + editor.setDecorations(decoration, ranges); +} + function newCompletionItem(text: string, range: vscode.Range, documentation?: string) { const item = new vscode.CompletionItem(JSON.stringify(text)); item.kind = vscode.CompletionItemKind.Value;