pyright setup, rust setup

pull/4/head
ray-x 3 years ago
parent 28f8407f4f
commit 56d891876c

@ -48,6 +48,8 @@ use {'ray-x/navigator.lua', requires = {'ray-x/guihua.lua', run = 'cd lua/fzy &&
## Setup ## Setup
Easy setup lspconfig and navigator with one liner
```lua ```lua
lua require'navigator'.setup() lua require'navigator'.setup()
``` ```

@ -54,7 +54,7 @@ M.on_attach = function(client, bufnr)
require("navigator.lspclient.mapping").setup({client = client, bufnr = bufnr, cap = client.resolved_capabilities}) require("navigator.lspclient.mapping").setup({client = client, bufnr = bufnr, cap = client.resolved_capabilities})
vim.cmd [[silent! packadd vim-illuminate]] vim.cmd [[silent! packadd vim-illuminate]]
local hasilm, ilm = pcall(require, "illuminate") -- package.loaded["illuminate"] local hasilm, ilm = pcall(require, "illuminate") -- package.loaded["illuminate"]
if hasilm then if hasilm then
ilm.on_attach(client) ilm.on_attach(client)
end end
@ -62,7 +62,7 @@ M.on_attach = function(client, bufnr)
local capabilities = vim.lsp.protocol.make_client_capabilities() local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true capabilities.textDocument.completion.completionItem.snippetSupport = true
local config = require'navigator'.config_value local config = require "navigator".config_value
if config ~= nil and config.on_attach ~= nil then if config ~= nil and config.on_attach ~= nil then
config.on_attach(client, bufnr) config.on_attach(client, bufnr)
end end

@ -1,21 +1,26 @@
-- todo allow config passed in -- todo allow config passed in
local lspconfig = nil local lspconfig = nil
local log = require "navigator.util".log
if packer_plugins ~= nil then if packer_plugins ~= nil then
if not packer_plugins["neovim/nvim-lspconfig"] or if not packer_plugins["neovim/nvim-lspconfig"] or not packer_plugins["neovim/nvim-lspconfig"].loaded then
not packer_plugins["neovim/nvim-lspconfig"].loaded then vim.cmd [[packadd nvim-lspconfig]]
vim.cmd [[packadd 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 vim.cmd [[packadd guihua.lua]]
not packer_plugins["guihua.lua"].loaded then -- if lazyloading
vim.cmd [[packadd guihua.lua]] end
-- if lazyloading end
end if package.loaded["lspconfig"] then
lspconfig = require "lspconfig"
end end
if package.loaded["lspconfig"] then lspconfig = require "lspconfig" end
local highlight = require "navigator.lspclient.highlight" local highlight = require "navigator.lspclient.highlight"
if lspconfig == nil then error("loading lsp config") end if lspconfig == nil then
local config = require"navigator".config_values() error("loading lsp config")
end
local util = lspconfig.util
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
@ -23,164 +28,218 @@ local on_attach = require("navigator.lspclient.attach").on_attach
-- gopls["ui.completion.usePlaceholders"] = true -- gopls["ui.completion.usePlaceholders"] = true
local golang_setup = { local golang_setup = {
on_attach = on_attach, on_attach = on_attach,
capabilities = cap, capabilities = cap,
-- init_options = { -- init_options = {
-- useplaceholders = true, -- useplaceholders = true,
-- completeunimported = true -- completeunimported = true
-- }, -- },
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", -- "-remote=auto",
--[[ debug options ]] --[[ debug options ]]
-- --
-- "-logfile=auto", -- "-logfile=auto",
-- "-debug=:0", -- "-debug=:0",
-- "-remote.debug=:0", -- "-remote.debug=:0",
-- "-rpc.trace", -- "-rpc.trace",
}, },
settings = { settings = {
gopls = { gopls = {
analyses = {unusedparams = true, unreachable = false}, analyses = {unusedparams = true, unreachable = false},
codelenses = { codelenses = {
generate = true, -- show the `go generate` lens. generate = true, -- show the `go generate` lens.
gc_details = true -- // Show a code lens toggling the display of gc's choices. gc_details = true -- // Show a code lens toggling the display of gc's choices.
}, },
usePlaceholders = true, usePlaceholders = true,
completeUnimported = true, completeUnimported = true,
staticcheck = true, staticcheck = true,
matcher = "fuzzy", matcher = "fuzzy",
symbolMatcher = "fuzzy", symbolMatcher = "fuzzy",
gofumpt = true, gofumpt = true,
buildFlags = {"-tags", "integration"} buildFlags = {"-tags", "integration"}
-- buildFlags = {"-tags", "functional"} -- buildFlags = {"-tags", "functional"}
} }
}, },
root_dir = function(fname) root_dir = function(fname)
local util = require("lspconfig").util local util = require("lspconfig").util
return util.root_pattern("go.mod", ".git")(fname) or return util.root_pattern("go.mod", ".git")(fname) or util.path.dirname(fname)
util.path.dirname(fname) end
end
} }
local clang_cfg = { local clang_cfg = {
cmd = { cmd = {
"clangd", "--background-index", "--suggest-missing-includes", "clangd",
"--clang-tidy", "--header-insertion=iwyu" "--background-index",
}, "--suggest-missing-includes",
on_attach = function(client) "--clang-tidy",
client.resolved_capabilities.document_formatting = true "--header-insertion=iwyu"
on_attach(client) },
end on_attach = function(client)
client.resolved_capabilities.document_formatting = true
on_attach(client)
end
} }
local rust_cfg = { local rust_cfg = {
settings = { settings = {
["rust-analyzer"] = { filetypes = {"rust"},
assist = {importMergeBehavior = "last", importPrefix = "by_self"}, root_dir = util.root_pattern("Cargo.toml", "rust-project.json", ".git"),
cargo = {loadOutDirsFromCheck = true}, ["rust-analyzer"] = {
procMacro = {enable = true} assist = {importMergeBehavior = "last", importPrefix = "by_self"},
} cargo = {loadOutDirsFromCheck = true},
procMacro = {enable = true}
} }
}
} }
local sqls_cfg = { local sqls_cfg = {
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"}
-- alterantively: -- alterantively:
-- connections = { -- connections = {
-- { -- {
-- driver = 'postgresql', -- driver = 'postgresql',
-- datasourcename = 'host=127.0.0.1 port=5432 user=postgres password=password dbname=user_db sslmode=disable', -- datasourcename = 'host=127.0.0.1 port=5432 user=postgres password=password dbname=user_db sslmode=disable',
-- }, -- },
-- }, -- },
} }
} }
-- 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 lua_cfg = { local lua_cfg = {
cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"}, cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"},
on_attach = on_attach, on_attach = on_attach,
settings = { settings = {
Lua = { Lua = {
runtime = { runtime = {
-- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim) -- Tell the language server which version of Lua you're using (most likely LuaJIT in the case of Neovim)
version = "LuaJIT", version = "LuaJIT",
-- Setup your lua path -- Setup your lua path
path = vim.split(package.path, ";") path = vim.split(package.path, ";")
}, },
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", "vim",
"teardown", "pending" "describe",
} "it",
}, "before_each",
workspace = { "after_each",
-- Make the server aware of Neovim runtime files "teardown",
library = { "pending"
[vim.fn.expand("$VIMRUNTIME/lua")] = true, }
[vim.fn.expand("$VIMRUNTIME/lua/vim")] = true, },
[vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true workspace = {
-- [vim.fn.expand("~/repos/nvim/lua")] = true -- Make the server aware of Neovim runtime files
} library = {
} [vim.fn.expand("$VIMRUNTIME/lua")] = true,
[vim.fn.expand("$VIMRUNTIME/lua/vim")] = true,
[vim.fn.expand("$VIMRUNTIME/lua/vim/lsp")] = true
-- [vim.fn.expand("~/repos/nvim/lua")] = true
} }
}
} }
}
} }
local pyright_cfg = {
cmd = {"pyright-langserver", "--stdio"},
filetypes = {"python"},
settings = {
python = {
analysis = {
autoSearchPaths = true,
useLibraryCodeForTypes = true
}
}
}
}
local rust_cfg = {
filetypes = {"rust"},
root_dir = util.root_pattern("Cargo.toml", "rust-project.json", ".git"),
message_level = vim.lsp.protocol.MessageType.error,
log_level = vim.lsp.protocol.MessageType.error,
on_attach = on_attach
}
local servers = { local servers = {
"gopls", "tsserver", "flow", "bashls", "dockerls", "pyls", "gopls",
"jedi_language_server", "jdtls", "sumneko_lua", "vimls", "html", "jsonls", "tsserver",
"cssls", "yamlls", "clangd", "sqls", "denols", "dartls", "dotls", "flow",
"kotlin_language_server", "nimls", "phpactor", "r_language_server", "bashls",
"rust_analyzer", "terraformls" "dockerls",
"pyls",
"pyright",
"jedi_language_server",
"jdtls",
"sumneko_lua",
"vimls",
"html",
"jsonls",
"cssls",
"yamlls",
"clangd",
"sqls",
"denols",
"dartls",
"dotls",
"kotlin_language_server",
"nimls",
"phpactor",
"r_language_server",
"rust_analyzer",
"terraformls"
} }
local function setup(user_opts) local function setup(user_opts)
if lspconfig == nil then if lspconfig == nil then
error("lsp-config need installed and enabled") error("lsp-config need installed and enabled")
return return
end end
highlight.diagnositc_config_sign() highlight.diagnositc_config_sign()
highlight.add_highlight() highlight.add_highlight()
for _, lspclient in ipairs(servers) do for _, lspclient in ipairs(servers) do
if lspconfig[lspclient] == nil then if lspconfig[lspclient] == nil then
print("not supported", lspclient) print("not supported", lspclient)
goto continue goto continue
end end
local lspft = lspconfig[lspclient].filetypes local lspft = lspconfig[lspclient].filetypes
if lspft ~= nil and #lspft > 0 then if lspft ~= nil and #lspft > 0 then
local ft = vim.bo.filetype local ft = vim.bo.filetype
local should_load = false local should_load = false
for _, value in ipairs(lspft) do for _, value in ipairs(lspft) do
if ft == value then should_load = true end if ft == value then
end should_load = true
if not should_load then goto continue end
end end
end
lspconfig[lspclient].setup { if not should_load then
message_level = vim.lsp.protocol.MessageType.error, goto continue
log_level = vim.lsp.protocol.MessageType.error, end
on_attach = on_attach
}
::continue::
end end
lspconfig.gopls.setup(golang_setup) ::continue::
lspconfig.sqls.setup(sqls_cfg) end
lspconfig.sumneko_lua.setup(lua_cfg) lspconfig.rust_analyzer.setup(rust_cfg)
lspconfig.clangd.setup(clang_cfg) lspconfig.gopls.setup(golang_setup)
lspconfig.rust_analyzer.setup(rust_cfg) lspconfig.sqls.setup(sqls_cfg)
lspconfig.sumneko_lua.setup(lua_cfg)
lspconfig.clangd.setup(clang_cfg)
lspconfig.rust_analyzer.setup(rust_cfg)
lspconfig.pyright.setup(pyright_cfg)
log("setup all clients finished")
end end
return {setup = setup, cap = cap} return {setup = setup, cap = cap}

@ -1,6 +1,6 @@
local lsp = require("vim.lsp") local lsp = require("vim.lsp")
M={} M = {}
local capabilities = vim.lsp.protocol.make_client_capabilities() local capabilities = vim.lsp.protocol.make_client_capabilities()
capabilities.textDocument.completion.completionItem.snippetSupport = true capabilities.textDocument.completion.completionItem.snippetSupport = true
@ -18,6 +18,6 @@ vim.cmd("command! -nargs=0 LspLog call v:lua.open_lsp_log()")
vim.cmd("command! -nargs=0 LspRestart call v:lua.reload_lsp()") vim.cmd("command! -nargs=0 LspRestart call v:lua.reload_lsp()")
local cfg = {} local cfg = {}
require('lsp.clients').setup(cfg)
require('lsp.mappings').setup(cfg) require("lsp.clients").setup(cfg)
return M return M

@ -2,6 +2,7 @@ local M = {}
M.setup = function(cfg) M.setup = function(cfg)
cfg = cfg or {} cfg = cfg or {}
require('navigator.lspclient.clients').setup(cfg) require('navigator.lspclient.clients').setup(cfg)
require("navigator.lspclient.mapping").setup(cfg)
end end
return M return M

@ -47,9 +47,7 @@ local function set_mapping(user_opts)
local user_key = user_opts.keymaps or {} local user_key = user_opts.keymaps or {}
local bufnr = user_opts.bufnr or 0 local bufnr = user_opts.bufnr or 0
local function buf_set_keymap(...) local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
vim.api.nvim_buf_set_keymap(bufnr, ...)
end
-- local function buf_set_option(...) -- local function buf_set_option(...)
-- vim.api.nvim_buf_set_option(bufnr, ...) -- vim.api.nvim_buf_set_option(bufnr, ...)
@ -80,13 +78,25 @@ local function set_mapping(user_opts)
-- format setup -- format setup
local range_fmt = false
local doc_fmt = false
for _, value in pairs(vim.lsp.buf_get_clients(0)) do
if value == nil or value.resolved_capabilities == nil then return end
if value.resolved_capabilities.document_formatting then doc_fmt = true end
if value.resolved_capabilities.document_range_formatting then range = true end
end
-- if user_opts.cap.document_formatting then -- if user_opts.cap.document_formatting then
buf_set_keymap("n", "<space>ff", "<cmd>lua vim.lsp.buf.formatting()<CR>", if doc_fmt then
buf_set_keymap("n", "<space>ff", "<cmd>lua vim.lsp.buf.formatting()<CR>",
opts) opts)
vim.cmd([[autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting()]]) vim.cmd([[autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting()]])
end
-- if user_opts.cap.document_range_formatting then -- if user_opts.cap.document_range_formatting then
buf_set_keymap("v", "<space>ff", if range_fmt then
buf_set_keymap("v", "<space>ff",
"<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts) "<cmd>lua vim.lsp.buf.range_formatting()<CR>", opts)
end
end end
local function set_event_handler(user_opts) local function set_event_handler(user_opts)

@ -98,7 +98,7 @@ local default_config = {
level = "info" level = "info"
} }
M._log = require("guihua.log").new({level = "error"}, true) M._log = require("guihua.log").new({level = "trace"}, true)
-- add log to you lsp.log -- add log to you lsp.log
M.log = M._log.info M.log = M._log.info

Loading…
Cancel
Save