Repository navigation
feat(lsp): decide declaration or usages; references can leave the declaration out - #20
Merged
Merged
Conversation
… declaration out
Go to declaration follows IntelliJ IDEA's Go to Declaration or Usages:
from a use it opens the declaration; from the declaration itself, where
the definition answer is the place the caret sits on, it shows usages.
- lsp.declarationOrUsages takes the gesture's document and position and
the definition answer and returns { action: usages | definitions }.
A location is the gesture's own place when it is in the same document
and contains the position, end included (an editor resolves the
identifier left of the caret). Fixture:
rust/fixtures/lsp/declaration-or-usages-v1.json.
- Semantic operation references accepts optional includeDeclaration,
sent as LSP context.includeDeclaration; unset keeps true, so existing
callers are unchanged. The usages list asks for false and the language
server leaves the declaration out.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
背景
桌面端要沿用 IntelliJ IDEA 的 Go to Declaration or Usages(⌘B / Ctrl+B、⌘/Ctrl+左键):在使用处跳到声明;在声明本身上按,定义请求的结果就是光标所在的位置,这时改为列出使用处(只有一处直接跳,多处列出来,没有就提示)。按 develop-lithe 的逻辑归属,这个判断放在 Core,桌面端只负责呈现。
改动
lsp.declarationOrUsages(rust/lithe-core/src/lsp/declaration_or_usages.rs):输入{ uri, position, definitions }(零起算line/utf16Column,definitions最多 100 个{uri, range}),返回{ action: "usages" | "definitions" }。所有定义位置都是“自己”(同一文档且范围包含该位置,含结束位置:光标紧跟在名字后面时编辑器解析的就是左边的标识符)才返回usages;空答案返回definitions,宿主照旧提示“没有定义”。rust/fixtures/lsp/declaration-or-usages-v1.json(13 个用例,含边界与非法输入)。protocol/command.rs、runtime/dispatcher.rs、lsp/mod.rs。references新增可选字段includeDeclaration:写入 LSPparams.context.includeDeclaration;不传等于true,现有调用(查找用法面板)行为不变。从声明列使用处时传false,由语言服务器(上游)去掉声明本身,Core 不再维护第二份过滤规则。涉及SemanticRequest、ClientFeatureRequest及转换,测试里的结构体字面量补了include_declaration: None。rust/contracts/rust-core-api.md:补充两处说明。验证
cargo test -p lithe-core:1741 passed(含新增lsp::declaration_or_usages::tests::matches_shared_fixture、lsp::tests::client_references_request_passes_include_declaration)。scripts/rust-core/verify-rust-core-comments.sh通过(唯一的 rustdoc 警告在plugins/capabilities.rs,改动前就有)。消费者
PINNED_CORE_REVISION升到本 PR 合并后的 commit,并接入 ⌘B / ⌘+左键 / F12 / 编辑器菜单。没有修改插件契约、能力版本或插件函数协议,所以不需要更新协议更新记录。🤖 Generated with Claude Code