elm-language-server icon indicating copy to clipboard operation
elm-language-server copied to clipboard

Confusing error message when elm-test absent in PATH

Open SomeoneSerge opened this issue 2 years ago • 9 comments

https://github.com/elm-tooling/elm-language-server/blob/964a7d0b50c123cf0aebe2f87c9bf6bb79fb298a/src/providers/diagnostics/elmMakeDiagnostics.ts#L304

I didn't quite follow the code, but here's what I observe at runtime:

  • Running neovim with nvim-lspconfig and elm-language-server=2.3.0

  • Just elm in PATH

  • Apply any edits to src/Whatever.elm and write, :w

  • Neovim interrupts with a pop-up window saying:

    The 'elm' compiler is not available. Install Elm via 'npm install -g elm'. I'm looking for commands at ...

    (note it says elm, not elm-test)

  • The window isn't closed until you press Enter once again

  • This happens on every subsequent :w as well

The workaround I found:

  • Add elm-test to the devshell
  • :w works fine

P.S. I'm not sure if I should open an issue about the pop-up window here or in nvim-lspconfig. Either https://github.com/elm-tooling/elm-language-server/blob/b22398b3398b20640cbdd9cc6d6b70a14826b800/src/compiler/utils/elmUtils.ts#L96 is the wrong way to report an error to the lsp client, or nvim-lspconfig handles it improperly, but the pop-up capturing the input makes for a very fragile UX (given that configuration issues just do happen from time to time)

SomeoneSerge avatar Mar 16 '22 19:03 SomeoneSerge

Yeah, that's probably a nvim-lspconfig thing, as vscode does not capture your focus in that case.

razzeee avatar Mar 16 '22 19:03 razzeee

Oh, but I don't think the error message has been fixed? At least the linked file hasn't been updated

SomeoneSerge avatar Mar 20 '22 22:03 SomeoneSerge

I think thats a newish regression, previously we ended up at https://github.com/elm-tooling/elm-language-server/blob/main/src/providers/diagnostics/elmMakeDiagnostics.ts#L274 , but we now chain to elm-test if I remember right, which likely causes this

razzeee avatar Mar 21 '22 00:03 razzeee

Not sure why, but if I uninstall elm-test and try this with vscode, I'm getting a hint that I need elm-test

razzeee avatar Mar 25 '22 00:03 razzeee

Hmm. I've just re-checked, I'm getting a message about the "elm compiler", not elm-test. Maybe something has changed since 2.3.0

SomeoneSerge avatar Mar 25 '22 14:03 SomeoneSerge

I wrote the code you linked to.

For files that are ambiguous – that might be tests, or might be not-yet-imported regular Elm code – the idea is to try type checking with elm-test, but not require it. The code tries to fall back on using elm.

If your workaround is to install elm-test, then the problem isn’t a confusing error message: The problem is that the fallback to plain elm doesn’t seem to work for you.

You can see here how we try the next command in the list if there’s an ENOENT error:

https://github.com/elm-tooling/elm-language-server/blob/b22398b3398b20640cbdd9cc6d6b70a14826b800/src/compiler/utils/elmUtils.ts#L83-L93

Maybe the error isn’t ENOENT on your system? 🤔

lydell avatar Apr 02 '22 15:04 lydell

Thank you @lydell! Given that I do not have a dev environment set up for elm-language-server, what would be the easiest way to verify your ENOENT hypothesis?

SomeoneSerge avatar Apr 02 '22 22:04 SomeoneSerge

You could edit the .js files of your elm-language-server installation. They’re pretty similar to the TypeScript source code. I’d add some console.logs and see if I can figure out how to see those. Or maybe some fs.writeFileSync or fs.appendFileSync to write to a log file. Or maybe there’s some log/debug system in the language server that I don’t remember of. @razzeee Any tips?

You could also try running elm-language-server with PATH set so that elm points to a shell script, so you can easily tell if that gets called, i.e. if we ever hit this line: https://github.com/elm-tooling/elm-language-server/blob/964a7d0b50c123cf0aebe2f87c9bf6bb79fb298a/src/providers/diagnostics/elmMakeDiagnostics.ts?rgh-link-date=2022-03-21T00%3A01%3A01Z#L300. Pretty hacky way, but might be doable.

Also, looking at the code again, it could be that the error message is wrong, too:

https://github.com/elm-tooling/elm-language-server/blob/964a7d0b50c123cf0aebe2f87c9bf6bb79fb298a/src/providers/diagnostics/elmMakeDiagnostics.ts?rgh-link-date=2022-03-21T00%3A01%3A01Z#L303-L307

The condition looks flipped to me: If settings.elmTestPath is explicitly set (to a non-empty string), the elm-test error is the most interesting one, otherwise the elm one.

Also, this line is wrong: https://github.com/elm-tooling/elm-language-server/blob/964a7d0b50c123cf0aebe2f87c9bf6bb79fb298a/src/providers/diagnostics/elmMakeDiagnostics.ts?rgh-link-date=2022-03-21T00%3A01%3A01Z#L274

It says “Install Elm via 'npm install -g elm-test'” but it should say “Install elm-test”.

This is a very complicated piece of code (unfortunate complexity), and it’s hard to test so it feels like there could be a few bugs hiding…

lydell avatar Apr 03 '22 08:04 lydell

If your using https://github.com/elm-tooling/elm-language-client-vscode#contributing--debugging you should be able to setup breakpoints and attach to the server with one of the profiles. It's quiet hard to attach right at the start, but I remember that there's a setting somewhere to wait for a debugger to attach - on the vscode side.

razzeee avatar Apr 03 '22 08:04 razzeee