From 52017a1172678683ffef7ff84a47bfe4c558e218 Mon Sep 17 00:00:00 2001 From: zhangdagou Date: Mon, 16 Nov 2026 23:51:06 +0800 Subject: [PATCH] =?UTF-8?q?fix(vcs):=20show=20the=20=E2=8C=98-hover=20decl?= =?UTF-8?q?aration=20info=20as=20a=20popup=20in=20diff=20views=20(#3783)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The ⌘/Ctrl-hover declaration info in a diff view used CodeMirror's default dark tooltip, clipped by the pane and covered by the tool window stripe. The hint is now styled in full by the LSP theme as a rounded popup with an arrow pointing at the word (same in the editor and diffs), and a diff side showing an open document parents its tooltips to the body with the editor's tooltip bounds. Co-authored-by: PLZY <41029728+PLZY@users.noreply.github.com> --- src/editor/lsp/navInfoTheme.test.ts | 27 +++++++++++++++++++++++++++ src/editor/lsp/navigation.ts | 1 + src/editor/lsp/theme.ts | 21 ++++++++++++++++++++- src/features/vcs/DiffEditor.tsx | 4 ++-- src/features/vcs/cm.ts | 13 ++++++++++++- 5 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 src/editor/lsp/navInfoTheme.test.ts diff --git a/src/editor/lsp/navInfoTheme.test.ts b/src/editor/lsp/navInfoTheme.test.ts new file mode 100644 index 000000000..e442e96ba --- /dev/null +++ b/src/editor/lsp/navInfoTheme.test.ts @@ -0,0 +1,27 @@ +import { afterEach, expect, it } from "vitest"; +import { EditorState } from "@codemirror/state"; +import { EditorView } from "@codemirror/view"; +import { lspTheme } from "./theme"; + +let view: EditorView | null = null; +afterEach(() => { + view?.destroy(); + view = null; +}); + +it("draws the ⌘-hover info as a popup in a view without the editor theme", () => { + // Diff viewers declare a dark theme and leave out the editor's `.cm-tooltip` rule. + view = new EditorView({ + state: EditorState.create({ extensions: [EditorView.theme({}, { dark: true }), lspTheme] }), + parent: document.body, + }); + const info = document.createElement("div"); + info.className = "cm-tooltip cm-lsp-hover cm-lsp-nav-info"; + view.dom.appendChild(info); + const style = getComputedStyle(info); + expect(style.backgroundColor).toBe("var(--bg-popup)"); + expect(style.color).toBe("var(--fg)"); + expect(style.width).toBe("max-content"); + expect(style.borderRadius).toBe("var(--radius-popup-large)"); + expect(style.overflow).toBe("visible"); +}); diff --git a/src/editor/lsp/navigation.ts b/src/editor/lsp/navigation.ts index 22eb01067..1a9861dbb 100644 --- a/src/editor/lsp/navigation.ts +++ b/src/editor/lsp/navigation.ts @@ -836,6 +836,7 @@ const linkField = StateField.define({ return { pos: v.from, above: true, + arrow: true, create: (view) => { const dom = document.createElement("div"); dom.className = "cm-lsp-hover cm-lsp-nav-info"; diff --git a/src/editor/lsp/theme.ts b/src/editor/lsp/theme.ts index bf8ddac9d..c46a5c2d4 100644 --- a/src/editor/lsp/theme.ts +++ b/src/editor/lsp/theme.ts @@ -328,7 +328,26 @@ export const lspTheme = EditorView.theme({ backgroundImage: "linear-gradient(to right, transparent var(--lsp-occurrence-from), var(--lsp-occurrence-bg) var(--lsp-occurrence-from))", }, - ".cm-lsp-nav-info": { padding: "4px 8px" }, + // IDEA's ⌘-hover hint: a rounded popup pointing at the word. Styled here in full, as diff + // viewers lack the editor theme and would show CodeMirror's default tooltip. A few lines at + // most, so no scrolling, which would clip the arrow. + ".cm-tooltip.cm-lsp-nav-info": { + ...tooltipSurface, + borderRadius: "var(--radius-popup-large)", + width: "max-content", + maxWidth: "100%", + maxHeight: "none", + overflow: "visible", + }, + ".cm-lsp-nav-info .cm-lsp-code": { overflowWrap: "anywhere" }, + ".cm-tooltip.cm-lsp-nav-info .cm-tooltip-arrow:before": { + borderTopColor: "var(--border-popup)", + borderBottomColor: "var(--border-popup)", + }, + ".cm-tooltip.cm-lsp-nav-info .cm-tooltip-arrow:after": { + borderTopColor: "var(--bg-popup)", + borderBottomColor: "var(--bg-popup)", + }, // Chooser highlight (tempHighlight.ts): the expression / occurrences a choice would take. ".cm-lsp-chooser-highlight": { backgroundColor: "var(--bg-text-search-result)" }, diff --git a/src/features/vcs/DiffEditor.tsx b/src/features/vcs/DiffEditor.tsx index 5cb011e1c..34da1d987 100644 --- a/src/features/vcs/DiffEditor.tsx +++ b/src/features/vcs/DiffEditor.tsx @@ -44,7 +44,7 @@ import { useWorkflowSettings } from "@/platform/workflowSettings"; import { IconButton, Select, Spinner, T, isPopupOpen, showContextMenu } from "@/ui"; import { registerSoftWrapSurface } from "@/workbench/softWrap"; import { editorService, notifications, type EditorInput } from "@/workbench/contributions"; -import { changedLineGutters, diffOverview, diffWords, languageFor, viewerBase } from "./cm"; +import { changedLineGutters, diffOverview, diffWords, documentTooltips, languageFor, viewerBase } from "./cm"; import { applyChunk, arrowControls, chunkAt, hoverRevert, revertUnifiedChunk } from "./diffControls"; import { HIGHLIGHT_OPTIONS, @@ -538,7 +538,7 @@ export function DiffEditor({ blameSlot(), att?.extension ?? [], // The file's open document: quick docs and ⌘/Ctrl-click navigation, as in its editor. - att ? diffSideExtensions(att.context()) : [], + att ? [diffSideExtensions(att.context()), documentTooltips] : [], editable ? [editableExtensions(), embeddedEditorExtensions(path)] : [], notes ? diffAnnotations( diff --git a/src/features/vcs/cm.ts b/src/features/vcs/cm.ts index 568fbff9c..f4f3b96c7 100644 --- a/src/features/vcs/cm.ts +++ b/src/features/vcs/cm.ts @@ -26,6 +26,7 @@ import { lineNumberMarkers, lineNumberWidgetMarker, lineNumbers, + tooltips, WidgetType, type DecorationSet, type ViewUpdate, @@ -40,7 +41,7 @@ import { findExtension } from "@/editor/core/cm/find"; import { overviewLane, overviewLaneIn } from "@/editor/core/cm/lanes"; import { LINE_INSET } from "@/editor/core/cm/lineInset"; import { caretExtension } from "@/editor/core/cm/prefs"; -import { fontExtension } from "@/editor/core/cm/setup"; +import { fontExtension, tooltipBounds } from "@/editor/core/cm/setup"; import { caretStyles, findLocals, findStyles, overviewStyles } from "@/editor/core/cm/theme"; import { editorPrefs } from "@/platform/editorSettings"; import { useProject } from "@/platform/project"; @@ -522,6 +523,16 @@ export function viewerBase(opts: { ]; } +/** + * Tooltips of a pane showing an open document (quick docs, ⌘-hover info), parented to the + * body as the editor's are, so the pane neither clips them nor keeps them under the tool + * window stripes, and they move left to fit. + */ +export const documentTooltips: Extension = tooltips({ + parent: typeof document === "undefined" ? undefined : document.body, + tooltipSpace: tooltipBounds, +}); + const cache = new Map>(); /**