From f26725f162a58454433521a8ed64c7ad555b1fe3 Mon Sep 17 00:00:00 2001 From: "lithe-support[bot]" <356900028+lithe-support[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:49:56 +0000 Subject: [PATCH 1/6] feat(editor): wire copy reference location through Viva and Rust Core (#2015) --- desktop/internal/core/reference_location.go | 29 ++++ desktop/internal/workbench/copy_reference.go | 130 ++++++++++++++++++ .../internal/workbench/copy_reference_test.go | 94 +++++++++++++ desktop/internal/workbench/editor_features.go | 1 + desktop/internal/workbench/editor_menu.go | 4 + desktop/internal/workbench/editor_requests.go | 6 + desktop/internal/workbench/editor_view.go | 5 + desktop/internal/workbench/pluginsemantics.go | 5 +- scripts/desktop/build-desktop-core.sh | 2 +- .../editor-copy-reference-location.json | 29 ++++ 10 files changed, 303 insertions(+), 2 deletions(-) create mode 100644 desktop/internal/core/reference_location.go create mode 100644 desktop/internal/workbench/copy_reference.go create mode 100644 desktop/internal/workbench/copy_reference_test.go mode change 100755 => 100644 scripts/desktop/build-desktop-core.sh create mode 100644 shared/platform-feature-matrix/features/editor-copy-reference-location.json diff --git a/desktop/internal/core/reference_location.go b/desktop/internal/core/reference_location.go new file mode 100644 index 0000000000..ab880deafb --- /dev/null +++ b/desktop/internal/core/reference_location.go @@ -0,0 +1,29 @@ +package core + +import "context" + +// ReferenceLocationRequest is a snapshot of the requested caret and the LSP +// symbols synchronized to that document revision. Coordinates are zero-based +// UTF-16 positions, while the result's human-readable line is one-based. +type ReferenceLocationRequest struct { + Path string `json:"path"` + Line int `json:"line"` + UTF16Column int `json:"utf16Column"` + Symbols []DocumentSymbol `json:"symbols"` +} + +type ReferenceLocationResult struct { + Reference string `json:"reference"` + Source string `json:"source"` +} + +// CopyReferenceLocation uses the shared Rust Core formatter. The desktop host +// does not interpret package, type, method names or signature conventions. +func (c *Client) CopyReferenceLocation(ctx context.Context, request ReferenceLocationRequest) (ReferenceLocationResult, error) { + if request.Symbols == nil { + request.Symbols = []DocumentSymbol{} + } + var result ReferenceLocationResult + err := c.Execute(ctx, "editor.copyReferenceLocation", request, &result) + return result, err +} diff --git a/desktop/internal/workbench/copy_reference.go b/desktop/internal/workbench/copy_reference.go new file mode 100644 index 0000000000..0f16631b7f --- /dev/null +++ b/desktop/internal/workbench/copy_reference.go @@ -0,0 +1,130 @@ +package workbench + +import ( + "context" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/i18n" + "github.com/vivaui/viva/app" +) + +// A secondary press chooses the line under the pointer, not the previous +// keyboard caret. The context-menu item consumes the coordinate after the +// popup closes; each operation owns a revision and an identity token. +type referenceClick struct { + documentID int + line, column int +} + +type referenceRequest struct { + project *project + documentID, revision int + line, column int + path string + pending *semanticPending +} + +type copyReferenceState struct { + click *referenceClick + request *referenceRequest +} + +type referenceKernel interface { + CopyReferenceLocation(context.Context, core.ReferenceLocationRequest) (core.ReferenceLocationResult, error) +} + +func (a *App) copyReferenceLocation(p *project, d *document) { + if p == nil || d == nil || d.virtual || d.path == "" || a.project != p { + return + } + kernel, ok := a.kernel.(referenceKernel) + if !ok { + return + } + a.performed("editor.copyReferenceLocation", surfaceContextMenu) + line, column := d.view.CaretUTF16() + if click := a.editor.copyReference.click; click != nil && click.documentID == d.id { + line, column = click.line, click.column + } + a.editor.copyReference.click = nil + if previous := a.editor.copyReference.request; previous != nil && previous.pending != nil { + a.cancelSemantic(previous.pending) + } + request := &referenceRequest{ + project: p, documentID: d.id, revision: d.view.Revision(), + line: line, column: column, path: d.path, + } + a.editor.copyReference.request = request + + // A loaded Structure result can be used only for exactly this document + // revision. Otherwise ask the same LSP documentSymbols feature directly; + // never use a stale tree from a previous document or unsaved edit. + outline := &a.editor.outline + if outline.project == p && outline.documentID == d.id && outline.loaded && + outline.revision == request.revision { + a.finishReferenceLocation(request, outline.symbols, kernel) + return + } + server, offered := a.editorServer(d, featureDocumentSymbols) + if offered && server != nil && a.semanticDocumentReady(d) { + request.pending = a.submitEditorRequest(pluginSemanticCopyReference, p, d, server, core.PluginSemanticRequest{}) + return + } + // An unavailable or unsynchronized language server does not block copying: + // the shared Core produces a path reference instead of guessing symbols. + a.finishReferenceLocation(request, nil, kernel) +} + +// applyReferenceSymbols is reached through the ordinary semantic event router. +// Failed, unsupported or malformed symbols retain a useful file/line fallback. +func (a *App) applyReferenceSymbols(pending *semanticPending, event core.BackendEvent, failed bool) { + request := a.editor.copyReference.request + if request == nil || request.pending != pending { + return + } + request.pending = nil + p, d := a.currentSemanticDocument(request.documentID) + if p != request.project || d == nil || d.view.Revision() != request.revision { + return + } + var symbols []core.DocumentSymbol + if !failed { + var err error + symbols, err = core.PluginDocumentSymbols(event) + if err != nil { + a.backgroundFailed("editor_copy_reference_symbols", err) + } + } + if kernel, ok := a.kernel.(referenceKernel); ok { + a.finishReferenceLocation(request, symbols, kernel) + } +} + +func (a *App) finishReferenceLocation(request *referenceRequest, symbols []core.DocumentSymbol, kernel referenceKernel) { + a.background(request.project, kernelCallTimeout, func(ctx context.Context) func(*App) { + result, err := kernel.CopyReferenceLocation(ctx, core.ReferenceLocationRequest{ + Path: request.path, Line: request.line, UTF16Column: request.column, Symbols: symbols, + }) + return func(a *App) { + if a.editor.copyReference.request != request || a.project != request.project { + return + } + d := request.project.docs.find(request.documentID) + if d == nil || d.view.Revision() != request.revision || + request.project.selectedDocument(request.project.docs.group) != d { + a.editor.copyReference.request = nil + return + } + a.editor.copyReference.request = nil + if err != nil { + a.operationFailed("editor_copy_reference", err) + a.notifyError(a.text.Errors.Core(err.Error())) + return + } + if err := app.SetClipboardText(result.Reference); err != nil { + a.operationFailed("clipboard_copy", err) + a.notifyError(i18n.SharedFormat(a.language(), "desktop.files.copyFailed", map[string]string{"reason": err.Error()})) + } + } + }) +} diff --git a/desktop/internal/workbench/copy_reference_test.go b/desktop/internal/workbench/copy_reference_test.go new file mode 100644 index 0000000000..1842409a6d --- /dev/null +++ b/desktop/internal/workbench/copy_reference_test.go @@ -0,0 +1,94 @@ +package workbench + +import ( + "os" + "path/filepath" + "strconv" + "strings" + "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" +) + +func TestCopyReferenceLocationWithoutServerCopiesFileLine(t *testing.T) { + h := newHarness(t, &testKernel{Client: core.NewClient()}) + root := t.TempDir() + h.open(root) + path := filepath.Join(root, "reference.go") + if err := os.WriteFile(path, []byte("package main\nfunc work() {}\n"), 0600); err != nil { + t.Fatal(err) + } + p := h.app.project + h.app.openFile(p, path) + h.settleChain() + d := p.docs.byPath(path) + if d == nil { + t.Fatal("document not opened") + } + d.view.GoToLine(2) + h.app.copyReferenceLocation(p, d) + h.await("copy file and line", func() bool { + return h.driver.Clipboard() == path+"#L2" + }) +} + +func TestCopyReferenceLocationUsesLanguageSymbols(t *testing.T) { + f := newSemanticFixture(t) + f.server.features = map[string]bool{featureDocumentSymbols: true} + f.d.view.SetSelection(0, 0) + f.h.app.copyReferenceLocation(f.p, f.d) + f.waitForRequests(t, 1) + if got := f.kernel.request(0).Operation; got != pluginSemanticDocumentSymbols { + t.Fatalf("LSP operation = %q", got) + } + f.deliver(t, "op-1", pluginMethodDocumentSymbols, symbolsResult(t, + symbolAt("DemoClass", 5, 0, 1, + symbolAt("goHome(String,Integer)", 6, 0, 1)), + )) + f.h.await("symbol reference copied", func() bool { + return f.h.driver.Clipboard() == "DemoClass#goHome(String,Integer)#L1" + }) +} + +func TestCopyReferenceLocationDiscardsOldDocumentRevision(t *testing.T) { + f := newSemanticFixture(t) + f.server.features = map[string]bool{featureDocumentSymbols: true} + f.h.app.copyReferenceLocation(f.p, f.d) + f.waitForRequests(t, 1) + f.h.app.insertForTest(f.d, "changed") + f.deliver(t, "op-1", pluginMethodDocumentSymbols, symbolsResult(t, + symbolAt("Outdated", 5, 0, 1), + )) + f.h.settleChain() + if got := f.h.driver.Clipboard(); strings.Contains(got, "Outdated") { + t.Fatalf("stale reference copied: %q", got) + } +} + +func TestEditorContextMenuCopiesReferenceAtSecondaryPress(t *testing.T) { + h := newHarness(t, &testKernel{Client: core.NewClient()}) + root := t.TempDir() + h.open(root) + path := filepath.Join(root, "reference.txt") + if err := os.WriteFile(path, []byte("one\ntwo\nthree\n"), 0600); err != nil { + t.Fatal(err) + } + p := h.app.project + h.app.openFile(p, path) + h.settleChain() + d := p.docs.byPath(path) + if d == nil { + t.Fatal("document missing") + } + bounds := h.topHit(d.hit) + at := center(bounds) + line, _, ok := d.view.PositionAt(at.X, at.Y) + if !ok { + t.Fatal("editor has not painted") + } + h.rightClickAt(bounds) + h.clickNamed(h.shared("native.copySourceLocation")) + h.await("right-click location copied", func() bool { + return h.driver.Clipboard() == path+"#L"+strconv.Itoa(line+1) + }) +} diff --git a/desktop/internal/workbench/editor_features.go b/desktop/internal/workbench/editor_features.go index a28c3cae81..9220bcc25a 100644 --- a/desktop/internal/workbench/editor_features.go +++ b/desktop/internal/workbench/editor_features.go @@ -8,6 +8,7 @@ type editorFeatures struct { // requests counts the editor's own language requests, which name them (editor_requests.go). requests uint64 outline outlineState + copyReference copyReferenceState refs referencesState encoding encodingState lsp lspLogState diff --git a/desktop/internal/workbench/editor_menu.go b/desktop/internal/workbench/editor_menu.go index e952b8b440..16c2e56aae 100644 --- a/desktop/internal/workbench/editor_menu.go +++ b/desktop/internal/workbench/editor_menu.go @@ -49,6 +49,10 @@ func (a *App) editorMenuItems(c ui.C, p *project, d *document) func(*ui.MenuItem } } menu.Separator() + if menu.Item(i18n.Shared(language, "native.copySourceLocation")).Clicked() { + c.After(func() { a.copyReferenceLocation(p, d) }) + } + menu.Separator() if menu.Item(i18n.Shared(language, "desktop.editorMenu.toggleComment")).Keys(primary, "/").Disabled(readOnly).Clicked() { c.After(func() { a.runLineOperation(p, d, core.ToggleLineComment) }) } diff --git a/desktop/internal/workbench/editor_requests.go b/desktop/internal/workbench/editor_requests.go index d1d35a928c..aecd9a12d7 100644 --- a/desktop/internal/workbench/editor_requests.go +++ b/desktop/internal/workbench/editor_requests.go @@ -16,6 +16,7 @@ const ( // pluginSemanticDocumentSymbols and pluginSemanticTokens are the operations of the // outline and the semantic colors; their methods are what Core reports on completion. pluginSemanticDocumentSymbols = "documentSymbols" + pluginSemanticCopyReference = "copyReferenceSymbols" pluginSemanticTokens = "semanticTokens" pluginMethodDocumentSymbols = "textDocument/documentSymbol" pluginMethodSemanticTokens = "textDocument/semanticTokens/full" @@ -56,6 +57,9 @@ func (a *App) submitEditorRequest(kind semanticKind, p *project, d *document, se } a.semantics.pending = append(a.semantics.pending, pending) request.Operation, request.URI = string(kind), d.sync.uri + if kind == pluginSemanticCopyReference { + request.Operation = pluginSemanticDocumentSymbols + } a.background(p, semanticStartTimeout, func(ctx context.Context) func(*App) { operation, err := a.plugins.RequestLanguageSession(ctx, server.session, request) return func(a *App) { a.semanticRequestStarted(pending, operation, err, ctx.Err()) } @@ -74,6 +78,8 @@ func (a *App) applyEditorEvent(pending *semanticPending, event core.BackendEvent switch pending.kind { case pluginSemanticDocumentSymbols: a.applyOutline(pending, event, failed) + case pluginSemanticCopyReference: + a.applyReferenceSymbols(pending, event, failed) case pluginSemanticTokens: a.applySemanticTokens(pending, event, failed) case pluginSemanticFoldingRanges: diff --git a/desktop/internal/workbench/editor_view.go b/desktop/internal/workbench/editor_view.go index d0988e343a..17d208210c 100644 --- a/desktop/internal/workbench/editor_view.go +++ b/desktop/internal/workbench/editor_view.go @@ -257,6 +257,11 @@ func (a *App) documentKey(p *project, d *document, event gfx.KeyEvent) gfx.Event // editor: the press on a text and the moves and the release of the selection it starts, // wherever they go. func (a *App) documentPointer(p *project, d *document, event gfx.PointerEvent) gfx.EventResult { + if event.Kind == gfx.PointerDown && event.Button == gfx.PointerButtonSecondary { + if line, column, ok := d.view.PositionAt(event.X, event.Y); ok { + a.editor.copyReference.click = &referenceClick{documentID: d.id, line: line, column: column} + } + } // A semantic popup or request belongs to the caret and symbol it was opened at; any // pointer work that moved either closes it before the frame paints. defer a.pluginSemanticsCaretSync() diff --git a/desktop/internal/workbench/pluginsemantics.go b/desktop/internal/workbench/pluginsemantics.go index 5db8717d34..c11253100d 100644 --- a/desktop/internal/workbench/pluginsemantics.go +++ b/desktop/internal/workbench/pluginsemantics.go @@ -110,7 +110,7 @@ func (k semanticKind) method() string { return pluginMethodRangeFormatting case pluginSemanticRename: return pluginMethodRename - case pluginSemanticDocumentSymbols: + case pluginSemanticDocumentSymbols, pluginSemanticCopyReference: return pluginMethodDocumentSymbols case pluginSemanticTokens: return pluginMethodSemanticTokens @@ -882,6 +882,9 @@ func (a *App) semanticRequestStarted(pending *semanticPending, operation string, if err != nil { a.removePending(pending) a.settleMergeSide(pending.join, true, nil, false) + if pending.kind == pluginSemanticCopyReference { + a.applyReferenceSymbols(pending, core.BackendEvent{}, true) + } if errors.Is(err, context.Canceled) || errors.Is(ctxErr, context.Canceled) { return } diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh old mode 100755 new mode 100644 index 6ff0db1f45..8cb9f71d93 --- a/scripts/desktop/build-desktop-core.sh +++ b/scripts/desktop/build-desktop-core.sh @@ -141,7 +141,7 @@ PINNED_CORE_REPOSITORY="https://github.com/Lithe-IDEA/Lithe-core-rust.git" # the contract, plugin guides, reference and SDKs live only in shared/plugins; on top of #16 (reported Git queries folded in the console), # #15 (git.write cherryPick, revert and reset fields), #14 (word-level changed ranges of diff # rows), #13, #8, #7, #6 and #4. -PINNED_CORE_REVISION="957a349a5d8b571d416925c8231509572c2053f5" +PINNED_CORE_REVISION="7836c6cbba45620c0eb8a72d8e6152201b56ed3c" PROFILE="debug" while [[ $# -gt 0 ]]; do case "$1" in diff --git a/shared/platform-feature-matrix/features/editor-copy-reference-location.json b/shared/platform-feature-matrix/features/editor-copy-reference-location.json new file mode 100644 index 0000000000..0571d28dd4 --- /dev/null +++ b/shared/platform-feature-matrix/features/editor-copy-reference-location.json @@ -0,0 +1,29 @@ +{ + "id": "editor-copy-reference-location", + "area": "编辑器", + "group": "导航", + "capability": "从编辑器右键菜单复制符号与代码行引用", + "macos": { + "implementationStatus": "implemented", + "verificationStatus": "pending", + "evidence": [ + "desktop/internal/workbench/copy_reference.go", + "desktop/internal/workbench/editor_menu.go", + "desktop/internal/workbench/copy_reference_test.go", + "desktop/internal/core/reference_location.go" + ] + }, + "windows": { + "implementationStatus": "implemented", + "verificationStatus": "pending", + "evidence": [ + "desktop/internal/workbench/copy_reference.go", + "desktop/internal/workbench/editor_menu.go", + "desktop/internal/workbench/copy_reference_test.go", + "desktop/internal/core/reference_location.go" + ] + }, + "owner": "Editor", + "notes": "通过 Viva 共用菜单复制右键所在行的引用;Rust Core 负责从同步的 documentSymbols 生成包/类/方法签名引用,没有可靠符号时回退为文件路径与行号。菜单复用现有“复制源码位置”中英文词条;Core 与桌面修复 PR 需配套合入。", + "verification": "Core 共享 fixture 和 Rust 单测;Viva Go 测试覆盖菜单、剪贴板、语言服务器回复、无服务器回退和过期结果。双端原生验收、视觉截图待运行。" +} From bb806dcd5675ee21ff6cba12c8afd0ff15057e3f Mon Sep 17 00:00:00 2001 From: "lithe-support[bot]" <356900028+lithe-support[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:53:41 +0000 Subject: [PATCH 2/6] test(editor): add Viva headless reference menu and clipboard paste screenshots (#2015) --- ...26-11-16-copy-editor-reference-location.md | 40 +++++++ .../workbench/copy_reference_visual_test.go | 113 ++++++++++++++++++ .../editor-copy-reference-location.json | 8 +- 3 files changed, 158 insertions(+), 3 deletions(-) create mode 100644 .agents/notes/implemented/feature/2026-11-16-copy-editor-reference-location.md create mode 100644 desktop/internal/workbench/copy_reference_visual_test.go diff --git a/.agents/notes/implemented/feature/2026-11-16-copy-editor-reference-location.md b/.agents/notes/implemented/feature/2026-11-16-copy-editor-reference-location.md new file mode 100644 index 0000000000..a8a48ae9b9 --- /dev/null +++ b/.agents/notes/implemented/feature/2026-11-16-copy-editor-reference-location.md @@ -0,0 +1,40 @@ +# Agent 笔记:编辑器复制代码引用位置 + +状态:已实现 + +## 先说结论 + +Viva 编辑器的右键菜单提供复制源码位置,默认把所点行复制到剪贴板。有语言服务器同步提供的文档符号时,Rust Core 把包、类、方法及原始签名组成引用;没有可靠符号时只复制文件路径和行号,不推测源码。macOS 与 Windows 共用实现,避免两端产生不同格式。 + +## 问题 + +#2015 需要从编辑器快速得到方法引用及行号。原有标签页“复制路径/引用”只处理文件路径;从文件名和源码文本自己猜方法签名会在重载方法、嵌套类和未保存编辑时产生错误引用。 + +## 决策 + +- 使用语言服务器协议(LSP)的 `documentSymbols`:先确认当前文档已同步,随后由现有异步请求链获取符号;优先使用与文档修订相同的 Structure 缓存。 +- 桌面端只捕获右键坐标、管理请求生命周期并写入系统剪贴板;格式规则属于 Rust Core 的 `editor.copyReferenceLocation`。 +- Core 只消费上游提供的符号名称、类型、作用域及方法签名,没有可靠信息就按 `文件路径#L行号` 回退。用户看到的一基行号由 Core 统一处理。 +- 旧文档或项目、关闭的标签、后续编辑以及新一次复制都不能接收过期操作。插件会话失败与缺少符号不阻断文件路径回退。 +- 菜单复用现有共享 i18n 的“复制源码位置”(`native.copySourceLocation`),而不是在桌面端增加无法生成的硬编码界面文案。 + +## 考虑过的备选方案 + +- **直接解析 Java 源文件提取类/方法**:不采用。需要为每门语言维护解析规则,还会误识别重载方法与泛型,违反 Core 不特判语言的约束。 +- **直接复制文件行号,不请求 LSP**:只作为缺失服务器的回退;否则无法实现 Issue 要求的符号级引用。 +- **把格式规则写入 Go/Viva**:不采用。相同功能在两个平台的语义必须由共享 Core 定义。 + +## 后果 + +右键复制不启动新的常驻服务,也不阻塞编辑器线程。符号质量取决于语言服务器提供的名字与签名;有些服务器不提供包名或方法参数时,输出会相应变短。未保存修改尚未完成 LSP 同步时,优先保证位置正确并回退文件路径,不能拿旧符号当新信息。 + +## 验证 + +- Core: `cargo test -p lithe-editor`;`cargo test -p lithe-core copy_reference_location`。 +- Viva: `scripts/desktop/desktop-go.sh test ./internal/workbench -run 'TestCopyReferenceLocation|TestEditorContextMenuCopiesReference' -count=1`。 +- 视觉: `LITHE_VISUAL_OUTPUT_DIR=.artifacts/issue-2015 scripts/desktop/desktop-go.sh test -tags 'vivahead lithevisual' ./internal/workbench -run '^TestVisualCopyReferenceLocation$' -count=1`。 +- 两个平台原生集成与粘贴结果仍需实际执行,不能以静态源代码检查替代。 + +## 适用范围 + +`desktop/internal/workbench/copy_reference.go`、`desktop/internal/workbench/editor_menu.go`、`desktop/internal/core/reference_location.go`、`rust/crates/editor/src/reference_location.rs`、`rust/contracts/rust-core-api.md`。 diff --git a/desktop/internal/workbench/copy_reference_visual_test.go b/desktop/internal/workbench/copy_reference_visual_test.go new file mode 100644 index 0000000000..888b780e1c --- /dev/null +++ b/desktop/internal/workbench/copy_reference_visual_test.go @@ -0,0 +1,113 @@ +//go:build vivahead && lithevisual + +package workbench + +import ( + "os" + "path/filepath" + "testing" + + "github.com/1lck/Lithe-IDEA/desktop/internal/core" + "github.com/1lck/Lithe-IDEA/desktop/internal/store" + "github.com/vivaui/viva/app" + "github.com/vivaui/viva/headless" +) + +// TestVisualCopyReferenceLocation captures the actual editor's secondary-click +// menu and the result pasted into an editor via the primary+V shortcut. +// Dark/light x Chinese/English are independent sessions and OS-free. +func TestVisualCopyReferenceLocation(t *testing.T) { + out := os.Getenv("LITHE_VISUAL_OUTPUT_DIR") + if out == "" { + t.Skip("set LITHE_VISUAL_OUTPUT_DIR") + } + if err := os.MkdirAll(out, 0755); err != nil { + t.Fatal(err) + } + for _, look := range []struct{ theme, language string }{ + {"dark", "zh-Hans"}, {"dark", "en"}, + {"light", "zh-Hans"}, {"light", "en"}, + } { + t.Run(look.theme+"-"+look.language, func(t *testing.T) { + prefs := store.At(t.TempDir()) + if err := prefs.Save(settingsFile, settings{ + Theme: themeChoice(look.theme), Language: look.language, + DisableAutoSave: true, + }); err != nil { + t.Fatal(err) + } + root := filepath.Join(t.TempDir(), "ReferenceDemo") + if err := os.MkdirAll(root, 0700); err != nil { + t.Fatal(err) + } + path := filepath.Join(root, "DemoClass.java") + source := "package com.example;\n\npublic class DemoClass {\n void goHome(String city, Integer count) {\n System.out.println(city);\n }\n}\n" + if err := os.WriteFile(path, []byte(source), 0600); err != nil { + t.Fatal(err) + } + var session *headless.Session + h := newHarnessWithDriver(t, Options{ + Kernel: &testKernel{Client: core.NewClient()}, + Store: prefs, Languages: []string{look.language}, + }, func(config app.Config) (*app.Driver, func(), error) { + config.Width, config.Height = 1440, 900 + var err error + session, err = headless.Open(config, nil, headless.Options{}) + if err != nil { + return nil, nil, err + } + return session.Driver(), session.Close, nil + }) + h.open(root) + p := h.app.project + h.app.openFile(p, path) + h.settleChain() + d := p.docs.byPath(path) + if d == nil { + t.Fatal("editor not opened") + } + d.view.GoToLine(5) + h.app.focusDocument(d.id) + h.settleChain() + h.rightClickAt(h.topHit(d.hit)) + if !h.shows(h.shared("native.copySourceLocation")) { + t.Fatal("reference copy action missing from context menu") + } + if err := session.Screenshot(filepath.Join(out, "reference-menu-"+look.theme+"-"+look.language+".png")); err != nil { + t.Fatal(err) + } + // PositionAt the secondary press controls the reference's line, not + // the caret set above. Copying a plain file is a valid fallback. + h.clickNamed(h.shared("native.copySourceLocation")) + h.await("reference on clipboard", func() bool { + return len(h.driver.Clipboard()) >= len(path)+3 && h.driver.Clipboard()[:len(path)+2] == path+"#L" + }) + reference := h.driver.Clipboard() + if reference[:len(path)] != path || reference[len(path):len(path)+2] != "#L" { + t.Fatalf("unexpected clipboard reference %q", reference) + } + resultPath := filepath.Join(root, "pasted-result.txt") + if err := os.WriteFile(resultPath, []byte(""), 0600); err != nil { + t.Fatal(err) + } + h.app.openFile(p, resultPath) + h.settleChain() + resultDoc := p.docs.byPath(resultPath) + if resultDoc == nil { + t.Fatal("result editor not opened") + } + h.app.focusDocument(resultDoc.id) + h.settleChain() + handled, err := h.driver.ShortcutChord(primaryModifier(), 'v') + if err != nil || !handled { + t.Fatalf("clipboard paste shortcut handled=%v error=%v", handled, err) + } + h.await("paste result appears", func() bool { + return resultDoc.view.TextSnapshot().String() == reference + }) + if err := session.Screenshot(filepath.Join(out, "reference-pasted-"+look.theme+"-"+look.language+".png")); err != nil { + t.Fatal(err) + } + }) + } +} diff --git a/shared/platform-feature-matrix/features/editor-copy-reference-location.json b/shared/platform-feature-matrix/features/editor-copy-reference-location.json index 0571d28dd4..1aed9f925b 100644 --- a/shared/platform-feature-matrix/features/editor-copy-reference-location.json +++ b/shared/platform-feature-matrix/features/editor-copy-reference-location.json @@ -10,7 +10,8 @@ "desktop/internal/workbench/copy_reference.go", "desktop/internal/workbench/editor_menu.go", "desktop/internal/workbench/copy_reference_test.go", - "desktop/internal/core/reference_location.go" + "desktop/internal/core/reference_location.go", + "desktop/internal/workbench/copy_reference_visual_test.go" ] }, "windows": { @@ -20,10 +21,11 @@ "desktop/internal/workbench/copy_reference.go", "desktop/internal/workbench/editor_menu.go", "desktop/internal/workbench/copy_reference_test.go", - "desktop/internal/core/reference_location.go" + "desktop/internal/core/reference_location.go", + "desktop/internal/workbench/copy_reference_visual_test.go" ] }, "owner": "Editor", "notes": "通过 Viva 共用菜单复制右键所在行的引用;Rust Core 负责从同步的 documentSymbols 生成包/类/方法签名引用,没有可靠符号时回退为文件路径与行号。菜单复用现有“复制源码位置”中英文词条;Core 与桌面修复 PR 需配套合入。", - "verification": "Core 共享 fixture 和 Rust 单测;Viva Go 测试覆盖菜单、剪贴板、语言服务器回复、无服务器回退和过期结果。双端原生验收、视觉截图待运行。" + "verification": "Core 共享 fixture 和 Rust 单测;Viva Go 测试覆盖菜单、剪贴板、语言服务器回复、无服务器回退和过期结果。双端原生验收、视觉截图待运行。 Viva Headless 测试定义在 copy_reference_visual_test.go,执行后输出四组菜单与真实粘贴截图。" } From 36f7ddd72eb954b12db045f0c3b5d63a6da8674f Mon Sep 17 00:00:00 2001 From: "lithe-support[bot]" <356900028+lithe-support[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:57:38 +0000 Subject: [PATCH 3/6] style(editor): align Viva Go files with gofmt (#2015) --- desktop/internal/workbench/copy_reference.go | 12 ++++++------ .../internal/workbench/copy_reference_visual_test.go | 2 +- desktop/internal/workbench/editor_features.go | 12 ++++++------ desktop/internal/workbench/editor_requests.go | 2 +- 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/desktop/internal/workbench/copy_reference.go b/desktop/internal/workbench/copy_reference.go index 0f16631b7f..d8090b225d 100644 --- a/desktop/internal/workbench/copy_reference.go +++ b/desktop/internal/workbench/copy_reference.go @@ -12,20 +12,20 @@ import ( // keyboard caret. The context-menu item consumes the coordinate after the // popup closes; each operation owns a revision and an identity token. type referenceClick struct { - documentID int + documentID int line, column int } type referenceRequest struct { - project *project + project *project documentID, revision int - line, column int - path string - pending *semanticPending + line, column int + path string + pending *semanticPending } type copyReferenceState struct { - click *referenceClick + click *referenceClick request *referenceRequest } diff --git a/desktop/internal/workbench/copy_reference_visual_test.go b/desktop/internal/workbench/copy_reference_visual_test.go index 888b780e1c..489588a37c 100644 --- a/desktop/internal/workbench/copy_reference_visual_test.go +++ b/desktop/internal/workbench/copy_reference_visual_test.go @@ -48,7 +48,7 @@ func TestVisualCopyReferenceLocation(t *testing.T) { var session *headless.Session h := newHarnessWithDriver(t, Options{ Kernel: &testKernel{Client: core.NewClient()}, - Store: prefs, Languages: []string{look.language}, + Store: prefs, Languages: []string{look.language}, }, func(config app.Config) (*app.Driver, func(), error) { config.Width, config.Height = 1440, 900 var err error diff --git a/desktop/internal/workbench/editor_features.go b/desktop/internal/workbench/editor_features.go index 9220bcc25a..a77265031e 100644 --- a/desktop/internal/workbench/editor_features.go +++ b/desktop/internal/workbench/editor_features.go @@ -6,11 +6,11 @@ package workbench type editorFeatures struct { nav navigationHistoryState // requests counts the editor's own language requests, which name them (editor_requests.go). - requests uint64 - outline outlineState + requests uint64 + outline outlineState copyReference copyReferenceState - refs referencesState - encoding encodingState - lsp lspLogState - tokens semanticTokensState + refs referencesState + encoding encodingState + lsp lspLogState + tokens semanticTokensState } diff --git a/desktop/internal/workbench/editor_requests.go b/desktop/internal/workbench/editor_requests.go index aecd9a12d7..d414c97430 100644 --- a/desktop/internal/workbench/editor_requests.go +++ b/desktop/internal/workbench/editor_requests.go @@ -16,7 +16,7 @@ const ( // pluginSemanticDocumentSymbols and pluginSemanticTokens are the operations of the // outline and the semantic colors; their methods are what Core reports on completion. pluginSemanticDocumentSymbols = "documentSymbols" - pluginSemanticCopyReference = "copyReferenceSymbols" + pluginSemanticCopyReference = "copyReferenceSymbols" pluginSemanticTokens = "semanticTokens" pluginMethodDocumentSymbols = "textDocument/documentSymbol" pluginMethodSemanticTokens = "textDocument/semanticTokens/full" From e650bc0417f1924fbcfc5bc3bd440a6b57e46737 Mon Sep 17 00:00:00 2001 From: "lithe-support[bot]" <356900028+lithe-support[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 11:59:37 +0000 Subject: [PATCH 4/6] fix(build): restore executable permission on desktop Core builder (#2015) --- scripts/desktop/build-desktop-core.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 scripts/desktop/build-desktop-core.sh diff --git a/scripts/desktop/build-desktop-core.sh b/scripts/desktop/build-desktop-core.sh old mode 100644 new mode 100755 From e1b49cce76c7736cea728da6a9a64140d8b44962 Mon Sep 17 00:00:00 2001 From: "lithe-support[bot]" <356900028+lithe-support[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 12:11:06 +0000 Subject: [PATCH 5/6] test(editor): expose symbol-copy lifecycle and clipboard diagnostics (#2015) --- desktop/internal/workbench/copy_reference_test.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/desktop/internal/workbench/copy_reference_test.go b/desktop/internal/workbench/copy_reference_test.go index 1842409a6d..3c09bb6b71 100644 --- a/desktop/internal/workbench/copy_reference_test.go +++ b/desktop/internal/workbench/copy_reference_test.go @@ -45,9 +45,16 @@ func TestCopyReferenceLocationUsesLanguageSymbols(t *testing.T) { symbolAt("DemoClass", 5, 0, 1, symbolAt("goHome(String,Integer)", 6, 0, 1)), )) - f.h.await("symbol reference copied", func() bool { - return f.h.driver.Clipboard() == "DemoClass#goHome(String,Integer)#L1" + t.Cleanup(func() { + req := f.h.app.editor.copyReference.request + t.Logf("reference diagnostics: clipboard=%q pendingRequest=%v activeGroup=%q docGroup=%q selected=%p expectedDoc=%p", f.h.driver.Clipboard(), req != nil, f.p.docs.group, f.d.group, f.p.selectedDocument(f.p.docs.group), f.d) }) + f.h.await("symbol reference request settled", func() bool { + return f.h.app.editor.copyReference.request == nil + }) + if got := f.h.driver.Clipboard(); got != "DemoClass#goHome(String,Integer)#L1" { + t.Fatalf("copied %q, want method reference", got) + } } func TestCopyReferenceLocationDiscardsOldDocumentRevision(t *testing.T) { From 3af51e1e2441421b6918473543f7d05fb457af36 Mon Sep 17 00:00:00 2001 From: "lithe-support[bot]" <356900028+lithe-support[bot]@users.noreply.github.com> Date: Mon, 16 Nov 2026 12:14:08 +0000 Subject: [PATCH 6/6] test(editor): wait for exact documentSymbols operation before injecting replies (#2015) --- .../internal/workbench/copy_reference_test.go | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/desktop/internal/workbench/copy_reference_test.go b/desktop/internal/workbench/copy_reference_test.go index 3c09bb6b71..8e9172f6f4 100644 --- a/desktop/internal/workbench/copy_reference_test.go +++ b/desktop/internal/workbench/copy_reference_test.go @@ -37,11 +37,12 @@ func TestCopyReferenceLocationUsesLanguageSymbols(t *testing.T) { f.server.features = map[string]bool{featureDocumentSymbols: true} f.d.view.SetSelection(0, 0) f.h.app.copyReferenceLocation(f.p, f.d) - f.waitForRequests(t, 1) - if got := f.kernel.request(0).Operation; got != pluginSemanticDocumentSymbols { - t.Fatalf("LSP operation = %q", got) - } - f.deliver(t, "op-1", pluginMethodDocumentSymbols, symbolsResult(t, + f.h.await("reference symbol request submitted", func() bool { + req := f.h.app.editor.copyReference.request + return req != nil && req.pending != nil && req.pending.operation != "" + }) + pending := f.h.app.editor.copyReference.request.pending + f.deliver(t, pending.operation, pluginMethodDocumentSymbols, symbolsResult(t, symbolAt("DemoClass", 5, 0, 1, symbolAt("goHome(String,Integer)", 6, 0, 1)), )) @@ -61,9 +62,13 @@ func TestCopyReferenceLocationDiscardsOldDocumentRevision(t *testing.T) { f := newSemanticFixture(t) f.server.features = map[string]bool{featureDocumentSymbols: true} f.h.app.copyReferenceLocation(f.p, f.d) - f.waitForRequests(t, 1) + f.h.await("stale-reference symbol request submitted", func() bool { + req := f.h.app.editor.copyReference.request + return req != nil && req.pending != nil && req.pending.operation != "" + }) + pending := f.h.app.editor.copyReference.request.pending f.h.app.insertForTest(f.d, "changed") - f.deliver(t, "op-1", pluginMethodDocumentSymbols, symbolsResult(t, + f.deliver(t, pending.operation, pluginMethodDocumentSymbols, symbolsResult(t, symbolAt("Outdated", 5, 0, 1), )) f.h.settleChain()