add lspinstall

neovim_0_5
ray-x 3 years ago
parent 6c753645c3
commit d034edbe0e

@ -212,6 +212,8 @@ require'navigator'.setup({
diagnostic_head_severity_1 = "🈲",
-- refer to lua/navigator.lua for more icons setups
},
lspinstall = false, -- set to true if you would like use the lsp installed by lspinstall
lsp = {
format_on_save = true, -- set to false to disasble lsp code format on save (if you are using prettier/efm/formater etc)
tsserver = {

@ -26,6 +26,7 @@ _NgConfigValues = {
-- cmd = {'lua-language-server'}
}
},
lspinstall = false, -- set to true if you would like use the lsp installed by lspinstall
icons = {
-- Code action
code_action_icon = "",
@ -93,6 +94,7 @@ M.setup = function(cfg)
-- log(debug.traceback())
-- log(cfg, _NgConfigValues)
-- print("loading navigator")
require('navigator.lazyloader')
require('navigator.lspclient.clients').setup(_NgConfigValues)
require("navigator.lspclient.mapping").setup(_NgConfigValues)
require("navigator.reference")

@ -25,7 +25,6 @@ local diag_hdlr = function(err, method, result, client_id, bufnr, config)
local uri = result.uri
if result and result.diagnostics then
local item_list = {}
for _, v in ipairs(result.diagnostics) do
local item = v
item.filename = assert(vim.uri_to_fname(uri))
@ -49,12 +48,12 @@ local diag_hdlr = function(err, method, result, client_id, bufnr, config)
end
local pos = v.range.start
local row = pos.line
local line = (vim.api.nvim_buf_get_lines(bufnr, row, row + 1, false) or {""})[1]
local line = (vim.api.nvim_buf_get_lines(bufnr1, row, row + 1, false) or {""})[1]
if line ~= nil then
item.text = head .. line .. _NgConfigValues.icons.diagnostic_head_description .. v.message
table.insert(item_list, item)
else
error("diagnostic result empty line", v, item)
error("diagnostic result empty line", v, row, bufnr1)
end
end
-- local old_items = vim.fn.getqflist()

@ -0,0 +1,29 @@
local log = require"navigator.util".log
_LoadedClients = {}
local loader = nil
packer_plugins = packer_plugins or nil -- suppress warnings
-- packer only
if packer_plugins ~= nil then -- packer install
local lazy_plugins = {
["nvim-lspconfig"] = "neovim/nvim-lspconfig",
["guihua.lua"] = "ray-x/guihua.lua"
}
if _NgConfigValues.lspinstall == true then
lazy_plugins["lspinstall"] = "kabouzeid/nvim-lspinstall"
end
-- packer installed
loader = require"packer".loader
for plugin, url in pairs(lazy_plugins) do
if not packer_plugins[url] or not packer_plugins[url].loaded then
log("loading ", plugin)
loader(plugin)
end
end
if _NgConfigValues.lspinstall == true then
local has_lspinst, lspinst = pcall(require, "lspinstall")
lspinst.setup()
end
end

@ -2,22 +2,15 @@
local log = require"navigator.util".log
local trace = require"navigator.util".trace
local uv = vim.loop
_Loading = false
_NG_Loading = false
_LoadedClients = {}
local loader = nil
packer_plugins = packer_plugins or nil -- suppress warnings
-- packer only
if packer_plugins ~= nil then
-- packer installed
local loader = require"packer".loader
if not packer_plugins["neovim/nvim-lspconfig"]
or not packer_plugins["neovim/nvim-lspconfig"].loaded then
loader("nvim-lspconfig")
end
if not packer_plugins["ray-x/guihua.lua"] or not packer_plugins["guihua.lua"].loaded then
loader("guihua.lua")
-- if lazyloading
end
end
local highlight = require "navigator.lspclient.highlight"
local has_lsp, lspconfig = pcall(require, "lspconfig")
if not has_lsp then
@ -27,7 +20,6 @@ if not has_lsp then
end
}
end
local highlight = require "navigator.lspclient.highlight"
local util = lspconfig.util
local config = require"navigator".config_values()
@ -248,6 +240,17 @@ local servers = {
"r_language_server", "rust_analyzer", "terraformls"
}
if _NgConfigValues.lspinstall == true then
local has_lspinst, lspinst = pcall(require, "lspinstall")
if has_lspinst then
local srvs = lspinst.installed_servers()
log('lspinstalled servers', srvs)
if #srvs > 0 then
servers = srvs
end
end
end
local default_cfg = {
on_attach = on_attach,
flags = {allow_incremental_sync = true, debounce_text_changes = 500}
@ -352,11 +355,11 @@ local function wait_lsp_startup(ft, retry, lsp_opts)
if i > 5 or #clients > 0 then
timer:close() -- Always close handles to avoid leaks.
log("active", #clients, i)
_Loading = false
_NG_Loading = false
return true
end
-- giveup
-- _Loading = false
-- _NG_Loading = false
end)
end
@ -372,7 +375,7 @@ local function setup(user_opts)
trace(debug.traceback())
user_opts = user_opts or _NgConfigValues -- incase setup was triggered from autocmd
if _Loading == true then
if _NG_Loading == true then
return
end
if ft == nil then
@ -409,7 +412,7 @@ local function setup(user_opts)
highlight.add_highlight()
local lsp_opts = user_opts.lsp
_Loading = true
_NG_Loading = true
if vim.bo.filetype == 'lua' then
local slua = lsp_opts.sumneko_lua
@ -427,7 +430,9 @@ local function setup(user_opts)
wait_lsp_startup(ft, retry, lsp_opts)
_LoadedClients[ft] = true
_Loading = false
-- _LoadedClients[ft] = vim.tbl_extend("keep", _LoadedClients[ft] or {}, {ft})
_NG_Loading = false
-- if not _NgConfigValues.loaded then
-- vim.cmd([[autocmd FileType * lua require'navigator.lspclient.clients'.setup()]]) -- BufWinEnter BufNewFile,BufRead ?

@ -5,9 +5,18 @@ local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true
function M.reload_lsp()
vim.lsp.stop_client(vim.lsp.get_active_clients())
vim.cmd [[edit]]
require'navigator.lspclient.clients'.setup()
vim.cmd("LspStop")
local timer = vim.loop.new_timer()
local i = 0
timer:start(500, 100, function()
if i >= 5 then
timer:close() -- Always close handles to avoid leaks.
end
i = i + 1
end)
vim.cmd("LspStart")
vim.cmd([[write]])
vim.cmd([[edit]])
end
function M.open_lsp_log()

Loading…
Cancel
Save