Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use quickpick UI to display addons list #2205

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions vscode/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@
"title": "Toggle features",
"category": "Ruby LSP"
},
{
"command": "rubyLsp.displayAddons",
"title": "Display addons",
"category": "Ruby LSP"
},
{
"command": "rubyLsp.runTest",
"title": "Run current test",
Expand Down
1 change: 1 addition & 0 deletions vscode/src/common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export enum Command {
RunTestInTerminal = "rubyLsp.runTestInTerminal",
DebugTest = "rubyLsp.debugTest",
ShowSyntaxTree = "rubyLsp.showSyntaxTree",
DisplayAddons = "rubyLsp.displayAddons",
}

export interface RubyInterface {
Expand Down
27 changes: 27 additions & 0 deletions vscode/src/rubyLsp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,33 @@ export class RubyLsp {
),
);
}),
vscode.commands.registerCommand(Command.DisplayAddons, async () => {
const client = this.currentActiveWorkspace()?.lspClient;

if (!client || !client.addons) {
return;
}

const options: vscode.QuickPickItem[] = client.addons
.sort((addon) => {
// Display errored addons last
if (addon.errored) {
return 1;
}

return -1;
})
.map((addon) => {
const icon = addon.errored ? "$(error)" : "$(pass)";
return {
label: `${icon} ${addon.name}`,
};
});

await vscode.window.showQuickPick(options, {
placeHolder: "Addons (readonly)",
});
}),
vscode.commands.registerCommand(Command.ToggleFeatures, async () => {
// Extract feature descriptions from our package.json
const enabledFeaturesProperties =
Expand Down
9 changes: 5 additions & 4 deletions vscode/src/status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,10 +196,11 @@ export class AddonsStatus extends StatusItem {
} else if (workspace.lspClient.addons.length === 0) {
this.item.text = "Addons: none";
} else {
const addonNames = workspace.lspClient.addons.map((addon) =>
addon.errored ? `${addon.name} (errored)` : `${addon.name}`,
);
this.item.text = `Addons: ${addonNames.join(", ")}`;
this.item.text = `Addons: ${workspace.lspClient.addons.length}`;
this.item.command = {
title: "Details",
command: Command.DisplayAddons,
};
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions vscode/src/test/suite/status.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -304,15 +304,17 @@ suite("StatusItems", () => {
assert.strictEqual(status.item.text, "Addons: none");
});

test("Status displays addon names and errored status", () => {
test("Status displays addon count and command to list commands", () => {
workspace.lspClient!.addons = [
{ name: "foo", errored: false },
{ name: "bar", errored: true },
];

status.refresh(workspace);

assert.strictEqual(status.item.text, "Addons: foo, bar (errored)");
assert.strictEqual(status.item.text, "Addons: 2");
assert.strictEqual(status.item.command?.title, "Details");
assert.strictEqual(status.item.command.command, Command.DisplayAddons);
});
});
});
Loading