mirror of
https://github.com/l0ng-ai/openidea.git
synced 2026-11-13 04:34:21 -10:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b3519c7f8 | ||
|
|
fdc8bc2d4c |
No files matched your search
@@ -46,7 +46,7 @@ it("keeps mapped lenses across edits instead of clearing them (#2710)", async ()
|
||||
data: [
|
||||
{
|
||||
range: { start: { line: 1, col: 0 }, end: { line: 1, col: 3 } },
|
||||
command: { title: "1 reference", command: "csharp.showReferences", arguments: [] },
|
||||
command: { title: "Run test", command: "csharp.runTest", arguments: [] },
|
||||
},
|
||||
],
|
||||
});
|
||||
@@ -67,5 +67,27 @@ it("keeps mapped lenses across edits instead of clearing them (#2710)", async ()
|
||||
const after = view.state.facet(codeLenses);
|
||||
expect(after).toHaveLength(1);
|
||||
expect(after[0]!.pos).toBe(posBefore + 1);
|
||||
expect(after[0]!.title).toBe("1 reference");
|
||||
expect(after[0]!.title).toBe("Run test");
|
||||
});
|
||||
|
||||
it("leaves reference counts to Code Vision's usages", async () => {
|
||||
vi.useFakeTimers();
|
||||
const lens = (line: number, title: string) => ({
|
||||
range: { start: { line, col: 0 }, end: { line, col: 1 } },
|
||||
command: { title, command: "csharp.showReferences", arguments: [] },
|
||||
});
|
||||
ipc.lspCodeLens.mockResolvedValue({
|
||||
status: "ok",
|
||||
data: [lens(0, "3 Reference(s)"), lens(1, "1 reference"), lens(2, "12 references"), lens(3, "2 implementations")],
|
||||
});
|
||||
const view = new EditorView({
|
||||
state: EditorState.create({
|
||||
doc: "a\nb\nc\nd",
|
||||
extensions: serverCodeLenses({ doc: 1, path: "/p/a.cs", language: "csharp", uiMode: null, readOnly: false }),
|
||||
}),
|
||||
parent: document.body,
|
||||
});
|
||||
views.push(view);
|
||||
await vi.advanceTimersByTimeAsync(400);
|
||||
expect(view.state.facet(codeLenses).map((l) => l.title)).toEqual(["2 implementations"]);
|
||||
});
|
||||
@@ -6,6 +6,12 @@ import { call, commands } from "@/platform/ipc";
|
||||
import { onNavigationProvidersChanged } from "@/editor/navigationProviders";
|
||||
import { posToOffset } from "./positions";
|
||||
import { onLspRefresh, onServerSettled } from "./availability";
|
||||
/**
|
||||
* A server's reference count ("3 references", csharp-ls's "3 Reference(s)"): Code Vision's
|
||||
* Usages shows the same count above the declaration, under its own setting.
|
||||
*/
|
||||
const REFERENCE_COUNT = /^\s*\d+\s+references?(\(s\))?\s*$/i;
|
||||
|
||||
const set = StateEffect.define<CodeLens[]>();
|
||||
const field = StateField.define<CodeLens[]>({
|
||||
create: () => [],
|
||||
@@ -62,7 +68,7 @@ export function serverCodeLenses(ctx: EditorDocContext): Extension {
|
||||
view.dispatch({
|
||||
effects: set.of(
|
||||
result.flatMap((l) =>
|
||||
l.command
|
||||
l.command && !REFERENCE_COUNT.test(l.command.title)
|
||||
? [
|
||||
{
|
||||
pos: posToOffset(text, l.range.start),
|
||||
|
||||
@@ -43,13 +43,23 @@ export function AddInterpreterDialog({
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const ids = { base: useId(), location: useId(), existing: useId() };
|
||||
|
||||
const baseValue = base ?? bases[0]?.path ?? null;
|
||||
const toOption = (s: { path: string; name: string }): SelectOption => ({
|
||||
value: s.path,
|
||||
label: s.name,
|
||||
detail: tildify(s.path),
|
||||
});
|
||||
const baseOptions = bases.map(toOption);
|
||||
// conda installs a fresh Python of the base's version: offer versions, not environments to copy.
|
||||
const versionOptions = (() => {
|
||||
const seen = new Map<string, SelectOption>();
|
||||
for (const s of bases) {
|
||||
const short = s.version?.split(".").slice(0, 2).join(".");
|
||||
if (short && !seen.has(short)) seen.set(short, { value: s.path, label: tx`Python ${short}` });
|
||||
}
|
||||
return [...seen.values()].sort((a, b) => b.label.localeCompare(a.label, undefined, { numeric: true }));
|
||||
})();
|
||||
const baseOptions = kind === "conda" ? versionOptions : bases.map(toOption);
|
||||
const baseValue =
|
||||
base ?? (kind === "conda" ? (versionOptions[0]?.value as string | undefined) : bases[0]?.path) ?? null;
|
||||
const existingOptions = [...browsed, ...list.filter((s) => !browsed.some((b) => b.path === s.path))].map((s) => ({
|
||||
value: s.path,
|
||||
label: `${s.name} — ${tildify(s.path)}`,
|
||||
@@ -108,7 +118,9 @@ export function AddInterpreterDialog({
|
||||
const canOk = !busy && (mode === "new" ? !!baseValue && !!location.trim() : !!existing?.trim());
|
||||
const note = {
|
||||
venv: tx("Runs “<base> -m venv <location>”; the new interpreter becomes the project interpreter."),
|
||||
conda: tx("Runs “conda create -p <location>”; the new interpreter becomes the project interpreter."),
|
||||
conda: tx(
|
||||
"Runs “conda create -p <location> python=<version>”: a new environment with only Python in it; the new interpreter becomes the project interpreter.",
|
||||
),
|
||||
uv: tx("Runs “uv venv <location> --python <base>”; the new interpreter becomes the project interpreter."),
|
||||
poetry: tx(
|
||||
"Runs “poetry env use <base>” in the project; poetry keeps the environment under its own cache directory.",
|
||||
@@ -143,6 +155,7 @@ export function AddInterpreterDialog({
|
||||
aria-current={kind === k.tool || undefined}
|
||||
onClick={() => {
|
||||
setKind(k.tool);
|
||||
setBase(null);
|
||||
setError(null);
|
||||
}}
|
||||
>
|
||||
@@ -199,9 +212,7 @@ export function AddInterpreterDialog({
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<label htmlFor={ids.base}>
|
||||
<T>Base interpreter:</T>
|
||||
</label>
|
||||
<label htmlFor={ids.base}>{kind === "conda" ? <T>Python version:</T> : <T>Base interpreter:</T>}</label>
|
||||
<div className={styles.pathRow}>
|
||||
<Select
|
||||
className={styles.pathInput}
|
||||
@@ -209,17 +220,19 @@ export function AddInterpreterDialog({
|
||||
options={baseOptions}
|
||||
onChange={setBase}
|
||||
placeholder={loading ? "Detecting…" : "No Python found"}
|
||||
aria-label="Base interpreter"
|
||||
/>
|
||||
<IconButton
|
||||
icon="folder-open"
|
||||
size="small"
|
||||
title="Browse…"
|
||||
onClick={async () => {
|
||||
const p = await choosePath({ directory: false, title: "Select Base Interpreter" });
|
||||
if (p) setBase(p);
|
||||
}}
|
||||
aria-label={kind === "conda" ? "Python version" : "Base interpreter"}
|
||||
/>
|
||||
{kind !== "conda" && (
|
||||
<IconButton
|
||||
icon="folder-open"
|
||||
size="small"
|
||||
title="Browse…"
|
||||
onClick={async () => {
|
||||
const p = await choosePath({ directory: false, title: "Select Base Interpreter" });
|
||||
if (p) setBase(p);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className={styles.note}>{note}</div>
|
||||
</>
|
||||
|
||||
@@ -68,6 +68,8 @@ export function PythonInterpreterPage() {
|
||||
const [activate, setActivate] = useSetting<boolean>("languages.python.activateVirtualenv");
|
||||
const root = useProject((s) => s.project?.root ?? null);
|
||||
const [auto, setAuto] = useState<string | null>(null);
|
||||
// Bumped when an environment is created: it may reuse the configured path, whose state changed.
|
||||
const [created, setCreated] = useState(0);
|
||||
// Detected interpreters plus the ones added to (or hidden from) the IDE-wide list.
|
||||
const { detected, rows, hidden } = usePythonInterpreters({ withProjects: false });
|
||||
const extras = useMemo(
|
||||
@@ -91,7 +93,7 @@ export function PythonInterpreterPage() {
|
||||
return () => {
|
||||
live = false;
|
||||
};
|
||||
}, [root]);
|
||||
}, [root, created]);
|
||||
|
||||
// The interpreter runs resolve to: the configured one while it exists, else the fallback.
|
||||
const [resolved, setResolved] = useState<{ interpreter: string; path: string | null } | null>(null);
|
||||
@@ -104,7 +106,7 @@ export function PythonInterpreterPage() {
|
||||
return () => {
|
||||
live = false;
|
||||
};
|
||||
}, [root, interpreter]);
|
||||
}, [root, interpreter, created]);
|
||||
// A configured interpreter whose executable is gone (PyCharm's "Invalid"): runs fall back.
|
||||
const invalid =
|
||||
!!interpreter && resolved?.interpreter === interpreter && !sameInterpreter(resolved.path, interpreter, root);
|
||||
@@ -362,6 +364,8 @@ export function PythonInterpreterPage() {
|
||||
onClose={() => setAdding(false)}
|
||||
onAdded={(path) => {
|
||||
setInterpreter(path);
|
||||
setCreated((n) => n + 1);
|
||||
reload();
|
||||
setAdding(false);
|
||||
}}
|
||||
/>
|
||||
|
||||
@@ -5217,7 +5217,9 @@
|
||||
"{count} modified action": "已修改 {count} 个操作",
|
||||
"{count} modified actions": "已修改 {count} 个操作",
|
||||
"Runs “<base> -m venv <location>”; the new interpreter becomes the project interpreter.": "运行“<base> -m venv <location>”;新的解释器将成为项目解释器。",
|
||||
"Runs “conda create -p <location>”; the new interpreter becomes the project interpreter.": "运行“conda create -p <location>”;新的解释器将成为项目解释器。",
|
||||
"Runs “conda create -p <location> python=<version>”: a new environment with only Python in it; the new interpreter becomes the project interpreter.": "运行“conda create -p <location> python=<version>”:新建一个只包含 Python 的环境;新的解释器将成为项目解释器。",
|
||||
"Python version": "Python 版本",
|
||||
"Python {short}": "Python {short}",
|
||||
"Runs “poetry env use <base>” in the project; poetry keeps the environment under its own cache directory.": "在项目中运行“poetry env use <base>”;Poetry 会将环境保存在其自己的缓存目录下。",
|
||||
"Runs “uv venv <location> --python <base>”; the new interpreter becomes the project interpreter.": "运行“uv venv <location> --python <base>”;新的解释器将成为项目解释器。",
|
||||
"{vendor} {version} is unpacked into a folder of its own in {location}, where JDK detection finds it.": "{vendor} {version} 将解压到 {location} 下它自己的文件夹中,JDK 检测会在那里找到它。",
|
||||
|
||||
Reference in new issue
Block a user