дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-05 17:47:08 +02:00
Go signatures already linked their type names (#3959). For other languages the name is looked up near the documented symbol's declaration and the language server's definition there is the target; parameters, the symbol's own name, inferred types and names with several definitions don't link. Names resolve on hover, so only those that lead somewhere look like links, and only the signature code blocks are considered (leading blocks, or the one after the last rule for clangd). Plain names a grammar leaves untagged get a tok-name span so they can be followed. Refs #3874 Co-authored-by: wildcatDownstairs <[email protected]>
50 рядки
2.5 KiB
TypeScript
50 рядки
2.5 KiB
TypeScript
import { describe, expect, it, vi } from "vitest";
|
|
import { fireEvent } from "@testing-library/react";
|
|
|
|
const signatureNameTarget = vi.fn(async (_decl: unknown, name: string, _lines: number) =>
|
|
name === "Item" ? { path: "/w/src/model.rs", line: 4, col: 11 } : null,
|
|
);
|
|
vi.mock("./docLinks/signature", () => ({ signatureNameTarget }));
|
|
|
|
const { linkSignatureTypes } = await import("./docs");
|
|
|
|
describe("signature names", () => {
|
|
it("resolve in the signature blocks only, and look like links once they lead somewhere", async () => {
|
|
const dom = document.createElement("div");
|
|
// rust-analyzer: module path, signature, rule, docs with an example.
|
|
dom.innerHTML =
|
|
'<pre><code class="language-rust">inventory</code></pre>' +
|
|
'<pre><code class="language-rust">pub fn take(<span class="tok-variableName tok-definition">items</span>: ' +
|
|
'<span class="tok-typeName">Vec</span><<span class="tok-typeName">Item</span>>)</code></pre>' +
|
|
'<hr><p>Takes them.</p><pre><code class="language-rust"><span class="tok-typeName">Item</span></code></pre>';
|
|
const decl = { path: "/w/src/lib.rs", range: { start: { line: 3, col: 7 }, end: { line: 3, col: 11 } } };
|
|
linkSignatureTypes(dom, "window", {
|
|
markup: { kind: "markdown", value: "" },
|
|
language: null,
|
|
source: async () => decl,
|
|
});
|
|
const [items, vec, item, example] = [...dom.querySelectorAll("span")];
|
|
for (const el of [items!, vec!, item!, example!]) fireEvent.mouseOver(el);
|
|
await vi.waitFor(() => expect(item!.hasAttribute("data-doc-ref")).toBe(true));
|
|
expect(vec!.hasAttribute("data-doc-ref")).toBe(false);
|
|
expect(signatureNameTarget.mock.calls.map((c) => c[1])).toEqual(["Vec", "Item"]);
|
|
expect(signatureNameTarget).toHaveBeenCalledWith(decl, "Item", 1);
|
|
});
|
|
|
|
it("include the block closing the documentation after a rule (clangd)", async () => {
|
|
signatureNameTarget.mockClear();
|
|
const dom = document.createElement("div");
|
|
dom.innerHTML =
|
|
"<h3>function take</h3><hr><p>Takes them.</p><hr>" +
|
|
'<pre><code class="language-cpp">void take(<span class="tok-typeName">Item</span> i)</code></pre>';
|
|
const decl = { path: "/w/take.cpp", range: { start: { line: 1, col: 5 }, end: { line: 1, col: 9 } } };
|
|
linkSignatureTypes(dom, "window", {
|
|
markup: { kind: "markdown", value: "" },
|
|
language: null,
|
|
source: async () => decl,
|
|
});
|
|
fireEvent.mouseOver(dom.querySelector("span")!);
|
|
await vi.waitFor(() => expect(dom.querySelector("[data-doc-ref]")?.textContent).toBe("Item"));
|
|
});
|
|
});
|