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?

    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.

            10 months later

            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?

                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!

                      17 days later

                      Actually, I found that the problem is really easy to reproduce:

                      1. Open VSCode
                      2. Open a PHP file, click Go to definition on a method defined in the same file - it works fine
                      3. Modify and save the file, leave the editor tab open
                      4. 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)
                      5. 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

                      Great, I'm glad I was able to help :) Can I expect an update on this thread when the fix is 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 :)

                          Write a Reply...