|
|
@ -1,15 +1,14 @@
|
|
|
|
-- 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
|
|
|
@ -17,13 +16,11 @@ if packer_plugins ~= nil then
|
|
|
|
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
|
|
|
@ -32,6 +29,37 @@ local on_attach = require("navigator.lspclient.attach").on_attach
|
|
|
|
-- lua setup
|
|
|
|
-- lua setup
|
|
|
|
local sumneko_root_path = config.sumneko_root_path
|
|
|
|
local sumneko_root_path = config.sumneko_root_path
|
|
|
|
local sumneko_binary = config.sumneko_binary
|
|
|
|
local sumneko_binary = config.sumneko_binary
|
|
|
|
|
|
|
|
local library = {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local path = vim.split(package.path, ";")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
table.insert(path, "lua/?.lua")
|
|
|
|
|
|
|
|
table.insert(path, "lua/?/init.lua")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local function add(lib)
|
|
|
|
|
|
|
|
for _, p in pairs(vim.fn.expand(lib, false, true)) do
|
|
|
|
|
|
|
|
p = vim.loop.fs_realpath(p)
|
|
|
|
|
|
|
|
library[p] = true
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- add runtime
|
|
|
|
|
|
|
|
add("$VIMRUNTIME")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- add your config
|
|
|
|
|
|
|
|
local home = vim.fn.expand("$HOME")
|
|
|
|
|
|
|
|
if vim.fn.isdirectory(home .. "/.config/nvim") then add(home .. "/.config/nvim") end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- add plugins it may be very slow to add all in path
|
|
|
|
|
|
|
|
-- if vim.fn.isdirectory(home .. "/.config/share/nvim/site/pack/packer") then
|
|
|
|
|
|
|
|
-- add(home .. "/.local/share/nvim/site/pack/packer/opt/*")
|
|
|
|
|
|
|
|
-- add(home .. "/.local/share/nvim/site/pack/packer/start/*")
|
|
|
|
|
|
|
|
-- end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
library[vim.fn.expand("$VIMRUNTIME/lua")] = true
|
|
|
|
|
|
|
|
library[vim.fn.expand("$VIMRUNTIME/lua/vim")] = true
|
|
|
|
|
|
|
|
library[vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true
|
|
|
|
|
|
|
|
-- [vim.fn.expand("~/repos/nvim/lua")] = true
|
|
|
|
|
|
|
|
|
|
|
|
local setups = {
|
|
|
|
local setups = {
|
|
|
|
gopls = {
|
|
|
|
gopls = {
|
|
|
@ -40,11 +68,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 +98,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 +109,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 +128,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,25 +156,16 @@ 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"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
completion = {callSnippet = "Both"},
|
|
|
|
workspace = {
|
|
|
|
workspace = {
|
|
|
|
-- Make the server aware of Neovim runtime files
|
|
|
|
-- Make the server aware of Neovim runtime files
|
|
|
|
library = {
|
|
|
|
library = library,
|
|
|
|
[vim.fn.expand("$VIMRUNTIME/lua")] = true,
|
|
|
|
maxPreload = 256,
|
|
|
|
[vim.fn.expand("$VIMRUNTIME/lua/vim")] = true,
|
|
|
|
preloadFileSize = 50000
|
|
|
|
[vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true
|
|
|
|
},
|
|
|
|
-- [vim.fn.expand("~/repos/nvim/lua")] = true
|
|
|
|
telemetry = {enable = false}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
@ -172,49 +186,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,16 +214,12 @@ 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
|
|
|
|
-- loaded
|
|
|
|
-- loaded
|
|
|
|
log(client, "already been loaded for", ft, loaded)
|
|
|
|
verbose(client, "already been loaded for", ft, loaded)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
@ -258,35 +236,27 @@ local function wait_lsp_startup(ft, retry)
|
|
|
|
local loaded = {}
|
|
|
|
local loaded = {}
|
|
|
|
for i = 1, 2 do
|
|
|
|
for i = 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
|
|
|
|
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)
|
|
|
|
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,
|
|
|
|
|
|
|
|
function()
|
|
|
|
|
|
|
|
clients = vim.lsp.get_active_clients() or {}
|
|
|
|
clients = vim.lsp.get_active_clients() or {}
|
|
|
|
i = i + 1
|
|
|
|
i = i + 1
|
|
|
|
if i > 5 or #clients > 0 then
|
|
|
|
if i > 5 or #clients > 0 then
|
|
|
|
timer:close() -- Always close handles to avoid leaks.
|
|
|
|
timer:close() -- Always close handles to avoid leaks.
|
|
|
|
log("active", #clients, i)
|
|
|
|
verbose("active", #clients, i)
|
|
|
|
_Loading = false
|
|
|
|
_Loading = false
|
|
|
|
return true
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
_Loading = false
|
|
|
|
_Loading = false
|
|
|
|
end,
|
|
|
|
end, 200)
|
|
|
|
200
|
|
|
|
|
|
|
|
)
|
|
|
|
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
@ -294,39 +264,36 @@ 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
|
|
|
|
if lspconfig == nil then
|
|
|
|
|
|
|
|
error("lsp-config need installed and enabled")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
end
|
|
|
|
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")
|
|
|
|
return
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
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", "vista_kind", "TelescopePrompt",
|
|
|
|
"guihua",
|
|
|
|
"csv", "txt", "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
|
|
|
|
if ft == disable_ft[i] then
|
|
|
|
|
|
|
|
log("navigator disabled for ft", ft)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if lspconfig == nil then
|
|
|
|
local bufnr = vim.fn.bufnr()
|
|
|
|
error("lsp-config need installed and enabled")
|
|
|
|
local uri = vim.uri_from_bufnr(bufnr)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
log("loading for ft ", ft, uri)
|
|
|
|
|
|
|
|
if uri == 'file://' or uri == 'file:///' then
|
|
|
|
|
|
|
|
log("skip loading for ft ", ft, uri)
|
|
|
|
return
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|