extension.ts 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. progressOnInitialization: true,
  30. }
  31. // Create the language client and start the client.
  32. let disposable = new LanguageClient('vhdltool', 'Language Server VHDL', serverOptions, clientOptions).start();
  33. // Push the disposable to the context's subscriptions so that the client can be deactivated on extension deactivation
  34. context.subscriptions.push(disposable);
  35. } else {
  36. const notInstalledMsg: string =
  37. 'Please download VHDL-Tool from https://www.vhdltool.com/download and place it somewhere in your $PATH';
  38. window.showErrorMessage(notInstalledMsg);
  39. }
  40. }