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

Confusing error message when elm-test absent in PATH #685

Open
SomeoneSerge opened this issue Mar 16, 2022 · 9 comments
Open

Confusing error message when elm-test absent in PATH #685

SomeoneSerge opened this issue Mar 16, 2022 · 9 comments

Comments

@SomeoneSerge
Copy link

SomeoneSerge commented Mar 16, 2022

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

connection.window.showErrorMessage(
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)

@razzeee
Copy link
Member

razzeee commented Mar 16, 2022

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

@razzeee razzeee closed this as completed Mar 19, 2022
@SomeoneSerge
Copy link
Author

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

@razzeee razzeee reopened this Mar 20, 2022
@razzeee
Copy link
Member

razzeee commented Mar 21, 2022

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
Copy link
Member

razzeee commented Mar 25, 2022

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

@SomeoneSerge
Copy link
Author

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

@lydell
Copy link
Member

lydell commented Apr 2, 2022

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:

const notFound = error.code === "ENOENT";
if (notFound && cmdStatic.length > 1) {
return execCmd(
cmdFromUser,
cmdStatic.slice(1) as NonEmptyArray<[string, string[]]>,
options,
cwd,
connection,
input,
);
}

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

@SomeoneSerge
Copy link
Author

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?

@lydell
Copy link
Member

lydell commented Apr 3, 2022

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:

["elm", argsElm(possiblyTestFiles)],
. Pretty hacky way, but might be doable.

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

notFoundText:
settings.elmTestPath === ""
? elmTestNotFound
: // This uses `elmNotFound` since "elm" is the last alternative above.
elmNotFound,

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:

"'elm-test' is not available. Install Elm via 'npm install -g elm-test'.";

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…

@razzeee
Copy link
Member

razzeee commented Apr 3, 2022

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.

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

No branches or pull requests

3 participants