Skip to content

feat(completion): array callable method completion#188

Merged
AJenbo merged 1 commit into
PHPantom-dev:mainfrom
calebdw:calebdw/push-otklwtrlzoxu
Jul 4, 2026
Merged

feat(completion): array callable method completion#188
AJenbo merged 1 commit into
PHPantom-dev:mainfrom
calebdw:calebdw/push-otklwtrlzoxu

Conversation

@calebdw

@calebdw calebdw commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

Summary

Add method name completion inside array callable strings. When the cursor is inside the method-name string of [Class::class, '|'] or [$obj, '|'], the LSP now offers method completions from the resolved class.

Motivation

The array-callable navigation work (commit 21a0105) added go-to-definition, find-references, and rename for array callable method strings. This PR extends that with completion — the last missing piece for a full editing experience with array callables like Route::get('/', [IndexPageController::class, 'indexPage']).

What's included

Detection (detect_array_callable_context)

  • Scans backward from cursor to identify [Class::class, '|'] and [$var, '|'] patterns
  • Handles ::class constants, $this, typed variables, namespaced classes
  • Whitespace-tolerant, works with unclosed strings (user still typing)
  • Rejects non-identifier content (e.g. [$this, 'not a method'])

Completion (try_array_callable_completion)

  • Resolves the class from the first array element:
    • Class::class → FQN resolution via use map / namespace / bare name
    • $this → enclosing class
    • Other variables → full variable type resolution
  • Reuses build_union_completion_items from the standard member-completion builder, so items have identical formatting to regular -> / :: completions:
    • Label details with class name
    • Return type in detail
    • Deprecation tags
    • data field for lazy documentation resolve (completionItem/resolve)
  • Post-processes to strip snippet parentheses from insert_text since we're inserting into a string literal
  • Filters to methods only (no properties/constants)
  • Shows both instance and static methods (PHP array callables work with either)

Integration

  • Hooked into handle_completion before the InStringLiteral suppression, alongside array shape and Eloquent string completions
  • Registered in completion/mod.rs with module docs

@calebdw calebdw force-pushed the calebdw/push-otklwtrlzoxu branch 3 times, most recently from c6eb341 to 1305bed Compare July 3, 2026 22:41
@codecov-commenter

codecov-commenter commented Jul 3, 2026

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 87.45387% with 34 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/completion/array_callable.rs 87.16% 34 Missing ⚠️

📢 Thoughts on this report? Let us know!

Add method name completion inside array callable strings. When the
cursor is inside the method-name string of [Class::class, '|'] or
[$obj, '|'], the LSP now offers method completions from the resolved
class.

Detection handles ::class constants, $this, typed variables,
namespaced classes, whitespace variations, and unclosed strings.

Completion reuses the standard member-completion builder so items have
identical formatting to regular -> / :: member completions: label
details, return type, deprecation tags, and data for lazy documentation
resolve. Insert text is post-processed to strip snippet parentheses
since we are inserting into a string literal.

Works with both instance and static methods.

Signed-off-by: Anders Jenbo <anders@jenbo.dk>
@AJenbo AJenbo force-pushed the calebdw/push-otklwtrlzoxu branch from 1305bed to 77bbdde Compare July 4, 2026 01:22
@AJenbo AJenbo merged commit d0f9077 into PHPantom-dev:main Jul 4, 2026
6 of 7 checks passed
@calebdw calebdw deleted the calebdw/push-otklwtrlzoxu branch July 4, 2026 01:24
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.

3 participants