Repository navigation
fix: return definition links and honor includeDeclaration - #168
lvliangxiong wants to merge 3 commits into
Conversation
|
中文说明:这个 PR 完善 Protols 语言服务器的定义跳转和引用查询,使返回范围更准确,并遵守 LSP 的能力协商和请求参数。
验证:本地 126 项测试、严格 Clippy 检查、格式检查、debug/release 构建和实际 LSP 请求验证均已通过,覆盖能力开关、完整路径与类型范围,以及不同引用数量。 在包含 309 个现有 proto 文件及一个测试文件的本地工作区中,原引用查询超过 45 秒超时;优化后同一查询约 10 毫秒返回两个预期引用。 |
There was a problem hiding this comment.
These tests should be at their own modules. such as reference, definition etc
There was a problem hiding this comment.
Thanks for the feedback! Addressed in be1190a. The definition and import navigation tests now live in definition.rs, and the reference query tests live in resolve.rs, alongside their implementations. I removed navigation_tests.rs; only shared fixtures and helpers remain in test_helpers.rs.
All 126 tests, formatting, build, and strict Clippy checks pass locally with Rust 1.99.0.
Protols currently returns only
Locationfor definition requests, omitting the source range needed to identify a complete import path or qualified type. Definition resolution also depends on which segment of a qualified type contains the cursor. Separately, reference requests always include declarations even whenincludeDeclarationis false, and resolving each reference repeatedly clones the entire workspace model, making queries unresponsive in larger workspaces.This change supplies the navigation information directly from Protols' parsed metamodel:
textDocument.definition.linkSupportduring initialization. ReturnLocationLink[]only when it is true, otherwise preserve the existingLocation/Location[]response format.originSelectionRangefrom the complete type reference or import path, and populate the target declaration and name ranges separately. Import paths exclude their quotes, keywords, and semicolons, including public/weak imports.example.api.Outer.HeadertargetsHeader; rename continues to use its existing segment-sensitive resolution.ReferenceParams.context.includeDeclaration, allowing clients to distinguish one actual use from the declaration plus that use.Validation on macOS arm64 with Rust 1.95.0:
cargo fmt --all -- --checkcargo clippy --locked --all-targets -- -D warningscargo test --locked --verbose: 126 passed, including 8 new tests for capability negotiation, legacy responses, complete type/import ranges, RPCs, multiple definitions, and reference filtering. Updated the expected definition and import-hover snapshots.cargo build --lockedandcargo build --locked --releaseStdio JSON-RPC smoke test against the built server using temporary proto files: initialize with
linkSupporttrue, false, and omitted; query every character of a qualified type and import path; verify response shape/ranges andincludeDeclarationtrue/false with one and two actual uses.Binary
--help/--version, plusprotocandclang-formatchecks usingsample/simple.proto.Large-workspace regression check with 309 existing proto files plus a test document: the previous reference query timed out after 45 seconds; the updated query returned the same two expected references in approximately 10 ms on the same local machine.