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,39 @@
# Agent 笔记:Viva 编辑器的代码操作、参数信息与内联提示

状态:已实现

## 先说结论

代码操作、参数信息和内联提示由标准语言服务器协议提供。Rust Core 校验请求、响应及文档版本,Viva 负责编辑器交互和文件写入。对于折叠的文档,编辑器把可见行拆成多个连续区间,分别请求提示。

## 问题

语言服务器的回复和正在编辑的文本可能属于不同版本。代码操作还可能先编辑几个文件,再要求语言服务器执行命令。滚动和折叠则会不断改变需要显示提示的行。

## 决策

- 按 Core 返回的操作 ID 接收结果。对于先到的完成事件,等同 ID 的提交确认后再处理。请求期间替换文档或更改版本时,丢弃旧结果。
- Core 校验服务器给出的文档版本。Viva 再核对当前同步状态和视图修订,在后台准备编辑。关闭工作区、取消或目标变化时,后台任务负责按旧内容恢复本次已经写入的文件。恢复时核对写入后的字节,保留同时发生的外部改动。
- 代码操作附带的命令在相关编辑内容同步到语言服务器后发送。参数信息使用服务端能力声明触发,并根据服务端返回的结果更新,避免用宿主的括号规则猜测不同语言的参数范围。
- 折叠块两侧的可见行分别请求。提示排版依赖不可变文本快照,并在视图修订匹配时安装。涉及超长单行时,继续分页绘制源码,该行省略内联提示。

## 考虑过的备选方案

- 按方法名匹配提前到达的完成事件。同一文档的前后两次操作会共用方法名,导致旧编辑误用新请求的修订。
- 从首个到最后一个可见逻辑行发出单次请求。折叠一千行后,这个区间仍包含一千行,隐藏结果可能先耗尽提示额度。
- 在字符表面叠放浮层或向文本插入空格。折行、选区和鼠标命中依赖同一几何,覆盖层不能可靠匹配,插入空格还会污染实际文档。

## 后果

编辑缓冲区和磁盘上的文件都可以参与代码操作。外部进程同时改写目标文件时,保护写入可能拒绝编辑或回滚,并记录对应失败。多段可见提示减少折叠区的工作量,语言服务器需要分段返回。

## 验证

运行 `scripts/desktop/desktop-go.sh test ./internal/workbench ./internal/editorview`,覆盖快捷键、编辑撤销、取消恢复、请求身份、提示生命周期及布局。使用 `TestVisualLSPActions` 生成中英文与明暗主题的无头截图,用 `scripts/desktop/perf/editor-bench.sh` 对比编辑器基准。

## 适用范围

- `desktop/internal/workbench/pluginsemantics_codeactions.go`
- `desktop/internal/workbench/signature_help.go`
- `desktop/internal/workbench/inlay_hints.go`
- `desktop/internal/editorview/inlayhints.go`
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Agent 笔记:Viva 内联提示请求失败后的视口重试

状态:已实现

## 先说结论

编辑器请求内联提示遇到临时错误时,会对同一视口自动重试一次。服务连续失败后,编辑器等到视口、文档版本或服务刷新事件变化时再请求。等待期间保留当前文档已有的提示。

## 问题

语言服务器可能在编辑过程中撤回请求,响应也可能无法解码。原来这两种情况都会把整个视口登记为已取回。停留在相同位置等服务恢复时,编辑器会一直跳过该视口的请求。

## 决策

- 每个可见范围批次成功返回后才缓存覆盖范围。一个分段失败时,丢弃这次批次收集到的结果,保留上一份已绘制的提示。
- 首次失败后通过画布调度一次延迟帧。重试仍失败便等待输入、文档版本或服务刷新事件。刷新从新批次开始,过期批次的结果直接丢弃。

## 考虑过的备选方案

- 把失败当作空结果缓存,编辑器将失去自动恢复机会。
- 失败后立即重新请求,服务持续失败时,每次响应都会引出新的请求和帧。

## 后果

短暂失败会增加一次视口请求。服务器恢复较慢时,旧提示会一直保留到下次成功刷新、文档版本变化或编辑器关闭。

## 验证

- `scripts/desktop/desktop-go.sh test ./internal/workbench -run '^TestLSPInlayHints'` 使用合成服务和虚拟时钟验证自动恢复、连续失败后停止,以及收到服务刷新后的恢复。
- `TestVisualLSPActions` 检查同一视口中一次失败前后的绘制,覆盖深浅主题与中英文。

## 适用范围

- `desktop/internal/workbench/inlay_hints.go`
- [Viva 编辑器的代码操作、参数信息与内联提示](../architecture/2026-11-18-viva-lsp-editor-actions-and-hints.md)
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Agent 笔记:Windows 工具链发现使用文件句柄读取最终路径

状态:已实现

## 先说结论

Windows 工具链发现通过文件句柄读取最终路径。目录联接点(junction,Windows 上把一个目录指向另一位置的重定向)也会被解析,Core 因此能在版本探测前检查实际目录是否仍在工作区内。

## 问题

PR #2175 和桌面主线的 Windows CI 都发现,指向工作区外的环境目录被当作工作区内的环境接受。Go 的 `filepath.EvalSymlinks` 无法完整解析经过联接点的路径。宿主遇到解析失败时,仍可能把原路径作为最终路径交给 Core。[Go #82447](https://github.com/golang/go/issues/82447)

## 决策

- Windows 使用 `GetFinalPathNameByHandleW` 读取系统解析出的路径,再以 Core 已支持的盘符或 UNC 共享路径形式上报。句柄仅用于读取元数据,候选读取结束即关闭。[Windows API 文档](https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfinalpathnamebyhandlew)
- 文件或目录候选必须同时有最终路径与匹配的文件类型证据。解析失败时,该路径不能作为文件或目录候选上报。是否允许探测和选择仍由 Core 判定。

## 考虑过的备选方案

- 逐段解析联接点需要维护 Windows 重定向类型、循环和长路径规则。通过已打开的句柄读取最终路径可以复用系统已完成的解析。

## 后果

Core 能区分项目内环境目录和指向外部的目录联接点。无法取得最终路径的候选会被排除。读取发生在工具链发现期间,无需修改工具配置或安装文件。

## 验证

`scripts/desktop/desktop-go.sh test ./internal/toolchain -run '^TestTrustedWorkspaceResolvesSubdirectoryEnvironmentAndRejectsEscapingDirectories$'`。用例同时检查合法的子目录环境可选,以及外部目录联接点返回 `unsafePath` 且没有启动任何探测。macOS 使用目录符号链接执行对应断言。

## 适用范围

- `desktop/internal/toolchain/native_path_windows.go`
- `desktop/internal/toolchain/scan.go`
- `desktop/internal/toolchain/project_trust_test.go`
20 changes: 20 additions & 0 deletions .github/workflows/desktop-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,26 @@ jobs:
- name: Vet and test
run: ./scripts/desktop/check.sh

- name: Run LSP editor headless tests
id: lsp-visual
# Capture evidence even when an unrelated test in the full suite fails.
if: ${{ !cancelled() && steps.rust.outcome == 'success' }}
timeout-minutes: 5
env:
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

- name: Upload LSP editor screenshots
if: ${{ !cancelled() && steps.lsp-visual.outcome != 'skipped' }}
uses: actions/upload-artifact@v7
with:
name: lsp-editor-visual-${{ runner.os }}-${{ runner.arch }}
path: .artifacts/lsp-editor-visual/*.png
if-no-files-found: error
retention-days: 14

- name: Upload native verification reports
if: always()
uses: actions/upload-artifact@v7
Expand Down
2 changes: 2 additions & 0 deletions desktop/internal/core/editor_essentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
type EditorStoredPreferences struct {
LineNumbers *bool `json:"lineNumbers,omitempty"`
Whitespace *bool `json:"whitespace,omitempty"`
InlayHints *bool `json:"inlayHints,omitempty"`
CursorStyle string `json:"cursorStyle,omitempty"`
CursorBlink *bool `json:"cursorBlink,omitempty"`
AutoSaveDelayMilliseconds *uint64 `json:"autoSaveDelayMilliseconds,omitempty"`
Expand All @@ -20,6 +21,7 @@ type EditorStoredPreferences struct {
type EditorPreferences struct {
LineNumbers bool `json:"lineNumbers"`
Whitespace bool `json:"whitespace"`
InlayHints bool `json:"inlayHints"`
CursorStyle string `json:"cursorStyle"`
CursorBlink bool `json:"cursorBlink"`
AutoSaveDelayMilliseconds uint64 `json:"autoSaveDelayMilliseconds"`
Expand Down
51 changes: 32 additions & 19 deletions desktop/internal/core/plugin_documents.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,19 @@ func (c *Client) ClosePluginDocument(ctx context.Context, session, uri string) e
// operation name rather than a raw LSP method, so Core decides which server
// feature answers it.
type PluginSemanticRequest struct {
SessionID string
Operation string
URI string
Position *PluginDocumentPosition
CompletionContext json.RawMessage
SessionID string
Operation string
URI string
Position *PluginDocumentPosition
Diagnostics []PluginDiagnostic
CodeActionContext json.RawMessage
CompletionContext json.RawMessage
SignatureHelpContext json.RawMessage
CodeAction json.RawMessage
InlayHint json.RawMessage
// NewName is the rename operation's replacement identifier.
NewName string
// Range is the range rangeFormatting formats; Core requires it for that operation.
// Range is the range rangeFormatting, codeActions or inlayHints covers.
Range *PluginDocumentRange
// FormattingOptions is optional for formatting and rangeFormatting; Core fills unset
// fields with its defaults.
Expand Down Expand Up @@ -152,26 +157,34 @@ func (c *Client) PluginDocumentURI(ctx context.Context, path, platform string) (

// pluginSemanticBody is the lsp.request payload.
type pluginSemanticBody struct {
SessionID string `json:"sessionId"`
Operation string `json:"operation"`
URI string `json:"uri,omitempty"`
Position *PluginDocumentPosition `json:"position,omitempty"`
CompletionContext json.RawMessage `json:"completionContext,omitempty"`
NewName string `json:"newName,omitempty"`
Range *PluginDocumentRange `json:"range,omitempty"`
FormattingOptions *FormattingOptions `json:"formattingOptions,omitempty"`
OperationID string `json:"operationId,omitempty"`
Command json.RawMessage `json:"command,omitempty"`
Query string `json:"query,omitempty"`
IncludeDeclaration *bool `json:"includeDeclaration,omitempty"`
SessionID string `json:"sessionId"`
Operation string `json:"operation"`
URI string `json:"uri,omitempty"`
Position *PluginDocumentPosition `json:"position,omitempty"`
Diagnostics []PluginDiagnostic `json:"diagnostics,omitempty"`
CodeActionContext json.RawMessage `json:"codeActionContext,omitempty"`
CompletionContext json.RawMessage `json:"completionContext,omitempty"`
SignatureHelpContext json.RawMessage `json:"signatureHelpContext,omitempty"`
CodeAction json.RawMessage `json:"codeAction,omitempty"`
InlayHint json.RawMessage `json:"inlayHint,omitempty"`
NewName string `json:"newName,omitempty"`
Range *PluginDocumentRange `json:"range,omitempty"`
FormattingOptions *FormattingOptions `json:"formattingOptions,omitempty"`
OperationID string `json:"operationId,omitempty"`
Command json.RawMessage `json:"command,omitempty"`
Query string `json:"query,omitempty"`
IncludeDeclaration *bool `json:"includeDeclaration,omitempty"`
}

// RequestPluginSemantics submits a semantic request and returns Core's opaque
// operation ID. Completion and results arrive in the session's ordered events.
func (c *Client) RequestPluginSemantics(ctx context.Context, request PluginSemanticRequest) (string, error) {
body := pluginSemanticBody{
SessionID: request.SessionID, Operation: request.Operation, URI: request.URI,
Position: request.Position, CompletionContext: request.CompletionContext, NewName: request.NewName,
Position: request.Position, Diagnostics: request.Diagnostics,
CodeActionContext: request.CodeActionContext, CompletionContext: request.CompletionContext,
SignatureHelpContext: request.SignatureHelpContext, CodeAction: request.CodeAction,
InlayHint: request.InlayHint, NewName: request.NewName,
Range: request.Range, FormattingOptions: request.FormattingOptions,
OperationID: request.OperationID, Command: request.Command, Query: request.Query,
IncludeDeclaration: request.IncludeDeclaration,
Expand Down
Loading
Loading