nvim: add gopls config for bazel generated code
This commit is contained in:
parent
75d1367a73
commit
98f602d510
1 changed files with 114 additions and 101 deletions
|
@ -3,17 +3,12 @@ local lspconfig = require("lspconfig")
|
||||||
local util = require("lspconfig.util")
|
local util = require("lspconfig.util")
|
||||||
|
|
||||||
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
local capabilities = vim.lsp.protocol.make_client_capabilities()
|
||||||
capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
|
capabilities = require("cmp_nvim_lsp").update_capabilities(capabilities)
|
||||||
|
|
||||||
|
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
|
||||||
vim.lsp.handlers["textDocument/publishDiagnostics"] =
|
|
||||||
vim.lsp.with(
|
|
||||||
vim.lsp.diagnostic.on_publish_diagnostics,
|
|
||||||
{
|
|
||||||
update_in_insert = false,
|
update_in_insert = false,
|
||||||
virtual_text = false,
|
virtual_text = false,
|
||||||
}
|
})
|
||||||
)
|
|
||||||
local signs = { Error = "🔥", Warn = "⚠️ ", Hint = "💡", Info = "💡" }
|
local signs = { Error = "🔥", Warn = "⚠️ ", Hint = "💡", Info = "💡" }
|
||||||
for type, icon in pairs(signs) do
|
for type, icon in pairs(signs) do
|
||||||
local hl = "DiagnosticSign" .. type
|
local hl = "DiagnosticSign" .. type
|
||||||
|
@ -22,14 +17,13 @@ end
|
||||||
|
|
||||||
local on_attach = function()
|
local on_attach = function()
|
||||||
require("folding").on_attach()
|
require("folding").on_attach()
|
||||||
require "lsp_signature".on_attach() -- Note: add in lsp client on-attach
|
require("lsp_signature").on_attach() -- Note: add in lsp client on-attach
|
||||||
end
|
end
|
||||||
|
|
||||||
-- simple setups --
|
-- simple setups --
|
||||||
local servers = {
|
local servers = {
|
||||||
"bashls",
|
"bashls",
|
||||||
"dockerls",
|
"dockerls",
|
||||||
"gopls",
|
|
||||||
"jsonls",
|
"jsonls",
|
||||||
-- "sql",
|
-- "sql",
|
||||||
"sumneko_lua",
|
"sumneko_lua",
|
||||||
|
@ -38,16 +32,33 @@ local servers = {
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, lsp in ipairs(servers) do
|
for _, lsp in ipairs(servers) do
|
||||||
lspconfig[lsp].setup {on_attach = on_attach}
|
lspconfig[lsp].setup({ on_attach = on_attach })
|
||||||
end
|
end
|
||||||
|
|
||||||
local efm_prettier = {
|
local efm_prettier = {
|
||||||
formatCommand = "prettier --stdin-filepath ${INPUT}",
|
formatCommand = "prettier --stdin-filepath ${INPUT}",
|
||||||
formatStdin = true
|
formatStdin = true,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lspconfig.gopls.setup({
|
||||||
|
on_attach = on_attach,
|
||||||
|
settings = {
|
||||||
|
gopls = {
|
||||||
|
env = {
|
||||||
|
GOPACKAGESDRIVER = "./tools/gopackagesdriver.sh",
|
||||||
|
},
|
||||||
|
directoryFilters = {
|
||||||
|
"-bazel-bin",
|
||||||
|
"-bazel-out",
|
||||||
|
"-bazel-testlogs",
|
||||||
|
"-bazel-mypkg",
|
||||||
|
},
|
||||||
|
...,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
lspconfig.sumneko_lua.setup {
|
lspconfig.sumneko_lua.setup({
|
||||||
on_attach = function()
|
on_attach = function()
|
||||||
on_attach()
|
on_attach()
|
||||||
vim.cmd([[autocmd BufWritePre <buffer> lua require'stylua-nvim'.format_file()]])
|
vim.cmd([[autocmd BufWritePre <buffer> lua require'stylua-nvim'.format_file()]])
|
||||||
|
@ -57,40 +68,42 @@ lspconfig.sumneko_lua.setup {
|
||||||
completion = { kewordSnippet = "Disable" },
|
completion = { kewordSnippet = "Disable" },
|
||||||
diagnostics = {
|
diagnostics = {
|
||||||
enable = true,
|
enable = true,
|
||||||
globals = {"renoise", "use", "vim"}
|
globals = { "renoise", "use", "vim" },
|
||||||
},
|
},
|
||||||
runtime = {
|
runtime = {
|
||||||
version = "LuaJIT",
|
version = "LuaJIT",
|
||||||
path = {"?.lua", "?/init.lua", "?/?.lua"}
|
path = { "?.lua", "?/init.lua", "?/?.lua" },
|
||||||
},
|
},
|
||||||
workspace = {
|
workspace = {
|
||||||
library = vim.api.nvim_get_runtime_file("", true),
|
library = vim.api.nvim_get_runtime_file("", true),
|
||||||
maxPreload = 2000,
|
maxPreload = 2000,
|
||||||
preloadFileSize = 1000,
|
preloadFileSize = 1000,
|
||||||
checkThirdParty = false,
|
checkThirdParty = false,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
lspconfig.terraformls.setup {}
|
lspconfig.terraformls.setup({})
|
||||||
|
|
||||||
local yaml_is_k8s = function(bufnr)
|
local yaml_is_k8s = function(bufnr)
|
||||||
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, 50, false) -- Stop after the first 50 lines
|
local lines = vim.api.nvim_buf_get_lines(bufnr, 0, 50, false) -- Stop after the first 50 lines
|
||||||
for _, l in pairs(lines) do
|
for _, l in pairs(lines) do
|
||||||
if string.find(l, "apiVersion") ~= nil then return true end
|
if string.find(l, "apiVersion") ~= nil then
|
||||||
|
return true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
lspconfig.cssls.setup {
|
lspconfig.cssls.setup({
|
||||||
cmd = { "vscode-css-languageserver", "--stdio" },
|
cmd = { "vscode-css-languageserver", "--stdio" },
|
||||||
capabilities = capabilities,
|
capabilities = capabilities,
|
||||||
}
|
})
|
||||||
|
|
||||||
lspconfig.cssmodules_ls.setup{}
|
lspconfig.cssmodules_ls.setup({})
|
||||||
|
|
||||||
lspconfig.html.setup {
|
lspconfig.html.setup({
|
||||||
cmd = { "vscode-html-languageserver", "--stdio" },
|
cmd = { "vscode-html-languageserver", "--stdio" },
|
||||||
filetypes = { "html" },
|
filetypes = { "html" },
|
||||||
init_options = {
|
init_options = {
|
||||||
|
@ -98,12 +111,12 @@ lspconfig.html.setup {
|
||||||
embeddedLanguages = {
|
embeddedLanguages = {
|
||||||
css = true,
|
css = true,
|
||||||
javascript = true,
|
javascript = true,
|
||||||
}
|
|
||||||
},
|
},
|
||||||
settings = {}
|
},
|
||||||
}
|
settings = {},
|
||||||
|
})
|
||||||
|
|
||||||
lspconfig.yamlls.setup {
|
lspconfig.yamlls.setup({
|
||||||
settings = {
|
settings = {
|
||||||
yaml = {
|
yaml = {
|
||||||
format = { enable = true, singleQuote = true },
|
format = { enable = true, singleQuote = true },
|
||||||
|
@ -142,18 +155,18 @@ lspconfig.yamlls.setup {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
validate = true
|
validate = true,
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
})
|
||||||
|
|
||||||
-- npm install -g typescript typescript-language-server
|
-- npm install -g typescript typescript-language-server
|
||||||
require'lspconfig'.tsserver.setup({
|
require("lspconfig").tsserver.setup({
|
||||||
on_attach = function(client, bufnr)
|
on_attach = function(client, bufnr)
|
||||||
client.resolved_capabilities.document_formatting = false
|
client.resolved_capabilities.document_formatting = false
|
||||||
on_attach(client)
|
on_attach(client)
|
||||||
|
|
||||||
require'lsp_signature'.on_attach({
|
require("lsp_signature").on_attach({
|
||||||
bind = false, -- This is mandatory, otherwise border config won't get registered.
|
bind = false, -- This is mandatory, otherwise border config won't get registered.
|
||||||
-- If you want to hook lspsaga or other signature handler, pls set to false
|
-- If you want to hook lspsaga or other signature handler, pls set to false
|
||||||
doc_lines = 2, -- will show two lines of comment/doc(if there are more than two lines in doc, will be truncated);
|
doc_lines = 2, -- will show two lines of comment/doc(if there are more than two lines in doc, will be truncated);
|
||||||
|
@ -172,14 +185,14 @@ require'lspconfig'.tsserver.setup({
|
||||||
-- to view the hiding contents
|
-- to view the hiding contents
|
||||||
max_width = 120, -- max_width of signature floating_window, line will be wrapped if exceed max_width
|
max_width = 120, -- max_width of signature floating_window, line will be wrapped if exceed max_width
|
||||||
handler_opts = {
|
handler_opts = {
|
||||||
border = "single" -- double, single, shadow, none
|
border = "single", -- double, single, shadow, none
|
||||||
},
|
},
|
||||||
extra_trigger_chars = {} -- Array of extra characters that will trigger signature completion, e.g., {"(", ","}
|
extra_trigger_chars = {}, -- Array of extra characters that will trigger signature completion, e.g., {"(", ","}
|
||||||
})
|
})
|
||||||
|
|
||||||
local ts_utils = require("nvim-lsp-ts-utils")
|
local ts_utils = require("nvim-lsp-ts-utils")
|
||||||
|
|
||||||
ts_utils.setup {
|
ts_utils.setup({
|
||||||
debug = false,
|
debug = false,
|
||||||
disable_commands = false,
|
disable_commands = false,
|
||||||
enable_import_on_completion = false,
|
enable_import_on_completion = false,
|
||||||
|
@ -188,13 +201,13 @@ require'lspconfig'.tsserver.setup({
|
||||||
-- eslint
|
-- eslint
|
||||||
eslint_enable_code_actions = true,
|
eslint_enable_code_actions = true,
|
||||||
eslint_enable_disable_comments = true,
|
eslint_enable_disable_comments = true,
|
||||||
eslint_bin = 'eslint_d',
|
eslint_bin = "eslint_d",
|
||||||
eslint_config_fallback = nil,
|
eslint_config_fallback = nil,
|
||||||
eslint_enable_diagnostics = true,
|
eslint_enable_diagnostics = true,
|
||||||
|
|
||||||
-- formatting
|
-- formatting
|
||||||
enable_formatting = true,
|
enable_formatting = true,
|
||||||
formatter = 'prettier',
|
formatter = "prettier",
|
||||||
formatter_config_fallback = nil,
|
formatter_config_fallback = nil,
|
||||||
|
|
||||||
-- parentheses completion
|
-- parentheses completion
|
||||||
|
@ -205,7 +218,7 @@ require'lspconfig'.tsserver.setup({
|
||||||
update_imports_on_move = true,
|
update_imports_on_move = true,
|
||||||
require_confirmation_on_move = true,
|
require_confirmation_on_move = true,
|
||||||
watch_dir = nil,
|
watch_dir = nil,
|
||||||
}
|
})
|
||||||
|
|
||||||
ts_utils.setup_client(client)
|
ts_utils.setup_client(client)
|
||||||
|
|
||||||
|
@ -213,5 +226,5 @@ require'lspconfig'.tsserver.setup({
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "qq", ":TSLspFixCurrent<CR>", { silent = true })
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "qq", ":TSLspFixCurrent<CR>", { silent = true })
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "<Leader>cR", ":TSLspRenameFile<CR>", { silent = true })
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<Leader>cR", ":TSLspRenameFile<CR>", { silent = true })
|
||||||
vim.api.nvim_buf_set_keymap(bufnr, "n", "<Leader>ci", ":TSLspImportAll<CR>", { silent = true })
|
vim.api.nvim_buf_set_keymap(bufnr, "n", "<Leader>ci", ":TSLspImportAll<CR>", { silent = true })
|
||||||
end
|
end,
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue