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
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Agent 笔记:补全名称和长签名的显示空间

状态:已实现

## 先说结论

补全列表优先给候选名称留出宽度,便于区分前缀相同的函数。签名在列表中放不下时,选中项的完整内容会在列表底部换行,超出详情区域时可以滚动。方向键切换候选时同步更新详情。

## 问题

固定宽度的补全弹窗在同一行压缩名称和签名。两个候选可能只显示相同的名称前缀,调用参数和返回类型也可能藏在省略号后。

## 决策

- 工作台使用实际字体测量候选,行内省略、详情触发和参数文档换行均使用扣除边框和内边距后的宽度。参数文档的卡片高度包含边框。
- 列表放不下选中项的全部文字时,在有界高度的详情区域展示完整文字。超长文本交由 Viva 虚拟列表按块换行,滚动条可直接定位到后面的内容,键盘焦点留在编辑器。
- 补全根据光标上下的可用高度限制候选行数,键盘导航始终能带入当前选中项。参数信息同时避开补全弹窗和当前编辑行。窗口空间只够一个弹窗时保留补全列表。

## 考虑过的备选方案

- 给所有弹窗改用更大的固定宽度。窄窗口和更长的签名仍会遇到截断。
- 在每个候选行换行显示签名。可见候选行数会随内容变化,用户逐项浏览时需要追踪位置。
- 用一个换行控件排版超长签名。控件会在首帧同步排版整段文本,压缩可见高度也无法减少这部分耗时。

## 后果

常用函数名可以直接在列表中辨认。详情会临时占用额外高度,光标附近空间有限时会少显示几项候选。超长详情的虚拟列表在接近文本块边界时可能多换一行。

## 验证

- `scripts/desktop/desktop-go.sh test ./internal/workbench -run 'TestCompletionPopup|TestLSPSignatureHelp'` 验证完整签名、键盘焦点、超长签名测量和末尾滚动、弹窗避让光标及参数文档的卡片边界。
- `TestVisualCompletionPopup` 通过 Viva 无头窗口截图,覆盖常规及窄窗口、中英文深浅主题,以及光标位于中部或靠近底边的场景。

## 适用范围

- `desktop/internal/workbench/pluginsemantics_view.go`
- `desktop/internal/workbench/signature_help.go`
2 changes: 1 addition & 1 deletion .github/workflows/desktop-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ jobs:
LITHE_VISUAL_OUTPUT_DIR: ${{ github.workspace }}/.artifacts/lsp-editor-visual
run: |
./scripts/desktop/desktop-go.sh test -v -tags 'vivahead lithevisual' ./internal/workbench \
-run '^(TestLSP|TestVisualLSPActions$)' -count=1 -timeout=120s
-run '^(TestLSP|TestCompletionPopup|TestVisual(LSPActions|CompletionPopup)$)' -count=1 -timeout=120s

- name: Upload LSP editor screenshots
if: ${{ !cancelled() && steps.lsp-visual.outcome != 'skipped' }}
Expand Down
86 changes: 86 additions & 0 deletions desktop/internal/workbench/lsp_actions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"os"
"path/filepath"
"strings"
"sync"
"testing"
"time"
Expand Down Expand Up @@ -150,6 +151,91 @@ func TestLSPSignatureHelpShortcutPresentsAndDismisses(t *testing.T) {
}
}

func TestLSPSignatureHelpKeepsCompletionPreviewVisible(t *testing.T) {
f := newSemanticFixture(t)
if err := f.h.driver.Resize(350, 600); err != nil {
t.Fatal(err)
}
f.openFunctionCompletions(t)
f.server.features = map[string]bool{featureSignatureHelp: true}
f.h.app.startPluginSignatureHelp(f.p, f.d, 0, 0, "")
f.waitForRequests(t, 2)
f.deliver(t, "op-2", pluginMethodSignatureHelp, json.RawMessage(`{
"signatureHelp": {
"signatures": [{"label":"call(arg: string)", "documentation":"Active call.",
"parameters": [{"documentation":"Active argument.", "byteStart":5, "byteEnd":8}]}],
"activeSignature":0, "activeParameter":0
}
}`))
completion := f.h.hitLabeled(f.h.shared("desktop.semantics.completion"))
parameters := f.h.hitLabeled(f.h.shared("desktop.semantics.signatureHelp"))
if completion.X < parameters.Right() && parameters.X < completion.Right() &&
completion.Y < parameters.Bottom() && parameters.Y < completion.Bottom() {
t.Fatalf("completion %v and parameter information %v overlap", completion, parameters)
}
if !f.h.showsWrapped(completionTimeoutDetail) || !f.h.shows("Active argument.") {
t.Fatal("the selected completion and current parameter details should both be visible")
}
}

func TestLSPSignatureHelpStaysClearOfCaretWhenCompletionIsAbove(t *testing.T) {
f := newSemanticFixture(t)
if err := f.h.driver.Resize(900, 600); err != nil {
t.Fatal(err)
}
caret := f.placeCompletionCaret(t, 19)
f.requestCompletions(t, longFunctionCandidates()...)
completion := f.h.hitLabeled(f.h.shared("desktop.semantics.completion"))
if completion.Bottom() > caret.Y {
t.Fatalf("expected completion %v to open above the caret %v", completion, caret)
}
f.openCompletionCaretSignature(t)
parameters := f.h.hitLabeled(f.h.shared("desktop.semantics.signatureHelp"))
if parameters.Y < caret.Bottom() {
t.Fatalf("parameters %v should fit below the caret %v", parameters, caret)
}
}

func (f *semanticFixture) openCompletionCaretSignature(t *testing.T) {
t.Helper()
line, column := f.d.caretView().CaretUTF16()
f.server.features = map[string]bool{featureSignatureHelp: true}
f.h.app.startPluginSignatureHelp(f.p, f.d, line, column, "")
f.waitForRequests(t, 2)
f.deliver(t, "op-2", pluginMethodSignatureHelp, json.RawMessage(`{
"signatureHelp": {
"signatures": [{"label":"call(arg: path.to.a.package.with.a.lengthy.qualified.parameter.Type)", "documentation":"Short help."}],
"activeSignature":0
}
}`))
}

func TestLSPSignatureHelpMeasuresDocumentationInsideBorder(t *testing.T) {
f := newSemanticFixture(t)
f.d.view.GoToNavigation(0, 0, false)
f.server.features = map[string]bool{featureSignatureHelp: true}
f.h.app.startPluginSignatureHelp(f.p, f.d, 0, 0, "")
f.waitForRequests(t, 1)
// At 11 px with the driver's reference fonts, this needs 198.15 px.
const doc = "Calls www iiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiiii daily."
f.deliver(t, "op-1", pluginMethodSignatureHelp, json.RawMessage(`{
"signatureHelp": {
"signatures": [{"label":"call(arg: string)", "documentation":"`+doc+`"}],
"activeSignature":0
}
}`))
popup := f.h.hitLabeled(f.h.shared("desktop.semantics.signatureHelp"))
for _, label := range f.h.driver.Snapshot().Labels {
if strings.HasSuffix(label.Value, "daily.") {
if label.Bounds.Bottom() > popup.Bottom() {
t.Fatalf("documentation line %v extends below its card %v", label.Bounds, popup)
}
return
}
}
t.Fatal("last line of the parameter documentation was not drawn")
}

func TestLSPInlayHintsReleaseWhenDisabled(t *testing.T) {
f := newSemanticFixture(t)
f.h.app.editorPreferences.InlayHints = true
Expand Down
1 change: 0 additions & 1 deletion desktop/internal/workbench/pluginsemantics.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@ const (
// operation kind is enough; a newer request cancels the older one.
maxSemanticPending = 3

semanticPopupWidth = float32(360)
semanticDefinitionWidth = float32(480)
semanticRowHeight = float32(24)
semanticPopupPad = float32(4)
Expand Down
Loading
Loading