refactor(resolver): catalog return-type resolution (ReturnType + 2 methods)#192
Open
Hessesian wants to merge 1 commit into
Open
refactor(resolver): catalog return-type resolution (ReturnType + 2 methods)#192Hessesian wants to merge 1 commit into
Hessesian wants to merge 1 commit into
Conversation
…thods) Folds the scattered call-return-type lookups behind two intent-named, documented catalog methods on `Resolver`, with a self-documenting `ReturnType` newtype replacing bare `Option<String>` on the trait surface: - `ReturnType(String)` — the as-written result type of a call (generics + `?` preserved); `Deref<str>` + `into_inner()` for the String-typed inference paths that haven't adopted the newtype yet. - `Resolver::function_return_type(fn, uri)` — import-aware: reachable bind first, workspace by-name fallback (the chain consumers were hand-rolling). - `Resolver::method_return_type(type, method, uri?)` — the single composite: member/extension methods then supertype inheritance, in one call. Routed the production consumers off the loose free functions onto the catalog: - `complete.rs` dot-receiver inference (function + method return types) — now import-aware (was the raw by-name scan). - `semantic_tokens/resolve.rs` `member_return_type` + the two call-callee function-return sites — now import-aware and gain the supertype fallback. - `indexer.rs::find_method_return_type_for_type` — collapsed: dropped the explicit `find_extension_fn_return_type` step (dead — `find_method_return_type` already probes extensions first) and the separate supertypes call; both now live inside `method_return_type`. Behaviour-preserving for unambiguous names; for same-named-cross-package functions the routed sites now pick the in-scope definition (same fix shape as the semantic-token symbol-kind slice). +2 catalog tests (`catalog_function_return_type_falls_back_to_by_name`, `catalog_method_return_type_folds_supertype_inheritance`). cargo test --bin kmp-lsp: 1421 passed. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01A7YFhRP8Eqwomdd1EzkDwv
There was a problem hiding this comment.
Pull request overview
This PR continues the unified-resolution refactor by centralizing Kotlin function/method return-type lookup behind an intent-named Resolver catalog API, replacing several “loose” Option<String> free-function call sites with import-aware catalog methods and a self-documenting ReturnType newtype.
Changes:
- Introduces
ReturnType(String)plus two catalog methods onResolver:function_return_type(fn, from_uri)andmethod_return_type(type, method, from_uri?). - Routes semantic-token and completion return-type inference through the catalog (import-aware + supertype folding), removing redundant/duplicated lookup steps.
- Adds two regression tests covering the catalog’s by-name fallback arm and the supertype-inheritance arm.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/semantic_tokens/resolve.rs | Switches call/member return-type inference to Resolver::{function_return_type, method_return_type} for scope-aware resolution. |
| src/resolver/mod.rs | Re-exports ReturnType alongside Resolver for crate-wide use. |
| src/resolver/infer_tests.rs | Adds catalog-focused tests for by-name fallback and supertype folding behavior. |
| src/resolver/complete.rs | Updates dot-receiver type inference to use the new catalog return-type methods. |
| src/resolver/api.rs | Defines ReturnType and extends the Resolver catalog with function/method return-type entry points. |
| src/indexer.rs | Collapses method return-type resolution to the single catalog composite (removing dead redundant steps). |
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.
Slice 4 of the unified-resolution work — collapses inventory hotspot #4 ("function return-type — 5 variants, all
Option<String>for different things"). Stacked on #191 (baserefactor/resolution-catalog-s3); GitHub will retarget down the stack as each merges.The disease
Five free functions in
infer.rsall return bareOption<String>for subtly different questions (by-name vs import-aware vs container vs extension vs supertype), and consumers hand-chained them —indexer.rs::find_method_return_type_for_typeeven calledfind_extension_fn_return_typeexplicitly afterfind_method_return_type, which already probes extensions first (dead step).The catalog surface
Two intent-named, documented methods on
Resolver, returning a self-documenting newtype instead of bareString:ReturnType(String)— the as-written result type of a call (generics +?preserved).Deref<str>+into_inner()for the String-typed inference paths not yet migrated.function_return_type(fn, uri)— import-aware: reachable bind first, workspace by-name fallback (exactly whatchain.rshand-rolled).method_return_type(type, method, uri?)— the single composite: member/extension methods → supertype inheritance, one call.Consumers routed off the loose free fns
complete.rsdot-receiver inference (fn + method) — now import-aware (was the raw by-name scan).semantic_tokens/resolve.rsmember_return_type+ both call-callee function-return sites — now import-aware and gain the supertype fallback.indexer.rs::find_method_return_type_for_type— collapsed: dropped the dead explicit extension step and the separate supertypes call; both now live insidemethod_return_type.Safety
Behavior-preserving for unambiguous names (the reachable arm falls back to the old by-name lookup). For same-named-cross-package functions, the routed sites now pick the in-scope definition — the same correctness shape as the symbol-kind slice (#191). +2 catalog tests proving the by-name fallback arm and the supertype-folding arm.
cargo test --bin kmp-lsp: 1421 passed; clippy + fmt clean.🤖 Generated with Claude Code