дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 01:01:17 +02:00
Roslyn's inlay hints are off unless the client turns them on, and csharp.toml passed no csharp|inlay_hints settings, so C# showed no parameter name or type hints. csharp.toml and razor.toml now enable parameter hints for literals, new-expressions and indexers (with Roslyn's suppressions) and var/lambda parameter types. Parameter info matches string parameter labels as whole words from the parameter list on (all servers) and keeps a variadic last parameter (params, ..., *args) bold. The real-server test is ignored by default (needs the .NET SDK). Closes #7678 Co-authored-by: wildcatDownstairs <[email protected]>
196 рядки
7.8 KiB
TypeScript
196 рядки
7.8 KiB
TypeScript
/**
|
||
* C# inlay hints and parameter info (#7678). The host is stubbed at the IPC layer with the answers
|
||
* Roslyn gives; `crates/ide-host/tests/roslyn_hints.rs` gets them from the real server.
|
||
*/
|
||
import type { Page } from "@playwright/test";
|
||
import type { InlayHint, SignatureHelp } from "../src/bindings";
|
||
import { expect, openFromTree, stubDesktop, stubSettingsWrites, test } from "./fixtures";
|
||
|
||
const SHOTS = process.env.E2E_SHOTS;
|
||
|
||
/** Roslyn's hints written in: `‹name:›` before an argument, `«type»` before a name. */
|
||
const ANNOTATED = `public class Demo
|
||
{
|
||
static int Add(int first, int second) => first + second;
|
||
static void Log(string format, params object[] args) { }
|
||
|
||
public void Run(int total)
|
||
{
|
||
var «int»sum = Add(‹first:›1, ‹second:›2);
|
||
var «Point?»point = new Point(‹X:›3, ‹Y:›4);
|
||
Add(total, ‹second:›3);
|
||
var «IEnumerable<int>?»xs = list.Select(«int»n => n + 1);
|
||
Log
|
||
}
|
||
}
|
||
`;
|
||
|
||
function fixture() {
|
||
const hints: InlayHint[] = [];
|
||
const text = ANNOTATED.split("\n")
|
||
.map((line, number) => {
|
||
let out = "";
|
||
for (const part of line.split(/(‹[^›]*›|«[^»]*»)/)) {
|
||
if (!/^[‹«]/.test(part)) {
|
||
out += part;
|
||
continue;
|
||
}
|
||
const parameter = part.startsWith("‹");
|
||
hints.push({
|
||
position: { line: number, col: out.length },
|
||
label: part.slice(1, -1),
|
||
kind: parameter ? "parameter" : "type",
|
||
paddingLeft: false,
|
||
paddingRight: true,
|
||
tooltip: null,
|
||
parts: [],
|
||
textEdits: [],
|
||
});
|
||
}
|
||
return out;
|
||
})
|
||
.join("\n");
|
||
return { text, hints };
|
||
}
|
||
|
||
/** A C# file in the sample project, open, with the host stubbed. */
|
||
async function openProgram(page: Page) {
|
||
const { text, hints } = fixture();
|
||
await page.evaluate(async () => {
|
||
const projectModule = "/src/platform/project.ts";
|
||
const filesModule = "/src/features/project-tree/fs.ts";
|
||
const { useProject } = await import(/* @vite-ignore */ projectModule);
|
||
const { projectFs } = await import(/* @vite-ignore */ filesModule);
|
||
const root = useProject.getState().project.root;
|
||
await projectFs(root).createFile(`${root}/Program.cs`);
|
||
});
|
||
const editor = await openFromTree(page, "Program.cs");
|
||
// The in-memory document starts as its path in a comment: replace it with the fixture.
|
||
const content = editor.locator(".cm-content");
|
||
await expect(content).toContainText("Program.cs");
|
||
await content.click();
|
||
await page.keyboard.press("Meta+a");
|
||
await page.keyboard.insertText(text);
|
||
await expect(content).toContainText("public class Demo");
|
||
await stubDesktop(page);
|
||
await stubSettingsWrites(page);
|
||
return { editor, hints };
|
||
}
|
||
|
||
/** Answers `lsp_inlay_hints` with `hints` and has the editor ask again. */
|
||
async function answerHints(page: Page, hints: InlayHint[]) {
|
||
await page.evaluate(async (hints) => {
|
||
const projectModule = "/src/platform/project.ts";
|
||
const availabilityModule = "/src/editor/lsp/availability.ts";
|
||
const { useProject } = await import(/* @vite-ignore */ projectModule);
|
||
const { clearBackoffs } = await import(/* @vite-ignore */ availabilityModule);
|
||
window.__ipc.handlers.lsp_inlay_hints = () => hints;
|
||
// The editor opened before the stub: its request failed, and it waits before asking again.
|
||
clearBackoffs();
|
||
// A new `editor.inlay` object has the editor ask again.
|
||
const { settings } = useProject.getState();
|
||
const editor = { ...settings?.editor, inlay: { ...settings?.editor?.inlay } };
|
||
useProject.setState({ settings: { ...settings, editor } });
|
||
}, hints);
|
||
}
|
||
|
||
test("C# parameter name and type hints show, and turn off by kind", async ({ workbench: page }) => {
|
||
const { editor, hints } = await openProgram(page);
|
||
const shown = editor.locator(".cm-lsp-inlay");
|
||
// What Roslyn answered without the `csharp|inlay_hints` settings: nothing.
|
||
await answerHints(page, []);
|
||
await expect(shown).toHaveCount(0);
|
||
if (SHOTS) await page.screenshot({ path: `${SHOTS}/csharp-hints-before.png` });
|
||
|
||
await answerHints(page, hints);
|
||
await expect(shown).toHaveCount(hints.length);
|
||
await expect(editor.locator(".cm-line", { hasText: "sum" })).toHaveText(
|
||
" var intsum = Add(first:1, second:2);",
|
||
);
|
||
if (SHOTS) await page.screenshot({ path: `${SHOTS}/csharp-hints-after.png` });
|
||
|
||
await editor.locator(".cm-lsp-inlay-parameter").first().click({ button: "right" });
|
||
await page.getByRole("menuitem", { name: "Disable Parameter name hints" }).click();
|
||
await expect(editor.locator(".cm-lsp-inlay-parameter")).toHaveCount(0);
|
||
await expect(editor.locator(".cm-lsp-inlay-type")).toHaveCount(hints.filter((h) => h.kind === "type").length);
|
||
|
||
await editor.locator(".cm-lsp-inlay-type").first().click({ button: "right" });
|
||
await page.getByRole("menuitem", { name: "Disable Type hints" }).click();
|
||
await expect(shown).toHaveCount(0);
|
||
});
|
||
|
||
test("C# parameter info bolds the argument being typed, `params` included", async ({ workbench: page }) => {
|
||
const { editor } = await openProgram(page);
|
||
// Roslyn's answer: the parameters by name, `activeParameter` counting past the `params` array.
|
||
const log: SignatureHelp["signatures"][number] = {
|
||
label: "void Demo.Log(string format, params object[] args)",
|
||
parameters: [
|
||
[21, 27],
|
||
[45, 49],
|
||
],
|
||
documentation: null,
|
||
};
|
||
await page.evaluate((log) => {
|
||
window.__ipc.handlers.lsp_signature_help = (args) => {
|
||
const { line, col } = (args as { pos: { line: number; col: number } }).pos;
|
||
// The caret's line up to the caret: no answer outside the parentheses.
|
||
const view = document.querySelectorAll(".cm-line")[line]!.textContent!.slice(0, col);
|
||
if (!view.includes("(") || view.includes(")")) return null;
|
||
return { signatures: [log], activeSignature: 0, activeParameter: view.split(",").length - 1 };
|
||
};
|
||
}, log);
|
||
await editor.locator(".cm-line", { hasText: /^ {8}Log$/ }).click();
|
||
await page.keyboard.press("End");
|
||
|
||
const popup = page.locator(".cm-lsp-signature");
|
||
await page.keyboard.type("(");
|
||
await expect(popup.locator("b")).toHaveText("format");
|
||
await page.keyboard.type('"{0}", ');
|
||
await expect(popup.locator("b")).toHaveText("args");
|
||
await page.keyboard.type("1, ");
|
||
// The third argument: past the last parameter. Reopened, so the old popup can't answer for it.
|
||
await page.keyboard.press("Escape");
|
||
await expect(popup).toBeHidden();
|
||
await page.keyboard.press("Meta+p");
|
||
await expect(popup.locator("b")).toHaveText("args");
|
||
if (SHOTS) await page.screenshot({ path: `${SHOTS}/csharp-parameter-info.png` });
|
||
await page.keyboard.type("2)");
|
||
await expect(popup).toBeHidden();
|
||
});
|
||
|
||
test("C# parameter info lists the overloads and marks the server's", async ({ workbench: page }) => {
|
||
const { editor } = await openProgram(page);
|
||
await page.evaluate(() => {
|
||
window.__ipc.handlers.lsp_signature_help = () => ({
|
||
signatures: [
|
||
{
|
||
label: "int Demo.Add(int first, int second)",
|
||
parameters: [
|
||
[17, 22],
|
||
[28, 34],
|
||
],
|
||
documentation: null,
|
||
},
|
||
{
|
||
label: "int Demo.Add(int first, int second, int third)",
|
||
parameters: [
|
||
[17, 22],
|
||
[28, 34],
|
||
[40, 45],
|
||
],
|
||
documentation: null,
|
||
},
|
||
],
|
||
activeSignature: 1,
|
||
activeParameter: 2,
|
||
});
|
||
});
|
||
await editor.locator(".cm-line", { hasText: "Add(total" }).click();
|
||
await page.keyboard.press("Meta+p");
|
||
const popup = page.locator(".cm-lsp-signature");
|
||
await expect(popup.locator(".cm-lsp-signature-row")).toHaveCount(2);
|
||
await expect(popup.locator(".cm-lsp-signature-active b")).toHaveText("third");
|
||
await expect(popup.locator(".cm-lsp-signature-disabled")).toHaveText("int Demo.Add(int first, int second)");
|
||
if (SHOTS) await page.screenshot({ path: `${SHOTS}/csharp-overloads.png` });
|
||
});
|