In my quest to make the code outline feature work for a custom language, I have made progress in generating symbols and displaying functions in the outline view. However, my next challenge is to display variables under the respective function in the outline view. While my symbols seem to have the correct containerName
value, I am currently stuck with a flat outline view.
The following is the current code snippet from extension.ts
:
'use strict';
import * as vscode from 'vscode';
export function activate(context: vscode.ExtensionContext) {
context.subscriptions.push(vscode.languages.registerDocumentSymbolProvider(
{language: "as"}, new FooDocumentSymbolProvider()
));
}
class FooDocumentSymbolProvider implements vscode.DocumentSymbolProvider {
public provideDocumentSymbols(document: vscode.TextDocument, token: vscode.CancellationToken): Thenable<vscode.SymbolInformation[]> {
return new Promise((resolve, reject) => {
var symbols = [];
var sym = "";
for (var i = 0; i < document.lineCount; i++) {
var line = document.lineAt(i);
if (line.text.startsWith(".PROGRAM")) {
var sym = "";
symbols.push({
name: line.text.substr(9).trimRight(),
kind: vscode.SymbolKind.Function,
containerName: sym,
location: new vscode.Location(document.uri, line.range)
});
sym = line.text.substr(9).trimRight();
}
if (line.text.includes("CALL") && !(line.text.startsWith(".*"))) {
symbols.push({
name: line.text.substr(0).trimLeft(),
kind: vscode.SymbolKind.Module,
containerName: sym,
location: new vscode.Location(document.uri, line.range)
});
}
}
resolve(symbols);
});
}
}
UPDATE #2:
public provideDocumentSymbols(document: vscode.TextDocument, token: vscode.CancellationToken): Thenable<vscode.DocumentSymbol[]> {
return new Promise((resolve, reject) => {
var symbols = [];
var sym = "";
for (var i = 0; i < document.lineCount; i++) {
var line = document.lineAt(i);
if (line.text.startsWith(".PROGRAM")) {
var sym = "";
var childrens = [];
symbols.push({
name: line.text.substr(9).trimRight(),
kind: vscode.SymbolKind.Function,
children: [],
range: line.range,
detail: "",
selectionRange: line.range
});
sym = line.text.substr(9).trimRight();
}
if (line.text.includes("CALL") && !(line.text.startsWith(".*"))) {
symbols.push({
name: line.text.substr(0).trimLeft(),
kind: vscode.SymbolKind.Module,
children: [],
range: line.range,
detail: "",
selectionRange: line.range
});
}
}
resolve(symbols);
});
}