stimulus-lsp icon indicating copy to clipboard operation
stimulus-lsp copied to clipboard

check for duplicate diagnostics before adding new one

Open nachiket87 opened this issue 9 months ago • 11 comments

possible fix #275

Alternatively, I tried checking if service.refresh() was called multiple times unnecessarily but that was not the case.

nachiket87 avatar May 15 '24 20:05 nachiket87

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

marcoroth avatar May 15 '24 23:05 marcoroth

This might still be worthwhile to add, nonetheless

marcoroth avatar May 15 '24 23:05 marcoroth

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.

nachiket87 avatar May 15 '24 23:05 nachiket87

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 avatar May 15 '24 23:05 marcoroth

@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.

  1. https://github.com/marcoroth/stimulus-lsp/blob/27a7283941dd75d5f945d48cf228d189453aa736/server/src/server.ts#L102

  2. 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.

nachiket87 avatar May 16 '24 01:05 nachiket87

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.

nachiket87 avatar May 16 '24 03:05 nachiket87

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?

marcoroth avatar May 16 '24 11:05 marcoroth

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.

nachiket87 avatar May 18 '24 15:05 nachiket87

Hey @nachiket87, FWIW, I still think this could be useful to add.

marcoroth avatar Aug 04 '24 18:08 marcoroth

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.

nachiket87 avatar Aug 07 '24 14:08 nachiket87

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

marcoroth avatar Aug 13 '24 10:08 marcoroth