vscode icon indicating copy to clipboard operation
vscode copied to clipboard

[php] autocomplete is not showing user variables

Open h2u opened this issue 10 years ago • 8 comments

I don't really understand how it's working. VSCode does not suggest me any of my variables. Only globals as $_COOKIE and etc. I was trying to type few letters of my variable name and press Ctrl+Space, and it's says "No suggestions".

h2u avatar Mar 08 '16 08:03 h2u

@h2u are you using a php extension for VS Code?

weinand avatar Mar 08 '16 16:03 weinand

No, i don't use any php extensions.

h2u avatar Mar 08 '16 17:03 h2u

Seems I'm only getting autocomplete suggestions when I start typing a variable name without the leading $.

mattacosta avatar Mar 08 '16 23:03 mattacosta

If i have variable like: $string = 'my string'; and on next line i start writing "$st" or "st" - there is no any suggestions like $string variable.

image

h2u avatar Mar 09 '16 20:03 h2u

Huh. Debugged a little more, seems I need to not have a leading $ AND press the up arrow on my keyboard to get it to sometimes show up as a possible selection. Either way, definitely bugged.

Edit: More information using the variable "$apple"

  1. Start typing 'ap', see results highlighting 'a', 'p', and 'ap' in functions like array_pop() and array_map().
    a. If I press esc and then ctrl+space here, I get 'no suggestions'.
  2. Type another 'p', all suggestions go away.
  3. Press backspace, suggestions from 1 show up, but without blue letters.
  4. Backspace again, get suggestions with just the 'a' highlighted in blue.
  5. Backspace again, empty line, suggestion window closes.
  6. Press ctrl+space, I can see $apple just after the super-globals.
  7. Type an 'a', and use the up arrow to find $apple.
  8. Typing more letters will correctly filter to $apple.

So basically, I guess you need to trigger the completion provider before typing anything to get variables to show up...

mattacosta avatar Mar 09 '16 22:03 mattacosta

Thank you, @mattacosta for information. But how can i trigger the completion provider? :)

h2u avatar Mar 10 '16 06:03 h2u

Afaik the whole PHP Intellisense is only based of a list of global functions and superglobals. I already thought about writing a PHP extension for better Intellisense, that actually constructs an AST of the code and looks at the variables in the current scope etc., suggests methods for classes following PSR autoloading, but I don't have the time for it.

felixfbecker avatar Mar 10 '16 12:03 felixfbecker

The same happens to me. VS Code 0.10.11 on OSX El Capitan.

jmoleiro avatar Mar 15 '16 15:03 jmoleiro