stimulus-lsp
stimulus-lsp copied to clipboard
check for duplicate diagnostics before adding new one
possible fix #275
Alternatively, I tried checking if service.refresh()
was called multiple times unnecessarily but that was not the case.
I guess this only really fixes the symptoms, but I wonder why they show up multiple times in the first place. It seems like there's another issue somewhere deeper in the stack
This might still be worthwhile to add, nonetheless
This might still be worthwhile to add, nonetheless
Hmm okay if you think so.
You are right though, I hesitated before opening this PR because i realise it only fixes the sypmtom.
My initial theory was the service.refresh()
was called multiple times but that is not the case. I can continue investigating.
The issue is here: https://github.com/marcoroth/stimulus-lsp/blob/93fdd53e5b41032a9f242b05460e89105c9050d7/server/src/diagnostics.ts#L324
Since the linked issue is importing two exports we also have two "import declarations" in the array, one for each import, thus resulting in the 4 diagnostics.
import { Controller, Context } from "stimulus"
But I'm not sure why we see 4 in that case and not just two.
@marcoroth okay, so I may have found the bug.
There are two locations from where diagnostic#validateStimulusImports
is run.
This causes two diagnostics to be added.
-
https://github.com/marcoroth/stimulus-lsp/blob/27a7283941dd75d5f945d48cf228d189453aa736/server/src/server.ts#L102
-
https://github.com/marcoroth/stimulus-lsp/blob/27a7283941dd75d5f945d48cf228d189453aa736/server/src/service.ts#L59
Here is a similar discussion of the issue: https://github.com/microsoft/vscode-discussions/discussions/511
What do you think we should do? imo we remove the onDidChangeWatchedFiles
as it handles an edge case where the file could be edited outside of VSCode.
EDIT - however, I'm not sure if this would work if the LSP is used outside of VScode e.g Neovim etc.
okay upon further investigation, the issue does not lie in what I previously thought^
I am quite certain It is this event and the usage that is causing the issue:
https://github.com/marcoroth/stimulus-lsp/blob/27a7283941dd75d5f945d48cf228d189453aa736/server/src/server.ts#L102-L108
the service.refresh()
call is adding multiple diagnostics.
Oh interesting, thanks for the investigation @nachiket87!
After thinking about this a bit more, it feels like this diagnostic should anyway be part of the Stimulus Parser itself and not part of the LSP. So maybe if we move the analysis to the parser we could solve the issue that way, would that make sense in your eyes?
Oh interesting, thanks for the investigation @nachiket87!
After thinking about this a bit more, it feels like this diagnostic should anyway be part of the Stimulus Parser itself and not part of the LSP. So maybe if we move the analysis to the parser we could solve the issue that way, would that make sense in your eyes?
Sure! I've been looking at the stimulus parser for this and at the moment I have no idea how I would implement it. I will continue trying though and let you know how it goes.
Hey @nachiket87, FWIW, I still think this could be useful to add.
Hey @nachiket87, FWIW, I still think this could be useful to add.
Really @marcoroth ? okay, do you have any feedback on this? Sorry I didn't come back to this.
I don't have any feedback right now, I just wanted to try to find the root cause and fix it and then merge this one