Working hierarchy

This commit is contained in:
Dag Evensberget 2019-11-30 08:52:39 +10:00
parent 45ec5f4ade
commit 2fb1535ec8

View File

@ -8,7 +8,7 @@ export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push( context.subscriptions.push(
vscode.languages.registerDocumentSymbolProvider( vscode.languages.registerDocumentSymbolProvider(
{language: "swmf-config"}, {scheme: "file", language: "swmf-config"},
new SwmfConfigDocumentSymbolProvider() new SwmfConfigDocumentSymbolProvider()
) )
); );
@ -18,45 +18,73 @@ class SwmfConfigDocumentSymbolProvider implements vscode.DocumentSymbolProvider
public provideDocumentSymbols( public provideDocumentSymbols(
document: vscode.TextDocument, document: vscode.TextDocument,
token: vscode.CancellationToken): Thenable<vscode.DocumentSymbol[]> token: vscode.CancellationToken): Promise<vscode.DocumentSymbol[]>
{ {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) =>
var symbols = []; {
let symbols: vscode.DocumentSymbol[] = [];
let nodes = [symbols]
let inside_marker = false
let inside_run = false
let inside_cmd = false
for (var i = 0; i < document.lineCount; i++) { for (var i = 0; i < document.lineCount; i++) {
var line = document.lineAt(i); var line = document.lineAt(i);
var marker
if (line.text.startsWith("#BEGIN_COMP")) { if (line.text.startsWith("#BEGIN_COMP")) {
let marker_symbol = { let marker_symbol = new vscode.DocumentSymbol(
name: line.text.substr(1,13), line.text.substr(1,13),
kind: vscode.SymbolKind.Namespace, 'Marker',
location: new vscode.Location(document.uri, line.range) vscode.SymbolKind.Class,
line.range, line.range)
nodes[nodes.length-1].push(marker_symbol)
if (!inside_marker) {
nodes.push(marker_symbol.children)
inside_marker = true
} }
marker = marker_symbol // marker_symbol.children.push(_boot)
}
else if (line.text.startsWith("#END_COMP")) {
// TODO check if nodes has length 1 before popping.
if (inside_marker) {
nodes.pop()
inside_marker = false
}
}
else if (line.text.startsWith("#RUN") || line.text.startsWith("#END")) {
let run_symbol = new vscode.DocumentSymbol(
line.text.substr(1,4),
'Session',
vscode.SymbolKind.Subroutine,
line.range, line.range)
if (inside_run) {
nodes.pop()
}
nodes[nodes.length-1].push(run_symbol)
nodes.push(run_symbol.children)
inside_run = true
} }
else if (line.text.startsWith("#")) { else if (line.text.startsWith("#")) {
let boo = line.text.substr(1) let marker_symbol = new vscode.DocumentSymbol(
line.text.substr(1,13).toLowerCase(),
'Command',
vscode.SymbolKind.Constructor,
line.range, line.range)
symbols.push({
name: boo, nodes[nodes.length-1].push(marker_symbol)
kind: vscode.SymbolKind.Module, // nodes.push(marker_symbol.children)
location: new vscode.Location(document.uri, line.range) // marker_symbol.children.push(_boot)
}) inside_cmd = true
}
else {
let boo = line.text
var regex = /^[1-9]\d{0,2}$/g
regex.test("2")
symbols.push({
name: boo,
kind: vscode.SymbolKind.Variable,
location: new vscode.Location(document.uri, line.range)
})
} }
} }
// Need this otherwise the outline view just says
// "Loading document symbols for <file>..." forever.
resolve(symbols); resolve(symbols);
}); });
} }