提交 34ee2970 编写于 作者: I isidor

launch.json decorations: use json parser for better parsing

上级 1985573f
...@@ -6,12 +6,11 @@ ...@@ -6,12 +6,11 @@
'use strict'; 'use strict';
import * as vscode from 'vscode'; import * as vscode from 'vscode';
import { getLocation } from 'jsonc-parser'; import { getLocation, visit } from 'jsonc-parser';
import * as path from 'path'; import * as path from 'path';
const decoration = vscode.window.createTextEditorDecorationType({ const decoration = vscode.window.createTextEditorDecorationType({
color: '#b1b1b1', color: '#b1b1b1'
isWholeLine: true
}); });
export function activate(context) { export function activate(context) {
...@@ -51,12 +50,20 @@ function updateLaunchJsonDecorations(editor: vscode.TextEditor) { ...@@ -51,12 +50,20 @@ function updateLaunchJsonDecorations(editor: vscode.TextEditor) {
} }
const ranges = []; const ranges = [];
for (let i = 0; i < editor.document.lineCount; i++) { let addPropertyAndValue = false;
const line = editor.document.lineAt(i); visit(editor.document.getText(), {
if (line.text.indexOf('\"version\"') >= 0 || line.text.indexOf('\"type\"') >= 0 || line.text.indexOf('\"request\"') >= 0) { onObjectProperty: (property, offset, length) => {
ranges.push(new vscode.Range(line.range.start, line.range.start)); addPropertyAndValue = property === 'version' || property === 'type' || property === 'request';
if (addPropertyAndValue) {
ranges.push(new vscode.Range(editor.document.positionAt(offset), editor.document.positionAt(offset + length)));
}
},
onLiteralValue: (value, offset, length) => {
if (addPropertyAndValue) {
ranges.push(new vscode.Range(editor.document.positionAt(offset), editor.document.positionAt(offset + length)));
}
} }
} });
editor.setDecorations(decoration, ranges); editor.setDecorations(decoration, ranges);
} }
...@@ -70,4 +77,4 @@ function newCompletionItem(text: string, range: vscode.Range, documentation?: st ...@@ -70,4 +77,4 @@ function newCompletionItem(text: string, range: vscode.Range, documentation?: st
newText: item.label newText: item.label
}; };
return item; return item;
} }
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册