Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions desktop/internal/workbench/editor_view.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,8 +513,7 @@ func verticalWheel(event *gfx.ScrollEvent) {
// closes the hover popup of the editor, which no control sees leave.
func (a *App) onPointer(event gfx.PointerEvent) gfx.EventResult {
if event.Kind == gfx.PointerExit {
a.closeSemanticHover()
a.cancelSemanticKind(pluginSemanticHover)
a.leaveSemanticHover()
}
return gfx.EventResult{}
}
26 changes: 12 additions & 14 deletions desktop/internal/workbench/pluginsemantics.go
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,16 @@ type hoverState struct {
page *hoverPage
}

// hoverCandidate is the symbol under the resting pointer.
// hoverCandidate is the symbol under the resting pointer. It stays after its hover was asked for,
// so moving within the character does not ask again, and is cleared once the pointer leaves the
// text (leaveSemanticHover).
type hoverCandidate struct {
active bool
documentID int
line, column int
anchor gfx.Rect
// cancel ends the delay before the request. It is replaced or called when
// the pointer moves, the document changes or the window closes.
// the pointer moves or leaves the text, the document changes or the window closes.
cancel context.CancelFunc
}

Expand Down Expand Up @@ -280,7 +282,7 @@ func (a *App) pluginSemanticsKey(event gfx.KeyEvent) gfx.EventResult {
return a.definitionKey(event)
}
if a.semantics.hover.open && event.Key == gfx.KeyEscape {
a.closeSemanticHover()
a.leaveSemanticHover()
return gfx.EventResult{Handled: true, Repaint: true}
}
return gfx.EventResult{}
Expand Down Expand Up @@ -470,12 +472,12 @@ func (a *App) pluginSemanticsPointer(event gfx.PointerEvent, p *project, d *docu
return gfx.EventResult{}, false
}
if d == nil {
a.closeSemanticHover()
a.cancelSemanticKind(pluginSemanticHover)
a.leaveSemanticHover()
return gfx.EventResult{}, false
}
line, column, ok := d.view.PositionAt(event.X, event.Y)
if !ok {
a.leaveSemanticHover()
return gfx.EventResult{}, false
}
// The pointer moving along the hovered symbol keeps the popup where it is instead of
Expand All @@ -488,8 +490,7 @@ func (a *App) pluginSemanticsPointer(event gfx.PointerEvent, p *project, d *docu
a.pointPluginHover(p, d, line, column, hoverRowAnchor(d, event.X, event.Y))
return gfx.EventResult{}, false
case gfx.PointerExit:
a.closeSemanticHover()
a.cancelSemanticKind(pluginSemanticHover)
a.leaveSemanticHover()
}
return gfx.EventResult{}, false
}
Expand Down Expand Up @@ -1548,10 +1549,10 @@ func (a *App) pluginSemanticsCaretSync() {
}
}

// pluginSemanticsScrolled closes popups whose screen position the scroll moved.
// pluginSemanticsScrolled closes popups whose screen position the scroll moved. A hover still
// waiting would open at the place its character scrolled away from.
func (a *App) pluginSemanticsScrolled(_ *document) {
a.closeSemanticHover()
a.cancelSemanticKind(pluginSemanticHover)
a.leaveSemanticHover()
a.closeSemanticCompletion()
a.closeSemanticDefinition()
}
Expand Down Expand Up @@ -1604,10 +1605,7 @@ func (a *App) closePluginSemantics() {
a.cancelSemanticKind(pluginSemanticReferences)
a.cancelSemanticKind(pluginSemanticFormatting)
a.cancelSemanticKind(pluginSemanticRangeFormatting)
if a.semantics.candidate.cancel != nil {
a.semantics.candidate.cancel()
}
a.semantics.candidate = hoverCandidate{}
a.dropHoverCandidate()
if a.semantics.autoCancel != nil {
a.semantics.autoCancel()
a.semantics.autoCancel = nil
Expand Down
37 changes: 29 additions & 8 deletions desktop/internal/workbench/pluginsemantics_hover.go
Original file line number Diff line number Diff line change
Expand Up @@ -560,11 +560,26 @@ func (a *App) hoverCovers(d *document, line, column int) bool {
// dropped so it cannot replace this one.
func (a *App) holdSemanticHover() {
a.stopSemanticHoverHide()
a.dropHoverCandidate()
a.cancelSemanticKind(pluginSemanticHover)
}

// leaveSemanticHover ends the hover once the pointer has left the text, it was dismissed or the
// text moved under the pointer: the popup closes, a hover already asked for is dropped and the
// character the pointer rested on is forgotten, so resting there again asks again.
func (a *App) leaveSemanticHover() {
a.closeSemanticHover()
a.cancelSemanticKind(pluginSemanticHover)
a.dropHoverCandidate()
}

// dropHoverCandidate stops the wait before asking for a hover and forgets the character it was
// for. pointPluginHover does not ask again for the character it already waits on or asked for.
func (a *App) dropHoverCandidate() {
if a.semantics.candidate.cancel != nil {
a.semantics.candidate.cancel()
}
a.semantics.candidate = hoverCandidate{}
a.cancelSemanticKind(pluginSemanticHover)
}

// releaseSemanticHover starts the delay after which a pointer hover the pointer left closes.
Expand Down Expand Up @@ -616,20 +631,26 @@ func (a *App) stopSemanticHoverHide() {
a.semantics.hideToken++
}

// hoverTrackPointer follows the pointer over the whole window for an open pointer hover: inside
// the popup it holds the hover, over the editor the editor decides, and anywhere else the hover
// starts to close. It runs before the pointer reaches the element under it.
// hoverTrackPointer follows the pointer over the whole window: inside the popup of an open pointer
// hover it holds the hover, over the editor the editor decides, and anywhere else the character
// the pointer rested on is forgotten and an open pointer hover starts to close. It runs before
// the pointer reaches the element under it, and is the only handler that sees the pointer go
// from the editor to another element, which gives the editor no exit.
func (a *App) hoverTrackPointer(event gfx.PointerEvent) {
hover := &a.semantics.hover
if event.Kind != gfx.PointerMove || !hover.open || !hover.fromPointer {
if event.Kind != gfx.PointerMove {
return
}
if pointInRect(hover.rect, event.X, event.Y) {
hover := &a.semantics.hover
pointerHover := hover.open && hover.fromPointer
if pointerHover && pointInRect(hover.rect, event.X, event.Y) {
a.holdSemanticHover()
return
}
if _, d := a.pluginSemanticHit(event.Target); d != nil {
return
}
a.releaseSemanticHover()
a.dropHoverCandidate()
if pointerHover {
a.releaseSemanticHover()
}
}
99 changes: 99 additions & 0 deletions desktop/internal/workbench/pluginsemantics_hover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,105 @@ func TestPointerHoverWaitsBeforeClosingAndThePointerComingBackKeepsIt(t *testing
}
}

// documentBounds is where the fixture's document control is in the window.
func (f *semanticFixture) documentBounds(t *testing.T) gfx.Rect {
t.Helper()
for _, hit := range f.h.driver.Snapshot().Hits {
if hit.ID == f.d.hit && !hit.IsLabel {
return hit.Bounds
}
}
t.Fatal("the document control is not in the frame")
return gfx.Rect{}
}

// Leaving the text forgets the character the pointer rested on, so resting on it again asks for
// the hover again instead of waiting for an answer that was already shown or dropped (#1995).
func TestPointerHoverAsksAgainOnTheSameCharacterAfterLeavingTheText(t *testing.T) {
cases := []struct {
name string
leave func(t *testing.T, f *semanticFixture, x, y float32)
}{
{"escape", func(t *testing.T, f *semanticFixture, _, _ float32) {
if err := f.h.driver.Key(gfx.KeyEscape, 0); err != nil {
t.Fatal(err)
}
f.h.settle()
}},
{"out of the window", func(t *testing.T, f *semanticFixture, _, _ float32) {
if err := f.h.driver.Leave(); err != nil {
t.Fatal(err)
}
f.h.settle()
}},
{"over the tab bar", func(t *testing.T, f *semanticFixture, x, _ float32) {
f.move(t, x, f.documentBounds(t).Y-4)
}},
{"scroll", func(t *testing.T, f *semanticFixture, x, y float32) {
if err := f.h.driver.Scroll(gfx.ScrollEvent{X: x, Y: y, DeltaY: 1}); err != nil {
t.Fatal(err)
}
f.h.settle()
}},
}
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
f := newSemanticFixture(t)
f.h.app.semantics.hoverDelay = -1
f.h.app.semantics.hoverHideDelay = -1
x, y := f.openPointerHover(t, hoverResult(t, "int one()"))
c.leave(t, f, x, y)
if f.h.app.semantics.hover.open {
t.Fatal("leaving the text kept the hover")
}
f.move(t, x+1, y)
f.waitForRequests(t, 2)
f.deliver(t, "op-2", pluginMethodHover, hoverResult(t, "int one()"))
if !f.h.app.semantics.hover.open {
t.Fatal("the hover asked again did not open")
}
})
}
}

// The pointer leaving the text before the wait for its hover ends drops the wait, so no popup
// opens where the pointer no longer is.
func TestPointerHoverLeavingTheTextDropsTheWait(t *testing.T) {
f := newSemanticFixture(t)
// The wait outlasts the test, so only leaving the text ends it.
f.h.app.semantics.hoverDelay = time.Hour
rect := f.caretRectAt(t, 0, 1)
x, y := rect.X+2, rect.Y+2
f.moveOnly(t, x, y)
if candidate := f.h.app.semantics.candidate; !candidate.active || candidate.cancel == nil {
t.Fatalf("resting on the text armed no hover: %+v", candidate)
}
f.moveOnly(t, x, f.documentBounds(t).Y-4)
if candidate := f.h.app.semantics.candidate; candidate.active || candidate.cancel != nil {
t.Fatalf("leaving the text kept the wait: %+v", candidate)
}
// settle returns only once the dropped wait has ended.
f.h.settle()
if f.kernel.requestCount() != 0 {
t.Fatalf("requests = %d, want none", f.kernel.requestCount())
}
}

// The pointer moving within a character the server had nothing to say about does not ask again.
func TestPointerHoverDoesNotAskAgainWithinACharacterWithoutHover(t *testing.T) {
f := newSemanticFixture(t)
f.h.app.semantics.hoverDelay = -1
rect := f.caretRectAt(t, 0, 1)
x, y := rect.X+2, rect.Y+2
f.move(t, x, y)
f.waitForRequests(t, 1)
f.deliver(t, "op-1", pluginMethodHover, json.RawMessage(`{"hover":null}`))
f.move(t, x+1, y)
if f.h.app.semantics.hover.open || f.kernel.requestCount() != 1 {
t.Fatalf("moving within the character: open %v, requests %d", f.h.app.semantics.hover.open, f.kernel.requestCount())
}
}

func TestHoverColorsItsCodeWithTheEditorGrammar(t *testing.T) {
f := newSemanticFixture(t)
f.h.app.semantics.hoverDelay = -1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
]
},
"owner": "Language Tooling",
"verification": "Viva(2026-11-14):Hover 弹窗按 Markdown 渲染(签名代码块、分隔线、正文、示例、链接),代码块用编辑器同一套语法着色,http/https/mailto 链接点击后用系统浏览器打开;宽度在 280–620 之间按内容收窄,超过 420 高度时可滚动。弹窗贴在指针所在行的下沿、左缘对齐指针;指针停在同一符号范围内不重新请求,移入弹窗时保持打开,离开符号和弹窗 400 ms 后才关闭,期间回到符号或弹窗会取消关闭。无头测试覆盖渲染、位置、保持、延迟关闭和代码着色,原生窗口验收待做。 Viva(2026-11-10):输入单个标识符字符或 . : > 后防抖(120 ms)自动请求补全,继续输入、移动光标或编辑会取消并丢弃过期结果;服务器声明的 triggerCharacters 尚未由 Core 暴露,暂用固定成员访问字符集。 Viva(2026-11-09):Hover 支持 F1 与 500 ms 指针停留,补全由 Control+Space 显式触发,上下键选择、回车/Tab 通过 Core 的 lsp.applyTextEdits 与 lsp.plainSnippet 接受;无头 Viva 窗口使用真实 clangd 隔离插件验证了 Hover 内容、补全列表和接受后的文本与光标位置。连续输入自动重新请求、isIncomplete 刷新、触发字符和多来源合并尚未接入,因此保持部分实现。 用测试内联的合成语言服务器插件验证补全、Hover、排序、超时和空结果。验证 initialize、didChangeConfiguration 与 workspace/configuration 三个配置入口一致,父级和叶级 section 均保留插件声明的其他配置。 连续输入时保留 isIncomplete 并通过 LSP triggerKind=3 重新请求候选;验证空未完整列表、完整/空响应、触发字符、快速修改及文档关闭/会话替换后的过期结果。 #1662 LSP-09:多个补全来源的合并由 Core 的 lsp.mergeCompletions 决定:同一来源的候选全部保留(同名不同签名的重载不再被丢弃),低优先级来源中与高优先级来源同 label 的候选被遮蔽。Windows 只有一个补全来源,原样显示服务器列表,不调用该命令。macOS 删除私有的 Go/Swift/Rust/Python/JS/TS 关键词表,关键词改由语言服务器或插件提供,与 Windows 一致。在 macOS 打开有重载方法的文件,确认同名重载全部出现;未运行语言服务器的 Go 文件不再出现内置关键词候选,当前文件标识符仍会出现。",
"verification": "Viva(2026-11-16,#1995):指针离开文本后忘掉停留过的字符:按 Esc、移出窗口、移到标签栏等其他控件、滚动编辑器后回到同一字符,会重新请求并显示 Hover;离开时还在 500 ms 等待中的 Hover 不再发出请求;没有 Hover 的字符内移动仍不重复请求。无头测试覆盖四种离开方式,原生窗口验收待做。 Viva(2026-11-14):Hover 弹窗按 Markdown 渲染(签名代码块、分隔线、正文、示例、链接),代码块用编辑器同一套语法着色,http/https/mailto 链接点击后用系统浏览器打开;宽度在 280–620 之间按内容收窄,超过 420 高度时可滚动。弹窗贴在指针所在行的下沿、左缘对齐指针;指针停在同一符号范围内不重新请求,移入弹窗时保持打开,离开符号和弹窗 400 ms 后才关闭,期间回到符号或弹窗会取消关闭。无头测试覆盖渲染、位置、保持、延迟关闭和代码着色,原生窗口验收待做。 Viva(2026-11-10):输入单个标识符字符或 . : > 后防抖(120 ms)自动请求补全,继续输入、移动光标或编辑会取消并丢弃过期结果;服务器声明的 triggerCharacters 尚未由 Core 暴露,暂用固定成员访问字符集。 Viva(2026-11-09):Hover 支持 F1 与 500 ms 指针停留,补全由 Control+Space 显式触发,上下键选择、回车/Tab 通过 Core 的 lsp.applyTextEdits 与 lsp.plainSnippet 接受;无头 Viva 窗口使用真实 clangd 隔离插件验证了 Hover 内容、补全列表和接受后的文本与光标位置。连续输入自动重新请求、isIncomplete 刷新、触发字符和多来源合并尚未接入,因此保持部分实现。 用测试内联的合成语言服务器插件验证补全、Hover、排序、超时和空结果。验证 initialize、didChangeConfiguration 与 workspace/configuration 三个配置入口一致,父级和叶级 section 均保留插件声明的其他配置。 连续输入时保留 isIncomplete 并通过 LSP triggerKind=3 重新请求候选;验证空未完整列表、完整/空响应、触发字符、快速修改及文档关闭/会话替换后的过期结果。 #1662 LSP-09:多个补全来源的合并由 Core 的 lsp.mergeCompletions 决定:同一来源的候选全部保留(同名不同签名的重载不再被丢弃),低优先级来源中与高优先级来源同 label 的候选被遮蔽。Windows 只有一个补全来源,原样显示服务器列表,不调用该命令。macOS 删除私有的 Go/Swift/Rust/Python/JS/TS 关键词表,关键词改由语言服务器或插件提供,与 Windows 一致。在 macOS 打开有重载方法的文件,确认同名重载全部出现;未运行语言服务器的 Go 文件不再出现内置关键词候选,当前文件标识符仍会出现。",
"notes": "Viva 已接入显式补全与接受(含 Core 的 snippet 转换)以及 Hover(F1 与指针停留);isIncomplete 连续请求、触发字符和多来源合并尚未接入。无头 clangd 测试不是原生窗口验收,平台验证保持 pending。 自动触发已接入,触发字符集暂为固定值,待 Core 暴露服务器声明。",
"legacy": {
"revision": "5a54c41aa37a4e6e6b68918a4b05765b9dd07a36",
Expand Down
Loading