|
|
@ -1,22 +1,32 @@
|
|
|
|
local ok, lspconfig = pcall(require, "lspconfig")
|
|
|
|
local ok, lspconfig = pcall(require, "lspconfig")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not ok then
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
local ok, util = pcall(require, "lspconfig/util")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if not ok then
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
local log_directory = vim.env.LOG_HOME
|
|
|
|
local log_directory = vim.env.LOG_HOME
|
|
|
|
|
|
|
|
|
|
|
|
if log_directory == nil then
|
|
|
|
if log_directory == nil then
|
|
|
|
log_directory = "/tmp"
|
|
|
|
log_directory = "/tmp"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
if not ok then
|
|
|
|
vim.api.nvim_create_autocmd('LspAttach', {
|
|
|
|
return
|
|
|
|
group = vim.api.nvim_create_augroup('UserLspConfig', {}),
|
|
|
|
end
|
|
|
|
callback = function(ev)
|
|
|
|
|
|
|
|
|
|
|
|
local custom_attach = function(_, bufnr)
|
|
|
|
|
|
|
|
local opts = { noremap=true, silent=true, buffer=bufnr }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Enable completion triggered by <c-x><c-o>
|
|
|
|
-- Enable completion triggered by <c-x><c-o>
|
|
|
|
vim.api.nvim_buf_set_option(bufnr, 'omnifunc', 'v:lua.vim.lsp.omnifunc')
|
|
|
|
vim.bo[ev.buf].omnifunc = 'v:lua.vim.lsp.omnifunc'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-- Buffer local mappings.
|
|
|
|
|
|
|
|
-- See `:help vim.lsp.*` for documentation on any of the below functions
|
|
|
|
-- See `:help vim.diagnostic.*` for documentation on any of the diagnostics functions
|
|
|
|
-- See `:help vim.diagnostic.*` for documentation on any of the diagnostics functions
|
|
|
|
|
|
|
|
local opts = { noremap=true, silent=true, buffer=ev.buf }
|
|
|
|
|
|
|
|
|
|
|
|
vim.keymap.set('n', '<leader>h', vim.lsp.buf.hover, opts)
|
|
|
|
vim.keymap.set('n', '<leader>h', vim.lsp.buf.hover, opts)
|
|
|
|
vim.keymap.set('n', '<leader>gd', vim.lsp.buf.definition, opts)
|
|
|
|
vim.keymap.set('n', '<leader>gd', vim.lsp.buf.definition, opts)
|
|
|
|
vim.keymap.set('n', '<leader>gr', vim.lsp.buf.references, opts)
|
|
|
|
vim.keymap.set('n', '<leader>gr', vim.lsp.buf.references, opts)
|
|
|
@ -29,11 +39,17 @@ local custom_attach = function(_, bufnr)
|
|
|
|
vim.keymap.set("n", '<leader>ff', function() vim.lsp.buf.format{ async = true } end, opts)
|
|
|
|
vim.keymap.set("n", '<leader>ff', function() vim.lsp.buf.format{ async = true } end, opts)
|
|
|
|
vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, opts)
|
|
|
|
vim.keymap.set('n', '<leader>ca', vim.lsp.buf.code_action, opts)
|
|
|
|
vim.keymap.set('n', '<leader>dec', vim.lsp.buf.declaration, opts)
|
|
|
|
vim.keymap.set('n', '<leader>dec', vim.lsp.buf.declaration, opts)
|
|
|
|
--buf_set_keymap('n', '<C-k>', vim.lsp.buf.signature_help, opts)
|
|
|
|
|
|
|
|
--buf_set_keymap('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
|
|
|
|
if vim.lsp.inlay_hint then
|
|
|
|
--buf_set_keymap('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
|
|
|
|
vim.keymap.set('n', '<leader>ih', function() vim.lsp.inlay_hint(0, nil) end, opts)
|
|
|
|
--buf_set_keymap('n', '<space>wl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end', opts)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
--vim.keymap.set('n', '<C-k>', vim.lsp.buf.signature_help, opts)
|
|
|
|
|
|
|
|
--vim.keymap.set('n', '<space>wa', vim.lsp.buf.add_workspace_folder, opts)
|
|
|
|
|
|
|
|
--vim.keymap.set('n', '<space>wr', vim.lsp.buf.remove_workspace_folder, opts)
|
|
|
|
|
|
|
|
--vim.keymap.set('n', '<space>wl', function() print(vim.inspect(vim.lsp.buf.list_workspace_folders())) end', opts)
|
|
|
|
|
|
|
|
end,
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
|
|
local lsp_flags = {
|
|
|
|
local lsp_flags = {
|
|
|
|
debounce_text_changes = 150,
|
|
|
|
debounce_text_changes = 150,
|
|
|
@ -41,23 +57,28 @@ local lsp_flags = {
|
|
|
|
|
|
|
|
|
|
|
|
-- Go
|
|
|
|
-- Go
|
|
|
|
lspconfig.gopls.setup{
|
|
|
|
lspconfig.gopls.setup{
|
|
|
|
on_attach = custom_attach,
|
|
|
|
|
|
|
|
cmd = {"gopls", "serve", "-logfile="..log_directory.."/gopls.log"},
|
|
|
|
cmd = {"gopls", "serve", "-logfile="..log_directory.."/gopls.log"},
|
|
|
|
|
|
|
|
filetypes = {"go", "gomod"},
|
|
|
|
|
|
|
|
root_dir = util.root_pattern("go.work", "go.mod", ".git"),
|
|
|
|
settings = {
|
|
|
|
settings = {
|
|
|
|
gopls = {
|
|
|
|
gopls = {
|
|
|
|
analyses = {
|
|
|
|
analyses = {
|
|
|
|
unusedparams = true,
|
|
|
|
unusedparams = true,
|
|
|
|
|
|
|
|
useany = true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
env = {
|
|
|
|
env = {
|
|
|
|
GOFLAGS = "-tags=mage"
|
|
|
|
GOFLAGS = "-tags=mage",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
gofumpt = true,
|
|
|
|
gofumpt = true,
|
|
|
|
staticcheck = true,
|
|
|
|
hints = {
|
|
|
|
|
|
|
|
parameterNames = true,
|
|
|
|
|
|
|
|
constantValues = true,
|
|
|
|
|
|
|
|
compositeLiteralFields = true,
|
|
|
|
|
|
|
|
assignVariableTypes = true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
init_options = {
|
|
|
|
staticcheck = true,
|
|
|
|
|
|
|
|
vulncheck = "Imports",
|
|
|
|
usePlaceholders = true,
|
|
|
|
usePlaceholders = true,
|
|
|
|
completeUnimported = true,
|
|
|
|
|
|
|
|
hoverKind = "FullDocumentation",
|
|
|
|
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
flags = lsp_flags,
|
|
|
|
flags = lsp_flags,
|
|
|
@ -65,14 +86,12 @@ lspconfig.gopls.setup{
|
|
|
|
|
|
|
|
|
|
|
|
-- Jsonnet
|
|
|
|
-- Jsonnet
|
|
|
|
lspconfig.jsonnet_ls.setup{
|
|
|
|
lspconfig.jsonnet_ls.setup{
|
|
|
|
on_attach = custom_attach,
|
|
|
|
|
|
|
|
cmd = {"jsonnet-language-server", "--lint"},
|
|
|
|
cmd = {"jsonnet-language-server", "--lint"},
|
|
|
|
flags = lsp_flags,
|
|
|
|
flags = lsp_flags,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-- Terraform
|
|
|
|
-- Terraform
|
|
|
|
lspconfig.terraformls.setup{
|
|
|
|
lspconfig.terraformls.setup{
|
|
|
|
on_attach = custom_attach,
|
|
|
|
|
|
|
|
cmd = {"terraform-ls", "serve", "-log-file="..log_directory.."/terraformls.log"},
|
|
|
|
cmd = {"terraform-ls", "serve", "-log-file="..log_directory.."/terraformls.log"},
|
|
|
|
filetypes = {"terraform", "hcl", "tf"},
|
|
|
|
filetypes = {"terraform", "hcl", "tf"},
|
|
|
|
root_dir = lspconfig.util.root_pattern{".terraform", ".git", "main.tf"},
|
|
|
|
root_dir = lspconfig.util.root_pattern{".terraform", ".git", "main.tf"},
|
|
|
@ -81,40 +100,40 @@ lspconfig.terraformls.setup{
|
|
|
|
|
|
|
|
|
|
|
|
-- Python
|
|
|
|
-- Python
|
|
|
|
lspconfig.pylsp.setup{
|
|
|
|
lspconfig.pylsp.setup{
|
|
|
|
on_attach = custom_attach,
|
|
|
|
|
|
|
|
cmd = { "pylsp" },
|
|
|
|
cmd = { "pylsp" },
|
|
|
|
filetypes = { "python" },
|
|
|
|
filetypes = { "python" },
|
|
|
|
flags = lsp_flags,
|
|
|
|
flags = lsp_flags,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
-- Lua
|
|
|
|
-- Lua
|
|
|
|
--local sumneko_root_path = vim.fn.expand('$HOME') .. "/Git/github.com/sumneko/lua-language-server"
|
|
|
|
lspconfig.lua_ls.setup {
|
|
|
|
--local sumneko_binary = sumneko_root_path .. "/bin/Linux/lua-language-server"
|
|
|
|
on_init = function(client)
|
|
|
|
--
|
|
|
|
local path = client.workspace_folders[1].name
|
|
|
|
--lspconfig.sumneko_lua.setup {
|
|
|
|
if not vim.loop.fs_stat(path..'/.luarc.json') and not vim.loop.fs_stat(path..'/.luarc.jsonc') then
|
|
|
|
-- on_attach = custom_attach,
|
|
|
|
client.config.settings = vim.tbl_deep_extend('force', client.config.settings, {
|
|
|
|
-- cmd = {sumneko_binary, "-E", sumneko_root_path .. "/main.lua"},
|
|
|
|
Lua = {
|
|
|
|
-- settings = {
|
|
|
|
runtime = {
|
|
|
|
-- Lua = {
|
|
|
|
-- Tell the language server which version of Lua you're using
|
|
|
|
-- runtime = {
|
|
|
|
-- (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
|
|
|
|
-- Make the server aware of Neovim runtime files
|
|
|
|
-- path = vim.split(package.path, ';')
|
|
|
|
workspace = {
|
|
|
|
-- },
|
|
|
|
checkThirdParty = false,
|
|
|
|
-- diagnostics = {
|
|
|
|
library = {
|
|
|
|
-- -- Get the language server to recognize the vim and awesome globals
|
|
|
|
vim.env.VIMRUNTIME
|
|
|
|
-- globals = {'vim', 'awesome'}
|
|
|
|
-- "${3rd}/luv/library"
|
|
|
|
-- },
|
|
|
|
-- "${3rd}/busted/library",
|
|
|
|
-- workspace = {
|
|
|
|
}
|
|
|
|
-- -- Make the server aware of Neovim runtime files
|
|
|
|
-- or pull in all of 'runtimepath'. NOTE: this is a lot slower
|
|
|
|
-- library = vim.api.nvim_get_runtime_file("", true),
|
|
|
|
-- library = vim.api.nvim_get_runtime_file("", true)
|
|
|
|
-- },
|
|
|
|
}
|
|
|
|
-- telemetry = {
|
|
|
|
}
|
|
|
|
-- -- Do not send telemetry data containing a randomized but unique identifier
|
|
|
|
})
|
|
|
|
-- enable = false,
|
|
|
|
|
|
|
|
-- },
|
|
|
|
client.notify("workspace/didChangeConfiguration", { settings = client.config.settings })
|
|
|
|
-- }
|
|
|
|
end
|
|
|
|
-- },
|
|
|
|
return true
|
|
|
|
-- flags = lsp_flags,
|
|
|
|
end,
|
|
|
|
--}
|
|
|
|
flags = lsp_flags,
|
|
|
|
|
|
|
|
}
|
|
|
|