private getLanguageClientOptions()

in src/extension/src/lspclient.ts [578:634]


  private getLanguageClientOptions(): lc.LanguageClientOptions {
    const ulspConfig = vscode.workspace.getConfiguration(UBER_ULSP_CONFIG)

    const currentLCSettings =
      ulspConfig.get<languageClientSettings>(LANGUAGE_CLIENT_OPTIONS) ?? {}

    const clientOptions: lc.LanguageClientOptions = {
      // Fixed values.
      diagnosticCollectionName: 'ulsp-diag',
      diagnosticPullOptions: {
        onChange: true,
        onSave: true,
        onTabs: true,
      },
      outputChannel: outputChannelClient,
      traceOutputChannel: outputChannelClient,
      markdown: {
        isTrusted: true,
        supportHtml: true,
      },
      errorHandler: {
        error: (
          error: Error,
          message: lc.Message | undefined,
          count: number | undefined
        ) => {
          return {action: lc.ErrorAction.Continue}
        },
        closed: async () => {
          this.restartCount++
          setTimeout(() => {
            this.restartCount = 0
          }, 750)
          if (this.restartCount > 3) {
            return {action: lc.CloseAction.DoNotRestart}
          }
          const running = await this.ensureRunningServer()
          if (running) return {action: lc.CloseAction.Restart}
          return {action: lc.CloseAction.DoNotRestart}
        },
      },

      // Dynamic values directly from settings.
      documentSelector: currentLCSettings.documentSelector,

      // Dynamic values derived from settings via additional logic.
      synchronize: {
        fileEvents: currentLCSettings.fileWatcherPatterns?.map(
          (pattern: string) => {
            return vscode.workspace.createFileSystemWatcher(pattern)
          }
        ),
      },
    }

    return clientOptions
  }