Skip to content

refactor(resolver): catalog return-type resolution (ReturnType + 2 methods)#192

Open
Hessesian wants to merge 1 commit into
refactor/resolution-catalog-s3from
refactor/resolution-catalog-s4
Open

refactor(resolver): catalog return-type resolution (ReturnType + 2 methods)#192
Hessesian wants to merge 1 commit into
refactor/resolution-catalog-s3from
refactor/resolution-catalog-s4

Conversation

@Hessesian

Copy link
Copy Markdown
Owner

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 (base refactor/resolution-catalog-s3); GitHub will retarget down the stack as each merges.

The disease

Five free functions in infer.rs all return bare Option<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_type even called find_extension_fn_return_type explicitly after find_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 bare String:

  • 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 what chain.rs hand-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.rs dot-receiver inference (fn + method) — now import-aware (was the raw by-name scan).
  • semantic_tokens/resolve.rs member_return_type + both call-callee function-return sites — now import-aware and gain the supertype fallback.
  • indexer.rs::find_method_return_type_for_typecollapsed: dropped the dead explicit extension step and the separate supertypes call; both now live inside method_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

…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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 on Resolver: function_return_type(fn, from_uri) and method_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).

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.

2 participants