|
| 1 | +import * as vscode from 'vscode'; |
| 2 | + |
| 3 | +export class ObjectScriptSymbolProvider implements vscode.DocumentSymbolProvider { |
| 4 | + public provideDocumentSymbols( |
| 5 | + document: vscode.TextDocument, |
| 6 | + token: vscode.CancellationToken |
| 7 | + ): Thenable<vscode.SymbolInformation[]> { |
| 8 | + return new Promise(resolve => { |
| 9 | + var symbols: any[] = []; |
| 10 | + |
| 11 | + // This line is here purely to satisfy linter |
| 12 | + token = token; |
| 13 | + |
| 14 | + const isClass = document.fileName.toLowerCase().endsWith('cls'); |
| 15 | + for (var i = 0; i < document.lineCount; i++) { |
| 16 | + var line = document.lineAt(i); |
| 17 | + |
| 18 | + if (isClass) { |
| 19 | + let method = line.text.match(/^(?:Class|Client)?Method ([^(]+)/i); |
| 20 | + if (method) { |
| 21 | + symbols.push({ |
| 22 | + name: method[1], |
| 23 | + kind: vscode.SymbolKind.Method, |
| 24 | + location: new vscode.Location(document.uri, line.range) |
| 25 | + }); |
| 26 | + } |
| 27 | + |
| 28 | + let property = line.text.match(/^(?:Property|Relationship) (\b\w+\b)/i); |
| 29 | + if (property) { |
| 30 | + symbols.push({ |
| 31 | + name: property[1], |
| 32 | + kind: vscode.SymbolKind.Property, |
| 33 | + location: new vscode.Location(document.uri, line.range) |
| 34 | + }); |
| 35 | + } |
| 36 | + |
| 37 | + let parameter = line.text.match(/^Parameter (\b\w+\b)/i); |
| 38 | + if (parameter) { |
| 39 | + symbols.push({ |
| 40 | + name: parameter[1], |
| 41 | + kind: vscode.SymbolKind.TypeParameter, |
| 42 | + location: new vscode.Location(document.uri, line.range) |
| 43 | + }); |
| 44 | + } |
| 45 | + |
| 46 | + let xdata = line.text.match(/^XData (\b\w+\b)/i); |
| 47 | + if (xdata) { |
| 48 | + symbols.push({ |
| 49 | + name: xdata[1], |
| 50 | + kind: vscode.SymbolKind.Struct, |
| 51 | + location: new vscode.Location(document.uri, line.range) |
| 52 | + }); |
| 53 | + } |
| 54 | + } else { |
| 55 | + let label = line.text.match(/^(\b\w+\b)/); |
| 56 | + if (label) { |
| 57 | + symbols.push({ |
| 58 | + name: label[1], |
| 59 | + kind: vscode.SymbolKind.Method, |
| 60 | + location: new vscode.Location(document.uri, line.range) |
| 61 | + }); |
| 62 | + } |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + resolve(symbols); |
| 67 | + }); |
| 68 | + } |
| 69 | +} |
0 commit comments