Skip to content

Commit cb10eb9

Browse files
authored
Use quickpick UI to display addons list (#2205)
- This allows the extension to display multiple addons with enough space to show more attributes (e.g. gem name, version, etc.) in the future - Each entry displays the addon's name and an icon indicating its errored status - Selecting an entry currently doesn't do anything
1 parent a8a03f0 commit cb10eb9

5 files changed

Lines changed: 42 additions & 6 deletions

File tree

vscode/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,11 @@
6666
"title": "Toggle features",
6767
"category": "Ruby LSP"
6868
},
69+
{
70+
"command": "rubyLsp.displayAddons",
71+
"title": "Display addons",
72+
"category": "Ruby LSP"
73+
},
6974
{
7075
"command": "rubyLsp.runTest",
7176
"title": "Run current test",

vscode/src/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export enum Command {
1818
RunTestInTerminal = "rubyLsp.runTestInTerminal",
1919
DebugTest = "rubyLsp.debugTest",
2020
ShowSyntaxTree = "rubyLsp.showSyntaxTree",
21+
DisplayAddons = "rubyLsp.displayAddons",
2122
}
2223

2324
export interface RubyInterface {

vscode/src/rubyLsp.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,33 @@ export class RubyLsp {
214214
),
215215
);
216216
}),
217+
vscode.commands.registerCommand(Command.DisplayAddons, async () => {
218+
const client = this.currentActiveWorkspace()?.lspClient;
219+
220+
if (!client || !client.addons) {
221+
return;
222+
}
223+
224+
const options: vscode.QuickPickItem[] = client.addons
225+
.sort((addon) => {
226+
// Display errored addons last
227+
if (addon.errored) {
228+
return 1;
229+
}
230+
231+
return -1;
232+
})
233+
.map((addon) => {
234+
const icon = addon.errored ? "$(error)" : "$(pass)";
235+
return {
236+
label: `${icon} ${addon.name}`,
237+
};
238+
});
239+
240+
await vscode.window.showQuickPick(options, {
241+
placeHolder: "Addons (readonly)",
242+
});
243+
}),
217244
vscode.commands.registerCommand(Command.ToggleFeatures, async () => {
218245
// Extract feature descriptions from our package.json
219246
const enabledFeaturesProperties =

vscode/src/status.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,11 @@ export class AddonsStatus extends StatusItem {
196196
} else if (workspace.lspClient.addons.length === 0) {
197197
this.item.text = "Addons: none";
198198
} else {
199-
const addonNames = workspace.lspClient.addons.map((addon) =>
200-
addon.errored ? `${addon.name} (errored)` : `${addon.name}`,
201-
);
202-
this.item.text = `Addons: ${addonNames.join(", ")}`;
199+
this.item.text = `Addons: ${workspace.lspClient.addons.length}`;
200+
this.item.command = {
201+
title: "Details",
202+
command: Command.DisplayAddons,
203+
};
203204
}
204205
}
205206
}

vscode/src/test/suite/status.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -305,15 +305,17 @@ suite("StatusItems", () => {
305305
assert.strictEqual(status.item.text, "Addons: none");
306306
});
307307

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

314314
status.refresh(workspace);
315315

316-
assert.strictEqual(status.item.text, "Addons: foo, bar (errored)");
316+
assert.strictEqual(status.item.text, "Addons: 2");
317+
assert.strictEqual(status.item.command?.title, "Details");
318+
assert.strictEqual(status.item.command.command, Command.DisplayAddons);
317319
});
318320
});
319321
});

0 commit comments

Comments
 (0)