diff options
| author | Ashkan Kiani <ashkan.k.kiani@gmail.com> | 2019-11-26 06:01:11 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-11-26 06:01:11 -0800 |
| commit | eb01aca460d3a657c8fda36e64d101d85dbd9f78 (patch) | |
| tree | 52f6229735db80ac44b0262a5eb0f3711968d208 /lua | |
| parent | Merge pull request #46 from neovim/fix-lsp-followup (diff) | |
| download | nvim-lspconfig-eb01aca460d3a657c8fda36e64d101d85dbd9f78.tar nvim-lspconfig-eb01aca460d3a657c8fda36e64d101d85dbd9f78.tar.gz nvim-lspconfig-eb01aca460d3a657c8fda36e64d101d85dbd9f78.tar.bz2 nvim-lspconfig-eb01aca460d3a657c8fda36e64d101d85dbd9f78.tar.lz nvim-lspconfig-eb01aca460d3a657c8fda36e64d101d85dbd9f78.tar.xz nvim-lspconfig-eb01aca460d3a657c8fda36e64d101d85dbd9f78.tar.zst nvim-lspconfig-eb01aca460d3a657c8fda36e64d101d85dbd9f78.zip | |
Add sumneko_lua installation and util.sh helper. (#49)
* Add sumneko_lua installation and util.sh helper.
* Add vspackage extraction for package.json information via vscode name.
* Allow specifying a tempdir at DOCGEN_TEMPDIR
* Fix on_new_config and add docs for root_dir
* User settings titles are not always useful
Diffstat (limited to 'lua')
| -rw-r--r-- | lua/nvim_lsp.lua | 3 | ||||
| -rw-r--r-- | lua/nvim_lsp/hie.lua | 1 | ||||
| -rw-r--r-- | lua/nvim_lsp/rls.lua | 1 | ||||
| -rw-r--r-- | lua/nvim_lsp/sumneko_lua.lua | 105 | ||||
| -rw-r--r-- | lua/nvim_lsp/util.lua | 61 |
5 files changed, 170 insertions, 1 deletions
diff --git a/lua/nvim_lsp.lua b/lua/nvim_lsp.lua index 2e00f079..1d5c35e0 100644 --- a/lua/nvim_lsp.lua +++ b/lua/nvim_lsp.lua @@ -2,8 +2,8 @@ local skeleton = require 'nvim_lsp/skeleton' require 'nvim_lsp/bashls' require 'nvim_lsp/ccls' -require 'nvim_lsp/cssls' require 'nvim_lsp/clangd' +require 'nvim_lsp/cssls' require 'nvim_lsp/elmls' require 'nvim_lsp/flow' require 'nvim_lsp/gopls' @@ -11,6 +11,7 @@ require 'nvim_lsp/hie' require 'nvim_lsp/pyls' require 'nvim_lsp/rls' require 'nvim_lsp/solargraph' +require 'nvim_lsp/sumneko_lua' require 'nvim_lsp/texlab' require 'nvim_lsp/tsserver' diff --git a/lua/nvim_lsp/hie.lua b/lua/nvim_lsp/hie.lua index dac2f7c8..cb18a164 100644 --- a/lua/nvim_lsp/hie.lua +++ b/lua/nvim_lsp/hie.lua @@ -12,6 +12,7 @@ skeleton.hie = { }; docs = { + vscode = "alanz.vscode-hie-server"; description = [[ https://github.com/haskell/haskell-ide-engine diff --git a/lua/nvim_lsp/rls.lua b/lua/nvim_lsp/rls.lua index efecd34d..28067999 100644 --- a/lua/nvim_lsp/rls.lua +++ b/lua/nvim_lsp/rls.lua @@ -11,6 +11,7 @@ skeleton.rls = { settings = {}; }; docs = { + vscode = "rust-lang.rust"; package_json = "https://github.com/rust-lang/rls-vscode/raw/master/package.json"; description = [[ https://github.com/rust-lang/rls diff --git a/lua/nvim_lsp/sumneko_lua.lua b/lua/nvim_lsp/sumneko_lua.lua new file mode 100644 index 00000000..365253cb --- /dev/null +++ b/lua/nvim_lsp/sumneko_lua.lua @@ -0,0 +1,105 @@ +local skeleton = require 'nvim_lsp/skeleton' +local util = require 'nvim_lsp/util' +local vim = vim + +local name = "sumneko_lua" + +local function make_installer() + local P = util.path.join + local install_dir = P{util.base_install_dir, name} + local git_dir = P{install_dir, "lua-language-server"} + + local bin = P{git_dir, "bin", "Linux", "lua-language-server"} + local main_file = P{git_dir, "main.lua"} + local cmd = {bin, '-E', main_file} + + local X = {} + function X.install() + local install_info = X.info() + if install_info.is_installed then + print(name, "is already installed") + return + end + if not (util.has_bins("ninja") or util.has_bins("curl")) then + error('Need either "ninja" or "curl" (to download ninja) to install this.') + return + end + if not util.has_bins("sh", "chmod", "unzip") then + error('Need the binaries "sh", "chmod", "unzip" to install this') + return + end + local script = [=[ +set -e +# Install ninja if not available. +which ninja >/dev/null || { + test -x ninja || { + curl -LO https://github.com/ninja-build/ninja/releases/download/v1.9.0/ninja-linux.zip + unzip ninja-linux.zip + chmod +x ninja + } + export PATH=$PWD:$PATH +} + +# clone project +git clone https://github.com/sumneko/lua-language-server +cd lua-language-server +git submodule update --init --recursive + +# build +cd 3rd/luamake +ninja -f ninja/linux.ninja +cd ../.. +./3rd/luamake/luamake rebuild + ]=] + vim.fn.mkdir(install_info.install_dir, "p") + util.sh(script, install_info.install_dir) + end + function X.info() + return { + is_installed = util.has_bins(bin); + install_dir = install_dir; + cmd = cmd; + } + end + function X.configure(config) + local install_info = X.info() + if install_info.is_installed then + config.cmd = cmd + end + end + return X +end + +local installer = make_installer() + +skeleton[name] = { + default_config = { + filetypes = {'lua'}; + root_dir = function(fname) + return util.find_git_ancestor(fname) or vim.loop.os_homedir() + end; + log_level = vim.lsp.protocol.MessageType.Warning; + settings = {}; + }; + on_new_config = function(config) + installer.configure(config) + end; + docs = { + vscode = "sumneko.lua"; + description = [[ +https://github.com/sumneko/lua-language-server + +Lua language server. **By default, this doesn't have a `cmd` set.** This is +because it doesn't provide a global binary. We provide an installer for Linux +using `:LspInstall`. If you wish to install it yourself, [here is a +guide](https://github.com/sumneko/lua-language-server/wiki/Build-and-Run). +]]; + default_config = { + root_dir = [[root_pattern(".git") or os_homedir]]; + }; + }; +} + +skeleton[name].install = installer.install +skeleton[name].install_info = installer.info +-- vim:et ts=2 diff --git a/lua/nvim_lsp/util.lua b/lua/nvim_lsp/util.lua index d015c932..0f96dd59 100644 --- a/lua/nvim_lsp/util.lua +++ b/lua/nvim_lsp/util.lua @@ -1,3 +1,4 @@ +local vim = vim local validate = vim.validate local api = vim.api local lsp = vim.lsp @@ -361,6 +362,66 @@ function M.npm_installer(config) } end +function M.sh(script, cwd) + api.nvim_command("10new") + assert(cwd and M.path.is_dir(cwd), "sh: Invalid directory") + local winnr = api.nvim_get_current_win() + local bufnr = api.nvim_get_current_buf() + local stdin = uv.new_pipe(false) + local stdout = uv.new_pipe(false) + local stderr = uv.new_pipe(false) + local handle, pid + handle, pid = uv.spawn("sh", { + stdio = {stdin, stdout, stderr}; + cwd = cwd; + }, function() + stdin:close() + stdout:close() + stderr:close() + handle:close() + vim.schedule(function() + api.nvim_command("silent bwipeout! "..bufnr) + end) + end) + + -- If the buffer closes, then kill our process. + api.nvim_buf_attach(bufnr, false, { + on_detach = function() + if not handle:is_closing() then + handle:kill(15) + end + end; + }) + + local output_buf = '' + local function update_chunk(err, chunk) + if chunk then + output_buf = output_buf..chunk + local lines = vim.split(output_buf, '\n', true) + api.nvim_buf_set_option(bufnr, "modifiable", true) + api.nvim_buf_set_lines(bufnr, 0, -1, false, lines) + api.nvim_buf_set_option(bufnr, "modifiable", false) + api.nvim_buf_set_option(bufnr, "modified", false) + if api.nvim_win_is_valid(winnr) then + api.nvim_win_set_cursor(winnr, {#lines, 0}) + end + end + end + update_chunk = vim.schedule_wrap(update_chunk) + stdout:read_start(update_chunk) + stderr:read_start(update_chunk) + stdin:write(script) + stdin:write("\n") + stdin:shutdown() +end + +function M.format_vspackage_url(extension_name) + local org, package = unpack(vim.split(extension_name, ".", true)) + assert(org and package) + return string.format("https://marketplace.visualstudio.com/_apis/public/gallery/publishers/%s/vsextensions/%s/latest/vspackage", org, package) +end + + function M.utf8_config(config) config.capabilities = config.capabilities or lsp.protocol.make_client_capabilities() config.capabilities.offsetEncoding = {"utf-8", "utf-16"} |
