diff options
| author | Ashkan Kiani <ashkan.k.kiani@gmail.com> | 2019-11-15 17:26:22 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-15 17:26:22 -0800 |
| commit | 5686a90890105e6271307e86b472f729af1cc4f8 (patch) | |
| tree | 7d691ac0e7ea2feb58c5862dd52a1c8bfbef6fb4 /lua/nvim_lsp/elmls.lua | |
| parent | [docgen] Update README.md (diff) | |
| download | nvim-lspconfig-5686a90890105e6271307e86b472f729af1cc4f8.tar nvim-lspconfig-5686a90890105e6271307e86b472f729af1cc4f8.tar.gz nvim-lspconfig-5686a90890105e6271307e86b472f729af1cc4f8.tar.bz2 nvim-lspconfig-5686a90890105e6271307e86b472f729af1cc4f8.tar.lz nvim-lspconfig-5686a90890105e6271307e86b472f729af1cc4f8.tar.xz nvim-lspconfig-5686a90890105e6271307e86b472f729af1cc4f8.tar.zst nvim-lspconfig-5686a90890105e6271307e86b472f729af1cc4f8.zip | |
Redo installation. (#17)
* Redo installation.
Servers which want to be auto installed should specify
skeleton[name].install()
and it will be automatically added to the list of installable servers.
- Add :LspInstall and :LspInstallInfo
- Auto generate docs for servers with .install() available.
- Add util.npm_installer
- Refactor utf8 capabilities common config into a single function
- Add contribution notes.
- Also expose util.base_install_dir for other installers potentially
- Fix tsserver's arguments and add javascript filetypes
Diffstat (limited to 'lua/nvim_lsp/elmls.lua')
| -rw-r--r-- | lua/nvim_lsp/elmls.lua | 112 |
1 files changed, 23 insertions, 89 deletions
diff --git a/lua/nvim_lsp/elmls.lua b/lua/nvim_lsp/elmls.lua index 08a28c45..93dce340 100644 --- a/lua/nvim_lsp/elmls.lua +++ b/lua/nvim_lsp/elmls.lua @@ -1,59 +1,27 @@ local skeleton = require 'nvim_lsp/skeleton' local util = require 'nvim_lsp/util' local lsp = vim.lsp -local fn = vim.fn local api = vim.api -local need_bins = util.need_bins - -local default_capabilities = lsp.protocol.make_client_capabilities() -default_capabilities.offsetEncoding = {"utf-8", "utf-16"} +local server_name = "elmls" local bin_name = "elm-language-server" -local install_dir = util.path.join(fn.stdpath("cache"), "nvim_lsp", "elmls") -local function get_install_info() - local bin_dir = util.path.join(install_dir, "node_modules", ".bin") - local bins = { bin_dir = bin_dir; install_dir = install_dir; } - bins.elmls = util.path.join(bin_dir, bin_name) - bins.elm = util.path.join(bin_dir, "elm") - bins.elm_format = util.path.join(bin_dir, "elm-format") - bins.elm_test = util.path.join(bin_dir, "elm-test") - bins.is_installed = need_bins(bins.elmls, bins.elm, bins.elm_format, bins.elm_test) - return bins -end - -local global_commands = { - ElmlsInstall = { - function() - if get_install_info().is_installed then - return print("ElmLS is already installed") - end - skeleton.elmls.install() - end; - description = 'Install elmls and its dependencies to stdpath("cache")/nvim_lsp/elmls'; - }; - ElmlsInstallInfo = { - function() - local install_info = get_install_info() - if not install_info.is_installed then - return print("ElmLS is not installed") - end - print(vim.inspect(install_info)) - end; - description = 'Print installation info for `elmls`'; - }; -}; - -util.create_module_commands("elmls", global_commands) +local installer = util.npm_installer { + server_name = server_name; + packages = { "elm", "elm-test", "elm-format", "@elm-tooling/elm-language-server" }; + binaries = {bin_name, "elm", "elm-format", "elm-test"}; +} +local default_capabilities = lsp.protocol.make_client_capabilities() +default_capabilities.offsetEncoding = {"utf-8", "utf-16"} local elm_root_pattern = util.root_pattern("elm.json") -skeleton.elmls = { - default_config = { +skeleton[server_name] = { + default_config = util.utf8_config { cmd = {bin_name}; -- TODO(ashkan) if we comment this out, it will allow elmls to operate on elm.json. It seems like it could do that, but no other editor allows it right now. filetypes = {"elm"}; - root_dir = function(fname, bufnr) + root_dir = function(fname) local filetype = api.nvim_buf_get_option(0, 'filetype') if filetype == 'elm' or (filetype == 'json' and fname:match("elm%.json$")) then return elm_root_pattern(fname) @@ -67,40 +35,27 @@ skeleton.elmls = { elmTestPath = "elm-test", elmAnalyseTrigger = "change", }; - capabilities = default_capabilities; - on_init = function(client, result) - if result.offsetEncoding then - client.offset_encoding = result.offsetEncoding - end - end }; - commands = global_commands; on_new_config = function(new_config) - local install_info = get_install_info() + local install_info = installer.info() if install_info.is_installed then - new_config.cmd = {install_info.elmls} + if type(new_config.cmd) == 'table' then + -- Try to preserve any additional args from upstream changes. + new_config.cmd[1] = install_info.binaries[bin_name] + else + new_config.cmd = {install_info.binaries[bin_name]} + end util.tbl_deep_extend(new_config.init_options, { - elmPath = install_info.elm; - elmFormatPath = install_info.elm_format; - elmTestPath = install_info.elm_test; + elmPath = install_info.binaries["elm"]; + elmFormatPath = install_info.binaries["elm-format"]; + elmTestPath = install_info.binaries["elm-test"]; }) end - print(vim.inspect(new_config)) end; docs = { description = [[ https://github.com/elm-tooling/elm-language-server#installation -You can install elmls automatically to the path at - `stdpath("cache")/nvim_lsp/elmls` -by using the function `nvim_lsp.elmls.install()` or the command `:ElmlsInstall`. - -This will only install if it can't find `elm-language-server` and if it hasn't -been installed before by neovim. - -You can see installation info via `:ElmlsInstallInfo` or via -`nvim_lsp.elmls.get_install_info()`. This will let you know if it is installed. - If you don't want to use neovim to install it, then you can use: ```sh npm install -g elm elm-test elm-format @elm-tooling/elm-language-server @@ -114,28 +69,7 @@ npm install -g elm elm-test elm-format @elm-tooling/elm-language-server }; } -function skeleton.elmls.install() - if not need_bins(bin_name) then return end - if not need_bins("sh", "npm", "mkdir", "cd") then - vim.api.nvim_err_writeln('Installation requires "sh", "npm", "mkdir", "cd"') - return - end - local install_info = get_install_info() - if install_info.is_installed then - return - end - local cmd = io.popen("sh", "w") - local install_script = ([[ -set -eo pipefail -mkdir -p "{{install_dir}}" -cd "{{install_dir}}" -npm install elm elm-test elm-format @elm-tooling/elm-language-server -]]):gsub("{{(%S+)}}", install_info) - print(install_script) - cmd:write(install_script) - cmd:close() -end - -skeleton.elmls.get_install_info = get_install_info +skeleton[server_name].install = installer.install +skeleton[server_name].install_info = installer.info -- vim:et ts=2 sw=2 |
