Browse Source

Initial Visual Studio Code plugin

VHDL Tool 2 years ago
commit
bf70a8aad8
14 changed files with 270 additions and 0 deletions
  1. 2 0
      .gitignore
  2. 28 0
      .vscode/launch.json
  3. 10 0
      .vscode/settings.json
  4. 30 0
      .vscode/tasks.json
  5. 10 0
      .vscodeignore
  6. 48 0
      README.md
  7. BIN
      images/autocompl-syntax.png
  8. BIN
      images/symbols-hover.png
  9. 42 0
      package.json
  10. 29 0
      src/extension.ts
  11. 22 0
      test/extension.test.ts
  12. 22 0
      test/index.ts
  13. 16 0
      tsconfig.json
  14. 11 0
      vhdltool-wrapper.sh

+ 2 - 0
.gitignore

@@ -0,0 +1,2 @@
1
+out
2
+node_modules

+ 28 - 0
.vscode/launch.json

@@ -0,0 +1,28 @@
1
+// A launch configuration that compiles the extension and then opens it inside a new window
2
+{
3
+    "version": "0.1.0",
4
+    "configurations": [
5
+        {
6
+            "name": "Launch Extension",
7
+            "type": "extensionHost",
8
+            "request": "launch",
9
+            "runtimeExecutable": "${execPath}",
10
+            "args": ["--extensionDevelopmentPath=${workspaceRoot}" ],
11
+            "stopOnEntry": false,
12
+            "sourceMaps": true,
13
+            "outFiles": ["${workspaceRoot}/out/src/*"],
14
+            "preLaunchTask": "npm"
15
+        },
16
+        {
17
+            "name": "Launch Tests",
18
+            "type": "extensionHost",
19
+            "request": "launch",
20
+            "runtimeExecutable": "${execPath}",
21
+            "args": ["--extensionDevelopmentPath=${workspaceRoot}", "--extensionTestsPath=${workspaceRoot}/out/test" ],
22
+            "stopOnEntry": false,
23
+            "sourceMaps": true,
24
+            "outFiles": ["${workspaceRoot}/out/test/*"],
25
+            "preLaunchTask": "npm"
26
+        }
27
+    ]
28
+}

+ 10 - 0
.vscode/settings.json

@@ -0,0 +1,10 @@
1
+// Place your settings in this file to overwrite default and user settings.
2
+{
3
+    "files.exclude": {
4
+        "out": false // set this to true to hide the "out" folder with the compiled JS files
5
+    },
6
+    "search.exclude": {
7
+        "out": true // set this to false to include "out" folder in search results
8
+    },
9
+    "typescript.tsdk": "./node_modules/typescript/lib" // we want to use the TS server from our node_modules folder to control its version
10
+}

+ 30 - 0
.vscode/tasks.json

@@ -0,0 +1,30 @@
1
+// Available variables which can be used inside of strings.
2
+// ${workspaceRoot}: the root folder of the team
3
+// ${file}: the current opened file
4
+// ${fileBasename}: the current opened file's basename
5
+// ${fileDirname}: the current opened file's dirname
6
+// ${fileExtname}: the current opened file's extension
7
+// ${cwd}: the current working directory of the spawned process
8
+
9
+// A task runner that calls a custom npm script that compiles the extension.
10
+{
11
+    "version": "0.1.0",
12
+
13
+    // we want to run npm
14
+    "command": "npm",
15
+
16
+    // the command is a shell script
17
+    "isShellCommand": true,
18
+
19
+    // show the output window only if unrecognized errors occur.
20
+    "showOutput": "silent",
21
+
22
+    // we run the custom script "compile" as defined in package.json
23
+    "args": ["run", "compile", "--loglevel", "silent"],
24
+
25
+    // The tsc compiler is started in watching mode
26
+    "isWatching": true,
27
+
28
+    // use the standard tsc in watch mode problem matcher to find compile problems in the output.
29
+    "problemMatcher": "$tsc-watch"
30
+}

+ 10 - 0
.vscodeignore

@@ -0,0 +1,10 @@
1
+.vscode/**
2
+.vscode-test/**
3
+typings/**
4
+out/test/**
5
+test/**
6
+src/**
7
+**/*.map
8
+.gitignore
9
+tsconfig.json
10
+vsc-extension-quickstart.md

+ 48 - 0
README.md

@@ -0,0 +1,48 @@
1
+# VHDL-Tool
2
+
3
+[VHDL-Tool](https://www.vhdltool.com/) provides a [language server](https://github.com/Microsoft/language-server-protocol) for the VHDL hardware description language. This plugin makes VHDL-Tool's language server interface available from within VSCode.
4
+
5
+**This is beta quality code. Report bugs here: http://git.vhdltool.com/vhdl-tool/vhdltool-vscode.**
6
+
7
+For now, only Linux is supported.
8
+
9
+## Features
10
+
11
+* Syntax checking
12
+* Go to definition
13
+* Find references
14
+* Browse file symbols
15
+* Basic autocompletion
16
+
17
+## Screenshots
18
+![Syntax check and autocompletion](https://git.vhdltool.com/vhdl-tool/vhdltool-vscode/raw/master/images/autocompl-syntax.png)
19
+![File symbols and hover](https://git.vhdltool.com/vhdl-tool/vhdltool-vscode/raw/master/images/symbols-hover.png)
20
+
21
+## Usage
22
+* F12 - go to definition
23
+* Ctrl-Shift-F10 - peek definition
24
+* Shift-F12 - find references
25
+* Ctrl-Shift-o - find symbol in current file
26
+* Syntax checking occurs on save and the first time a file is opened
27
+* Autocompletion happens automatically when you type 
28
+
29
+## Requirements
30
+
31
+Before using this plugin, you must ensure that the `vhdl-tool` binary is installed on your system. To install `vhdl-tool` and setup your environment, do the following:
32
+
33
+1. Install this plugin.
34
+2. Download the `vhdl-tool` binary from [here](https://www.vhdltool.com/download), make sure it has execute permissions, and put it somewhere in your $PATH.
35
+3. Create a vhdltool-config.yaml configuration file for your project by following the instructions [here](http://www.vhdltool.com/configuration).
36
+4. Install one of the other VHDL plugins available in the marketplace for syntax highlighting. Search for VHDL in the extensions sidebar. **This step is compulsory as these plugins define the VHDL language and if VSCode does not know about VHDL it cannot launch the language server**.
37
+5. Launch VSCode and open the folder containing the configuration file created in the previous step.
38
+
39
+## Known Limitations
40
+* The go to definition and find references commands are not accurate in the presence of overloading. In the case of multiple overloaded identifiers with the same name, the type correct one may not be chosen.
41
+* No VHDL 2008 support yet.
42
+
43
+## Release Notes
44
+
45
+### 0.0.1
46
+
47
+Initial beta release of VHDL-Tool.
48
+

BIN
images/autocompl-syntax.png


BIN
images/symbols-hover.png


+ 42 - 0
package.json

@@ -0,0 +1,42 @@
1
+{
2
+    "name": "vhdl-tool",
3
+    "displayName": "VHDL Language Server",
4
+    "description": "Language Server Protocol for VHDL via VHDL-Tool",
5
+    "version": "0.0.1",
6
+    "license": "MIT",
7
+    "publisher": "vhdl-tool",
8
+    "homepage": "https://www.vhdltool.com",
9
+    "repository": {
10
+        "type": "git",
11
+        "url": "https://git.vhdltool.com/vhdl-tool/vhdltool-vscode"
12
+    },
13
+    "bugs": {
14
+        "url": "https://git.vhdltool.com/vhdl-tool/vhdltool-vscode/issues"
15
+    },
16
+    "engines": {
17
+        "vscode": "^1.8.0"
18
+    },
19
+    "categories": [
20
+        "Languages",
21
+        "Linters"
22
+    ],
23
+    "activationEvents": [
24
+        "onLanguage:vhdl"
25
+    ],
26
+    "main": "./out/src/extension",
27
+    "scripts": {
28
+        "vscode:prepublish": "tsc -p ./",
29
+        "compile": "tsc -watch -p ./",
30
+        "postinstall": "node ./node_modules/vscode/bin/install"
31
+    },
32
+    "dependencies": {
33
+        "vscode-languageclient": "^2.6.2"
34
+    },
35
+    "devDependencies": {
36
+        "typescript": "^2.0.3",
37
+        "vscode": "^1.0.3",
38
+        "mocha": "^2.3.3",
39
+        "@types/mocha": "^2.2.32",
40
+        "@types/node": "^6.0.40"
41
+    }
42
+}

+ 29 - 0
src/extension.ts

@@ -0,0 +1,29 @@
1
+'use strict';
2
+
3
+import * as path from 'path';
4
+import { workspace, Disposable, ExtensionContext } from 'vscode';
5
+import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, TransportKind } from 'vscode-languageclient';
6
+
7
+export function activate(context: ExtensionContext) {
8
+
9
+	let serverPath   = context.asAbsolutePath(path.join('.', 'vhdltool-wrapper.sh'));
10
+	
11
+	// If the extension is launched in debug mode then the debug server options are used
12
+	// Otherwise the run options are used
13
+	let serverOptions: ServerOptions = {
14
+		run:   { command: serverPath },
15
+		debug: { command: serverPath }
16
+	} 
17
+	
18
+	// Options to control the language client
19
+	let clientOptions: LanguageClientOptions = {
20
+		// Register the server for VHDL files
21
+		documentSelector: ['vhdl'],
22
+	}
23
+	
24
+	// Create the language client and start the client.
25
+	let disposable = new LanguageClient('Language Server VHDL', serverOptions, clientOptions).start();
26
+	
27
+	// Push the disposable to the context's subscriptions so that the client can be deactivated on extension deactivation
28
+	context.subscriptions.push(disposable);
29
+}

+ 22 - 0
test/extension.test.ts

@@ -0,0 +1,22 @@
1
+//
2
+// Note: This example test is leveraging the Mocha test framework.
3
+// Please refer to their documentation on https://mochajs.org/ for help.
4
+//
5
+
6
+// The module 'assert' provides assertion methods from node
7
+import * as assert from 'assert';
8
+
9
+// You can import and use all API from the 'vscode' module
10
+// as well as import your extension to test it
11
+import * as vscode from 'vscode';
12
+import * as myExtension from '../src/extension';
13
+
14
+// Defines a Mocha test suite to group tests of similar kind together
15
+suite("Extension Tests", () => {
16
+
17
+    // Defines a Mocha unit test
18
+    test("Something 1", () => {
19
+        assert.equal(-1, [1, 2, 3].indexOf(5));
20
+        assert.equal(-1, [1, 2, 3].indexOf(0));
21
+    });
22
+});

+ 22 - 0
test/index.ts

@@ -0,0 +1,22 @@
1
+//
2
+// PLEASE DO NOT MODIFY / DELETE UNLESS YOU KNOW WHAT YOU ARE DOING
3
+//
4
+// This file is providing the test runner to use when running extension tests.
5
+// By default the test runner in use is Mocha based.
6
+//
7
+// You can provide your own test runner if you want to override it by exporting
8
+// a function run(testRoot: string, clb: (error:Error) => void) that the extension
9
+// host can call to run the tests. The test runner is expected to use console.log
10
+// to report the results back to the caller. When the tests are finished, return
11
+// a possible error to the callback or null if none.
12
+
13
+var testRunner = require('vscode/lib/testrunner');
14
+
15
+// You can directly control Mocha options by uncommenting the following lines
16
+// See https://github.com/mochajs/mocha/wiki/Using-mocha-programmatically#set-options for more info
17
+testRunner.configure({
18
+    ui: 'tdd', 		// the TDD UI is being used in extension.test.ts (suite, test, etc.)
19
+    useColors: true // colored output from test results
20
+});
21
+
22
+module.exports = testRunner;

+ 16 - 0
tsconfig.json

@@ -0,0 +1,16 @@
1
+{
2
+    "compilerOptions": {
3
+        "module": "commonjs",
4
+        "target": "es6",
5
+        "outDir": "out",
6
+        "lib": [
7
+            "es6"
8
+        ],
9
+        "sourceMap": true,
10
+        "rootDir": "."
11
+    },
12
+    "exclude": [
13
+        "node_modules",
14
+        ".vscode-test"
15
+    ]
16
+}

+ 11 - 0
vhdltool-wrapper.sh

@@ -0,0 +1,11 @@
1
+#!/bin/sh
2
+
3
+export WRAPPER_PATH=`which vhdl-tool`
4
+
5
+if [ "X" = "X$WRAPPER_PATH" ]; then
6
+  echo "Content-Length: 100\r\n\r"
7
+  echo '{"jsonrpc":"2.0","id":1,"error":{"code":-32099,"message":"Cannot find vhdl-tool executable in $PATH"}}'
8
+  exit 1
9
+fi
10
+
11
+vhdl-tool lsp