Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to tell PhpStorm that function argument is file path

In PhpStorm (and other JetBrains IDE), is it possible to make function attributes as file / resource path?

E.g. in this function:

function mix($file): string
{
  // check mix maninfest for $file and return path from mix manifest
  return $fire_path_with_cachebuster;
}

I'd like PHP to suggest files in the project as I define $file attribute when calling mix function.

like image 680
demicanadian Avatar asked Mar 03 '26 16:03

demicanadian


1 Answers

Only manually for the moment, when calling that function 😒. And it's a temp injection (for a session) so it's not convenient:

mix('')
  • Place caret inside the string parameter
  • Use Alt + Enter (or via light bulb icon) to bring the Quick Fix / Intentions menu (on some Keymaps it might be different one)
  • Use "Inject language or reference" option
    enter image description here
  • Then choose "File Reference" entry there (just start typing to filter the list). enter image description here

The result:
enter image description here


Hopefully they will implement the following tickets for a permanent solution:

  • Using #[Language] PHP attribute at the function declaration: https://youtrack.jetbrains.com/issue/WI-56996
  • Or in-place via PHPDoc-like comment (before the parameter when calling that function): https://youtrack.jetbrains.com/issue/WI-20028

Watch those tickets (star/vote/comment) to get notified on any progress (and hopefully speed it up by bringing dev's attention).

like image 130
LazyOne Avatar answered Mar 08 '26 17:03

LazyOne



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!