async startLanguageServer()

in src/common/language_server/language_server_manager.ts [88:197]


  async startLanguageServer() {
    if (this.#client) {
      log.warn('Language server already started');
      return;
    }
    const { gitLabPlatformManager, gitLabTelemetryEnvironment } = this.#dependencyContainer;
    const stateManager = new CodeSuggestionsStateManager(
      gitLabPlatformManager,
      this.#context,
      this.#languageServerFeatureStateProvider,
    );
    const statusBarItem = new CodeSuggestionsStatusBarItem(stateManager);
    const gutterIcon = new CodeSuggestionsGutterIcon(this.#context, stateManager);
    const middleware = new LanguageClientMiddleware(stateManager);
    const baseAssetsUrl = vscode.Uri.joinPath(
      this.#context.extensionUri,
      './assets/language-server/',
    ).toString();

    this.#client = this.#clientFactory.createLanguageClient(this.#context, {
      documentSelector: [
        { scheme: 'file' },
        { notebook: '*' },
        { scheme: 'gitlab-web-ide' },
        { scheme: 'untitled' },
      ],
      initializationOptions: {
        ...getClientContext(),
        baseAssetsUrl,
      },
      middleware,
    });

    middleware.client = this.#client;
    await stateManager.init();

    const suggestionsManager = new GitLabPlatformManagerForCodeSuggestions(gitLabPlatformManager);
    this.#wrapper = new LanguageClientWrapper(
      this.#client,
      suggestionsManager,
      gitLabTelemetryEnvironment,
      this.#dependencyContainer.lsGitProvider,
      this.#webviewMessageRegistry,
      this.#languageServerFeatureStateProvider,
    );

    await this.#wrapper.initAndStart();
    const subscriptions = [
      suggestionsManager,
      this.#wrapper,
      vscode.commands.registerCommand(
        SUGGESTION_ACCEPTED_COMMAND,
        this.#wrapper.sendSuggestionAcceptedEvent,
      ),
      vscode.commands.registerCommand(COMMAND_TOGGLE_CODE_SUGGESTIONS, () =>
        toggleCodeSuggestions({ stateManager }),
      ),
      vscode.commands.registerCommand(SHOW_QUICK_PICK_MENU, () =>
        showDuoQuickPickMenu({ stateManager }),
      ),
      vscode.commands.registerCommand(
        CODE_SUGGESTION_STREAM_ACCEPTED_COMMAND,
        codeSuggestionStreamAccepted(this.#client),
      ),
      vscode.commands.registerCommand(
        COMMAND_RUN_SECURITY_SCAN,
        runSecurityScan(this.#client, gitLabPlatformManager, 'command'),
      ),
      vscode.commands.registerCommand(
        COMMAND_RUN_SECURITY_SCAN_VIEW_TITLE,
        runSecurityScan(this.#client, gitLabPlatformManager, 'command'),
      ),
      vscode.commands.registerCommand(
        COMMAND_SHOW_VULNS_DETAILS,
        openRemoteSecurityVulnsDetails(this.#client),
      ),
      onDidSaveActiveTextDocument(async () => {
        if (this.#client && getSecurityScannerConfiguration().scanFileOnSave) {
          await runSecurityScan(this.#client, gitLabPlatformManager, 'save')();
        }
      }),
      vscode.commands.registerCommand(
        COMMAND_QUICK_CHAT_OPEN_TELEMETRY,
        this.#wrapper?.sendQuickChatOpenEvent,
      ),
      vscode.commands.registerCommand(
        COMMAND_QUICK_CHAT_MESSAGE_TELEMETRY,
        this.#wrapper?.sendQuickChatMessageEvent,
      ),
      extensionConfigurationService.onChange(async () => this.#wrapper?.syncConfig()),
      gitLabTelemetryEnvironment.onDidChangeTelemetryEnabled(this.#wrapper.syncConfig),
      gitLabPlatformManager.onAccountChange(this.#wrapper.syncConfig),

      statusBarItem,
      gutterIcon,
      vscode.window.onDidChangeActiveTextEditor(async te => {
        if (te) {
          await this.#client?.sendNotification(
            DidChangeDocumentInActiveEditor,
            te.document.uri.toString(),
          );
        }
      }),
    ];
    this.#context.subscriptions.push(...subscriptions);
    this.#subscriptions = subscriptions;
    this.#versionChangeEmitter.fire({
      version: this.version,
    });
  }