Skip to content

Show inlay hints for php attributes (maybe as option) #383

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
still-dreaming-1 opened this issue Aug 22, 2023 · 11 comments
Closed

Show inlay hints for php attributes (maybe as option) #383

still-dreaming-1 opened this issue Aug 22, 2023 · 11 comments
Assignees
Labels
feature New feature or request

Comments

@still-dreaming-1
Copy link

still-dreaming-1 commented Aug 22, 2023

PHP 8.0 added official support for attributes. In that link you can see some examples where you are actually passing parameters into a constructor while...attributing. I created a framework I am using that makes heavy use of attributes and it can get pretty gnarly. It would be nice if the inlay hints worked for these parameter names. I'm not sure, but it might be even better as a separate setting. Some people may want inlay hints in other places but not in the attributes. Or maybe I'm over thinking it and they should show up here if inlay hints are enabled.

Here is an example of me attributing a method where inlay hints may be helpful. I put the tests directly above the method they are testing as attributes:

#[Test(new self(0, 0), [new self(0, 0)], new Returns(new self(0, 0)))]
#[Test(new self(2, 99), [new self(1, 99)], new Returns(new self(4, 98)))]
@jakubmisek
Copy link
Member

Thank you for the suggestion!

I'll enable inlay parameter hints for attributes. A separate setting makes sense as well.

@jakubmisek jakubmisek self-assigned this Aug 22, 2023
@jakubmisek jakubmisek added the feature New feature or request label Aug 22, 2023
@jakubmisek
Copy link
Member

The pre-release 1.37.13695 adds inlay hints for parameters in attributes.

Please feel free to try it, and thank you for your suggestions!

@still-dreaming-1
Copy link
Author

Thanks. It often is not working right for me. Some files it doesn't work at all. One file it will work until I scroll down far enough and then it turns off. So I will literally scroll down one tiny bit more with the mouse wheel, and then all the places it was showing the inlay hints before suddenly turn off. If I scroll up, they turn back on again. There isn't anything different that I can see about the attributes that scroll into view when it turns off. I'm trying to come up with a good reproduce, but it's hard.

@jakubmisek
Copy link
Member

thank you, I'll try to repro the issue.

@still-dreaming-1
Copy link
Author

still-dreaming-1 commented Aug 26, 2023

I found a different example where the inlay hints are not completely working even when they are not randomly turning off and on. When attributing, you are allowed to instantiate new objects (something I make heavy use of). When you do this, it is not showing hints for the constructor arguments. Here is an example:

class MyClass
{
    public function __construct(public string $message) {
    }

    #[Test(new self('hi'))]
    public function myMethod(): void {
    }
}

In that example, it is not showing a hint for the $message argument upon calling new self('hi'). Your extension still works better than any others I have tried. Just keep focusing on quality and don't feel rushed to implement my suggestions.

@jakubmisek
Copy link
Member

Thank you, got it.

Pre-release v1.37.13728 adds named arguments for the entire attribute expression.

@still-dreaming-1
Copy link
Author

Thank you, got it.

Pre-release v1.37.13728 adds named arguments for the entire attribute expression.

This is working. The problem with the hints turning on and off is still present. I will see if I can come up with a good reproduce for you.

@still-dreaming-1
Copy link
Author

I think I figured it out. If some of the attributing does not use parenthesis, the hints stop working.

#[AttributeA([])]
private static function doThis() {
}

#[AttributeB]
private static function doThat() {
}

In this example, AttributeB is backed by a class with a constructor with parameters that all have default value. In this case, #[AttributeB] is equivalent to #[AttributeB()], but the latter does not break the hints. I'm not saying I want to see hints in the AttributeB example, I'm saying it affects the hint shown with AttributeA.

@jakubmisek
Copy link
Member

Thank you, it seems there was an internal exception when handling attributes without the parenthesis.

@still-dreaming-1
Copy link
Author

Works great!

@jakubmisek
Copy link
Member

awesome! thank you very much for testing it and for your feedback

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
Status: Done
Development

No branches or pull requests

2 participants