Skip to content

Commit 54acbd0

Browse files
committed
add symbol information support
1 parent 5f89451 commit 54acbd0

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

extension.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
const vscode = require('vscode');
2+
3+
function activate(context) {
4+
const selector = { language: 'lark', scheme: 'file' };
5+
const provider = new LarkSymbolProvider();
6+
context.subscriptions.push(
7+
vscode.languages.registerDocumentSymbolProvider(selector, provider)
8+
);
9+
}
10+
11+
class LarkSymbolProvider {
12+
provideDocumentSymbols(document) {
13+
const symbols = [];
14+
const re = /^\s*([A-Za-z_]\w*)\s*:/;
15+
for (let i = 0; i < document.lineCount; i++) {
16+
const text = document.lineAt(i).text;
17+
const m = re.exec(text);
18+
if (m) {
19+
const name = m[1];
20+
const kind = /^[A-Z]/.test(name)
21+
? vscode.SymbolKind.Constant
22+
: vscode.SymbolKind.Function;
23+
const range = new vscode.Range(i, 0, i, text.length);
24+
symbols.push(new vscode.DocumentSymbol(name, '', kind, range, range));
25+
}
26+
}
27+
return symbols;
28+
}
29+
}
30+
31+
function deactivate() { }
32+
33+
module.exports = { activate, deactivate };

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vscode-lark",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"publisher": "dirk-thomas",
55
"engines": {
66
"vscode": "^1.2.0"
@@ -19,6 +19,10 @@
1919
"bugs": {
2020
"url": "https://github.com/dirk-thomas/vscode-lark/issues"
2121
},
22+
"main": "./extension.js",
23+
"activationEvents": [
24+
"onLanguage:lark"
25+
],
2226
"contributes": {
2327
"languages": [
2428
{

0 commit comments

Comments
 (0)