Repository navigation
feat(lsp-engine): keep hover answers so resting on a symbol again answers at once - #61
Merged
Merged
Conversation
…wers at once Refs 1lck/Lithe-IDEA#1995. Every hover went to the language server, so resting on the same symbol again waited for the server a second time. The LSP engine now keeps each session's hover answers in a bounded cache (HOVER_CACHE_CAPACITY = 32, least recently used first; answers over HOVER_CACHE_MAX_CONTENT_BYTES = 64 KiB are not kept). A host hover for the same document version and position, or for a position inside the answer's same-line range, completes from the cache without writing textDocument/hover. Empty answers, errors, and answers that arrive after a clear are delivered but not kept. Every kept answer is forgotten when anything can change what the server knows: document open/change/save/close, workspace file changes, configuration or indexing-exclusion changes, executeCommand, plugin backend languageServer requests and notifications, host notifications, any request from the server, the end of a $/progress, and session stop. A generation counter refuses answers the server computed before such a clear. Documents the behaviour in the contract README, the languages reference and the protocol changelog; the requestCompleted result shape is unchanged.
22 of 25 tasks
xiaoyumuxi
marked this pull request as ready for review
November 16, 2026 02:52
19 of 25 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
关联 Issue / Linked issue
#1995 的桌面端部分(指针离开文本后同一字符不再悬浮)在 1lck/Lithe-IDEA#2004 修复。本 PR 是 Core 部分:在同一个符号上再次停留时直接给出答案,不再等语言服务器。Lithe-IDEA 把
PINNED_CORE_REVISION升到包含本 PR 的 commit 后,由那个 PR 关闭 #1995。PR 类型 / Type
改动说明 / What changes
背景 / Why
每次悬浮都会给语言服务器发一次
textDocument/hover。在同一个符号上移开再停回来,桌面端要再等 500 ms 的悬浮延迟,再加一次服务器往返;gopls 在大型仓库上忙于索引时,这次往返也会很慢。答案没有变,却要重新等一次。本 PR 在 LSP 引擎里为每个会话保留悬浮答案。同一文档版本的同一位置,或答案
range在同一行内覆盖的位置,直接用保留的答案完成请求,不再写给服务器。服务器可能知道新东西时,清空所有保留的答案。改动 / Changes
新模块
rust/crates/lsp-engine/src/hover_cache.rsHOVER_CACHE_CAPACITY = 32:每个会话最多 32 个答案,先丢最久没用的(LRU,命中时移到队尾);HOVER_CACHE_MAX_CONTENT_BYTES = 64 KiB:更长的答案照常交付,但不保留。range是同一行上的非空范围、并且包含请求位置时,范围内的其他列也命中,和编辑器把悬浮窗留在整个符号上的做法一致。hover为null、contents为空或只有空白、错误、超长,以及在缓存清空之后才到达的答案。generation加一。请求发出时记下generation,答案到达时generation变了就不保留,因为服务器可能是按变化前的状态算出的答案。server_message_clears_hovers(value):服务器发来的任何请求(刷新、编辑、注册能力、拉配置、创建进度 token 等),以及$/progress的end,都表示服务器可能知道了新东西。report、begin和publishDiagnostics这类通知不清空。状态(
state.rs、engine.rs)SessionState.hover_cache:缓存属于会话状态,会话结束随状态一起释放。PendingRequest.hover: Option<HoverRequest>:只有宿主自己的悬浮请求(PendingKind::Feature)带它,答案到达时据此保留。其他构造点(lifecycle.rs、plugin_server_calls.rs、operations.rs)填None。命中与保留(
operations.rs、server_messages.rs)request_with_kind:宿主的Hover请求在能力检查之后查缓存。文档必须是打开的、版本 > 0、请求带位置。push_request_event推送requestCompleted,不写消息、不建 pending。结果和服务器答案逐字节相同,method不变。HoverRequest。InvalidRequest。handle_server_message:Feature 响应没有错误、有结果、带HoverRequest时调用store。清空点(都在
outbound_order锁下,与写给服务器的消息原子;锁顺序不变,仍是indexing_roots→outbound_order→state)documents.rssyncdidSave时;文本落后于已同步版本的延迟保存不发也不清空)documents.rssavedocuments.rsclosedocuments.rsworkspace_files_changedconfiguration.rsupdate_plugin_configuration)configuration.rsworkspace/executeCommandoperations.rsrequest_with_kindlanguageServer/request(方法名无法区分是不是会改状态的命令,所以一律清空)plugin_server_calls.rsregister_plugin_server_requestlanguageServer/notifyoperations.rsplugin_server_notifyhost_notify)operations.rshost_notify$/progressserver_messages.rsevents.rsclear_runtime_state;重启是新会话,状态本来就是新的文档
shared/plugins/contract/v1/README.md“Language servers”:写明宿主保留悬浮答案的规则、上限、不保留的答案、清空条件,以及悬浮因其他原因变化的服务器要用请求(例如刷新)或结束一项进度来告知。shared/plugins/reference/domains/languages.md中英两节各加一段,链接到契约。shared/plugins/reference/protocol-changelog.md时间线新增 2026-11-16 一行:languageServers0 内的补充,没有新增方法、字段或能力版本。测试
hover_cache.rs单元测试:$/progress结束会清空。tests.rs用脚本化服务器的会话测试(新增 harness 方法request_at、answer_hover、hover_from_cache、hover_asks_server,后两个断言有没有新的textDocument/hover写给服务器):a_kept_hover_answers_its_position_and_range_without_asking_again:命中时结果、method和服务器答案相同;range 内的列命中,range 末尾和别的行重新请求。a_range_over_several_lines_or_elsewhere_answers_only_the_requested_positionan_empty_failed_or_oversized_hover_is_asked_for_again:null、空串、只有空白、空数组、-32801错误、超长答案都重新请求,超长答案仍然完整交付。anything_that_can_change_what_the_server_knows_forgets_kept_hovers:逐个验证编辑另一个文档、保存、关闭后以同一版本重新打开、磁盘文件变化、运行命令、服务器发来请求、$/progress结束都会清空。progress_reports_and_other_documents_hovers_keep_kept_hovers:进度report、重复同步相同文本、另一个文档的悬浮都不清空。a_hover_answered_across_an_invalidation_is_delivered_but_not_keptan_edit_to_the_hovered_document_asks_again_at_its_new_version不在本 PR 范围内 / Out of scope
update_plugin_configuration和host_notify两个清空点需要插件会话,本 PR 的测试没有覆盖,只做了代码检查。PINNED_CORE_REVISION(同时带上 fix(project): batch Git ignore checks per directory level #60 对 [Bug] 大型 Git 仓库中 Core 启动语言服务器前逐个目录执行 git check-ignore,Kubernetes 上 gopls 晚约 30 秒才启动 1lck/Lithe-IDEA#1994 的修复),在桌面端复测后关闭 #1994 和 #1995,本 PR 合入后另开。providers.hover)不走这个缓存。类型专属:feat
多平台对齐
范围检查 / Scope checks
lsp-completion-hover条目,由 #2004 和随后升级 Core 修订的 PR 更新。file:///workspace/*.go合成文档,没有按语言或服务器 ID 分支。requestCompleted事件。generate-log-events.mjs --check通过。sdk-e2e.mjs,也没有方法表。验证 / Verification
本机为 Apple M4、macOS arm64。
cargo fmt --manifest-path rust/Cargo.toml --all -- --checknode scripts/rust-core/affected-crates.mjs-p lithe-core -p lithe-lsp-enginecargo test --locked --manifest-path rust/Cargo.toml -p lithe-core -p lithe-lsp-enginecargo clippy --locked …(同上 2 个包)--all-targets -- -D warnings,以及--all-featurescargo clippy --locked …(同上 2 个包)--all-targets --target x86_64-pc-windows-msvc -- -D warningsscripts/rust-core/verify-rust-core-comments.sh lsp-enginenode scripts/rust-core/verify-platform-tests.mjsnode scripts/logging/generate-log-events.mjs --checknode shared/plugins/scripts/verify-docs.mjs、node --test shared/plugins/scripts/*.test.mjsclear()不清空条目、store()忽略generationhandle_server_message里的清空anything_that_can_change_what_the_server_knows_forgets_kept_hovers按预期失败(a request from the server must forget kept hovers),恢复后通过未能执行的检查和原因:
提交前确认 / Final checks
main(ca80599)创建,目标分支main