mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-24 16:04:21 +00:00
fix(python): an interpreter chosen but not applied yet is not reported missing (#3871)
The interpreter page compared the chosen interpreter with the one the backend resolves, which follows the applied setting. A virtualenv just created (or any other choice before Apply) showed "The configured Python interpreter no longer exists" until the page was opened again. Only the applied interpreter is judged now, and the check runs again once a choice is applied.
This commit is contained in:
@@ -104,3 +104,16 @@ describe("run target interpreter", () => {
|
||||
expect(mocks.container).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
describe("missing interpreter", () => {
|
||||
it("reports the applied interpreter gone, not one chosen and not applied yet", async () => {
|
||||
const { stage } = await import("../model/staging");
|
||||
mocks.effective.mockResolvedValue(ok("/usr/bin/python3"));
|
||||
mount("/gone/bin/python");
|
||||
expect(await screen.findByRole("alert")).toHaveTextContent("no longer exists");
|
||||
// An environment just created, staged until Apply: the backend still resolves the old setting.
|
||||
stage("python.interpreter", "project", "languages.python.interpreter", "/p/.venv/bin/python");
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
expect(screen.queryByRole("alert")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -33,6 +33,15 @@ export function useSetting<T>(key: string, scopeOverride?: Scope): [T, (value: T
|
||||
return [value, set];
|
||||
}
|
||||
|
||||
/** The value of a settings key as last applied, without this dialog's staged edits. */
|
||||
export function useAppliedSetting<T>(key: string, scopeOverride?: Scope): T {
|
||||
const { scope: pageScope } = usePageContext();
|
||||
const scope = scopeOverride ?? pageScope;
|
||||
const base = useSettingsDialog((s) => s.base);
|
||||
const globalBase = useSettingsDialog((s) => s.globalBase);
|
||||
return useMemo(() => stagedValue({ base, globalBase, staged: {} }, scope, key), [base, globalBase, scope, key]) as T;
|
||||
}
|
||||
|
||||
/** `stagedValue` for components; recomputed only when the base or the staged edits change. */
|
||||
export function useStagedValue(scope: Scope, key: string): unknown {
|
||||
const base = useSettingsDialog((s) => (scope === "global" ? s.globalBase : s.base));
|
||||
|
||||
@@ -24,7 +24,7 @@ import {
|
||||
} from "./api";
|
||||
import { validateRunTargets, type RunTargetValid } from "@/platform/remoteSettings";
|
||||
import { AddInterpreterDialog } from "./AddInterpreterDialog";
|
||||
import { useSetting } from "../components/context";
|
||||
import { useAppliedSetting, useSetting } from "../components/context";
|
||||
import { SdkField, tildify } from "./components";
|
||||
import { interpreterIcon, sameInterpreterPath, usePythonInterpreters } from "./interpreters";
|
||||
import styles from "./Sdk.module.css";
|
||||
@@ -160,21 +160,25 @@ export function PythonInterpreterPage() {
|
||||
}, [root, created]);
|
||||
|
||||
// The interpreter runs resolve to: the configured one while it exists, else the fallback.
|
||||
// The backend resolves the applied setting, so only that one can be judged here: a choice
|
||||
// not applied yet (an environment just created) is not reported missing.
|
||||
const applied = useAppliedSetting<string>("languages.python.interpreter");
|
||||
const [resolved, setResolved] = useState<{ interpreter: string; path: string | null } | null>(null);
|
||||
useEffect(() => {
|
||||
if (!interpreter) return;
|
||||
if (!applied) return;
|
||||
let live = true;
|
||||
effectivePython()
|
||||
.then((path) => live && setResolved({ interpreter, path }))
|
||||
.then((path) => live && setResolved({ interpreter: applied, path }))
|
||||
.catch(() => live && setResolved(null));
|
||||
return () => {
|
||||
live = false;
|
||||
};
|
||||
}, [root, interpreter, created]);
|
||||
}, [root, applied, created]);
|
||||
// A configured interpreter whose executable is gone (PyCharm's "Invalid"): runs fall back.
|
||||
const invalid =
|
||||
!target &&
|
||||
!!interpreter &&
|
||||
interpreter === applied &&
|
||||
resolved?.interpreter === interpreter &&
|
||||
!sameInterpreter(resolved.path, interpreter, root);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user