From 1f973f385098b1a096a88220acd96ca3cdf22805 Mon Sep 17 00:00:00 2001 From: FollieHiyuki Date: Tue, 5 Oct 2021 00:42:41 +0700 Subject: [PATCH] neovim: add scripts to install lsp servers --- home/.config/nvim/lua/modules/lsp.lua | 59 ++++++++++++++++--- home/.config/nvim/lua/plugins.lua | 4 +- home/.config/nvim/scripts/install | 32 ++++++++++ home/.config/nvim/scripts/lsp/bashls | 12 ++++ home/.config/nvim/scripts/lsp/cmake | 13 ++++ home/.config/nvim/scripts/lsp/dockerls | 12 ++++ home/.config/nvim/scripts/lsp/emmet_ls | 12 ++++ home/.config/nvim/scripts/lsp/gopls | 12 ++++ home/.config/nvim/scripts/lsp/pyright | 12 ++++ home/.config/nvim/scripts/lsp/sqls | 12 ++++ .../{sumneko_lua.sh => lsp/sumneko_lua} | 12 ++-- home/.config/nvim/scripts/lsp/tailwindcss | 12 ++++ home/.config/nvim/scripts/lsp/tsserver | 12 ++++ home/.config/nvim/scripts/lsp/vimls | 12 ++++ home/.config/nvim/scripts/lsp/vscode | 12 ++++ home/.config/nvim/scripts/lsp/yamlls | 12 ++++ 16 files changed, 235 insertions(+), 17 deletions(-) create mode 100755 home/.config/nvim/scripts/install create mode 100755 home/.config/nvim/scripts/lsp/bashls create mode 100755 home/.config/nvim/scripts/lsp/cmake create mode 100755 home/.config/nvim/scripts/lsp/dockerls create mode 100755 home/.config/nvim/scripts/lsp/emmet_ls create mode 100755 home/.config/nvim/scripts/lsp/gopls create mode 100755 home/.config/nvim/scripts/lsp/pyright create mode 100755 home/.config/nvim/scripts/lsp/sqls rename home/.config/nvim/scripts/{sumneko_lua.sh => lsp/sumneko_lua} (66%) create mode 100755 home/.config/nvim/scripts/lsp/tailwindcss create mode 100755 home/.config/nvim/scripts/lsp/tsserver create mode 100755 home/.config/nvim/scripts/lsp/vimls create mode 100755 home/.config/nvim/scripts/lsp/vscode create mode 100755 home/.config/nvim/scripts/lsp/yamlls diff --git a/home/.config/nvim/lua/modules/lsp.lua b/home/.config/nvim/lua/modules/lsp.lua index 22b0be6..23be636 100644 --- a/home/.config/nvim/lua/modules/lsp.lua +++ b/home/.config/nvim/lua/modules/lsp.lua @@ -70,6 +70,7 @@ function M.lsp_conf() -- Server configurations -- --------------------------- -- https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md + local servers_path = vim.fn.stdpath('data') .. '/lsp' -- C/C++ lspconf.clangd.setup { @@ -121,9 +122,9 @@ function M.lsp_conf() on_attach = on_attach, capabilities = capabilities, cmd = { - vim.fn.stdpath('data') .. '/lsp/lua-language-server/bin/Linux/lua-language-server', - '-E', - vim.fn.stdpath('data') .. '/lsp/lua-language-server/main.lua' + servers_path .. '/sumneko_lua/bin/Linux/lua-language-server', + '-E', '-e', 'LANG=en', + servers_path .. '/sumneko_lua/main.lua' }, settings = { Lua = { @@ -145,18 +146,41 @@ function M.lsp_conf() lspconf.gopls.setup { on_attach = on_attach, capabilities = capabilities, - cmd = {'gopls', '--remote=auto'}, + cmd = {servers_path .. '/gopls/gopls', '--remote=auto'}, init_options = { usePlaceholders = true, completeUnimported = true } } + -- Yaml + -- lspconf.yamlls.setup { + -- on_attach = on_attach, + -- capabilities = capabilities, + -- cmd = {servers_path .. '/yamlls/node_modules/.bin/yaml-language-server', '--stdio'}, + -- settings = { + -- redhat = {telemetry = {enabled = false}}, + -- yaml = {format = {bracketSpacing = true}} + -- } + -- } + + -- Tailwind + -- lspconf.tailwindcss.setup { + -- on_attach = on_attach, + -- capabilities = capabilities, + -- cmd = {servers_path .. '/tailwindcss/node_modules/.bin/tailwindcss-language-server', '--stdio'}, + -- settings = { + -- tailwindCSS = { + -- emmetCompletions = true + -- } + -- } + -- } + -- Emmet if not lspconf.emmet_ls then require('lspconfig/configs').emmet_ls = { default_config = { - cmd = {'emmet-ls', '--stdio'}, + cmd = {servers_path .. '/emmet_ls/node_modules/.bin/emmet-ls', '--stdio'}, filetypes = {'html', 'css'}, root_dir = function(fname) return vim.loop.cwd() @@ -167,15 +191,32 @@ function M.lsp_conf() end lspconf.emmet_ls.setup {capabilities = capabilities} + -- HTML + lspconf.html.setup { + on_attach = on_attach, + capabilities = capabilities, + cmd = {servers_path .. '/vscode/node_modules/.bin/vscode-html-language-server', '--stdio'}, + filetypes = {'html', 'markdown'} + } + -- Others local servers = { - 'dockerls', 'bashls', 'pyright', 'tsserver', - 'html', 'jsonls', 'cmake', 'sqls', 'rust_analyzer' + rust_analyzer = {'rust-analyzer'}, + sqls = {servers_path .. '/sqls/sqls'}, + cmake = {servers_path .. '/cmake/venv/bin/cmake-language-server'}, + bashls = {servers_path .. '/bashls/node_modules/.bin/bash-language-server', 'start'}, + dockerls = {servers_path .. '/dockerls/node_modules/.bin/docker-langserver', '--stdio'}, + jsonls = {servers_path .. '/vscode/node_modules/.bin/vscode-json-language-server', '--stdio'}, + cssls = {servers_path .. '/vscode/node_modules/.bin/vscode-css-language-server', '--stdio'}, + pyright = {servers_path .. '/pyright/node_modules/.bin/pyright-langserver', '--stdio'}, + -- vimls = {servers_path .. '/vimls/node_modules/.bin/vim-language-server', '--stdio'}, + tsserver = {servers_path .. '/tsserver/node_modules/.bin/typescript-language-server', '--stdio'} } - for _, server in ipairs(servers) do + for server, _ in pairs(servers) do lspconf[server].setup { on_attach = on_attach, - capabilities = capabilities + capabilities = capabilities, + cmd = servers[server] } end diff --git a/home/.config/nvim/lua/plugins.lua b/home/.config/nvim/lua/plugins.lua index 2975f49..02517ad 100644 --- a/home/.config/nvim/lua/plugins.lua +++ b/home/.config/nvim/lua/plugins.lua @@ -145,7 +145,7 @@ return packer.startup(function(use) -- LSP -- --------- local lsp = require('modules.lsp') - use { -- TODO: scripts to install/update lsp servers + use { 'neovim/nvim-lspconfig', event = 'BufReadPre', wants = 'lsp_signature.nvim', @@ -154,7 +154,7 @@ return packer.startup(function(use) } use { 'nanotee/sqls.nvim', - ft = {'sql', 'mysql', 'plsql'}, + ft = {'sql', 'mysql'}, wants = 'nvim-lspconfig', config = lsp.sqls_conf } diff --git a/home/.config/nvim/scripts/install b/home/.config/nvim/scripts/install new file mode 100755 index 0000000..bcd7131 --- /dev/null +++ b/home/.config/nvim/scripts/install @@ -0,0 +1,32 @@ +#!/bin/sh + +# TODO: consider forking 'kabouzeid/nvim-lspinstall' or 'anott03/nvim-lspinstall' +# instead of running scripts +if [ "$#" -ne 1 ]; then + echo "Usage:" + printf " - %s server_name: install specified server\n" "$0" + printf " - %s -lsp: install all lsp servers\n" "$0" + printf " - %s -dap: install all dap servers\n" "$0" + printf " - %s -lint: install everything\n" "$0" + exit 1 +fi + +nvim_script_dir=${XDG_CONFIG_HOME:-$HOME/.config}/nvim/scripts + +if [ "$1" = "-lsp" ]; then + find "${nvim_script_dir}/lsp" -type f -exec '{}' \; +elif [ "$1" = '-dap' ]; then + find "${nvim_script_dir}/dap" -type f -exec '{}' \; +elif [ "$1" = '-lint' ]; then + find "${nvim_script_dir}/lint" -type f -exec '{}' \; +elif [ "$1" = '-all' ]; then + find "${nvim_script_dir}" -mindepth 2 -type f -exec '{}' \; +else + # Each server should have an unique name + server_path=$(find "${nvim_script_dir}" -mindepth 2 -type f -name "$1" | head -n 1) + if [ -z "${server_path}" ]; then + echo "Incorrect server name." + exit 1 + fi + exec ${server_path} +fi diff --git a/home/.config/nvim/scripts/lsp/bashls b/home/.config/nvim/scripts/lsp/bashls new file mode 100755 index 0000000..0e6d8b1 --- /dev/null +++ b/home/.config/nvim/scripts/lsp/bashls @@ -0,0 +1,12 @@ +#!/bin/sh -e + +current_path="$PWD" +server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lsp/bashls" + +[ ! -d "${server_path}" ] && mkdir -p "${server_path}" +cd ${server_path} + +[ ! -f package.json ] && npm init -y --scope=lsp || true +npm install bash-language-server@latest + +cd ${current_path} diff --git a/home/.config/nvim/scripts/lsp/cmake b/home/.config/nvim/scripts/lsp/cmake new file mode 100755 index 0000000..e652e05 --- /dev/null +++ b/home/.config/nvim/scripts/lsp/cmake @@ -0,0 +1,13 @@ +#!/bin/sh -e + +current_path="$PWD" +server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lsp/cmake" + +[ ! -d "${server_path}" ] && mkdir -p "${server_path}" +cd ${server_path} + +python3 -m venv ${server_path}/venv +${server_path}/venv/bin/pip3 install -U pip +${server_path}/venv/bin/pip3 install -U cmake-language-server + +cd ${current_path} diff --git a/home/.config/nvim/scripts/lsp/dockerls b/home/.config/nvim/scripts/lsp/dockerls new file mode 100755 index 0000000..349d73d --- /dev/null +++ b/home/.config/nvim/scripts/lsp/dockerls @@ -0,0 +1,12 @@ +#!/bin/sh -e + +current_path="$PWD" +server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lsp/dockerls" + +[ ! -d "${server_path}" ] && mkdir -p "${server_path}" +cd ${server_path} + +[ ! -f package.json ] && npm init -y --scope=lsp || true +npm install dockerfile-language-server-nodejs@latest + +cd ${current_path} diff --git a/home/.config/nvim/scripts/lsp/emmet_ls b/home/.config/nvim/scripts/lsp/emmet_ls new file mode 100755 index 0000000..ed38dfe --- /dev/null +++ b/home/.config/nvim/scripts/lsp/emmet_ls @@ -0,0 +1,12 @@ +#!/bin/sh -e + +current_path="$PWD" +server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lsp/emmet_ls" + +[ ! -d "${server_path}" ] && mkdir -p "${server_path}" +cd ${server_path} + +[ ! -f package.json ] && npm init -y --scope=lsp || true +npm install emmet-ls@latest + +cd ${current_path} diff --git a/home/.config/nvim/scripts/lsp/gopls b/home/.config/nvim/scripts/lsp/gopls new file mode 100755 index 0000000..889f69e --- /dev/null +++ b/home/.config/nvim/scripts/lsp/gopls @@ -0,0 +1,12 @@ +#!/bin/sh -e + +current_path="$PWD" +server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lsp/gopls" + +[ ! -d "${server_path}" ] && mkdir -p "${server_path}" +cd ${server_path} + +GOPATH="${server_path}" GOBIN="${server_path}" go install golang.org/x/tools/gopls@latest +GOPATH="${server_path}" GOBIN="${server_path}" go clean -modcache + +cd ${current_path} diff --git a/home/.config/nvim/scripts/lsp/pyright b/home/.config/nvim/scripts/lsp/pyright new file mode 100755 index 0000000..164a9db --- /dev/null +++ b/home/.config/nvim/scripts/lsp/pyright @@ -0,0 +1,12 @@ +#!/bin/sh -e + +current_path="$PWD" +server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lsp/pyright" + +[ ! -d "${server_path}" ] && mkdir -p "${server_path}" +cd ${server_path} + +[ ! -f package.json ] && npm init -y --scope=lsp || true +npm install pyright@latest + +cd ${current_path} diff --git a/home/.config/nvim/scripts/lsp/sqls b/home/.config/nvim/scripts/lsp/sqls new file mode 100755 index 0000000..5ec1b94 --- /dev/null +++ b/home/.config/nvim/scripts/lsp/sqls @@ -0,0 +1,12 @@ +#!/bin/sh -e + +current_path="$PWD" +server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lsp/sqls" + +[ ! -d "${server_path}" ] && mkdir -p "${server_path}" +cd ${server_path} + +GOPATH="${server_path}" GOBIN="${server_path}" go install github.com/lighttiger2505/sqls@latest +GOPATH="${server_path}" GOBIN="${server_path}" go clean -modcache + +cd ${current_path} diff --git a/home/.config/nvim/scripts/sumneko_lua.sh b/home/.config/nvim/scripts/lsp/sumneko_lua similarity index 66% rename from home/.config/nvim/scripts/sumneko_lua.sh rename to home/.config/nvim/scripts/lsp/sumneko_lua index 62db02c..6389e66 100755 --- a/home/.config/nvim/scripts/sumneko_lua.sh +++ b/home/.config/nvim/scripts/lsp/sumneko_lua @@ -1,17 +1,17 @@ #!/bin/sh -e current_path="$PWD" -luals_path="$HOME/.local/share/nvim/lsp/lua-language-server" +server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lsp/sumneko_lua" # Clone / Update -if [ -d "$luals_path" ]; then - cd $luals_path +if [ -d "${server_path}" ]; then + cd ${server_path} git pull --rebase else - git clone https://github.com/sumneko/lua-language-server.git $luals_path + git clone https://github.com/sumneko/lua-language-server.git ${server_path} fi -cd $luals_path +cd ${server_path} git submodule update --init --recursive # Build @@ -23,4 +23,4 @@ cd ../.. # The build process automatically exports path to `~/.profile` rm -rf ~/.profile -cd $current_path +cd ${current_path} diff --git a/home/.config/nvim/scripts/lsp/tailwindcss b/home/.config/nvim/scripts/lsp/tailwindcss new file mode 100755 index 0000000..b27cecb --- /dev/null +++ b/home/.config/nvim/scripts/lsp/tailwindcss @@ -0,0 +1,12 @@ +#!/bin/sh -e + +current_path="$PWD" +server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lsp/tailwindcss" + +[ ! -d "${server_path}" ] && mkdir -p "${server_path}" +cd ${server_path} + +[ ! -f package.json ] && npm init -y --scope=lsp || true +npm install @tailwindcss/language-server + +cd ${current_path} diff --git a/home/.config/nvim/scripts/lsp/tsserver b/home/.config/nvim/scripts/lsp/tsserver new file mode 100755 index 0000000..7f8ad7f --- /dev/null +++ b/home/.config/nvim/scripts/lsp/tsserver @@ -0,0 +1,12 @@ +#!/bin/sh -e + +current_path="$PWD" +server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lsp/tsserver" + +[ ! -d "${server_path}" ] && mkdir -p "${server_path}" +cd ${server_path} + +[ ! -f package.json ] && npm init -y --scope=lsp || true +npm install typescript@latest typescript-language-server@latest + +cd ${current_path} diff --git a/home/.config/nvim/scripts/lsp/vimls b/home/.config/nvim/scripts/lsp/vimls new file mode 100755 index 0000000..f6bc408 --- /dev/null +++ b/home/.config/nvim/scripts/lsp/vimls @@ -0,0 +1,12 @@ +#!/bin/sh -e + +current_path="$PWD" +server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lsp/vimls" + +[ ! -d "${server_path}" ] && mkdir -p "${server_path}" +cd ${server_path} + +[ ! -f package.json ] && yarn init -y || true +yarn add vim-language-server@latest + +cd ${current_path} diff --git a/home/.config/nvim/scripts/lsp/vscode b/home/.config/nvim/scripts/lsp/vscode new file mode 100755 index 0000000..5c9e25d --- /dev/null +++ b/home/.config/nvim/scripts/lsp/vscode @@ -0,0 +1,12 @@ +#!/bin/sh -e + +current_path="$PWD" +server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lsp/vscode" + +[ ! -d "${server_path}" ] && mkdir -p "${server_path}" +cd ${server_path} + +[ ! -f package.json ] && npm init -y --scope=lsp || true +npm install vscode-langservers-extracted@latest + +cd ${current_path} diff --git a/home/.config/nvim/scripts/lsp/yamlls b/home/.config/nvim/scripts/lsp/yamlls new file mode 100755 index 0000000..e240624 --- /dev/null +++ b/home/.config/nvim/scripts/lsp/yamlls @@ -0,0 +1,12 @@ +#!/bin/sh -e + +current_path="$PWD" +server_path="${XDG_DATA_HOME:-$HOME/.local/share}/nvim/lsp/yamlls" + +[ ! -d "${server_path}" ] && mkdir -p "${server_path}" +cd ${server_path} + +[ ! -f package.json ] && yarn init -y || true +yarn add yaml-language-server@latest + +cd ${current_path}