vscode-languageclient#ErrorAction TypeScript Examples

The following examples show how to use vscode-languageclient#ErrorAction. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: syntaxLanguageClient.ts    From vscode-stripe with MIT License 5 votes vote down vote up
public initialize(
    clientOptions: LanguageClientOptions,
    serverOptions: ServerOptions,
  ) {
    if (!serverOptions) {
      return;
    }

    const newClientOptions: LanguageClientOptions = Object.assign({}, clientOptions, {
      errorHandler: {
        error: (error: string, message: string) => {
          console.log(message);
          console.log(error);

          return ErrorAction.Continue;
        },
        closed: () => CloseAction.DoNotRestart,
      },
    });

    this.languageClient = new LanguageClient(
      'java',
      EXTENSION_NAME_SYNTAX,
      serverOptions,
      newClientOptions,
    );

    this.languageClient.onReady().then(() => {
      if (this.languageClient) {
        this.languageClient.onNotification(StatusNotification.type, (report: {type: any}) => {
          switch (report.type) {
            case 'Started':
              this.status = ClientStatus.Started;
              break;
            case 'Error':
              this.status = ClientStatus.Error;
              break;
            default:
              break;
          }
        });
      }
    });

    this.status = ClientStatus.Initialized;
  }
Example #2
Source File: languageServerClient.ts    From vscode-stripe with MIT License 4 votes vote down vote up
static async activateDotNetServer(
    context: ExtensionContext,
    outputChannel: OutputChannel,
    projectFile: string,
    telemetry: Telemetry,
  ) {
    outputChannel.appendLine('Detected C# Project file: ' + projectFile);

    // Applie Silicon is not supported for dotnet < 6.0:
    // https://github.com/dotnet/core/issues/4879#issuecomment-729046912
    if (getOSType() === OSType.macOSarm) {
      outputChannel.appendLine(
        `.NET runtime v${REQUIRED_DOTNET_RUNTIME_VERSION} is not supported for M1`,
      );
      telemetry.sendEvent('dotnetRuntimeAcquisitionSkippedForM1');
      return;
    }

    const result = await commands.executeCommand<{dotnetPath: string}>('dotnet.acquire', {
      version: REQUIRED_DOTNET_RUNTIME_VERSION,
      requestingExtensionId: 'stripe.vscode-stripe',
    });

    if (!result) {
      outputChannel.appendLine(
        `Failed to install .NET runtime v${REQUIRED_DOTNET_RUNTIME_VERSION}. Unable to start language server`,
      );

      telemetry.sendEvent('dotnetRuntimeAcquisitionFailed');
      return;
    }

    const dotNetExecutable = path.resolve(result.dotnetPath);
    outputChannel.appendLine('dotnet runtime acquired: ' + dotNetExecutable);

    const serverAssembly = context.asAbsolutePath(
      'dist/stripeDotnetLanguageServer/stripe.LanguageServer.dll',
    );

    const serverOptions: ServerOptions = {
      command: dotNetExecutable,
      args: [serverAssembly, projectFile],
    };

    // Options to control the language client
    const clientOptions: LanguageClientOptions = {
      // Register the server for plain text documents
      documentSelector: [{scheme: 'file', language: 'csharp'}],
      synchronize: {
        configurationSection: 'stripeCsharpLangaugeServer',
        fileEvents: workspace.createFileSystemWatcher('**/*.cs'),
      },
      diagnosticCollectionName: 'Stripe C# language server',
      errorHandler: {
        error: (error, message, count) => {
          console.log(message);
          console.log(error);

          return ErrorAction.Continue;
        },
        closed: () => CloseAction.DoNotRestart,
      },
    };

    // Create the language client and start the client.
    // We are overriding the show notification for the dotnet client.
    const dotnetClient = new (class extends LanguageClient {
      error(message: string, data: any, showNotification: boolean) {
        super.error(message, data, false);
      }
    })('stripeCsharpLanguageServer', 'Stripe C# Server', serverOptions, clientOptions);

    dotnetClient.trace = Trace.Verbose;
    outputChannel.appendLine('Starting C# language service for ' + projectFile);

    const disposable = dotnetClient.start();
    // Push the disposable to the context's subscriptions so that the
    // client can be deactivated on extension deactivation
    context.subscriptions.push(disposable);

    await dotnetClient.onReady();
    outputChannel.appendLine('C# language service is running.');
    telemetry.sendEvent('dotnetServerStarted');
  }
Example #3
Source File: languageServerClient.ts    From vscode-stripe with MIT License 4 votes vote down vote up
static async activateJavaServer(
    context: ExtensionContext,
    jdkInfo: JDKInfo,
    outputChannel: OutputChannel,
    projectFiles: string[],
    telemetry: Telemetry,
  ) {
    outputChannel.appendLine('Detected Java Project file: ' + projectFiles[0]);

    let storagePath = context.storagePath;
    if (!storagePath) {
      storagePath = path.resolve(os.tmpdir(), 'vscodesws_' + makeRandomHexString(5));
    }

    const workspacePath = path.resolve(storagePath + '/jdt_ws');
    const syntaxServerWorkspacePath = path.resolve(storagePath + '/ss_ws');

    javaServerMode = getJavaServerLaunchMode();
    commands.executeCommand('setContext', 'java:serverMode', javaServerMode);
    const requireSyntaxServer = javaServerMode !== ServerMode.STANDARD;
    const requireStandardServer = javaServerMode !== ServerMode.LIGHTWEIGHT;

    // Options to control the language client
    const clientOptions: LanguageClientOptions = {
      // Register the server for java
      documentSelector: [{scheme: 'file', language: 'java'}],
      synchronize: {
        configurationSection: ['java', 'editor.insertSpaces', 'editor.tabSize'],
      },
      initializationOptions: {
        extendedClientCapabilities: {
          classFileContentsSupport: true,
          clientHoverProvider: true,
          clientDocumentSymbolProvider: true,
          shouldLanguageServerExitOnShutdown: true,
        },
        projectFiles,
      },
      revealOutputChannelOn: 4, // never
      errorHandler: {
        error: (error, message, count) => {
          console.log(message);
          console.log(error);

          return ErrorAction.Continue;
        },
        closed: () => CloseAction.DoNotRestart,
      },
    };

    if (requireSyntaxServer) {
      try {
        await this.startSyntaxServer(
          clientOptions,
          prepareExecutable(
            jdkInfo,
            syntaxServerWorkspacePath,
            context,
            true,
            outputChannel,
            telemetry,
          ),
          outputChannel,
          telemetry,
        );
      } catch (e) {
        outputChannel.appendLine(`${e}`);
        telemetry.sendEvent('syntaxJavaServerFailedToStart');
      }
    }

    // handle server mode changes from syntax to standard
    this.registerSwitchJavaServerModeCommand(
      context,
      jdkInfo,
      clientOptions,
      workspacePath,
      outputChannel,
      telemetry,
    );

    onDidServerModeChangeEmitter.event((event: ServerMode) => {
      if (event === ServerMode.STANDARD) {
        syntaxClient.stop();
      }
      commands.executeCommand('setContext', 'java:serverMode', event);
    });

    // register hover provider
    registerHoverProvider(context);

    if (requireStandardServer) {
      try {
        await this.startStandardServer(
          context,
          clientOptions,
          prepareExecutable(jdkInfo, workspacePath, context, false, outputChannel, telemetry),
          outputChannel,
          telemetry,
        );
      } catch (e) {
        outputChannel.appendLine(`${e}`);
        telemetry.sendEvent('standardJavaServerFailedToStart');
      }
    }
  }