Skip to content

feat: add method chain autocomplete support#109

Open
abanchev wants to merge 7 commits intobobbylight:masterfrom
abanchev:fix/method-chain-completions
Open

feat: add method chain autocomplete support#109
abanchev wants to merge 7 commits intobobbylight:masterfrom
abanchev:fix/method-chain-completions

Conversation

@abanchev
Copy link

@abanchev abanchev commented Mar 7, 2026

Summary

  • Adds chain-aware type resolution for qualified completions like AudioEngine.sharedEngine().playMusic()
  • Overrides getAlreadyEnteredText to scan backward through balanced parentheses so the full chain expression is captured
  • findMethodReturnType matches overloads by parameter count (not just name), preventing incorrect return type resolution when overloads have different return types
  • Includes countArguments() helper that counts top-level comma-separated args with nested-paren awareness

How it works

  1. getAlreadyEnteredText now returns the full chain (e.g., foo.bar(x).baz().) instead of stopping at )
  2. resolveChainType splits the prefix into segments, resolves each through ClassFile metadata
  3. findMethodReturnType / findFieldType walk the superclass chain to find inherited members
  4. resolveLocalVarType handles local variable type lookup for the first segment

What was previously broken

  • loadCompletionsForCaretPositionQualified had two early-return restrictions rejecting any prefix with dots or non-identifier characters
  • getAlreadyEnteredText excluded parentheses, so foo.bar(). only returned .
  • No overload disambiguation — first matching method name was used regardless of parameter count

Test plan

  • 14 unit tests in SourceCompletionProviderTest covering:
    • getAlreadyEnteredText with simple dots, method chains, nested parens, multi-arg, multi-level chains
    • countArguments with empty, single, multi-arg, nested, and malformed inputs
  • All existing tests pass
  • Manual testing done

bobbylight and others added 7 commits January 5, 2026 21:37
- Add resolveChainType() to walk dotted prefixes through ClassFile metadata
- Add findMethodReturnType() and findFieldType() with superclass chain walking
- Add resolveLocalVarType() for local variable type resolution
- Replace early-return restrictions with chain-aware resolution logic
- Backwards compatible: single identifiers still use existing code path
The parent DefaultCompletionProvider.getAlreadyEnteredText() uses
isValidChar() to scan backward, which excludes parentheses. This
meant method chains like AudioEngine.sharedEngine().something only
returned "." as the entered text, preventing chain resolution.

The override scans backward through balanced parentheses so the
full chain expression is captured and passed to the chain resolver.
…traction

- 8 tests covering simple identifiers, method chains, nested parens, multi-arg, multi-level chains, prefix trimming, plain identifiers
- Documents overload return type limitation in findMethodReturnType
findMethodReturnType now accepts an argCount parameter and matches
it against MethodInfo.getParameterCount(). Arguments are counted
from the call-site expression via countArguments(), which handles
nested parentheses. This prevents incorrect type resolution when
overloaded methods have different return types.

Includes 6 new tests for countArguments covering empty, single,
multi-arg, nested parens, and malformed input cases.
Track whether the last scanned token was a dot to distinguish method
call parens (foo.bar().) from cast expression parens ((Cast)var.).
When ')' follows identifier chars instead of a dot, stop scanning
instead of treating the cast parens as part of the chain expression.

Also adds tests for cast expression handling and parser verification
that local variables with cast assignments inside for loops are
correctly parsed.
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