After changing the parameter specs for a function, intellisense remembers old method parameters. Please check attached image. The first variant does not exist anymore. If I go there with F12, I go to a readonly file with the same path as the current file. Could it have to do with Git?
Intellisense remembers old method parameters
Hi,
It is possible there is another file with previous changes? The PHP editor implicitly ignores files specified in:
- vscode' "exclude" setting
- /.git folder
We'll try to replicate the issue tho. Maybe VSCode still keeps another version of the file opened in the editor?
JakubMisek The function getPublicationLine4Api exists only once in this project/workspace. The first method suggestion is old code; I changed the parameter type from PublicationLine to PublicationLineSuperclass.
By the way, re-opening vscode seems to solve it. Does the old definition stay in memory perhaps?
Yes, it is stored in-memory.
If you try to go-to-definition of getPublicationLine4Api
(F12
), does it open two locations?
Thanks!
JakubMisek Yes it does. If I then choose for the out-dated definition, I go to a readonly file with the same path as the current file.
- Edited
Hi All,
Is there a solution to this problem? I'm facing the same issue with go-to-definition. If I Ctrl-click a method reference, I'm presented two identical definitions in the same file. One of them leads to the editable file, and the other to a readonly version of the same, sometimes outdated, sometimes not. This does not occur always, and as Jorrit mentioned above, restarting VSCode makes it go away for a while. I found no other way to fix it.
Thanks,
Gabor
GaborDicso Thank you for the update. May I ask quickly:
- Is it still happening in Visual Studio Code, or is it Visual Studio?
- Are the file names identical as well? (the same letter casing?)
- Is it on Windows?
- Edited
Hi JakubMisek,
I'm using Visual Studio Code on Windows 10. The file names are identical as well, same casing. PHP Tools version: v1.28.12200, Community edition.
I noticed that after restarting VSCode, everything works fine until I open the Source Control view on the left, and push my local changes to Git. Then the files I modified appear twice when using the "Go to definition" feature.
Say, I modified and pushed X.php
. In Y.php
, I Ctrl-click a method defined in X.php
. Then, X.php
appears twice. If I Ctrl-click a method defined in Z.php
, it still works fine. It might be worth noting that I'm using namespaces and classes, and the classloader implementation that can be found at https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader-examples.md (see the "Class Example" section).
I tried to reproduce the problem with a plain function definition instead of a class method, and the problem does not seem to occur (it was just a quick test though). I'm having a folder and file name structure that corresponds to the namespace and class name, i.e. Namespace\X.php
contains class \Namespace\X
, Namespace\Y.php
contains class \Namespace\Y
etc., and the code of Y
references e.g. $instanceOfX->methodName()
. When the problem occurs, the reference count above the definition also counts references twice.
EDIT: if I modify the plain function and push it again, then clicking "Go to definition" lists the function twice as well, i.e. the problem is not related to classes. Sorry for the confusion.
Let me know if you need more info.
Thanks,
Gabor
GaborDicso thank you for the details! we'll try step by step.
I think I found what may be causing this ...
That sounds good, thank you for the update!
- Edited
Actually, I found that the problem is really easy to reproduce:
- Open VSCode
- Open a PHP file, click Go to definition on a method defined in the same file - it works fine
- Modify and save the file, leave the editor tab open
- Open the Source Control view on the left, and click the modified file under Changes - the "Working Tree" split view is opened (you don't need to push or commit your changes)
- Go back to the editor tab and try Go to definition again - you are presented with two identical choices
To me it seems that upon opening the "Working Tree" split view, PHP Tools somehow thinks that the old version in the left pane is a separate document, and remembers it even if I close the "Working Tree" view or discard my changes. If I add a new method and use Go to definition on it, it still works fine because it is not there in the old version.
I tested with v1.30.12417
Thanks,
Gabor
GaborDicso I see! VSCode creates a virtual document with a weird path, and we don't handle that!
Awesome, thank you @GaborDicso
Great, I'm glad I was able to help :) Can I expect an update on this thread when the fix is out?
GaborDicso preparing pre-release now - within an hour it'll be out :)
That's what I call a quick fix :) Thank you! It's going to be nice to see this resolved.
GaborDicso Thank you! Well it took us way too much time, and there are a few issues left unresolved ... so stay tuned :)