diff --git a/src/features/tools/LanguageServersPage.tsx b/src/features/tools/LanguageServersPage.tsx index 593b6aba16..6b5cf59f4c 100644 --- a/src/features/tools/LanguageServersPage.tsx +++ b/src/features/tools/LanguageServersPage.tsx @@ -84,10 +84,14 @@ function firstToInstall(tools: readonly ToolInfo[]): ToolInfo | undefined { function languageEntry(name: string, tools: ToolInfo[]): LanguageEntry { const servers = tools.filter((t) => t.kind === "languageServer"); + // When there is a primary server with fallbacks, an additional server (e.g. Ruff) + // does not satisfy that chain. + const alternatives = servers.filter((t) => t.alternatives.length > 0); + const primaryServers = alternatives.length ? alternatives : servers; const debuggers = tools.filter((t) => t.kind === "debugger"); - const noServer = servers.length > 0 && !servers.some(available); + const noServer = primaryServers.length > 0 && !primaryServers.some(available); const noDebugger = debuggers.length > 0 && !debuggers.some(available); - const missing = [noServer && firstToInstall(servers), noDebugger && firstToInstall(debuggers)].filter( + const missing = [noServer && firstToInstall(primaryServers), noDebugger && firstToInstall(debuggers)].filter( (t): t is ToolInfo => !!t, ); const state = !missing.length ? "ready" : noServer && (noDebugger || !debuggers.length) ? "none" : "partial"; diff --git a/src/features/tools/__tests__/tools.test.tsx b/src/features/tools/__tests__/tools.test.tsx index f81e03d102..d5fde8659b 100644 --- a/src/features/tools/__tests__/tools.test.tsx +++ b/src/features/tools/__tests__/tools.test.tsx @@ -224,6 +224,23 @@ describe("tools store", () => { expect(filterLanguages(langs, "", true).map((l) => l.name)).not.toContain("TypeScript"); }); + it("still reports a missing Python analyzer when Ruff and refactorings are installed", () => { + const python = sampleTools().filter((t) => t.languages.includes("Python")); + const template = python[0]!; + const supplemental = [ + { ...template, name: "ruff", alternatives: [], status: "onPath" as const }, + { ...template, name: "pylsp", alternatives: [], companion: true, status: "installed" as const }, + ]; + const entry = groupByLanguage([...python, ...supplemental])[0]!; + expect(entry.missing.map((t) => t.name)).toEqual(["basedpyright"]); + expect( + groupByLanguage([ + ...python.map((t) => (t.name === "pyright" ? { ...t, status: "onPath" as const } : t)), + ...supplemental, + ])[0]!.missing, + ).toEqual([]); + }); + it("lists tools serving no language under Other Tools, last", () => { const cli = { ...sampleTools()[0]!, @@ -355,7 +372,25 @@ describe("missing language server prompt", () => { }); }); + it("offers a primary analyzer despite installed Python supplemental servers", async () => { + const template = sampleTools().find((t) => t.name === "basedpyright")!; + backend.tools.push( + { ...template, name: "ruff", alternatives: [], status: "onPath" }, + { ...template, name: "pylsp", alternatives: [], companion: true, status: "installed" }, + ); + expect(await promptInstall("basedpyright")).toBe(true); + expect(notes.map((n) => n.key)).toEqual([missingKey("basedpyright")]); + }); + + it("stays silent when a genuine Python analyzer fallback is available", async () => { + backend.tools = backend.tools.map((t) => (t.name === "pyright" ? { ...t, status: "onPath" } : t)); + expect(await promptInstall("basedpyright")).toBe(false); + expect(notes).toEqual([]); + }); + it("stays silent when an installed alternative serves the same languages", async () => { + const alternatives = ["vtsls", "typescript-language-server"]; + backend.tools = backend.tools.map((t) => (alternatives.includes(t.name) ? { ...t, alternatives } : t)); const off = installMissingServerPrompts(); // typescript-language-server (on PATH) covers vtsls' languages. emitLocalIdeEvent({ @@ -372,6 +407,26 @@ describe("missing language server prompt", () => { off(); }); + it("does not treat an installed TypeScript linter as a primary server", async () => { + const alternatives = ["vtsls", "typescript-language-server"]; + backend.tools = backend.tools.map((t) => + alternatives.includes(t.name) ? { ...t, alternatives, status: "missing" } : t, + ); + backend.tools.push({ + ...backend.tools.find((t) => t.name === "vtsls")!, + name: "eslint", + alternatives: [], + status: "onPath", + }); + expect( + groupByLanguage(backend.tools) + .find((entry) => entry.name === "TypeScript")! + .missing.map((t) => t.name), + ).toEqual(["vtsls"]); + expect(await promptInstall("vtsls")).toBe(true); + expect(notes.map((n) => n.key)).toEqual([missingKey("vtsls")]); + }); + it("offers only the first missing server of interchangeable ones", async () => { const off = installMissingServerPrompts(); // basedpyright is missing, so its fallbacks start and turn out missing too; gopls isn't one of them. diff --git a/src/features/tools/missing.ts b/src/features/tools/missing.ts index 817cf47ced..e1ad131f36 100644 --- a/src/features/tools/missing.ts +++ b/src/features/tools/missing.ts @@ -44,6 +44,7 @@ export async function promptInstall( t.name !== name && t.kind === tool.kind && t.status !== "missing" && + (!tool.alternatives.length || tool.alternatives.includes(t.name)) && t.languages.some((l) => tool.languages.includes(l)), ); if (!formatter && !refactoring && served) return false;