дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-09 19:25:54 +02:00
feat(python): support Ruff formatting and config directories (#1573)
Ruff is now an external formatter for Python next to the Ruff language server: Settings › Languages & Frameworks › Ruff has the executable path, a configuration directory (or file), the provider preference, enabled languages, run-on-save, and Reformat with Ruff. Formatting runs on the unsaved document through stdin (with Ruff's --range for selections, in 1-based code-point columns) and never writes the file first. The configuration directory is shared with Ruff LSP, which can then start without a root marker. Tools that can't format a language are rejected even when requested. Co-authored-by: muutot <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
Цей коміт міститься в:
24 files changed
+643
-69
No files matched your search
@@ -147,6 +147,25 @@ describe("missing language server prompt", () => {
|
||||
off();
|
||||
});
|
||||
|
||||
it("offers Ruff formatting even when another Python server is installed", async () => {
|
||||
const installed = sampleTools().find((t) => t.name === "basedpyright")!;
|
||||
backend.tools.push({
|
||||
...installed,
|
||||
name: "ruff",
|
||||
displayName: "Ruff",
|
||||
command: "ruff",
|
||||
installMethod: "uv (virtualenv)",
|
||||
languages: ["Python"],
|
||||
alternatives: [],
|
||||
});
|
||||
await promptInstall("ruff", true, new Set(), true);
|
||||
expect(notes.at(-1)).toMatchObject({
|
||||
title: "Ruff is not installed",
|
||||
body: "Reformat Code needs Ruff. Install it via uv (virtualenv)?",
|
||||
key: missingKey("ruff"),
|
||||
});
|
||||
});
|
||||
|
||||
it("stays silent when an installed alternative serves the same languages", async () => {
|
||||
const off = installMissingServerPrompts();
|
||||
// typescript-language-server (on PATH) covers vtsls' languages.
|
||||
|
||||
@@ -46,7 +46,12 @@ export function activate(): () => void {
|
||||
hidden: true,
|
||||
run: async ({ arg }) => {
|
||||
if (arg && typeof arg === "object" && "name" in arg && typeof arg.name === "string") {
|
||||
await promptInstall(arg.name, !("sticky" in arg) || arg.sticky !== false);
|
||||
await promptInstall(
|
||||
arg.name,
|
||||
!("sticky" in arg) || arg.sticky !== false,
|
||||
new Set(),
|
||||
"formatter" in arg && arg.formatter === true,
|
||||
);
|
||||
}
|
||||
},
|
||||
},
|
||||
|
||||
@@ -21,12 +21,14 @@ export async function promptInstall(
|
||||
name: string,
|
||||
sticky = true,
|
||||
offered: ReadonlySet<string> = new Set(),
|
||||
formatter = false,
|
||||
): Promise<boolean> {
|
||||
if (!useTools.getState().loaded) await refreshTools();
|
||||
const tool = toolByName(name);
|
||||
if (!tool || !tool.canInstall || tool.status !== "missing") return false;
|
||||
const position = tool.alternatives.indexOf(name);
|
||||
if (position > 0 && tool.alternatives.slice(0, position).some((n) => offered.has(n))) return false;
|
||||
formatter ||= tool.kind === "formatter";
|
||||
// An installed alternative (typescript-language-server for vtsls) already serves these files.
|
||||
const served = useTools
|
||||
.getState()
|
||||
@@ -37,17 +39,16 @@ export async function promptInstall(
|
||||
t.status !== "missing" &&
|
||||
t.languages.some((l) => tool.languages.includes(l)),
|
||||
);
|
||||
if (tool.kind !== "formatter" && served) return false;
|
||||
if (!formatter && served) return false;
|
||||
const key = missingKey(name);
|
||||
const langs = tool.languages.length ? tool.languages.join(", ") : "these files";
|
||||
notifications().notify({
|
||||
group: "tools",
|
||||
level: "warning",
|
||||
title: tx`${tool.displayName} is not installed`,
|
||||
body:
|
||||
tool.kind === "formatter"
|
||||
? tx`Reformat Code needs ${tool.displayName}. Install it via ${tool.installMethod}?`
|
||||
: tx`Code insight for ${langs} needs ${tool.command}. Install it via ${tool.installMethod}?`,
|
||||
body: formatter
|
||||
? tx`Reformat Code needs ${tool.displayName}. Install it via ${tool.installMethod}?`
|
||||
: tx`Code insight for ${langs} needs ${tool.command}. Install it via ${tool.installMethod}?`,
|
||||
key,
|
||||
sticky,
|
||||
actions: [
|
||||
|
||||
Reference in new issue
Заблокувати користувача