From fdc8bc2d4cbb3002eae5c20e70720f28fb8a0ea5 Mon Sep 17 00:00:00 2001 From: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com> Date: Fri, 13 Nov 2026 18:41:34 +0800 Subject: [PATCH] fix(editor): leave reference counts to Code Vision's usages (#3139) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit csharp-ls adds a "3 Reference(s)" lens above each declaration, next to Code Vision's own "3 usages". It duplicated the count, ignored the Code Vision settings, and was a second set of lens rows replaced after every edit. Language-server lenses that are only a reference count are now left out; Settings › Editor › Inlay Hints › Code Vision › Usages governs the count. Refs #3107 --- src/editor/lsp/serverCodeLens.test.ts | 26 ++++++++++++++++++++++++-- src/editor/lsp/serverCodeLens.ts | 8 +++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/src/editor/lsp/serverCodeLens.test.ts b/src/editor/lsp/serverCodeLens.test.ts index 636c0a197..c0b877aae 100644 --- a/src/editor/lsp/serverCodeLens.test.ts +++ b/src/editor/lsp/serverCodeLens.test.ts @@ -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"]); }); diff --git a/src/editor/lsp/serverCodeLens.ts b/src/editor/lsp/serverCodeLens.ts index 9c0902aa4..6651f4f23 100644 --- a/src/editor/lsp/serverCodeLens.ts +++ b/src/editor/lsp/serverCodeLens.ts @@ -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(); const field = StateField.define({ 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),