From 2f44f0115a0bad19e3a2da1a28a401d6fba806e1 Mon Sep 17 00:00:00 2001 From: ray-x Date: Fri, 26 Nov 2021 18:26:30 +1100 Subject: [PATCH] add servers options for #109 --- README.md | 21 +++++++++++++++++++-- lua/navigator.lua | 7 ++++++- lua/navigator/lspclient/clients.lua | 14 +++++++++++--- 3 files changed, 36 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1f26d82..019181b 100644 --- a/README.md +++ b/README.md @@ -290,6 +290,10 @@ require'navigator'.setup({ sumneko_root_path = vim.fn.expand("$HOME") .. "/github/sumneko/lua-language-server", sumneko_binary = vim.fn.expand("$HOME") .. "/github/sumneko/lua-language-server/bin/macOS/lua-language-server", }, + servers = {'cmake', 'ltex'}, -- by default empty, but if you whant navigator load e.g. `cmake` and `ltex` for you , you + -- can put them in the `servers` list and navigator will auto load them. + -- you could still specify the custom config like this + -- cmake = {filetypes = {'cmake', 'makefile'}, single_file_support = false}, } }) @@ -306,7 +310,7 @@ local servers = { "jedi_language_server", "jdtls", "sumneko_lua", "vimls", "html", "jsonls", "solargraph", "cssls", "yamlls", "clangd", "ccls", "sqls", "denols", "graphql", "dartls", "dotls", "kotlin_language_server", "nimls", "intelephense", "vuels", "phpactor", "omnisharp", - "r_language_server", "rust_analyzer", "terraformls", "clojure_lsp" + "r_language_server", "rust_analyzer", "terraformls", "svelte", "texlab", "clojure_lsp" } ``` @@ -332,10 +336,23 @@ servers. (Prevent loading multiple LSP for same source code.) e.g. I saw strange pylsp+pyright+jedi together. If you have multiple similar LSP installed and have trouble with the plugin, please enable only one at a time. -Note: If you have multiple lsp installed for same language, please only enable one at a time by disable others with e.g. `disable_lsp={'denols', 'clangd'}` +#### Add your own servers + +Above servers covered a small part neovim lspconfig support, You can still use lspconfig to add and config servers not +in the list. If you would like to add a server not in the list, you can check this PR https://github.com/ray-x/navigator.lua/pull/107 + +Also, an option in setup: + +```lua +require'navigator'setup{lsp={servers={'cmake', 'lexls'}}} + +``` + +Above example add cmake and lexls to the default server list ### Disable a lsp client loading from navigator +Note: If you have multiple lsp installed for same language, please only enable one at a time by disable others with e.g. `disable_lsp={'denols', 'clangd'}` To disable a specific LSP, set `filetypes` to {} e.g. ```lua diff --git a/lua/navigator.lua b/lua/navigator.lua index d89d115..71237e3 100644 --- a/lua/navigator.lua +++ b/lua/navigator.lua @@ -66,7 +66,8 @@ _NgConfigValues = { -- sumneko_root_path = sumneko_root_path, -- sumneko_binary = sumneko_binary, -- cmd = {'lua-language-server'} - } + }, + servers = {} -- you can add additional lsp server so navigator will load the default for you }, lsp_installer = false, -- set to true if you would like use the lsp installed by williamboman/nvim-lsp-installer icons = { @@ -133,6 +134,10 @@ local extend_config = function(opts) if next(opts) == nil then return end + if opts.lsp and opts.lsp.servers then + require('navigator.lspclient.clients').add_servers(opts.lsp.servers) + opts.lsp.server = nil + end for key, value in pairs(opts) do if _NgConfigValues[key] == nil then warn(string.format("[] Deprecated? Key %s is not in default setup, it could be incorrect to set to %s", key, diff --git a/lua/navigator/lspclient/clients.lua b/lua/navigator/lspclient/clients.lua index 2df7e08..99ef2a6 100644 --- a/lua/navigator/lspclient/clients.lua +++ b/lua/navigator/lspclient/clients.lua @@ -101,9 +101,10 @@ end -- TODO end local setups = { - clojure_lsp = { + clojure_lsp = { root_dir = function(fname) - return util.root_pattern("deps.edn", "build.boot", "project.clj", "shadow-cljs.edn", "bb.edn", ".git")(fname) or util.path.dirname(fname) + return util.root_pattern("deps.edn", "build.boot", "project.clj", "shadow-cljs.edn", "bb.edn", ".git")(fname) + or util.path.dirname(fname) end, on_attach = on_attach, filetypes = {"clojure", "edn"}, @@ -627,4 +628,11 @@ local function setup(user_opts) -- _LoadedFiletypes[ft] = vim.tbl_extend("keep", _LoadedFiletypes[ft] or {}, {ft}) end -return {setup = setup, get_cfg = get_cfg, lsp = servers} + +-- append lsps to servers +function add_servers(lsps) + vim.validate {lsps = {lsps, 't'}} + vim.list_extend(servers, lsps) +end + +return {setup = setup, get_cfg = get_cfg, lsp = servers, add_servers = add_servers}