"Go to implementation" jumps to library file included in different (wrong) project
The way I usually use Webstorm is by opening many node.js projects in one window using File → Open, select the project folder and then choose “Attach” (I was so happy when this feature finally became a possibility some versions ago). Many if these projects depend on some common libraries.
When doing this Webstorm mixes up the files included through the dependencies (node_modules) of the different attached projects. Lets say I have Project A and Project B which both have their own package.json, node_modules directory and both depend on libX. Let's say libX exposes some functionY(). What happens is that when I use “Go to implementation” on functionY() in project A, Webstorm will actually open the file implementing functionY() from the node_modules directory of project B.
So let's say the layout is like this:
ProjectA
projectA.js
node_modules
libX
libX.js
ProjectB
projectB.js
node_modules
libX
libX.js
projectA.js:
const libX = require("libX");
libX.functionY();
projectB.js
const libX = require("libX");
libX.functionY();
Then using right-click → Go To → Implementation on the libX.functionY(); call in projectA.js may jump to ProjectB/node_modules/libX/libX.js, which seems objectively wrong but at the very least is very inconvenient for me.
I (would like to) use this functionality quite a lot since I am also the maintainer of said common libraries and one of my usual workflows when working on a library itself is to npm-link it in one of the projects and jump back and forth to the library code from there. Or when a library is misbehaving in some cases and I try to follow the code flow using Go To → Implementation, I sometimes find myself looking at a completely different version of the same library. So obviously for my use-cases it's not working very well and instead I find myself using ‘Find in files’ all the time. While, let's be honest, a properly functioning go to implementation is pretty much the bare minimum one would expect from any IDE.
When I open (attach) projects this way I would expect Webstorm to treat them as completely isolated, as if they were opened in different windows, and therefore each of them to have its own, independent, indexes etc. This behavior seems to indicate that this is not whats happening, which apart from my issue here may also be a reason for indexing to be much slower/more complex/more energy consuming than necessary (because even on my super up-to-date laptop it sometimes still is disturbingly slow). But apart from any of that, I would at the very least expect Go To → Implementation to just simply follow the same rules in resolving the symbol that node.js does.
I'm experiencing this issue with Webstorm 2023.3.1 on Linux, but have been experiencing it with any prior version since the ‘Attach to window’ function was introduced.
请先登录再写评论。
Attaching a project is actually equal to adding a content root, i.e. to adding a folder. Attached projects are not isolated, it's a one big project with a set of folders, where only a main project preferences matter, the other projects settings from their
.idea
folders (run configurations, libraries, etc.) are ignored. So, if you like to jhave a set of independent projects, using the Attach option won't work.Please see
https://www.jetbrains.com/help/webstorm/2023.3/opening-reopening-and-closing-projects.html#known-limitations
for the list of known limitations
Okay, thank you for clarifying that Elena Pogorelova. That is somewhat unexpected for me, but so be it. However the main point of my issue is that symbols are being resolved incorrectly, whether or not all attached directories are considered as independent projects.
Elena Pogorelova It took a some effort because the issue would not manifest itself with just 2 or 3 projects with a single common dependency, but I finally managed to get a reproducible reproduction scenario.
You'll find the complete project setup, a video that demonstrates the issue (plus some accidental other issues) in webstorm-resolve-issue.webm and a transcript in README.txt here: https://github.com/dreusel/webstorm-resolve-issue.
Thank you for your help in providing all the details. I managed to reproduce the problem and have created a new ticket: https://youtrack.jetbrains.com/issue/WEB-65023/In-project-with-multiple-subprojects-with-similar-dependencies-NavigateImplementation-sometimes-opens-the-wrong-library. Please subscribe to it to get notified on updates.
Note that a suggestion to include JavaScript files in project on the first attempt to Navigate > Implementation is expected: in npm packages that include
d.ts
files in distribution alljs
files are explicitly excluded from indexing (note the cross sign in the icon), as the IDE usesd.ts
files for completion/types resolving. The first time you try to navigate to implementation for such package, the IDE prompts you to include thejs
files to get navigation work.Hey Elena Pogorelova ,
Thank you for taking the time to reproduce and filing the issue. I hope the team will find the time to pick it up.
I am aware that the prompt to include JavaScript files in project on the first attempt is expected; what was slightly unexpected was that it also happened the second time I used it, but I supposed that might have to do with the freeze and then force-killing of Webstorm after the first use.
Also, I would like to express my appreciation for what you are doing. For as long as I can remember I have seen you on this forum answering everyone's questions, helping with issues and filing tickets when necessary and you clearly know the product in and out. From my perspective as a customer, it's rare to see someone doing this job as well as you and it adds great value to the product. Many times it has helped me with issues or questions I've had without even needing to post about it myself. So thank you for that :)
Thank you for the kind words! You are very welcome!