Elm language server and a new VSCode Plugin

Hey everybody,

after finishing the Elm-tree-sitter implementation in April
I set off to build a language server integration for the elm community based on that.

At the moment, there are instructions for:

  • VSCode
  • VIM
  • Kakoune
  • Emacs

More are hopefully coming, as soon as people think it’s useful.

So what can it do? (I’m using VSCode for this example)

Those are just some of the features, here is a list of most things that are implemented:

Feature Description
Diagnostics Provided via elm make, elm-test and elm-analyse
Formatting Provided via elm-format and post-processed to only return a diff of changes. This way it should not be as intrusive as running elm-format normal
codeLenses Currently only shows if a type alias, custom type or function is exposed from that module
completions Show completions for the current file and snippets
definitions Enables you to jump to the definition of a type alias, module, custom type or function
documentSymbols Identifies all symbols in a document.
folding Let’s you fold the code on certain elm constructs
hover Shows type annotations and documentation for a type alias, module, custom type or function
references Lists all references to a type alias, module, custom type or function
rename Enables you to rename a type alias, module, custom type or function
workspaceSymbols Identifies all symbols in the current workspace

So please see the project pages on github:

And feel free to test (it will need a lot of testing) and contribute in any way. That being code, issues or maybe graphics. :slight_smile:
Or maybe join the #elm-language-server channel on the elm slack.

I had a lot of help by some lovely people like @hpate, @buinauskas, @andys8 and various others.

Let’s build on this and make it even better!

64 Likes

One thing that I’m actively looking for is what features people are missing and which would bring the biggest benefits. So if you got ideas/opinions about that feel free to reach out here, via the issue tracker or slack.

Improving your Elm experience since 2019

:joy: :joy: :joy:

4 Likes

Great work. Thanks for creating this.

I’ve installed the plugin and am using it currently but I cannot seem to remove an elm-analyse error on line 1 of Main.elm that says:

Error parsing file elm-analyse(1)

Running elm-analyse --serve directly from the project root seems to have no problems with my elm-analyse.json file.

I attempted fixing any errors in the file initially and ended up deleting the file altogether but the error persists even after restarting VSCode.

Happy to open a github issue but thought I might ask here first.

1 Like

Interesting, not sure how we can reproduce that best. So I would think, moving this to a github issue would be the right thing to do. Or even the slack channel?

Nesting elm projects (like benchmarks and tests) seems to interfere with the plugin. For examle: I have an inner projects that utilizes ports, but because the outer project is a package, I’m getting warnings. A workaround I’ve used was to open the inner projects in a separate window. I could perhaps instead flatten my repo in a separate folder for each project.

Haven’t had any other issues so far :sunny: it’s really great!

2 Likes

The logic for that is here. https://github.com/elm-tooling/elm-language-client-vscode/blob/master/client/src/extension.ts#L52-L70

If we can find a way to autodetect all needed elm.json files that would be great. But there might be elm.json files in node_modules or even elm-stuff?
Well I’m filtering out node_modules here https://github.com/elm-tooling/elm-language-client-vscode/blob/master/client/src/extension.ts#L27 so we might be able to get away with a more generous logic.

Using this with Vim and Coc and it’s excellent, with a bit of tweaking it’s buttery smooth. I didn’t realise how much I missed “gd” working properly! Good job.

1 Like

So awesome to have this. I’m sure Elm and its community will benefit a lot from proper tooling.

1 Like

Hi, I think this is some cracking work.

One feature I use a lot is ‘symbols’, so if you hit Ctrl+Shift+O you can then go to a definition in a similar way to Ctrl+g is goto line. As you type it shows you completions.

I know there is ‘go to definition’, but that requires you to be near a call site, sometimes I know for example I want to add a new message so I do Ctrl+Shift+O Msg and I’m at the definition for the Msg type.

1 Like

Unfortunately I cannot try it as it won’t work on NixOS (hit me up on Slack if you want to talk about possible solutions), but I think having a Language Server is definitely a must have for any serious language, so kudos for the important work!

1 Like

That should already work, both for symbols in the same file and global (as in the same project scope). Workspace wide might not work.

Okay great, thanks, I will investigate why that didn’t seem to work for me and report back.

Still not working for me, the only error I can see in the output is:
command 'elmLS.elmAnalyseFixer' already exists

When I do Ctrl+Shift+O it tells me No symbols found.

Can you try with https://github.com/rtfeldman/elm-spa-example ?
Do you get an outline in the outline view?

While trying to repro this, I found a file that doesn’t seem to lint, that also had no symbols. Will investigate later.

A ha, yes it does work for `elm-spa-example’, apologies I just tried it on the code I was working on and perhaps that has a file that isn’t linting or something. I will investigate further and report back.

In the folder that isn’t working, there is no outline.

1 Like

So the ‘folder’ I had open in VSCode actually had two elm projects, let’s call them A and B, and hence two elm.json files.
The outline + symbols were not working in the files in project B that I was working on.
It turns out, they were working in project A (I just hadn’t noticed because I wasn’t working on that project).

If I close the containing folder and open a sub folder that contains project B but not A, then the outline+symbols works for me.

So in summary, the issue seemed to be caused by having a folder open (in the VSCode sense) which contained more than one elm project. It didn’t seem related to having a non-linting elm file (I don’t seem to have one in either project).

Thanks.

1 Like

Hrm, that might actually be an upstream bug, can you create an issue on github, so that I can track this? I will probably need to report that to the https://github.com/Microsoft/vscode-languageserver-node people. After checking if i’m using the api correctly.

Sure, done: https://github.com/elm-tooling/elm-language-client-vscode/issues/8

make sure you have module Main exporting (…) or whatever it needs to export at the top. I had this issue and that fixed it for me

1 Like