marcoroth/stimulus-lsp

More explicit behavior if parsing controller fails

Closed this issue · 2 comments

I found a bug in the parser where it can't properly parse some of my controllers (issue open for that: marcoroth/stimulus-parser#20). It took me a while to figure out what was going on, because the LSP is giving a ton of false positives and it wasn't clear to me that it actually couldn't parse the code until I pulled out the code and ran a debugger on it.

Because it can't parse the file, it doesn't register any actions, targets or values. It then starts giving you "xxx" isn't a valid Stimulus Action/Target/Value on the "blabla" controller everywhere.

This is not super friendly, because it gives a false idea that something's wrong with your code.

Possible solutions:

  • Not give any diagnostics (is that right term?) when it can't parse the controller. I think the big down side of this is that you then get a false sense of safety (no warnings, so nothing wrong).
  • Give a generic error diagnostic that it can't parse the controller. Maybe they can be pointed here to help fix a bug etc. At least you then have the idea that the LSP is working.

Also happy to contribute a bit here, but not sure in what direction to take it!

Ugh, this is annoying! Thanks for digging into this @djfpaagman!

I think adding a diagnostic to the first line of the controller file would make sense here. Even better would be to add a diagnostic to the line of where the parser error occurred, but this might be trickier.

The stimulus-parser exposes a parseError field on the controller definition object, maybe it's just a matter of checking it's presence and rendering a diagnostic for it.

Resolved via #86