Giter Site home page Giter Site logo

ilyakard / elm-language-server Goto Github PK

View Code? Open in Web Editor NEW

This project forked from elm-tooling/elm-language-server

0.0 1.0 0.0 1.43 MB

Language server implementation for Elm

Home Page: https://www.npmjs.com/package/@elm-tooling/elm-language-server

License: MIT License

TypeScript 99.32% JavaScript 0.68%

elm-language-server's Introduction

elm-language-server

Build Status

This is the language server implementation for the Elm programming language.

Installation

Note for VSCode users: The plugin contains the language-server. No installation necessary.

The server can be installed via npm (or from source).

npm install -g @elm-tooling/elm-language-server

Then, you should be able to run the language server with the following command:

elm-language-server

Follow the instructions below to integrate the language server into your editor.

Alternative: Compile and install from source

First, clone this repo and compile it. npm link will add elm-language-server to the PATH.

git clone [email protected]:elm-tooling/elm-language-server.git
cd elm-language-server
npm install
npm run compile
npm link

Alternative: Install with Nix

elm-languager-server and its dependencies are available in nixpkgs.

nix-env -i -A nixpkgs.elmPackages.elm-language-server

Requirements

You will need to install elm and elm-test to get all diagnostics and elm-format for formatting. Alternatively you can also just install these to your local npm package.json.

npm install -g elm elm-test elm-format

Or use local versions from your node_modules directory, if you want to do that you need to set the paths, via the settings (e.g. set elmPath to ./node_modules/.bin/elm).

Features

Supports Elm 0.19

Feature Description
diagnostics Provided via elm, 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
selectionRange Enables navigation by selectionRange (extend selection for e.g.)

Server Settings

This server contributes the following settings:

  • elmLS.trace.server: Enable/disable trace logging of client and server communication
  • elmLS.elmPath: The path to your elm executable. Should be empty by default, in that case it will assume the name and try to first get it from a local npm installation or a global one. If you set it manually it will not try to load from the npm folder.
  • elmLS.elmFormatPath: The path to your elm-format executable. Should be empty by default, in that case it will assume the name and try to first get it from a local npm installation or a global one. If you set it manually it will not try to load from the npm folder.
  • elmLS.elmTestPath: The path to your elm-test executable. Should be empty by default, in that case it will assume the name and try to first get it from a local npm installation or a global one. If you set it manually it will not try to load from the npm folder.
  • elmLS.elmAnalyseTrigger: elm-analyse executed on 'change', 'save' or 'never' (default: 'change')

Settings may need a restart to be applied.

Elm-Analyse Configuration

elm-analyse is used for static code analysis. All checks are enabled by default. An (optional) elm-analyse.json configuration file will be respected, if added to your project. See its documentation for details regarding configuration and checks.

Editor Support

Editor Diagnostics Formatting Code Lenses Completions Definitions Document Symbols Folding Hover References Rename Workspace Symbols
VSCode ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
VIM CoC ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
VIM LanguageClient ✔️ ✔️ ✔️
VIM ALE ✔️ ✔️ ✔️ ✔️ ✔️
Kakoune ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
Emacs ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️
Sublime ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️ ✔️

VSCode

Just install the elm-tooling/elm-language-client-vscode plugin from the VSCode MarketPlace

Vim

There are general setup instructions and FAQ for Vim.

It's recommended to install syntax highlighting, which also adds the required detection of elm as filetype. An example vim configuration can be found in elm-vim/vim-config-example.

coc.nvim

To enable support with coc.nvim, run :CocConfig and add the language server config below.

If needed, you can set the paths to elm, elm-test and elm-format with the elmPath, elmTestPath and elmFormatPath variables.

{
  "languageserver": {
    "elmLS": {
      "command": "elm-language-server",
      "filetypes": ["elm"],
      "rootPatterns": ["elm.json"],
      "initializationOptions": {
        "elmAnalyseTrigger": "change"
      }
    }
  },
  // If you use neovim you can enable codelenses with this
  "codeLens.enable": true
}

Much of this is covered in the Example vim configuration section in Coc's readme.

Feature How to use it
Diagnostics :CocList diagnostics
Configure refresh with "diagnostic.refreshAfterSave": false
Formatting :call CocAction('format')
CodeLenses Requires Neovim. Add "coc.preferences.codeLens.enable": true to your coc-settings.json through :CocConfig
Completions On by default, see Completion with sources for customizations
Definitions Provided as <Plug> mapping so that you can set it yourself, e.g.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
DocumentSymbols :CocList outline
Folding You must set foldmethod=manual in your vimrc, one set Coc will handle folding with the usual commands, zc, zo, etc
Hover :call CocAction('doHover')
References Provided as a <Plug> mapping, e.g. nmap <silent> gr <Plug>(coc-references)
Rename Provided as a <Plug> mapping, e.g. nmap <leader>rn <Plug>(coc-rename)
Workspace Symbols :CocList symbols

ALE

ALE contains the elm_ls linter.

let g:ale_linters = { 'elm': ['elm_ls'] }

If needed, you can set the paths to elm, elm-test and elm-format. The configuration can be found here

let g:ale_elm_ls_use_global = 1
let g:ale_elm_ls_executable = "/path/to/elm-language-server"
let g:ale_elm_ls_elm_analyse_trigger = 'change'
let g:ale_elm_ls_elm_path = "/path/to/elm"
let g:ale_elm_ls_elm_format_path = "/path/to/elm-format"
let g:ale_elm_ls_elm_test_path = "/path/to/elm-test"
Feature How to use it
Diagnostics :ALENext/:ALEPrevious
Configure refresh with let g:ale_lint_on_text_changed = 0
let g:ale_lint_on_insert_leave = 1
let g:ale_lint_on_save = 1
Formatting ALE doesn't currently support this through the language server integration, but elm-format is a supported ALE Fixer
CodeLenses Not currently supported
Completions On by default, see :h ale-completion for more info
Definitions :ALEGoToDefinition, :ALEGoToTypeDefinition, see :h ale-go-to-definition and :h ale-go-to-type-definition
DocumentSymbols Only workspace symbols are currently supported
Folding Not currently supported
Hover :ALEHover
References :ALEFindReferences
Rename Not currently supported
Workspace Symbols :ALESymbolSearch <query>

LanguageClient

To use this language server with LanguageClient add the following configuration to you neovim/vim.

let g:LanguageClient_serverCommands = {
  \ 'elm': ['elm-language-server'],
  \ }

let g:LanguageClient_rootMarkers = {
  \ 'elm': ['elm.json'],
  \ }

Kakoune

kak-lsp

First install kak-lsp, and enable it in the kakrc. One way would be to add these lines to your .config/kak/kakrc file:

eval %sh{kak-lsp --kakoune -s $kak_session}
lsp-enable

Then, assuming installation of elm-language-server, elm-format, and elm-test, add this section to your .config/kak-lsp/kak-lsp.toml file:

[language.elm]
filetypes = ["elm"]
roots = ["elm.json"]
command = "elm-language-server"

[language.elm.initialization_options]
elmAnalyseTrigger = "change"

Emacs

The language client is included in lsp-mode, specifically here. See specifically this section for a minimal use-package configuration for lsp-mode.

Sublime

First install the language server via npm npm i -g @elm-tooling/elm-language-server Install Elm Syntax Highlighting from Package Control. Then we also need the LSP Package to be able to connect Sublime to the Language Server.

Add this to your LSP settings under the clients node:

"elm": {
    "command": [
        "elm-language-server"
    ],
    "enabled": true,
    "languageId": "elm",
    "scopes":
    [
        "source.elm"
    ],
    "syntaxes":
    [
        "Packages/Elm Syntax Highlighting/src/elm.sublime-syntax"
    ],
    "initializationOptions": {
        "elmAnalyseTrigger": "change"
    }
}

You should now be able to use the integrations from Sublime.

Awesome libraries this is based on

Contributing

Please do :) As the best thing about a language server is that multiple clients will improve that way.

elm-language-server's People

Contributors

razzeee avatar andys8 avatar antew avatar jmbockhorst avatar buinauskas avatar sentience avatar bburdette avatar bengolds avatar brianhicks avatar danielmv1 avatar jssee avatar jonmast avatar lpil avatar rlefevre avatar ssbb avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.