Skip to content

feat(lsp): decide declaration or usages; references can leave the declaration out - #20

Merged
1lck merged 1 commit into
mainfrom
feat/declaration-or-usages
Nov 12, 2026
Merged

1lck merged 1 commit into
mainfrom
feat/declaration-or-usages

Conversation

@1lck

@1lck 1lck commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

背景

桌面端要沿用 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,宿主照旧提示“没有定义”。
    • 共享 fixture:rust/fixtures/lsp/declaration-or-usages-v1.json(13 个用例,含边界与非法输入)。
    • 注册:protocol/command.rs、runtime/dispatcher.rs、lsp/mod.rs。
  • 语义请求 references 新增可选字段 includeDeclaration:写入 LSP params.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,改动前就有)。

消费者

  • Lithe 桌面端随后把 PINNED_CORE_REVISION 升到本 PR 合并后的 commit,并接入 ⌘B / ⌘+左键 / F12 / 编辑器菜单。没有修改插件契约、能力版本或插件函数协议,所以不需要更新协议更新记录。

🤖 Generated with Claude Code

… 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>
@1lck
1lck merged commit 74d5aac into main Nov 12, 2026
5 checks passed
@1lck
1lck deleted the feat/declaration-or-usages branch November 12, 2026 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant