Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check for duplicate diagnostics before adding new one #282

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

nachiket87
Copy link
Contributor

possible fix #275

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

@marcoroth
Copy link
Owner

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

@nachiket87 nachiket87 marked this pull request as draft May 15, 2024 23:16
@marcoroth
Copy link
Owner

This might still be worthwhile to add, nonetheless

@nachiket87 nachiket87 marked this pull request as ready for review May 15, 2024 23:26
@nachiket87
Copy link
Contributor Author

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.

@marcoroth
Copy link
Owner

The issue is here:

sourceFile.importDeclarations.forEach((importDeclaration) => {

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.

@nachiket87
Copy link
Contributor Author

nachiket87 commented May 16, 2024

@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. connection.onDidChangeWatchedFiles((_params) => {

  2. this.documentService.onDidChangeContent((change) => {

Here is a similar discussion of the issue: microsoft/vscode-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
Copy link
Contributor Author

nachiket87 commented May 16, 2024

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:

connection.onDidChangeWatchedFiles((_params) => {
// params.changes.forEach((event) => {
// service.refreshFile(event)
// })
service.refresh()
})

the service.refresh() call is adding multiple diagnostics.

@marcoroth
Copy link
Owner

marcoroth commented May 16, 2024

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?

@nachiket87
Copy link
Contributor Author

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 nachiket87 marked this pull request as draft May 18, 2024 15:45
@nachiket87 nachiket87 closed this Aug 2, 2024
@marcoroth
Copy link
Owner

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

@nachiket87 nachiket87 reopened this Aug 7, 2024
@nachiket87
Copy link
Contributor Author

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.

@marcoroth
Copy link
Owner

marcoroth commented Aug 13, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Suggestion is duplicated 3 times
2 participants