5 Commits 4c138ffb87 ... 81d641400b

Author SHA1 Message Date
  VHDL Tool 81d641400b bump version 1 month ago
  VHDL Tool dd4e452f6b Show error message if vhdl-tool executable cannot be found 1 month ago
  VHDL Tool 82ff695b94 remove wrapper 1 month ago
  VHDL Tool 071339aa6a update deps 1 month ago
  Adam Walker 4c138ffb87 update deps 11 months ago
3 changed files with 40 additions and 32 deletions
  1. 1 1
      package.json
  2. 39 20
      src/extension.ts
  3. 0 11
      vhdltool-wrapper.sh

+ 1 - 1
package.json

@@ -2,7 +2,7 @@
2 2
     "name": "vhdl-tool",
3 3
     "displayName": "VHDL Language Server",
4 4
     "description": "Language Server Protocol for VHDL via VHDL-Tool",
5
-    "version": "0.0.2",
5
+    "version": "0.0.5",
6 6
     "license": "MIT",
7 7
     "publisher": "vhdl-tool",
8 8
     "homepage": "https://www.vhdltool.com",

+ 39 - 20
src/extension.ts

@@ -1,29 +1,48 @@
1 1
 'use strict';
2 2
 
3 3
 import * as path from 'path';
4
-import { workspace, Disposable, ExtensionContext } from 'vscode';
4
+import { workspace, Disposable, ExtensionContext, window } from 'vscode';
5 5
 import { LanguageClient, LanguageClientOptions, SettingMonitor, ServerOptions, TransportKind } from 'vscode-languageclient';
6
+import * as child_process from 'child_process';
7
+import * as fs from 'fs';
8
+
9
+/*
10
+ * Checks if the executable is on the PATH
11
+ */
12
+export function executableExists(exe: string): boolean {
13
+  const isWindows = process.platform === 'win32';
14
+  const cmd: string = isWindows ? 'where' : 'which';
15
+  const out = child_process.spawnSync(cmd, [exe]);
16
+  return out.status === 0 || (isWindows && fs.existsSync(exe));
17
+}
6 18
 
7 19
 export function activate(context: ExtensionContext) {
8 20
 
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'],
21
+	if (executableExists('vhdl-tool')) {
22
+
23
+		let args: string[] = ['lsp'];
24
+
25
+		// If the extension is launched in debug mode then the debug server options are used
26
+		// Otherwise the run options are used
27
+		let serverOptions: ServerOptions = {
28
+			run:   { command: 'vhdl-tool', args},
29
+			debug: { command: 'vhdl-tool', args}
30
+		} 
31
+		
32
+		// Options to control the language client
33
+		let clientOptions: LanguageClientOptions = {
34
+			// Register the server for VHDL files
35
+			documentSelector: ['vhdl'],
36
+		}
37
+		
38
+		// Create the language client and start the client.
39
+		let disposable = new LanguageClient('vhdltool', 'Language Server VHDL', serverOptions, clientOptions).start();
40
+		
41
+		// Push the disposable to the context's subscriptions so that the client can be deactivated on extension deactivation
42
+		context.subscriptions.push(disposable);
43
+	} else {
44
+		const notInstalledMsg: string =
45
+			'Please download VHDL-Tool from https://www.vhdltool.com/download and place it somewhere in your $PATH';
46
+		window.showErrorMessage(notInstalledMsg);
22 47
 	}
23
-	
24
-	// Create the language client and start the client.
25
-	let disposable = new LanguageClient('vhdltool', '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 48
 }

+ 0 - 11
vhdltool-wrapper.sh

@@ -1,11 +0,0 @@
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