дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 01:01:17 +02:00
fix(completion): complete a keyword rather than a declaration snippet of the same name
jdtls lists both the keyword `interface` and a snippet `interface` that inserts a whole declaration named after the file. Picking the snippet while changing `class` to `interface` duplicated the declaration. A server snippet whose label matches a keyword the same list offers is dropped, as IDEA completes only the keyword. Fixes #7151
Цей коміт міститься в:
1 джерело
dd8de05013
коміт
a9714d98ca
2 files changed
+39
No files matched your search
@@ -540,6 +540,41 @@ describe("applying completions", () => {
|
||||
expect(a!.apply).not.toBe(b!.apply);
|
||||
});
|
||||
|
||||
it("completes a keyword rather than a declaration snippet with the same name", async () => {
|
||||
const { view } = setup("public interf| Demo {}");
|
||||
setInvokeRoute((cmd) => {
|
||||
if (cmd === "cancel_request") return Promise.resolve(null);
|
||||
if (cmd === "lsp_completion") {
|
||||
return Promise.resolve({
|
||||
isIncomplete: false,
|
||||
items: [
|
||||
item({ label: "interface", kind: "keyword", insertText: "interface" }),
|
||||
item({
|
||||
label: "interface",
|
||||
kind: "snippet",
|
||||
insertText: "public interface ${1:Demo} {\n\t$0\n}",
|
||||
isSnippet: true,
|
||||
}),
|
||||
],
|
||||
});
|
||||
}
|
||||
return Promise.resolve(null);
|
||||
});
|
||||
try {
|
||||
view.dispatch({
|
||||
effects: StateEffect.appendConfig.of([
|
||||
lspDoc.of({ doc: 7151, path: "/p/Demo.java", language: "java", uiMode: "Java", readOnly: false }),
|
||||
completionExtension(),
|
||||
]),
|
||||
});
|
||||
startCompletion(view);
|
||||
await vi.waitFor(() => expect(currentCompletions(view.state)).toHaveLength(1));
|
||||
expect((currentCompletions(view.state)[0] as unknown as { lsp: CompletionItem }).lsp.kind).toBe("keyword");
|
||||
} finally {
|
||||
setInvokeRoute(null);
|
||||
}
|
||||
});
|
||||
|
||||
it("lists same-name Java imports from different packages", async () => {
|
||||
const { view } = setup("@RequestBod|");
|
||||
const packages = ["org.springframework.web.bind.annotation", "io.swagger.v3.oas.annotations.parameters"];
|
||||
|
||||
@@ -875,6 +875,10 @@ async function lspCompletionSource(ctx: CompletionContext): Promise<CompletionRe
|
||||
if (inVarCall(ctx)) items = items.filter((it) => !it.label.startsWith("--"));
|
||||
const pruned = pruneItems(items, typed);
|
||||
items = [...pruned.items];
|
||||
// A server snippet named like a keyword it also lists (jdtls `interface`, `class`, `enum` declaration
|
||||
// skeletons) would replace one word with a whole declaration; IDEA completes the keyword.
|
||||
const keywords = new Set(items.filter((it) => it.kind === "keyword").map((it) => it.label));
|
||||
if (keywords.size) items = items.filter((it) => it.kind !== "snippet" || !keywords.has(it.label));
|
||||
// A server snippet named like a live template (jdtls `sout`, `fori`) would be listed twice; the template wins.
|
||||
if (items.some((it) => it.kind === "snippet")) {
|
||||
const own = await contributedSource(ctx);
|
||||
|
||||
Reference in new issue
Заблокувати користувача