Skip to content

Commit

Permalink
Remove ERB from document selector for outdated servers
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Jul 15, 2024
1 parent e7f54ad commit 22a772d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
1 change: 1 addition & 0 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def run_initialize(message)
type_hierarchy_provider: type_hierarchy_provider,
experimental: {
addon_detection: true,
erb_support: true,
},
),
serverInfo: {
Expand Down
12 changes: 11 additions & 1 deletion vscode/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
ErrorAction,
CloseAction,
State,
DocumentFilter,
} from "vscode-languageclient/node";

import {
Expand Down Expand Up @@ -106,6 +107,7 @@ function collectClientOptions(
outputChannel: WorkspaceChannel,
ruby: Ruby,
isMainWorkspace: boolean,
erbSupport: boolean,
): LanguageClientOptions {
const pullOn: "change" | "save" | "both" =
configuration.get("pullDiagnosticsOn")!;
Expand All @@ -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}/**/*` };
},
Expand Down Expand Up @@ -158,6 +160,12 @@ function collectClientOptions(
});
}

if (!erbSupport) {
documentSelector = documentSelector.filter((selector) => {
return (selector as DocumentFilter).language !== "erb";
});
}

return {
documentSelector,
workspaceFolder,
Expand Down Expand Up @@ -234,6 +242,7 @@ export default class Client extends LanguageClient implements ClientInterface {
workspaceFolder: vscode.WorkspaceFolder,
outputChannel: WorkspaceChannel,
isMainWorkspace = false,
erbSupport = true,
) {
super(
LSP_NAME,
Expand All @@ -244,6 +253,7 @@ export default class Client extends LanguageClient implements ClientInterface {
outputChannel,
ruby,
isMainWorkspace,
erbSupport,
),
);

Expand Down
21 changes: 16 additions & 5 deletions vscode/src/workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -105,6 +105,7 @@ export class Workspace implements WorkspaceInterface {
this.workspaceFolder,
this.outputChannel,
this.isMainWorkspace,
erbSupport,
);

try {
Expand All @@ -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}`);
Expand All @@ -129,7 +140,7 @@ export class Workspace implements WorkspaceInterface {
await this.lspClient?.stop();
}

async restart() {
async restart(erbSupport = true) {
try {
if (this.#rebaseInProgress) {
return;
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit 22a772d

Please sign in to comment.