Skip to content

Commit

Permalink
Show that server is running on degraded mode
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed Oct 30, 2024
1 parent 29c434b commit 8838642
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/ruby_lsp/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ def run_initialize(message)
version: VERSION,
},
formatter: @global_state.formatter,
degraded_mode: !!(@install_error || @setup_error),
}

send_message(Result.new(id: message[:id], response: response))
Expand Down
6 changes: 6 additions & 0 deletions vscode/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ export default class Client extends LanguageClient implements ClientInterface {
public readonly ruby: Ruby;
public serverVersion?: string;
public addons?: Addon[];
public degraded = false;
private readonly workingDirectory: string;
private readonly telemetry: vscode.TelemetryLogger;
private readonly createTestItems: (response: CodeLens[]) => void;
Expand Down Expand Up @@ -355,6 +356,11 @@ export default class Client extends LanguageClient implements ClientInterface {
async afterStart() {
this.#formatter = this.initializeResult?.formatter;
this.serverVersion = this.initializeResult?.serverInfo?.version;

if (this.initializeResult?.degraded_mode) {
this.degraded = this.initializeResult?.degraded_mode;
}

await this.fetchAddons();
}

Expand Down
1 change: 1 addition & 0 deletions vscode/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ export interface ClientInterface {
formatter: string;
addons?: Addon[];
serverVersion?: string;
degraded: boolean;
sendRequest<T>(
method: string,
param: any,
Expand Down
9 changes: 8 additions & 1 deletion vscode/src/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,15 @@ export class ServerStatus extends StatusItem {
this.item.text = workspace.lspClient.serverVersion
? `Ruby LSP v${workspace.lspClient.serverVersion}: Running`
: "Ruby LSP: Running";

if (workspace.lspClient.degraded) {
this.item.text += " (degraded)";
this.item.severity = vscode.LanguageStatusSeverity.Warning;
} else {
this.item.severity = vscode.LanguageStatusSeverity.Information;
}

this.item.command!.arguments = [STARTED_SERVER_OPTIONS];
this.item.severity = vscode.LanguageStatusSeverity.Information;
break;
}
case State.Starting: {
Expand Down
19 changes: 19 additions & 0 deletions vscode/src/test/suite/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ suite("StatusItems", () => {
formatter: "none",
serverVersion: "1.0.0",
sendRequest: <T>() => Promise.resolve([] as T),
degraded: false,
},
error: false,
};
Expand Down Expand Up @@ -78,6 +79,7 @@ suite("StatusItems", () => {
formatter: "none",
serverVersion: "1.0.0",
sendRequest: <T>() => Promise.resolve([] as T),
degraded: false,
},
error: false,
};
Expand Down Expand Up @@ -128,6 +130,19 @@ suite("StatusItems", () => {
);
assert.strictEqual(status.item.name, "Ruby LSP Server Status");
});

test("Refresh when server is in degraded mode", () => {
workspace.lspClient!.degraded = true;
status.refresh(workspace);
assert.strictEqual(
status.item.text,
"Ruby LSP v1.0.0: Running (degraded)",
);
assert.strictEqual(
status.item.severity,
vscode.LanguageStatusSeverity.Warning,
);
});
});

suite("ExperimentalFeaturesStatus", () => {
Expand All @@ -141,6 +156,7 @@ suite("StatusItems", () => {
formatter,
serverVersion: "1.0.0",
sendRequest: <T>() => Promise.resolve([] as T),
degraded: false,
},
error: false,
};
Expand Down Expand Up @@ -170,6 +186,7 @@ suite("StatusItems", () => {
formatter: "none",
serverVersion: "1.0.0",
sendRequest: <T>() => Promise.resolve([] as T),
degraded: false,
},
error: false,
};
Expand Down Expand Up @@ -258,6 +275,7 @@ suite("StatusItems", () => {
state: State.Running,
formatter: "auto",
serverVersion: "1.0.0",
degraded: false,
sendRequest: <T>() => Promise.resolve([] as T),
},
error: false,
Expand All @@ -283,6 +301,7 @@ suite("StatusItems", () => {
addons: undefined,
state: State.Running,
formatter: "auto",
degraded: false,
serverVersion: "1.0.0",
sendRequest: <T>() => Promise.resolve([] as T),
},
Expand Down

0 comments on commit 8838642

Please sign in to comment.