From 22a772d1bc1a9307a5b0f250dbc53b2c4dfdd8e9 Mon Sep 17 00:00:00 2001 From: Vinicius Stock Date: Mon, 15 Jul 2024 14:23:20 -0400 Subject: [PATCH] Remove ERB from document selector for outdated servers --- lib/ruby_lsp/server.rb | 1 + vscode/src/client.ts | 12 +++++++++++- vscode/src/workspace.ts | 21 ++++++++++++++++----- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/lib/ruby_lsp/server.rb b/lib/ruby_lsp/server.rb index 33bdafb00..08c957ab1 100644 --- a/lib/ruby_lsp/server.rb +++ b/lib/ruby_lsp/server.rb @@ -205,6 +205,7 @@ def run_initialize(message) type_hierarchy_provider: type_hierarchy_provider, experimental: { addon_detection: true, + erb_support: true, }, ), serverInfo: { diff --git a/vscode/src/client.ts b/vscode/src/client.ts index 79b231578..aa7c62a72 100644 --- a/vscode/src/client.ts +++ b/vscode/src/client.ts @@ -21,6 +21,7 @@ import { ErrorAction, CloseAction, State, + DocumentFilter, } from "vscode-languageclient/node"; import { @@ -106,6 +107,7 @@ function collectClientOptions( outputChannel: WorkspaceChannel, ruby: Ruby, isMainWorkspace: boolean, + erbSupport: boolean, ): LanguageClientOptions { const pullOn: "change" | "save" | "both" = configuration.get("pullDiagnosticsOn")!; @@ -119,7 +121,7 @@ function collectClientOptions( const enabledFeatures = Object.keys(features).filter((key) => features[key]); const fsPath = workspaceFolder.uri.fsPath.replace(/\/$/, ""); - const documentSelector: DocumentSelector = SUPPORTED_LANGUAGE_IDS.map( + let documentSelector: DocumentSelector = SUPPORTED_LANGUAGE_IDS.map( (language) => { return { language, pattern: `${fsPath}/**/*` }; }, @@ -158,6 +160,12 @@ function collectClientOptions( }); } + if (!erbSupport) { + documentSelector = documentSelector.filter((selector) => { + return (selector as DocumentFilter).language !== "erb"; + }); + } + return { documentSelector, workspaceFolder, @@ -234,6 +242,7 @@ export default class Client extends LanguageClient implements ClientInterface { workspaceFolder: vscode.WorkspaceFolder, outputChannel: WorkspaceChannel, isMainWorkspace = false, + erbSupport = true, ) { super( LSP_NAME, @@ -244,6 +253,7 @@ export default class Client extends LanguageClient implements ClientInterface { outputChannel, ruby, isMainWorkspace, + erbSupport, ), ); diff --git a/vscode/src/workspace.ts b/vscode/src/workspace.ts index 4e5840fae..8f1bc3411 100644 --- a/vscode/src/workspace.ts +++ b/vscode/src/workspace.ts @@ -47,7 +47,7 @@ export class Workspace implements WorkspaceInterface { this.registerRebaseWatcher(context); } - async start() { + async start(erbSupport = true) { await this.ruby.activateRuby(); if (this.ruby.error) { @@ -105,6 +105,7 @@ export class Workspace implements WorkspaceInterface { this.workspaceFolder, this.outputChannel, this.isMainWorkspace, + erbSupport, ); try { @@ -119,6 +120,16 @@ export class Workspace implements WorkspaceInterface { this.needsRestart = false; await this.restart(); } + + if ( + erbSupport && + !this.lspClient.initializeResult?.capabilities.experimental?.erb_support + ) { + this.outputChannel.warn( + "A dependency is blocking the `ruby-lsp` from updating. Restarting the server without ERB support", + ); + await this.restart(false); + } } catch (error: any) { this.error = true; this.outputChannel.error(`Error starting the server: ${error.message}`); @@ -129,7 +140,7 @@ export class Workspace implements WorkspaceInterface { await this.lspClient?.stop(); } - async restart() { + async restart(erbSupport = true) { try { if (this.#rebaseInProgress) { return; @@ -139,7 +150,7 @@ export class Workspace implements WorkspaceInterface { // If there's no client, then we can just start a new one if (!this.lspClient) { - return this.start(); + return this.start(erbSupport); } switch (this.lspClient.state) { @@ -154,13 +165,13 @@ export class Workspace implements WorkspaceInterface { await this.stop(); await this.lspClient.dispose(); this.lspClient = undefined; - await this.start(); + await this.start(erbSupport); break; // If the server is already stopped, then we need to dispose it and start a new one case State.Stopped: await this.lspClient.dispose(); this.lspClient = undefined; - await this.start(); + await this.start(erbSupport); break; } } catch (error: any) {