Skip to content
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

PHP: wrong inlay hints #19

Open
AndreiOrmanji opened this issue Oct 10, 2023 · 5 comments
Open

PHP: wrong inlay hints #19

AndreiOrmanji opened this issue Oct 10, 2023 · 5 comments

Comments

@AndreiOrmanji
Copy link

Description:
php_inlay_hints

Method Definition:
image

Extension settings (default overriden):
"inline-parameters.php.suppressWhenArgumentMatchesName": false

Inlay settings:
"editor.inlayHints.enabled": "offUnlessPressed"

If there is some additional info, feel free to ask.

@RobertOstermann
Copy link
Owner

What parameters do you see when you hover your mouse over the $this->paymentCreatorService->createPayment? I use those parameters (from intelephense) to determine the hints to show

@AndreiOrmanji
Copy link
Author

AndreiOrmanji commented Oct 17, 2023

What parameters do you see when you hover your mouse over the $this->paymentCreatorService->createPayment? I use those parameters (from intelephense) to determine the hints to show

This is the output from hints by pressing Parameter hint (CTRL+SHIFT+SPACE)
image

image

@RobertOstermann
Copy link
Owner

I have unfortunately been unable to recreate this issue. Are you able to recreate this in a file such as the test/example.php in this repository? If so, that would be helpful for me to see and fix the issue.

@AndreiOrmanji
Copy link
Author

AndreiOrmanji commented Oct 22, 2023

@RobertOstermann,
I was able to reproduce it and it seems annotations handling issue(if there are no annotations, everything works fine). The issue is with call of PaymentServiceInterface::transfer() method in testInterface function.
This code show one more issue with parameter name if parameter has brackets: check $currency argument and hint locations (in my opinion, it should be outside of brackets)
Code of example:

<?php


class Account
{
    private int $minorUnits = 0;


    public function getMinorUnits(): int
    {
        return $this->minorUnits;
    }

    public function setMinorUnits(int $minorUnits): self
    {
        $this->minorUnits = $minorUnits;

        return $this;
    }
}

class Currency
{
    private string $currencyCode = 'USD';


    public function getCurrencyCode(): int
    {
        return $this->currencyCode;
    }

    public function setCurrencyCode(int $currencyCode): self
    {
        $this->currencyCode = $currencyCode;

        return $this;
    }
}

class Payment
{
    private ?Currency $currency = null;


    public function getCurrency(): ?Currency
    {
        return $this->currency;
    }

    public function setCurrencyCode(Currency $currency): self
    {
        $this->currency = $currency;

        return $this;
    }
}

interface PaymentServiceInterface
{
    /**
     * @param callable $minorUnitsCallback (Account $sourceAccount, Account $destAccount): int
     * @param callable|null $beforePaymentIsBuilt (Account $sourceAccount, Account $destAccount, int $minorUnits): void
     * @param callable|null $whenPaymentIsCreated (Payment $payment, Account $sourceAccount, Account $destAccount): void
     * @param callable|null $whenMoneyAreTransferred (Payment $payment, Account $sourceAccount, Account $destAccount): void
     */
    public function transfer(
        int $sourceAccountId,
        int $destinationAccountId,
        Currency $currency,
        callable $minorUnitsCallback,
        string $paymentReference,
        int $paymentType,
        ?Payment $parent = null,
        callable $beforePaymentIsBuilt = null,
        callable $whenPaymentIsCreated = null,
        callable $whenMoneyAreTransferred = null
    ): Payment;
}

function testInterface(PaymentServiceInterface $p)
{
    return $p->transfer(
        1,
        2,
        ((new Currency())->setCurrencyCode('USD')),
        fn () => 1,
        'qqq',
        1,
        null,
    );
}

@RobertOstermann
Copy link
Owner

@AndreiOrmanji You are correct, seems to be an issue with handling annotations. I use the hover provided by PHP Intelephense to determine the parameters and display them. When annotations are present, it seems the hover has a different order the parameters are presented in.

image

I am currently just using a regex to parse the parameters and return them. It will probably require parsing the function part of the hover (definition) to determine the correct order of the parameters and reordering them after I grab them from the definition.

image

I am busy with other projects and it might be some time before I am able to work on this. If you wanted to work on this and provide a pull request I would get that merged and published. Or you can workaround it by providing annotations for all the variables (in the correct order) or not using annotations at all, though in this case that is probably not ideal.

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

No branches or pull requests

2 participants