|
@@ -7,61 +7,41 @@ import {
|
|
|
Range
|
|
|
} from 'vscode';
|
|
|
|
|
|
+import GDScriptSymbolParser from '../gdscript/symbolparser';
|
|
|
+import config from '../config';
|
|
|
+
|
|
|
class GDScriptSymbolProvider implements DocumentSymbolProvider {
|
|
|
- constructor() {}
|
|
|
+ private parser: GDScriptSymbolParser = null;
|
|
|
+
|
|
|
+ constructor() {
|
|
|
+ this.parser = new GDScriptSymbolParser();
|
|
|
+ }
|
|
|
|
|
|
provideDocumentSymbols(document: TextDocument, token: CancellationToken): SymbolInformation[] | Thenable<SymbolInformation[]> {
|
|
|
|
|
|
const symbols: SymbolInformation[] = [];
|
|
|
- const text =document.getText();
|
|
|
- const lines = text.split(/\r?\n/);
|
|
|
+ const script = this.parser.parseContent(document.getText());
|
|
|
+ config.setSymbols(document.fileName, script);
|
|
|
|
|
|
- const getMatches = (string, regex, index=1) => {
|
|
|
- var matches = [];
|
|
|
- var match;
|
|
|
- while (match = regex.exec(string)) {
|
|
|
- matches.push(match[index]);
|
|
|
- }
|
|
|
- return matches;
|
|
|
- };
|
|
|
-
|
|
|
- const findLineRanges = (symbols, reg)=>{
|
|
|
- const sm = {};
|
|
|
- symbols.map((name:string)=>{
|
|
|
- let line = 0;
|
|
|
- let curline = 0;
|
|
|
- lines.map(l=>{
|
|
|
- const nreg = reg.replace("$X$", name);
|
|
|
- if(l.match(nreg) != null) {
|
|
|
- line = curline;
|
|
|
- return;
|
|
|
- }
|
|
|
- curline += 1;
|
|
|
- });
|
|
|
- sm[name] = line;
|
|
|
- });
|
|
|
- return sm;
|
|
|
- }
|
|
|
-
|
|
|
- let funcsnames = getMatches(text, /func\s+([_A-Za-z]+[_A-Za-z0-9]*)\s*\(.*\)/gi, 1);
|
|
|
- const funcs = findLineRanges(funcsnames, "func\\s+$X$\\s*\\(.*\\)");
|
|
|
+ const funcs = script.functions;
|
|
|
for (let key of Object.keys(funcs))
|
|
|
- symbols.push(new SymbolInformation(key, SymbolKind.Function, new Range(funcs[key], 0, funcs[key],lines[funcs[key]].length)));
|
|
|
+ symbols.push(new SymbolInformation(key, SymbolKind.Function, funcs[key]));
|
|
|
|
|
|
- let signalnames = getMatches(text, /signal\s+([_A-Za-z]+[_A-Za-z0-9]*)\s*\(.*\)/gi, 1);
|
|
|
- const signals = findLineRanges(signalnames, "signal\\s+$X$\\s*\\(.*\\)");
|
|
|
+ const signals = script.signals;
|
|
|
for (let key of Object.keys(signals))
|
|
|
- symbols.push(new SymbolInformation(key, SymbolKind.Interface, new Range(signals[key], 0, signals[key],lines[signals[key]].length)));
|
|
|
-
|
|
|
- let varnames = getMatches(text, /var\s+([_A-Za-z]+[_A-Za-z0-9]*)\s*/gi, 1);
|
|
|
- const vars = findLineRanges(varnames, "var\\s+$X$\\s*");
|
|
|
+ symbols.push(new SymbolInformation(key, SymbolKind.Interface, signals[key]));
|
|
|
+
|
|
|
+ const vars = script.variables;
|
|
|
for (let key of Object.keys(vars))
|
|
|
- symbols.push(new SymbolInformation(key, SymbolKind.Variable, new Range(vars[key], 0, vars[key],lines[vars[key]].length)));
|
|
|
+ symbols.push(new SymbolInformation(key, SymbolKind.Variable, vars[key]));
|
|
|
|
|
|
- let constnames = getMatches(text, /const\s+([_A-Za-z]+[_A-Za-z0-9]*)\s*/gi, 1);
|
|
|
- const consts = findLineRanges(constnames, "const\\s+$X$\\s*");
|
|
|
+ const consts = script.constants;
|
|
|
for (let key of Object.keys(consts))
|
|
|
- symbols.push(new SymbolInformation(key, SymbolKind.Constant, new Range(consts[key], 0, consts[key],lines[consts[key]].length)));
|
|
|
+ symbols.push(new SymbolInformation(key, SymbolKind.Constant, consts[key]));
|
|
|
+
|
|
|
+ const classes = script.classes;
|
|
|
+ for (let key of Object.keys(classes))
|
|
|
+ symbols.push(new SymbolInformation(key, SymbolKind.Class, classes[key]));
|
|
|
|
|
|
return symbols;
|
|
|
}
|