mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
parent
0b34f40d49
commit
19a21211b9
|
@ -145,4 +145,39 @@ function updateLaunchJsonDecorations(editor: vscode.TextEditor | undefined): voi
|
|||
});
|
||||
|
||||
editor.setDecorations(decoration, ranges);
|
||||
}
|
||||
}
|
||||
|
||||
vscode.languages.registerDocumentSymbolProvider({ pattern: '**/launch.json', language: 'json' }, {
|
||||
provideDocumentSymbols(document: vscode.TextDocument, token: vscode.CancellationToken): vscode.ProviderResult<vscode.SymbolInformation[]> {
|
||||
const result: vscode.SymbolInformation[] = [];
|
||||
let name: string = '';
|
||||
let lastProperty = '';
|
||||
let startOffset = 0;
|
||||
let depthInObjects = 0;
|
||||
|
||||
visit(document.getText(), {
|
||||
onObjectProperty: (property, offset, length) => {
|
||||
lastProperty = property;
|
||||
},
|
||||
onLiteralValue: (value: any, offset: number, length: number) => {
|
||||
if (lastProperty === 'name') {
|
||||
name = value;
|
||||
}
|
||||
},
|
||||
onObjectBegin: (offset: number, length: number) => {
|
||||
depthInObjects++;
|
||||
if (depthInObjects === 2) {
|
||||
startOffset = offset;
|
||||
}
|
||||
},
|
||||
onObjectEnd: (offset: number, length: number) => {
|
||||
if (name && depthInObjects === 2) {
|
||||
result.push(new vscode.SymbolInformation(name, vscode.SymbolKind.Object, new vscode.Range(document.positionAt(startOffset), document.positionAt(offset))));
|
||||
}
|
||||
depthInObjects--;
|
||||
},
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue