extension.ts 1.7 KB

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