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

elm make Fails After Starting Elm Language Server #687

Closed
tmciver-mackey opened this issue Mar 23, 2022 · 7 comments
Closed

elm make Fails After Starting Elm Language Server #687

tmciver-mackey opened this issue Mar 23, 2022 · 7 comments

Comments

@tmciver-mackey
Copy link

Emacs' integration with elm-language-server does not work as server responds with an error for all interactions.

Expected Behavior

No error reported by elm-language-server.

Current Behavior

Starting lsp in a buffer containing an Elm source file with elm-mode activated causes the following text to be displayed in lsp-log:

Command "/home/tim/.nvm/versions/node/v16.4.0/bin/elm-language-server --stdio" is present on the path.
Command "/home/tim/.nvm/versions/node/v16.4.0/bin/elm-language-server --stdio" is present on the path.
Found the following clients for /home/tim/workspace/front-end/elm/src/Layout/SearchBox.elm: (server-id elm-ls, priority -1)
The following clients were selected based on priority: (server-id elm-ls, priority -1)
Loading Elm tree-sitter syntax from ../../.nvm/versions/node/v16.4.0/lib/node_modules/@elm-tooling/elm-language-server/out/tree-sitter-elm.wasm
Found 2 elm.json files for workspace /home/tim/workspace/front-end
Found 1 unique elmWorkspaces for workspace /home/tim/workspace/front-end
Starting language server for folder: file:///home/tim/workspace/front-end
Elm version 0.19.1 detected.
Reading elm.json from /home/tim/workspace/front-end/elm.json
{"shortMessage":"Command failed with exit code 1: elm make","command":"elm make","escapedCommand":"elm make","exitCode":1,"stdout":"","stderr":"-- NO INPUT --------------------------------------------------------------------\n\nWhat should I make though? I need specific files like:\n\n    elm make src/Main.elm\n    elm make src/This.elm src/That.elm\n\nI recommend reading through https://guide.elm-lang.org for guidance on what to\nactually put in those files!\n\n","failed":true,"timedOut":false,"isCanceled":false,"killed":false}
Error parsing files for /home/tim/workspace/front-end/elm.json:
Error: ENOENT: no such file or directory, open '/home/tim/.elm/0.19.1/packages/ContaSystemer/elm-menu/1.1.1/elm.json'
Notification handler 'textDocument/didOpen' failed with message: Cannot read property 'getTree' of undefined
TypeError: Cannot read property 'getTree' of undefined delayed processing of request

Possible Solution

Steps to Reproduce (for bugs)

  1. Install elm-laguage-server globally with:
    npm i -g @elm-tooling/elm-language-server
  2. Create a fresh emacs environment by (re)moving any current emacs configuration and putting the following in a new $HOME/.emacs/init.el:
(require 'package)

(setq package-archives '(("org" . "https://orgmode.org/elpa/")
                         ("gnu" . "https://elpa.gnu.org/packages/")
                         ("melpa" . "https://melpa.org/packages/")))

;; initialize built-in package management
(package-initialize)

;; update packages list if we are on a new install
(unless package-archive-contents
  (package-refresh-contents))

(exec-path-from-shell-initialize)
  1. Start Emacs.
  2. Run package-list-package and find and install elm-mode and lsp-mode.
  3. Restart Emacs.
  4. Open an Elm source file.
  5. Start lsp-mode with M-x lsp.
  6. Observe that elm-language-server starts and stays running but produces the error mentioned above in lsp-log.

Context

Your Environment

  • Version used: 2.4.1
  • Editor used: Emacs 28.0.91 installed via Nix
  • Environment name and version (e.g. node.js 5.4):
    • node 16.4.0
    • npm 7.18.1
  • Operating System and version: Ubuntu 20.04.4
@razzeee
Copy link
Member

razzeee commented Mar 23, 2022

Can you clean out the .elm folder? And run elm install again?

@tmciver-mackey
Copy link
Author

tmciver-mackey commented Mar 23, 2022

Sure. Do you mean the ~/.elm directory? I have removed that directory.
Also, when you say "run elm install", do you mean globally or for the project? I don't have elm installed globally. I did do a rm -rf node_modules followed by a npm install in the project directory but this did not change the error. It also did not repopulate ~/.elm.

A colleague suggested this has something to do with tree-sitter. I tried installing several tree-sitter related Emacs packages but that did not change the situation.

@razzeee
Copy link
Member

razzeee commented Mar 23, 2022

it should be enough to run elm install in that project, it should still recreate the kinda global .elm folder

@joncol
Copy link

joncol commented Mar 28, 2022

A colleague suggested this has something to do with tree-sitter. I tried installing several tree-sitter related Emacs packages but that did not change the situation.

Thanks for this hint. I had similar troubles the last couple of days, but disabling tree-sitter in my Emacs config seems to have helped. I'm also using Nix (on NixOS, btw)...

@tmciver-mackey
Copy link
Author

@razzeee For some reason that isn't working for me. When I run elm install in my project's directory, I get this:

tim@inara:~/workspace/front-end$ elm install
-- INSTALL WHAT? ---------------------------------------------------------------

I am expecting commands like:

    elm install elm/http
    elm install elm/json
    elm install elm/random

Hint: In JavaScript folks run `npm install` to start projects. "Gotta download
everything!" But why download packages again and again? Instead, Elm caches
packages in /home/tim/.elm so each one is downloaded and built ONCE on your
machine. Elm projects check that cache before trying the internet. This reduces
build times, reduces server costs, and makes it easier to work offline. As a
result elm install is only for adding dependencies to elm.json, whereas elm make
is in charge of gathering dependencies and building everything. So maybe try
elm make instead?

If I try elm make, I get this:

tim@inara:~/workspace/front-end$ elm make
-- NO INPUT --------------------------------------------------------------------

What should I make though? I need specific files like:

    elm make src/Main.elm
    elm make src/This.elm src/That.elm

I recommend reading through https://guide.elm-lang.org/ for guidance on what to
actually put in those files!

~/.elm does not get populated.

@razzeee
Copy link
Member

razzeee commented Mar 28, 2022

I'm not sure how that works anymore, would have to look at it.

From memory we run elm make https://github.com/elm-tooling/elm-language-server/blob/main/src/compiler/program.ts#L385
And that error is expected, it should still download deps, not sure if only in elm-stuff, but I think it should also add them to .elm unless you've moved that folder around with the env var. But we should also be aware of that.

@tmciver-mackey
Copy link
Author

I solved my problem. In addition to removing ~/.elm directory I also had to remove

  • elm-stuff directory from the project
  • run elm make elm/src/Main.elm

I'm not very familiar with Elm and did not realize there was also a project local cache. This may or may not be related to my project's use of shelm.

Closing since it's not an issue with elm-language-server.

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