Pārlūkot izejas kodu

[Feature] Allow for custom path to a language server binary (#1043)

ichigo-gyuunyuu 4 gadi atpakaļ
vecāks
revīzija
0064b446a0

+ 3 - 0
lua/default-config.lua

@@ -165,7 +165,9 @@ require("core.which-key").config()
 require("core.nvimtree").config()
 
 require("lang.clang").config()
+require("lang.clojure").config()
 require("lang.cmake").config()
+require("lang.cs").config()
 require("lang.css").config()
 require("lang.dart").config()
 require("lang.dockerfile").config()
@@ -194,3 +196,4 @@ require("lang.vim").config()
 require("lang.vue").config()
 require("lang.yaml").config()
 require("lang.zig").config()
+require("lang.zsh").config()

+ 4 - 1
lua/lang/clang.lua

@@ -25,6 +25,9 @@ M.config = function()
       },
       stop_on_entry = false,
     },
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/cpp/clangd/bin/clangd",
+    },
   }
 end
 
@@ -69,7 +72,7 @@ M.lsp = function()
   table.insert(clangd_flags, "--header-insertion=" .. O.lang.clang.header_insertion)
 
   require("lspconfig").clangd.setup {
-    cmd = { DATA_PATH .. "/lspinstall/cpp/clangd/bin/clangd", unpack(clangd_flags) },
+    cmd = { O.lang.clang.lsp.path, unpack(clangd_flags) },
     on_attach = require("lsp").common_on_attach,
     handlers = {
       ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {

+ 6 - 2
lua/lang/clojure.lua

@@ -1,7 +1,11 @@
 local M = {}
 
 M.config = function()
-  O.lang.erlang = {}
+  O.lang.erlang = {
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/clojure/clojure-lsp",
+    },
+  }
 end
 
 M.format = function()
@@ -20,7 +24,7 @@ M.lsp = function()
   end
 
   require("lspconfig").clojure_lsp.setup {
-    cmd = { DATA_PATH .. "/lspinstall/clojure/clojure-lsp" },
+    cmd = { O.lang.erlang.lsp.path },
     on_attach = require("lsp").common_on_attach,
   }
 end

+ 4 - 1
lua/lang/cmake.lua

@@ -6,6 +6,9 @@ M.config = function()
       exe = "clang-format",
       args = {},
     },
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/cmake/venv/bin/cmake-language-server",
+    },
   }
 end
 
@@ -25,7 +28,7 @@ M.lsp = function()
   end
 
   require("lspconfig").cmake.setup {
-    cmd = { DATA_PATH .. "/lspinstall/cmake/venv/bin/cmake-language-server" },
+    cmd = { O.lang.cmake.lsp.path },
     on_attach = require("lsp").common_on_attach,
     filetypes = { "cmake" },
   }

+ 6 - 3
lua/lang/cs.lua

@@ -1,8 +1,11 @@
 local M = {}
 
 M.config = function()
-  -- TODO: implement config for language
-  return "No config available!"
+  O.lang.csharp = {
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/csharp/omnisharp/run",
+    },
+  }
 end
 
 M.format = function()
@@ -23,7 +26,7 @@ M.lsp = function()
   -- C# language server (csharp/OmniSharp) setup
   require("lspconfig").omnisharp.setup {
     on_attach = require("lsp").common_on_attach,
-    cmd = { DATA_PATH .. "/lspinstall/csharp/omnisharp/run", "--languageserver", "--hostPID", tostring(vim.fn.getpid()) },
+    cmd = { O.lang.csharp.lsp.path, "--languageserver", "--hostPID", tostring(vim.fn.getpid()) },
   }
 end
 

+ 4 - 1
lua/lang/css.lua

@@ -7,6 +7,9 @@ M.config = function()
       exe = "prettier",
       args = {},
     },
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/css/vscode-css/css-language-features/server/dist/node/cssServerMain.js",
+    },
   }
 end
 
@@ -57,7 +60,7 @@ M.lsp = function()
     require("lspconfig").cssls.setup {
       cmd = {
         "node",
-        DATA_PATH .. "/lspinstall/css/vscode-css/css-language-features/server/dist/node/cssServerMain.js",
+        O.lang.css.lsp.path,
         "--stdio",
       },
       on_attach = require("lsp").common_on_attach,

+ 6 - 2
lua/lang/dockerfile.lua

@@ -1,7 +1,11 @@
 local M = {}
 
 M.config = function()
-  O.lang.docker = {}
+  O.lang.docker = {
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/dockerfile/node_modules/.bin/docker-langserver",
+    },
+  }
 end
 
 M.format = function()
@@ -21,7 +25,7 @@ M.lsp = function()
 
   -- npm install -g dockerfile-language-server-nodejs
   require("lspconfig").dockerls.setup {
-    cmd = { DATA_PATH .. "/lspinstall/dockerfile/node_modules/.bin/docker-langserver", "--stdio" },
+    cmd = { O.lang.docker.lsp.path, "--stdio" },
     on_attach = require("lsp").common_on_attach,
     root_dir = vim.loop.cwd,
   }

+ 4 - 1
lua/lang/elixir.lua

@@ -7,6 +7,9 @@ M.config = function()
       args = { "format" },
       stdin = true,
     },
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/elixir/elixir-ls/language_server.sh",
+    },
   }
 end
 
@@ -38,7 +41,7 @@ M.lsp = function()
   end
 
   require("lspconfig").elixirls.setup {
-    cmd = { DATA_PATH .. "/lspinstall/elixir/elixir-ls/language_server.sh" },
+    cmd = { O.lang.elixir.lsp.path },
     on_attach = require("lsp").common_on_attach,
   }
 end

+ 14 - 5
lua/lang/elm.lua

@@ -1,7 +1,16 @@
 local M = {}
 
 M.config = function()
-  O.lang.elm = {}
+  local elm_bin = DATA_PATH .. "/lspinstall/elm/node_modules/.bin"
+
+  O.lang.elm = {
+    lsp = {
+      path = elm_bin .. "/elm-language-server",
+      format = elm_bin .. "/elm-format",
+      root = elm_bin,
+      test = elm_bin .. "/elm-test",
+    },
+  }
 end
 
 M.format = function()
@@ -20,13 +29,13 @@ M.lsp = function()
   end
 
   require("lspconfig").elmls.setup {
-    cmd = { DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-language-server" },
+    cmd = { O.lang.elm.lsp.path },
     on_attach = require("lsp").common_on_attach,
     init_options = {
       elmAnalyseTrigger = "change",
-      elmFormatPath = DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-format",
-      elmPath = DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm",
-      elmTestPath = DATA_PATH .. "/lspinstall/elm/node_modules/.bin/elm-test",
+      elmFormatPath = O.lang.elm.lsp.format,
+      elmPath = O.lang.elm.lsp.root,
+      elmTestPath = O.lang.elm.lsp.test,
     },
   }
 end

+ 4 - 1
lua/lang/go.lua

@@ -11,6 +11,9 @@ M.config = function()
       "golangcilint",
       "revive",
     },
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/go/gopls",
+    },
   }
 end
 
@@ -40,7 +43,7 @@ end
 M.lsp = function()
   if not require("lv-utils").check_lsp_client_active "gopls" then
     require("lspconfig").gopls.setup {
-      cmd = { DATA_PATH .. "/lspinstall/go/gopls" },
+      cmd = { O.lang.go.lsp.path },
       settings = { gopls = { analyses = { unusedparams = true }, staticcheck = true } },
       root_dir = require("lspconfig").util.root_pattern(".git", "go.mod"),
       init_options = { usePlaceholders = true, completeUnimported = true },

+ 9 - 2
lua/lang/graphql.lua

@@ -1,7 +1,11 @@
 local M = {}
 
 M.config = function()
-  O.lang.graphql = {}
+  O.lang.graphql = {
+    lsp = {
+      path = "graphql-lsp",
+    },
+  }
 end
 
 M.format = function()
@@ -20,7 +24,10 @@ M.lsp = function()
   end
 
   -- npm install -g graphql-language-service-cli
-  require("lspconfig").graphql.setup { on_attach = require("lsp").common_on_attach }
+  require("lspconfig").graphql.setup {
+    cmd = { O.lang.graphql.lsp.path, "server", "-m", "stream" },
+    on_attach = require("lsp").common_on_attach,
+  }
 end
 
 M.dap = function()

+ 4 - 1
lua/lang/html.lua

@@ -7,6 +7,9 @@ M.config = function()
       -- https://docs.errata.ai/vale/scoping#html
       "vale",
     },
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/html/vscode-html/html-language-features/server/dist/node/htmlServerMain.js",
+    },
   }
 end
 
@@ -30,7 +33,7 @@ M.lsp = function()
     require("lspconfig").html.setup {
       cmd = {
         "node",
-        DATA_PATH .. "/lspinstall/html/vscode-html/html-language-features/server/dist/node/htmlServerMain.js",
+        O.lang.html.lsp.path,
         "--stdio",
       },
       on_attach = require("lsp").common_on_attach,

+ 4 - 1
lua/lang/json.lua

@@ -12,6 +12,9 @@ M.config = function()
       args = { "-m", "json.tool" },
       stdin = true,
     },
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/json/vscode-json/json-language-features/server/dist/node/jsonServerMain.js",
+    },
   }
 end
 
@@ -46,7 +49,7 @@ M.lsp = function()
   require("lspconfig").jsonls.setup {
     cmd = {
       "node",
-      DATA_PATH .. "/lspinstall/json/vscode-json/json-language-features/server/dist/node/jsonServerMain.js",
+      O.lang.json.lsp.path,
       "--stdio",
     },
     on_attach = require("lsp").common_on_attach,

+ 6 - 2
lua/lang/julia.lua

@@ -1,7 +1,11 @@
 local M = {}
 
 M.config = function()
-  O.lang.julia = {}
+  O.lang.julia = {
+    lsp = {
+      path = CONFIG_PATH .. "/lua/lsp/julia/run.jl",
+    },
+  }
 end
 
 M.format = function()
@@ -30,7 +34,7 @@ M.lsp = function()
     "--startup-file=no",
     "--history-file=no",
     -- vim.fn.expand "~/.config/nvim/lua/lsp/julia/run.jl",
-    CONFIG_PATH .. "/lua/lsp/julia/run.jl",
+    O.lang.julia.lsp.path,
   }
   require("lspconfig").julials.setup {
     cmd = cmd,

+ 6 - 2
lua/lang/kotlin.lua

@@ -1,7 +1,11 @@
 local M = {}
 
 M.config = function()
-  O.lang.kotlin = {}
+  O.lang.kotlin = {
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/kotlin/server/bin/kotlin-language-server",
+    },
+  }
 end
 
 M.format = function()
@@ -29,7 +33,7 @@ M.lsp = function()
 
   local util = require "lspconfig/util"
 
-  local bin_name = DATA_PATH .. "/lspinstall/kotlin/server/bin/kotlin-language-server"
+  local bin_name = O.lang.kotlin.lsp.path
   if vim.fn.has "win32" == 1 then
     bin_name = bin_name .. ".bat"
   end

+ 5 - 3
lua/lang/lua.lua

@@ -13,6 +13,9 @@ M.config = function()
       stdin = false,
     },
     linters = { "luacheck" },
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/lua/sumneko-lua-language-server",
+    },
   }
 end
 
@@ -43,11 +46,10 @@ end
 M.lsp = function()
   if not require("lv-utils").check_lsp_client_active "sumneko_lua" then
     -- https://github.com/sumneko/lua-language-server/wiki/Build-and-Run-(Standalone)
-    local sumneko_root_path = DATA_PATH .. "/lspinstall/lua"
-    local sumneko_binary = sumneko_root_path .. "/sumneko-lua-language-server"
+    local sumneko_main = string.gsub(O.lang.lua.lsp.path, "sumneko-lua-language-server", "main.lua")
 
     require("lspconfig").sumneko_lua.setup {
-      cmd = { sumneko_binary, "-E", sumneko_root_path .. "/main.lua" },
+      cmd = { O.lang.lua.lsp.path, "-E", sumneko_main },
       on_attach = require("lsp").common_on_attach,
       settings = {
         Lua = {

+ 4 - 1
lua/lang/php.lua

@@ -21,6 +21,9 @@ M.config = function()
       args = { "--standard=PSR12", vim.api.nvim_buf_get_name(0) },
       stdin = false,
     },
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/php/node_modules/.bin/intelephense",
+    },
   }
 end
 
@@ -53,7 +56,7 @@ M.lsp = function()
   end
 
   require("lspconfig").intelephense.setup {
-    cmd = { DATA_PATH .. "/lspinstall/php/node_modules/.bin/intelephense", "--stdio" },
+    cmd = { O.lang.php.lsp.path, "--stdio" },
     on_attach = require("lsp").common_on_attach,
     handlers = {
       ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {

+ 4 - 1
lua/lang/python.lua

@@ -25,6 +25,9 @@ M.config = function()
       "pylint",
       "mypy",
     },
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/python/node_modules/.bin/pyright-langserver",
+    },
   }
 end
 
@@ -58,7 +61,7 @@ M.lsp = function()
   -- npm i -g pyright
   require("lspconfig").pyright.setup {
     cmd = {
-      DATA_PATH .. "/lspinstall/python/node_modules/.bin/pyright-langserver",
+      O.lang.python.lsp.path,
       "--stdio",
     },
     on_attach = require("lsp").common_on_attach,

+ 4 - 1
lua/lang/ruby.lua

@@ -14,6 +14,9 @@ M.config = function()
       stdin = true,
     },
     linters = { "ruby" },
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/ruby/solargraph/solargraph",
+    },
   }
 end
 
@@ -48,7 +51,7 @@ M.lsp = function()
   if not require("lv-utils").check_lsp_client_active "solargraph" then
     -- If you are using rvm, make sure to change below configuration
     require("lspconfig").solargraph.setup {
-      cmd = { DATA_PATH .. "/lspinstall/ruby/solargraph/solargraph", "stdio" },
+      cmd = { O.lang.ruby.lsp.path, "stdio" },
       on_attach = require("lsp").common_on_attach,
       handlers = {
         ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {

+ 5 - 2
lua/lang/rust.lua

@@ -19,6 +19,9 @@ M.config = function()
       signs = true,
       underline = true,
     },
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/rust/rust-analyzer",
+    },
   }
 end
 
@@ -118,14 +121,14 @@ M.lsp = function()
       -- these override the defaults set by rust-tools.nvim
       -- see https://github.com/neovim/nvim-lspconfig/blob/master/CONFIG.md#rust_analyzer
       server = {
-        cmd = { DATA_PATH .. "/lspinstall/rust/rust-analyzer" },
+        cmd = { O.lang.rust.lsp.path },
         on_attach = require("lsp").common_on_attach,
       }, -- rust-analyser options
     }
     require("rust-tools").setup(opts)
   else
     require("lspconfig").rust_analyzer.setup {
-      cmd = { DATA_PATH .. "/lspinstall/rust/rust-analyzer" },
+      cmd = { O.lang.rust.lsp.path },
       on_attach = require("lsp").common_on_attach,
       filetypes = { "rust" },
       root_dir = require("lspconfig.util").root_pattern("Cargo.toml", "rust-project.json"),

+ 4 - 1
lua/lang/sh.lua

@@ -16,6 +16,9 @@ M.config = function()
       stdin = false,
     },
     linters = { "shellcheck" },
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/bash/node_modules/.bin/bash-language-server",
+    },
   }
 end
 
@@ -47,7 +50,7 @@ M.lsp = function()
   if not require("lv-utils").check_lsp_client_active "bashls" then
     -- npm i -g bash-language-server
     require("lspconfig").bashls.setup {
-      cmd = { DATA_PATH .. "/lspinstall/bash/node_modules/.bin/bash-language-server", "start" },
+      cmd = { O.lang.sh.lsp.path, "start" },
       on_attach = require("lsp").common_on_attach,
       filetypes = { "sh", "zsh" },
     }

+ 6 - 2
lua/lang/svelte.lua

@@ -1,7 +1,11 @@
 local M = {}
 
 M.config = function()
-  O.lang.svelte = {}
+  O.lang.svelte = {
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/svelte/node_modules/.bin/svelteserver",
+    },
+  }
 end
 
 M.format = function()
@@ -20,7 +24,7 @@ M.lsp = function()
   end
 
   require("lspconfig").svelte.setup {
-    cmd = { DATA_PATH .. "/lspinstall/svelte/node_modules/.bin/svelteserver", "--stdio" },
+    cmd = { O.lang.svelte.lsp.path, "--stdio" },
     filetypes = { "svelte" },
     root_dir = require("lspconfig.util").root_pattern("package.json", ".git"),
     on_attach = require("lsp").common_on_attach,

+ 4 - 1
lua/lang/swift.lua

@@ -7,6 +7,9 @@ M.config = function()
       args = {},
       stdin = true,
     },
+    lsp = {
+      path = "sourcekit-lsp",
+    },
   }
 end
 
@@ -38,7 +41,7 @@ M.lsp = function()
   end
 
   require("lspconfig").sourcekit.setup {
-    cmd = { "xcrun", "sourcekit-lsp" },
+    cmd = { "xcrun", O.lang.swift.lsp.path },
     on_attach = require("lsp").common_on_attach,
     filetypes = { "swift" },
   }

+ 4 - 1
lua/lang/terraform.lua

@@ -7,6 +7,9 @@ M.config = function()
       args = { "fmt" },
       stdin = false,
     },
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/terraform/terraform-ls",
+    },
   }
 end
 
@@ -40,7 +43,7 @@ M.lsp = function()
   end
 
   require("lspconfig").terraformls.setup {
-    cmd = { DATA_PATH .. "/lspinstall/terraform/terraform-ls", "serve" },
+    cmd = { O.lang.terraform.lsp.path, "serve" },
     on_attach = require("lsp").common_on_attach,
     filetypes = { "tf", "terraform", "hcl" },
   }

+ 4 - 1
lua/lang/tex.lua

@@ -8,6 +8,9 @@ M.config = function()
     diagnostics_delay = 300,
     formatter_line_length = 80,
     latex_formatter = "latexindent",
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/latex/texlab",
+    },
     build = {
       executable = "latexmk",
       args = { "-pdf", "-interaction=nonstopmode", "-synctex=1", "%f" },
@@ -77,7 +80,7 @@ M.lsp = function()
   end
 
   require("lspconfig").texlab.setup {
-    cmd = { DATA_PATH .. "/lspinstall/latex/texlab" },
+    cmd = { O.lang.latex.lsp.path },
     on_attach = require("lsp").common_on_attach,
     handlers = {
       ["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {

+ 4 - 1
lua/lang/vim.lua

@@ -3,6 +3,9 @@ local M = {}
 M.config = function()
   O.lang.vim = {
     linters = { "vint" },
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/vim/node_modules/.bin/vim-language-server",
+    },
   }
 end
 
@@ -24,7 +27,7 @@ M.lsp = function()
 
   -- npm install -g vim-language-server
   require("lspconfig").vimls.setup {
-    cmd = { DATA_PATH .. "/lspinstall/vim/node_modules/.bin/vim-language-server", "--stdio" },
+    cmd = { O.lang.vim.lsp.path, "--stdio" },
     on_attach = require("lsp").common_on_attach,
   }
 end

+ 4 - 1
lua/lang/vue.lua

@@ -11,6 +11,9 @@ M.config = function()
       stdin = true,
     },
     auto_import = true,
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/vue/node_modules/.bin/vls",
+    },
   }
 end
 
@@ -53,7 +56,7 @@ M.lsp = function()
 
   -- Vue language server configuration (vetur)
   require("lspconfig").vuels.setup {
-    cmd = { DATA_PATH .. "/lspinstall/vue/node_modules/.bin/vls", "--stdio" },
+    cmd = { O.lang.vue.lsp.path, "--stdio" },
     on_attach = require("lsp").common_on_attach,
   }
 

+ 4 - 1
lua/lang/yaml.lua

@@ -7,6 +7,9 @@ M.config = function()
       args = { "--stdin-filepath", vim.api.nvim_buf_get_name(0), "--single-quote" },
       stdin = true,
     },
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/yaml/node_modules/.bin/yaml-language-server",
+    },
   }
 end
 
@@ -38,7 +41,7 @@ M.lsp = function()
 
   -- npm install -g yaml-language-server
   require("lspconfig").yamlls.setup {
-    cmd = { DATA_PATH .. "/lspinstall/yaml/node_modules/.bin/yaml-language-server", "--stdio" },
+    cmd = { O.lang.yaml.lsp.path, "--stdio" },
     on_attach = require("lsp").common_on_attach,
   }
 end

+ 4 - 0
lua/lang/zig.lua

@@ -7,6 +7,9 @@ M.config = function()
       args = { "fmt" },
       stdin = false,
     },
+    lsp = {
+      path = "zls",
+    },
   }
 end
 
@@ -41,6 +44,7 @@ M.lsp = function()
   -- Further custom install zls in
   -- https://github.com/zigtools/zls/wiki/Downloading-and-Building-ZLS
   require("lspconfig").zls.setup {
+    cmd = { O.lang.zig.lsp.path },
     root_dir = require("lspconfig").util.root_pattern(".git", "build.zig", "zls.json"),
     on_attach = require("lsp").common_on_attach,
   }

+ 6 - 3
lua/lang/zsh.lua

@@ -1,8 +1,11 @@
 local M = {}
 
 M.config = function()
-  -- TODO: implement config for language
-  return "No config available!"
+  O.lang.zsh = {
+    lsp = {
+      path = DATA_PATH .. "/lspinstall/bash/node_modules/.bin/bash-language-server",
+    },
+  }
 end
 
 M.format = function()
@@ -35,7 +38,7 @@ M.lsp = function()
   if not require("lv-utils").check_lsp_client_active "bashls" then
     -- npm i -g bash-language-server
     require("lspconfig").bashls.setup {
-      cmd = { DATA_PATH .. "/lspinstall/bash/node_modules/.bin/bash-language-server", "start" },
+      cmd = { O.lang.zsh.lsp.path, "start" },
       on_attach = require("lsp").common_on_attach,
       filetypes = { "sh", "zsh" },
     }