fix(tools): don't mistake supplemental servers for analyzer fallbacks (#8235)

* fix(tools): don't mistake supplemental servers for analyzer fallbacks

* fix(tools): scope language server alternative chains to the current language
Цей коміт міститься в:
l0ng-ai authored and GitHub committed 2026-12-06 20:37:56 +08:00
1 джерело fb6d60a577
коміт d1b03e837a
3 files changed
+115 -2

No files matched your search

+9 -2
Переглянути файл
@@ -84,10 +84,17 @@ 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 for this language, an additional
// server (e.g. Ruff) does not satisfy that chain. Require >1 chain member in this
// language so a shared server's alternatives from another language do not drop
// this language's standalone primary server (e.g. YAML + phpantom, Vue/CSS + vtsls).
const serverNames = new Set(servers.map((t) => t.name));
const alternatives = servers.filter((t) => t.alternatives.filter((a) => serverNames.has(a)).length > 1);
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";
+105
Переглянути файл
@@ -224,6 +224,73 @@ 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("keeps a language's standalone primary server when a shared server has alternatives from another language", () => {
const template = sampleTools().find((t) => t.name === "vtsls")!;
const yamlPrimary = {
...template,
name: "yaml-language-server",
displayName: "yaml-language-server",
command: "yaml-language-server",
languages: ["YAML"],
alternatives: [],
status: "installed" as const,
};
const phpShared = {
...template,
name: "phpantom",
displayName: "PHPantom",
command: "phpantom",
languages: ["PHP", "YAML"],
alternatives: ["intelephense", "phpactor", "phpantom"],
status: "missing" as const,
};
const yamlReady = groupByLanguage([yamlPrimary, phpShared]).find((e) => e.name === "YAML")!;
expect(yamlReady).toMatchObject({ state: "ready", missing: [] });
const yamlMissing = groupByLanguage([{ ...yamlPrimary, status: "missing" as const }, phpShared]).find(
(e) => e.name === "YAML",
)!;
expect(yamlMissing.state).toBe("none");
expect(yamlMissing.missing.map((t) => t.name)).toEqual(["yaml-language-server"]);
// Vue with standalone vue-language-server + vtsls carrying TypeScript alternatives.
const vuePrimary = {
...template,
name: "vue-language-server",
displayName: "Vue Language Server",
command: "vue-language-server",
languages: ["Vue"],
alternatives: [],
status: "installed" as const,
};
const vtslsShared = {
...template,
name: "vtsls",
languages: ["TypeScript", "Vue"],
alternatives: ["vtsls", "typescript-language-server"],
status: "missing" as const,
};
const vueReady = groupByLanguage([vuePrimary, vtslsShared]).find((e) => e.name === "Vue")!;
expect(vueReady).toMatchObject({ state: "ready", missing: [] });
});
it("lists tools serving no language under Other Tools, last", () => {
const cli = {
...sampleTools()[0]!,
@@ -355,7 +422,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 +457,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.
+1
Переглянути файл
@@ -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;