дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-11-09 11:15:40 +02:00
feat(lsp): run language servers in a plugin run target (#2250)
* feat(lsp): run language servers in a plugin run target * test(settings): list the language server targets page
Цей коміт міститься в:
1 джерело
f8e15a7980
коміт
0e81c6aeb1
38 files changed
+1462
-40
No files matched your search
@@ -1,6 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { commands } from "@/platform/ipc";
|
||||
import { provideEditorService } from "@/workbench/contributions";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { Text } from "@codemirror/state";
|
||||
import { fragmentOffset, linkReference, looksLikePath, resolvePath, textReference } from "./links";
|
||||
import { fragmentOffset, followReference, linkReference, looksLikePath, resolvePath, textReference } from "./links";
|
||||
|
||||
const at = (src: string, marker = "|") => {
|
||||
const offset = src.indexOf(marker);
|
||||
@@ -90,3 +92,30 @@ describe("links and fragments", () => {
|
||||
expect(fragmentOffset("x", "/i.html", "nope")).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
it("opens a container document link in the editor and resolves its fragment through virtual content", async () => {
|
||||
const uri = "openidea-target://target/7/usr/lib/library.php";
|
||||
const openFile = vi.fn(async () => {});
|
||||
provideEditorService({ openFile } as never);
|
||||
const read = vi.spyOn(commands, "lspVirtualDocument").mockResolvedValue({
|
||||
status: "ok",
|
||||
data: {
|
||||
uri,
|
||||
text: "<?php\nfunction library() {}\n",
|
||||
title: "library.php",
|
||||
description: null,
|
||||
languageId: "php",
|
||||
decompiled: false,
|
||||
},
|
||||
});
|
||||
const disk = vi.spyOn(commands, "fsReadText");
|
||||
try {
|
||||
await followReference({ kind: "file", path: uri, fragment: "L2", from: 0, to: 1 });
|
||||
expect(read).toHaveBeenCalledWith(uri);
|
||||
expect(disk).not.toHaveBeenCalled();
|
||||
expect(openFile).toHaveBeenCalledWith(uri, { focus: true, selection: { line: 1, col: 0 } });
|
||||
} finally {
|
||||
read.mockRestore();
|
||||
disk.mockRestore();
|
||||
}
|
||||
});
|
||||
@@ -10,6 +10,7 @@ import type { Text } from "@codemirror/state";
|
||||
import type { EditorView } from "@codemirror/view";
|
||||
import { whenSynced, type EditorDocContext } from "@/editor/api";
|
||||
import { call, commands, isTauri, type DocumentLink } from "@/platform/ipc";
|
||||
import { isVirtualUri } from "@/platform/virtualDocs";
|
||||
import { openExternalUrl } from "@/platform/openUrl";
|
||||
import { executeAction } from "@/platform/actions";
|
||||
import { editorService } from "@/workbench/contributions";
|
||||
@@ -179,7 +180,11 @@ export async function followReference(ref: Reference): Promise<void> {
|
||||
if (ref.kind !== "file") return;
|
||||
let selection: { line: number; col: number } | undefined;
|
||||
if (ref.fragment) {
|
||||
const text = await call(commands.fsReadText(ref.path)).catch(() => null);
|
||||
const text = await (
|
||||
isVirtualUri(ref.path)
|
||||
? call(commands.lspVirtualDocument(ref.path)).then((doc) => doc.text)
|
||||
: call(commands.fsReadText(ref.path))
|
||||
).catch(() => null);
|
||||
const offset = text === null ? null : fragmentOffset(text, ref.path, ref.fragment);
|
||||
if (text !== null && offset !== null) {
|
||||
const before = text.slice(0, offset);
|
||||
@@ -202,7 +207,7 @@ export async function referenceAt(view: EditorView, doc: EditorDocContext, offse
|
||||
if (!ref || doc.virtual) return ref?.kind === "url" ? ref : null;
|
||||
return resolvePath(ref, doc.path);
|
||||
}
|
||||
if (await isFile(link.path)) return link;
|
||||
if (isVirtualUri(link.path) || (await isFile(link.path))) return link;
|
||||
// Servers resolve `/x` against the file system or workspace root; web roots (`public/`) are ours.
|
||||
const own = ref && !doc.virtual ? await resolvePath(ref, doc.path) : null;
|
||||
if (own) return own;
|
||||
|
||||
Reference in new issue
Заблокувати користувача