feat: macro hover with origin indicator and inferred return types#244
Conversation
This makes me much less annoyed with them |
Probably a good way to remind people to go fix it |
Macro methods now show a "macro" origin indicator in hover instead of the generic "virtual" label, helping users distinguish ::macro() registrations from @method/@mixin synthesized members. When a macro closure has no explicit return type hint, the return type is inferred from the closure body and displayed with an "(inferred)" annotation. This also applies to regular methods whose return types are inferred at hover time. A new preserve_static flag on ResolutionCtx controls whether $this/self/static resolve to their keyword form or the concrete class name. For method chains like $this->transform(...), the last method's declared return type is used directly via resolve_chain_declared_return(), preserving $this, static, and generic parameters that the general expression resolver would flatten to a bare class name. Raw class methods are checked before the fully-resolved class so template parameter names (e.g. TValue) are preserved instead of being replaced with their bounds. Key changes: - is_macro and is_inferred_return fields on MethodInfo - MemberOrigin::Macro variant for hover rendering - preserve_static on ResolutionCtx with chain-aware resolution - resolve_chain_declared_return() for declared return type lookup - 4 new integration tests for hover behavior
157ee19 to
d3f45ed
Compare
Yeah, this is mainly because I wanted the server to know about E.g.: final class CollectionMacros
{
public static function boot(): void
{
Collection::macro(
'asValueLabel',
// phpstan errors with: Anonymous function should return static(Eagle\Common\Macros\CollectionMacros) but returns Illuminate\Support\Collection<int, array<string, mixed>>
fn (): static => $this->map(fn ($l, $v) => ['value' => $v, 'label' => $l])->values(),
);
}
} |
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Macro methods now show a "macro" origin indicator in hover instead of the generic "virtual" label, helping users distinguish ::macro() registrations from @method/@mixin synthesized members.
When a macro closure has no explicit return type hint, the return type is inferred from the closure body and displayed with an "(inferred)" annotation. This also applies to regular methods whose return types are inferred at hover time.
A new preserve_static flag on ResolutionCtx controls whether $this/self/static resolve to their keyword form or the concrete class name. For method chains like $this->transform(...), the last method's declared return type is used directly via resolve_chain_declared_return(), preserving $this, static, and generic parameters that the general expression resolver would flatten to a bare class name. Raw class methods are checked before the fully-resolved class so template parameter names (e.g. TValue) are preserved instead of being replaced with their bounds.
Key changes: