|
|
@ -1,29 +1,26 @@
|
|
|
|
-- todo allow config passed in
|
|
|
|
-- todo allow config passed in
|
|
|
|
local log = require "navigator.util".log
|
|
|
|
local log = require"navigator.util".log
|
|
|
|
local verbose = require "navigator.util".verbose
|
|
|
|
local verbose = require"navigator.util".verbose
|
|
|
|
|
|
|
|
|
|
|
|
_Loading = false
|
|
|
|
_Loading = false
|
|
|
|
|
|
|
|
|
|
|
|
if packer_plugins ~= nil then
|
|
|
|
if packer_plugins ~= nil then
|
|
|
|
-- packer installed
|
|
|
|
-- packer installed
|
|
|
|
local loader = require "packer".loader
|
|
|
|
local loader = require"packer".loader
|
|
|
|
if not packer_plugins["neovim/nvim-lspconfig"] or not packer_plugins["neovim/nvim-lspconfig"].loaded then
|
|
|
|
if not packer_plugins["neovim/nvim-lspconfig"] or
|
|
|
|
loader("nvim-lspconfig")
|
|
|
|
not packer_plugins["neovim/nvim-lspconfig"].loaded then loader("nvim-lspconfig") end
|
|
|
|
end
|
|
|
|
|
|
|
|
if not packer_plugins["ray-x/guihua.lua"] or not packer_plugins["guihua.lua"].loaded then
|
|
|
|
if not packer_plugins["ray-x/guihua.lua"] or not packer_plugins["guihua.lua"].loaded then
|
|
|
|
loader("guihua.lua")
|
|
|
|
loader("guihua.lua")
|
|
|
|
-- if lazyloading
|
|
|
|
-- if lazyloading
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local has_lsp, lspconfig = pcall(require, "lspconfig")
|
|
|
|
local has_lsp, lspconfig = pcall(require, "lspconfig")
|
|
|
|
if not has_lsp then
|
|
|
|
if not has_lsp then error("loading lsp config") end
|
|
|
|
error("loading lsp config")
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
local highlight = require "navigator.lspclient.highlight"
|
|
|
|
local highlight = require "navigator.lspclient.highlight"
|
|
|
|
|
|
|
|
|
|
|
|
local util = lspconfig.util
|
|
|
|
local util = lspconfig.util
|
|
|
|
local config = require "navigator".config_values()
|
|
|
|
local config = require"navigator".config_values()
|
|
|
|
|
|
|
|
|
|
|
|
local cap = vim.lsp.protocol.make_client_capabilities()
|
|
|
|
local cap = vim.lsp.protocol.make_client_capabilities()
|
|
|
|
local on_attach = require("navigator.lspclient.attach").on_attach
|
|
|
|
local on_attach = require("navigator.lspclient.attach").on_attach
|
|
|
@ -40,11 +37,8 @@ local setups = {
|
|
|
|
filetypes = {"go", "gomod"},
|
|
|
|
filetypes = {"go", "gomod"},
|
|
|
|
message_level = vim.lsp.protocol.MessageType.Error,
|
|
|
|
message_level = vim.lsp.protocol.MessageType.Error,
|
|
|
|
cmd = {
|
|
|
|
cmd = {
|
|
|
|
"gopls",
|
|
|
|
"gopls", -- share the gopls instance if there is one already
|
|
|
|
-- share the gopls instance if there is one already
|
|
|
|
"-remote=auto", --[[ debug options ]] --
|
|
|
|
"-remote=auto",
|
|
|
|
|
|
|
|
--[[ debug options ]]
|
|
|
|
|
|
|
|
--
|
|
|
|
|
|
|
|
-- "-logfile=auto",
|
|
|
|
-- "-logfile=auto",
|
|
|
|
-- "-debug=:0",
|
|
|
|
-- "-debug=:0",
|
|
|
|
"-remote.debug=:0"
|
|
|
|
"-remote.debug=:0"
|
|
|
@ -73,10 +67,7 @@ local setups = {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
clangd = {
|
|
|
|
clangd = {
|
|
|
|
cmd = {
|
|
|
|
cmd = {
|
|
|
|
"clangd",
|
|
|
|
"clangd", "--background-index", "--suggest-missing-includes", "--clang-tidy",
|
|
|
|
"--background-index",
|
|
|
|
|
|
|
|
"--suggest-missing-includes",
|
|
|
|
|
|
|
|
"--clang-tidy",
|
|
|
|
|
|
|
|
"--header-insertion=iwyu"
|
|
|
|
"--header-insertion=iwyu"
|
|
|
|
},
|
|
|
|
},
|
|
|
|
filetypes = {"c", "cpp", "objc", "objcpp"},
|
|
|
|
filetypes = {"c", "cpp", "objc", "objcpp"},
|
|
|
@ -87,7 +78,8 @@ local setups = {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
rust_analyzer = {
|
|
|
|
rust_analyzer = {
|
|
|
|
root_dir = function(fname)
|
|
|
|
root_dir = function(fname)
|
|
|
|
return util.root_pattern("Cargo.toml", "rust-project.json", ".git")(fname) or util.path.dirname(fname)
|
|
|
|
return util.root_pattern("Cargo.toml", "rust-project.json", ".git")(fname) or
|
|
|
|
|
|
|
|
util.path.dirname(fname)
|
|
|
|
end,
|
|
|
|
end,
|
|
|
|
filetypes = {"rust"},
|
|
|
|
filetypes = {"rust"},
|
|
|
|
message_level = vim.lsp.protocol.MessageType.error,
|
|
|
|
message_level = vim.lsp.protocol.MessageType.error,
|
|
|
@ -105,7 +97,7 @@ local setups = {
|
|
|
|
on_attach = function(client, bufnr)
|
|
|
|
on_attach = function(client, bufnr)
|
|
|
|
client.resolved_capabilities.execute_command = true
|
|
|
|
client.resolved_capabilities.execute_command = true
|
|
|
|
highlight.diagnositc_config_sign()
|
|
|
|
highlight.diagnositc_config_sign()
|
|
|
|
require "sqls".setup {picker = "telescope"} -- or default
|
|
|
|
require"sqls".setup {picker = "telescope"} -- or default
|
|
|
|
end,
|
|
|
|
end,
|
|
|
|
settings = {
|
|
|
|
settings = {
|
|
|
|
cmd = {"sqls", "-config", "$HOME/.config/sqls/config.yml"}
|
|
|
|
cmd = {"sqls", "-config", "$HOME/.config/sqls/config.yml"}
|
|
|
@ -133,15 +125,7 @@ local setups = {
|
|
|
|
diagnostics = {
|
|
|
|
diagnostics = {
|
|
|
|
enable = true,
|
|
|
|
enable = true,
|
|
|
|
-- Get the language server to recognize the `vim` global
|
|
|
|
-- Get the language server to recognize the `vim` global
|
|
|
|
globals = {
|
|
|
|
globals = {"vim", "describe", "it", "before_each", "after_each", "teardown", "pending"}
|
|
|
|
"vim",
|
|
|
|
|
|
|
|
"describe",
|
|
|
|
|
|
|
|
"it",
|
|
|
|
|
|
|
|
"before_each",
|
|
|
|
|
|
|
|
"after_each",
|
|
|
|
|
|
|
|
"teardown",
|
|
|
|
|
|
|
|
"pending"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
workspace = {
|
|
|
|
workspace = {
|
|
|
|
-- Make the server aware of Neovim runtime files
|
|
|
|
-- Make the server aware of Neovim runtime files
|
|
|
@ -172,49 +156,17 @@ local setups = {
|
|
|
|
init_options = {
|
|
|
|
init_options = {
|
|
|
|
compilationDatabaseDirectory = "build",
|
|
|
|
compilationDatabaseDirectory = "build",
|
|
|
|
root_dir = [[ util.root_pattern("compile_commands.json", "compile_flags.txt", "CMakeLists.txt", "Makefile", ".git") or util.path.dirname ]],
|
|
|
|
root_dir = [[ util.root_pattern("compile_commands.json", "compile_flags.txt", "CMakeLists.txt", "Makefile", ".git") or util.path.dirname ]],
|
|
|
|
index = {
|
|
|
|
index = {threads = 2},
|
|
|
|
threads = 2
|
|
|
|
clang = {excludeArgs = {"-frounding-math"}}
|
|
|
|
},
|
|
|
|
|
|
|
|
clang = {
|
|
|
|
|
|
|
|
excludeArgs = {"-frounding-math"}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
local servers = {
|
|
|
|
local servers = {
|
|
|
|
"angularls",
|
|
|
|
"angularls", "gopls", "tsserver", "flow", "bashls", "dockerls", "julials", "pyls", "pyright",
|
|
|
|
"gopls",
|
|
|
|
"jedi_language_server", "jdtls", "sumneko_lua", "vimls", "html", "jsonls", "solargraph", "cssls",
|
|
|
|
"tsserver",
|
|
|
|
"yamlls", "clangd", "ccls", "sqls", "denols", "dartls", "dotls", "kotlin_language_server",
|
|
|
|
"flow",
|
|
|
|
"nimls", "intelephense", "vuels", "phpactor", "omnisharp", "r_language_server", "rust_analyzer",
|
|
|
|
"bashls",
|
|
|
|
|
|
|
|
"dockerls",
|
|
|
|
|
|
|
|
"julials",
|
|
|
|
|
|
|
|
"pyls",
|
|
|
|
|
|
|
|
"pyright",
|
|
|
|
|
|
|
|
"jedi_language_server",
|
|
|
|
|
|
|
|
"jdtls",
|
|
|
|
|
|
|
|
"sumneko_lua",
|
|
|
|
|
|
|
|
"vimls",
|
|
|
|
|
|
|
|
"html",
|
|
|
|
|
|
|
|
"jsonls",
|
|
|
|
|
|
|
|
"solargraph",
|
|
|
|
|
|
|
|
"cssls",
|
|
|
|
|
|
|
|
"yamlls",
|
|
|
|
|
|
|
|
"clangd",
|
|
|
|
|
|
|
|
"ccls",
|
|
|
|
|
|
|
|
"sqls",
|
|
|
|
|
|
|
|
"denols",
|
|
|
|
|
|
|
|
"dartls",
|
|
|
|
|
|
|
|
"dotls",
|
|
|
|
|
|
|
|
"kotlin_language_server",
|
|
|
|
|
|
|
|
"nimls",
|
|
|
|
|
|
|
|
"intelephense",
|
|
|
|
|
|
|
|
"vuels",
|
|
|
|
|
|
|
|
"phpactor",
|
|
|
|
|
|
|
|
"omnisharp",
|
|
|
|
|
|
|
|
"r_language_server",
|
|
|
|
|
|
|
|
"rust_analyzer",
|
|
|
|
|
|
|
|
"terraformls"
|
|
|
|
"terraformls"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -232,11 +184,7 @@ local function load_cfg(ft, client, cfg, loaded)
|
|
|
|
|
|
|
|
|
|
|
|
local should_load = false
|
|
|
|
local should_load = false
|
|
|
|
if lspft ~= nil and #lspft > 0 then
|
|
|
|
if lspft ~= nil and #lspft > 0 then
|
|
|
|
for _, value in ipairs(lspft) do
|
|
|
|
for _, value in ipairs(lspft) do if ft == value then should_load = true end end
|
|
|
|
if ft == value then
|
|
|
|
|
|
|
|
should_load = true
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
if should_load then
|
|
|
|
if should_load then
|
|
|
|
for _, c in pairs(loaded) do
|
|
|
|
for _, c in pairs(loaded) do
|
|
|
|
if client == c then
|
|
|
|
if client == c then
|
|
|
@ -252,41 +200,40 @@ local function load_cfg(ft, client, cfg, loaded)
|
|
|
|
-- need to verify the lsp server is up
|
|
|
|
-- need to verify the lsp server is up
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local function wait_lsp_startup(ft, retry)
|
|
|
|
local function wait_lsp_startup(ft, retry, lsp_opts)
|
|
|
|
retry = retry or false
|
|
|
|
retry = retry or false
|
|
|
|
local clients = vim.lsp.get_active_clients() or {}
|
|
|
|
local clients = vim.lsp.get_active_clients() or {}
|
|
|
|
local loaded = {}
|
|
|
|
local loaded = {}
|
|
|
|
for i = 1, 2 do
|
|
|
|
for _ = 1, 2 do
|
|
|
|
for _, client in ipairs(clients) do
|
|
|
|
for _, client in ipairs(clients) do
|
|
|
|
if client ~= nil then
|
|
|
|
if client ~= nil then table.insert(loaded, client.name) end
|
|
|
|
table.insert(loaded, client.name)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
for _, lspclient in ipairs(servers) do
|
|
|
|
for _, lspclient in ipairs(servers) do
|
|
|
|
|
|
|
|
if lsp_opts[lspclient] ~= nil and lsp_opts[lspclient].filetypes ~= nil then
|
|
|
|
|
|
|
|
if not vim.tbl_contains(lsp_opts[lspclient].filetypes, ft) then
|
|
|
|
|
|
|
|
log("ft", ft, "disabled for", lspclient)
|
|
|
|
|
|
|
|
goto continue
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
local cfg = setups[lspclient] or default_cfg
|
|
|
|
local cfg = setups[lspclient] or default_cfg
|
|
|
|
load_cfg(ft, lspclient, cfg, loaded)
|
|
|
|
load_cfg(ft, lspclient, cfg, loaded)
|
|
|
|
|
|
|
|
::continue::
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if not retry or ft == nil then
|
|
|
|
if not retry or ft == nil then return end
|
|
|
|
return
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
--
|
|
|
|
--
|
|
|
|
local timer = vim.loop.new_timer()
|
|
|
|
local timer = vim.loop.new_timer()
|
|
|
|
local i = 0
|
|
|
|
local i = 0
|
|
|
|
vim.wait(
|
|
|
|
vim.wait(1000, function()
|
|
|
|
1000,
|
|
|
|
clients = vim.lsp.get_active_clients() or {}
|
|
|
|
function()
|
|
|
|
i = i + 1
|
|
|
|
clients = vim.lsp.get_active_clients() or {}
|
|
|
|
if i > 5 or #clients > 0 then
|
|
|
|
i = i + 1
|
|
|
|
timer:close() -- Always close handles to avoid leaks.
|
|
|
|
if i > 5 or #clients > 0 then
|
|
|
|
log("active", #clients, i)
|
|
|
|
timer:close() -- Always close handles to avoid leaks.
|
|
|
|
|
|
|
|
log("active", #clients, i)
|
|
|
|
|
|
|
|
_Loading = false
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
_Loading = false
|
|
|
|
_Loading = false
|
|
|
|
end,
|
|
|
|
return true
|
|
|
|
200
|
|
|
|
end
|
|
|
|
)
|
|
|
|
_Loading = false
|
|
|
|
|
|
|
|
end, 200)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -294,13 +241,11 @@ vim.cmd([[autocmd FileType * lua require'navigator.lspclient.clients'.setup()]])
|
|
|
|
|
|
|
|
|
|
|
|
local function setup(user_opts)
|
|
|
|
local function setup(user_opts)
|
|
|
|
verbose(debug.traceback())
|
|
|
|
verbose(debug.traceback())
|
|
|
|
if _Loading == true then
|
|
|
|
log(user_opts)
|
|
|
|
return
|
|
|
|
user_opts = user_opts or _NgConfigValues -- incase setup was triggered from autocmd
|
|
|
|
end
|
|
|
|
if _Loading == true then return end
|
|
|
|
local ft = vim.bo.filetype
|
|
|
|
local ft = vim.bo.filetype
|
|
|
|
if ft == nil then
|
|
|
|
if ft == nil then ft = vim.api.nvim_buf_get_option(0, "filetype") end
|
|
|
|
ft = vim.api.nvim_buf_get_option(0, "filetype")
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if ft == nil or ft == "" then
|
|
|
|
if ft == nil or ft == "" then
|
|
|
|
log("nil filetype")
|
|
|
|
log("nil filetype")
|
|
|
@ -309,22 +254,10 @@ local function setup(user_opts)
|
|
|
|
log("loading for ft ", ft)
|
|
|
|
log("loading for ft ", ft)
|
|
|
|
local retry = true
|
|
|
|
local retry = true
|
|
|
|
local disable_ft = {
|
|
|
|
local disable_ft = {
|
|
|
|
"NvimTree",
|
|
|
|
"NvimTree", "guihua", "clap_input", "clap_spinner", "vista", "TelescopePrompt", "csv", "txt",
|
|
|
|
"guihua",
|
|
|
|
"markdown", "defx"
|
|
|
|
"clap_input",
|
|
|
|
|
|
|
|
"clap_spinner",
|
|
|
|
|
|
|
|
"vista",
|
|
|
|
|
|
|
|
"TelescopePrompt",
|
|
|
|
|
|
|
|
"csv",
|
|
|
|
|
|
|
|
"txt",
|
|
|
|
|
|
|
|
"markdown",
|
|
|
|
|
|
|
|
"defx"
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for i = 1, #disable_ft do
|
|
|
|
for i = 1, #disable_ft do if ft == disable_ft[i] then return end end
|
|
|
|
if ft == disable_ft[i] then
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
if lspconfig == nil then
|
|
|
|
if lspconfig == nil then
|
|
|
|
error("lsp-config need installed and enabled")
|
|
|
|
error("lsp-config need installed and enabled")
|
|
|
|
return
|
|
|
|
return
|
|
|
@ -332,9 +265,9 @@ local function setup(user_opts)
|
|
|
|
|
|
|
|
|
|
|
|
highlight.diagnositc_config_sign()
|
|
|
|
highlight.diagnositc_config_sign()
|
|
|
|
highlight.add_highlight()
|
|
|
|
highlight.add_highlight()
|
|
|
|
|
|
|
|
local lsp_opts = user_opts.lsp
|
|
|
|
_Loading = true
|
|
|
|
_Loading = true
|
|
|
|
wait_lsp_startup(ft, retry)
|
|
|
|
wait_lsp_startup(ft, retry, lsp_opts)
|
|
|
|
_Loading = false
|
|
|
|
_Loading = false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return {setup = setup, cap = cap}
|
|
|
|
return {setup = setup, cap = cap}
|
|
|
|