From 516d643ffe183807581886eb4165b5a4ae4fd24d Mon Sep 17 00:00:00 2001 From: ray-x Date: Sun, 12 Jun 2022 20:44:20 +1000 Subject: [PATCH] lsp installer update issue #181 --- README.md | 28 +++++++++- lua/navigator/lazyloader.lua | 6 ++ lua/navigator/lspclient/clients.lua | 29 +++++++--- playground/init_lsp_installer.lua | 29 +--------- playground/init_lsp_installer_cmp.lua | 79 +++++++++++++++++++++++++++ 5 files changed, 135 insertions(+), 36 deletions(-) create mode 100644 playground/init_lsp_installer_cmp.lua diff --git a/README.md b/README.md index ff19287..9c7497a 100644 --- a/README.md +++ b/README.md @@ -500,7 +500,33 @@ lsp_installer = true In the config. Also please setup the lsp server from installer setup with `server:setup{opts}` -Alternatively, Navigator can be used to startup the server installed by lsp-installer. Please do not call `server:setup{opts}` from lsp installer +example: +```lua + use({ + 'williamboman/nvim-lsp-installer', + config = function() + local lsp_installer = require('nvim-lsp-installer') + lsp_installer.setup{} + end, + }) + use({ + 'ray-x/navigator.lua', + config = function() + require('navigator').setup({ + debug = true, + lsp_installer = true, + keymaps = { { key = 'gR', func = "require('navigator.reference').async_ref()" } }, + }) + end, + }) + +``` + +Please refer to [lsp_installer_config](https://github.com/ray-x/navigator.lua/blob/master/playground/init_lsp_installer.lua) +for more info + + +Alternatively, Navigator can be used to startup the server installed by lsp-installer. as it will override the navigator setup To start LSP installed by lsp_installer, please use following setups diff --git a/lua/navigator/lazyloader.lua b/lua/navigator/lazyloader.lua index 08f0d79..84f87a4 100644 --- a/lua/navigator/lazyloader.lua +++ b/lua/navigator/lazyloader.lua @@ -22,9 +22,15 @@ return { loader(plugin) end end + else + loader = function(plugin) + local cmd = 'packadd ' .. plugin + vim.cmd(cmd) + end end if _NgConfigValues.lsp_installer == true then + vim.cmd('packadd nvim-lsp-installer') local has_lspinst, lspinst = pcall(require, 'nvim-lsp-installer') log('lsp_installer installed', has_lspinst) if has_lspinst then diff --git a/lua/navigator/lspclient/clients.lua b/lua/navigator/lspclient/clients.lua index a277d01..68fed45 100644 --- a/lua/navigator/lspclient/clients.lua +++ b/lua/navigator/lspclient/clients.lua @@ -46,6 +46,9 @@ local luadevcfg = { local luadev = {} require('navigator.lazyloader').load('lua-dev.nvim', 'folke/lua-dev.nvim') +if _NgConfigValues.lsp_installer then + require('navigator.lazyloader').load('nvim-lsp-installer', 'williamboman/nvim-lsp-installer') +end local ok, l = pcall(require, 'lua-dev') if ok and l then luadev = l.setup(luadevcfg) @@ -367,7 +370,6 @@ local ng_default_cfg = { flags = { allow_incremental_sync = true, debounce_text_changes = 1000 }, } - -- check and load based on file type local function load_cfg(ft, client, cfg, loaded) log(ft, client, loaded) @@ -477,7 +479,7 @@ local function lsp_startup(ft, retry, user_lsp_opts) if lspclient.name then lspclient = lspclient.name else - warn('incorrect set for lspclient'.. vim.inspect(lspclient)) + warn('incorrect set for lspclient' .. vim.inspect(lspclient)) goto continue end end @@ -613,13 +615,26 @@ local function lsp_startup(ft, retry, user_lsp_opts) if has_lspinst and _NgConfigValues.lsp_installer then local installed, installer_cfg = require('nvim-lsp-installer.servers').get_server(lspconfig[lspclient].name) - log('lsp installer server config' .. lspconfig[lspclient].name, installer_cfg) + log('lsp installer server config ' .. lspconfig[lspclient].name, installer_cfg) if installed and installer_cfg then - log('options', installer_cfg:get_default_options()) - -- if cfg.cmd / {lsp_server_name, arg} not present or lsp_server_name is not in PATH - if vim.fn.empty(cfg.cmd) == 1 or vim.fn.executable(cfg.cmd[1] or '') == 0 then - cfg.cmd = { installer_cfg.root_dir .. path_sep .. installer_cfg.name } + local paths = installer_cfg:get_default_options().cmd_env.PATH + paths = vim.split(paths, ':') + if vim.fn.empty(cfg.cmd) == 1 then + cfg.cmd = { installer_cfg.name } + end + + if vim.fn.executable(cfg.cmd[1]) == 0 then + for _, path in ipairs(paths) do + log(path) + if vim.fn.isdirectory(path) == 1 and string.find(path, installer_cfg.root_dir) then + cfg.cmd[1] = path .. path_sep .. cfg.cmd[1] + log(cfg.cmd) + break + end + end log('update cmd', cfg.cmd) + else + log('cmd installed', cfg.cmd) end end end diff --git a/playground/init_lsp_installer.lua b/playground/init_lsp_installer.lua index 80ddd3e..7d4c81f 100644 --- a/playground/init_lsp_installer.lua +++ b/playground/init_lsp_installer.lua @@ -16,34 +16,7 @@ local function load_plugins() 'williamboman/nvim-lsp-installer', config = function() local lsp_installer = require('nvim-lsp-installer') - local coq = require('coq') - - local enhance_server_opts = { - ['sumneko_lua'] = function(options) - options.settings = { - Lua = { - diagnostics = { - globals = { 'vim' }, - }, - }, - } - end, - ['tsserver'] = function(options) - options.on_attach = function(client) - client.resolved_capabilities.document_formatting = false - end - end, - } - - lsp_installer.on_server_ready(function(server) - local options = {} - - if enhance_server_opts[server.name] then - enhance_server_opts[server.name](options) - end - - server:setup(coq.lsp_ensure_capabilities(options)) - end) + lsp_installer.setup{} end, }) use({ diff --git a/playground/init_lsp_installer_cmp.lua b/playground/init_lsp_installer_cmp.lua new file mode 100644 index 0000000..b824c76 --- /dev/null +++ b/playground/init_lsp_installer_cmp.lua @@ -0,0 +1,79 @@ +vim.cmd([[set runtimepath=$VIMRUNTIME]]) +vim.cmd([[set packpath=/tmp/nvim/site]]) + +local package_root = '/tmp/nvim/site/pack' +local install_path = package_root .. '/packer/start/packer.nvim' + +local function load_plugins() + require('packer').startup({ + function(use) + use('wbthomason/packer.nvim') + use('neovim/nvim-lspconfig') + use({ + 'williamboman/nvim-lsp-installer', + config = function() + require('nvim-lsp-installer').setup({}) + end, + }) + use({ + 'ray-x/navigator.lua', + -- '~/github/ray-x/navigator.lua', + config = function() + require('navigator').setup({ + debug = true, + lsp_installer = true, + keymaps = { { key = 'gR', func = "require('navigator.reference').async_ref()" } }, + }) + end, + }) + use('ray-x/guihua.lua') + + use({ + 'hrsh7th/nvim-cmp', + requires = { + 'hrsh7th/cmp-nvim-lsp', + }, + config = function() + local cmp = require('cmp') + cmp.setup({ + mapping = { + [''] = cmp.mapping.confirm({ select = true }), + [''] = cmp.mapping(function(fallback) + if cmp.visible() then + cmp.confirm({ select = true }) + else + fallback() + end + end, { 'i', 's' }), + }, + sources = { + { name = 'nvim_lsp' }, + }, + }) + end, + }) + use('ray-x/aurora') + end, + config = { + package_root = package_root, + compile_path = install_path .. '/plugin/packer_compiled.lua', + }, + }) + -- navigator/LSP setup +end + +if vim.fn.isdirectory(install_path) == 0 then + print('install packer') + vim.fn.system({ + 'git', + 'clone', + 'https://github.com/wbthomason/packer.nvim', + install_path, + }) + load_plugins() + require('packer').sync() + vim.cmd('colorscheme aurora') +else + load_plugins() + vim.cmd('colorscheme aurora') +end