From 45ec5f4ade222f8b7bf8a833034cf3d5e8dcec63 Mon Sep 17 00:00:00 2001 From: Dag Evensberget Date: Fri, 29 Nov 2019 16:53:01 +1000 Subject: [PATCH] Work in progress on symbol provider --- package.json | 18 ++++++++++++-- src/extension.ts | 63 ++++++++++++++++++++++++++++++++++++++++++++++++ tsconfig.json | 16 ++++++++++++ 3 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 src/extension.ts create mode 100644 tsconfig.json diff --git a/package.json b/package.json index c83438b..e2d8acc 100644 --- a/package.json +++ b/package.json @@ -6,13 +6,18 @@ "publisher": "svaberg", "repository": { "type": "git", - "url": "https://github.com/svaberg/SWMF-grammar"}, + "url": "https://github.com/svaberg/SWMF-grammar" + }, "engines": { "vscode": "^1.40.0" }, "categories": [ "Programming Languages" ], + "main": "./out/extension.js", + "activationEvents": [ + "onLanguage:swmf-config" + ], "contributes": { "languages": [ { @@ -36,7 +41,16 @@ } ] }, + "scripts": { + "vscode:prepublish": "npm run compile", + "compile": "tsc -p ./", + "watch": "tsc -watch -p ./", + "pretest": "npm run compile", + "test": "node ./out/test/runTest.js" + }, "dependencies": { - "vsce": "^1.69.0" + "tsc": "^1.20150623.0", + "vsce": "^1.69.0", + "vscode-languageclient": "^5.1.0" } } diff --git a/src/extension.ts b/src/extension.ts new file mode 100644 index 0000000..7299975 --- /dev/null +++ b/src/extension.ts @@ -0,0 +1,63 @@ +'use strict'; + +// src/extension.ts + +import * as vscode from 'vscode'; + +export function activate(context: vscode.ExtensionContext) { + + context.subscriptions.push( + vscode.languages.registerDocumentSymbolProvider( + {language: "swmf-config"}, + new SwmfConfigDocumentSymbolProvider() + ) + ); +} + +class SwmfConfigDocumentSymbolProvider implements vscode.DocumentSymbolProvider { + + public provideDocumentSymbols( + document: vscode.TextDocument, + token: vscode.CancellationToken): Thenable + { + return new Promise((resolve, reject) => { + var symbols = []; + + for (var i = 0; i < document.lineCount; i++) { + var line = document.lineAt(i); + + var marker + + if (line.text.startsWith("#BEGIN_COMP")) { + let marker_symbol = { + name: line.text.substr(1,13), + kind: vscode.SymbolKind.Namespace, + location: new vscode.Location(document.uri, line.range) + } + marker = marker_symbol + } + else if (line.text.startsWith("#")) { + let boo = line.text.substr(1) + + symbols.push({ + name: boo, + kind: vscode.SymbolKind.Module, + location: new vscode.Location(document.uri, line.range) + }) + } + 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) + }) + } + } + + resolve(symbols); + }); + } +} \ No newline at end of file diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..8a1d847 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "target": "es6", + "outDir": "out", + "lib": [ + "es6" + ], + "sourceMap": true, + "rootDir": "src" + }, + "exclude": [ + "node_modules", + ".vscode-test" + ] +} \ No newline at end of file