nvim config stolen from @Lukacms
This commit is contained in:
10
nvim/lua/lsp/asm.lua
Normal file
10
nvim/lua/lsp/asm.lua
Normal file
@@ -0,0 +1,10 @@
|
||||
local M = {}
|
||||
|
||||
M.setup = function(on_attach, capabilities)
|
||||
require("lspconfig").asm.setup({
|
||||
capabilities = capabilities,
|
||||
cmd = { "asm-lsp" },
|
||||
on_attach = on_attach,
|
||||
})
|
||||
end
|
||||
return M
|
||||
12
nvim/lua/lsp/clangd.lua
Normal file
12
nvim/lua/lsp/clangd.lua
Normal file
@@ -0,0 +1,12 @@
|
||||
local M = {}
|
||||
|
||||
M.setup = function(on_attach, capabilities)
|
||||
require("lspconfig").clangd.setup({
|
||||
capabilities = capabilities,
|
||||
cmd = { "clangd", "--background-index", "-clang-tidy" },
|
||||
on_attach = on_attach,
|
||||
filetype = { "c", "cpp", "objc", "objcpp" },
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
7
nvim/lua/lsp/csharp-ls.lua
Normal file
7
nvim/lua/lsp/csharp-ls.lua
Normal file
@@ -0,0 +1,7 @@
|
||||
local M = {}
|
||||
|
||||
M.setup = function(on_attach, capabilities)
|
||||
require 'lspconfig'.csharp_ls.setup {}
|
||||
end
|
||||
|
||||
return M
|
||||
46
nvim/lua/lsp/elsint.lua
Normal file
46
nvim/lua/lsp/elsint.lua
Normal file
@@ -0,0 +1,46 @@
|
||||
local M = {}
|
||||
|
||||
M.setup = function(on_attach, capabilities)
|
||||
require("lspconfig").eslint.setup({
|
||||
capabilities = capabilities,
|
||||
filetypes = {
|
||||
"javascript",
|
||||
"javascriptreact",
|
||||
"javascript.jsx",
|
||||
"typescript",
|
||||
"typescriptreact",
|
||||
"typescript.tsx",
|
||||
"vue",
|
||||
},
|
||||
on_attach = on_attach,
|
||||
settings = {
|
||||
codeAction = {
|
||||
disableRuleComment = {
|
||||
enable = true,
|
||||
location = "separateLine",
|
||||
},
|
||||
showDocumentation = {
|
||||
enable = true,
|
||||
},
|
||||
},
|
||||
codeActionOnSave = {
|
||||
enable = false,
|
||||
mode = "all",
|
||||
},
|
||||
format = false,
|
||||
nodePath = "",
|
||||
onIgnoredFiles = "off",
|
||||
packageManager = "yarn",
|
||||
quiet = false,
|
||||
rulesCustomizations = {},
|
||||
run = "onType",
|
||||
useESLintClass = false,
|
||||
validate = "on",
|
||||
workingDirectory = {
|
||||
mode = "location",
|
||||
},
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
19
nvim/lua/lsp/hls.lua
Normal file
19
nvim/lua/lsp/hls.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
local M = {}
|
||||
|
||||
M.setup = function(on_attach, capabilities)
|
||||
require("lspconfig").hls.setup({
|
||||
capabilities = capabilities,
|
||||
cmd = { "haskell-language-server-wrapper", "--lsp" },
|
||||
on_attach = on_attach,
|
||||
filetypes = { "haskell", "lhaskell" },
|
||||
settings = {
|
||||
haskell = {
|
||||
-- formattingProvider = "stylish-haskell",
|
||||
--[[ formattingProvider = "",
|
||||
cabalFormattingProvider = "cabalfmt", ]]
|
||||
},
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
110
nvim/lua/lsp/init.lua
Normal file
110
nvim/lua/lsp/init.lua
Normal file
@@ -0,0 +1,110 @@
|
||||
local lsp_utils = require("lsp.utils")
|
||||
local u = require("utils")
|
||||
|
||||
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(vim.lsp.diagnostic.on_publish_diagnostics, {
|
||||
underline = true,
|
||||
update_in_insert = false,
|
||||
virtual_text = {
|
||||
prefix = "",
|
||||
},
|
||||
})
|
||||
|
||||
vim.fn.sign_define("DiagnosticSignError", { text = "", texthl = "DiagnosticSignError" })
|
||||
vim.fn.sign_define("DiagnosticSignWarn", { text = "", texthl = "DiagnosticSignWarn" })
|
||||
vim.fn.sign_define("DiagnosticSignInfo", { text = "", texthl = "DiagnosticSignInfo" })
|
||||
vim.fn.sign_define("DiagnosticSignHint", { text = "", texthl = "DiagnosticSignHint" })
|
||||
|
||||
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})
|
||||
|
||||
local lsp_formatting = function(bufnr, async, range)
|
||||
vim.lsp.buf.format({
|
||||
async = async,
|
||||
bufnr = bufnr,
|
||||
filter = function(client)
|
||||
local excluded_clients = { "html", "tsserver" }
|
||||
|
||||
for _, excluded_client in ipairs(excluded_clients) do
|
||||
if excluded_client == client.name then
|
||||
return false
|
||||
end
|
||||
end
|
||||
return true
|
||||
end,
|
||||
range = range,
|
||||
})
|
||||
end
|
||||
|
||||
local on_attach = function(client, bufnr)
|
||||
u.buf_map(bufnr, "n", "gd", vim.lsp.buf.definition)
|
||||
u.buf_map(bufnr, "n", "gi", vim.lsp.buf.implementation)
|
||||
u.buf_map(bufnr, "n", "K", vim.lsp.buf.hover)
|
||||
u.buf_map(bufnr, "n", "<C-l>", vim.lsp.buf.signature_help)
|
||||
u.buf_map(bufnr, "n", "gt", vim.lsp.buf.type_definition)
|
||||
u.buf_map(bufnr, "n", "gr", vim.lsp.buf.references)
|
||||
u.buf_map(bufnr, "n", "<C-c>", ":CodeActionMenu<CR>")
|
||||
u.buf_map(bufnr, "n", "<leader>d", vim.diagnostic.open_float)
|
||||
u.buf_map(bufnr, "n", "<leader>r", vim.lsp.buf.rename)
|
||||
u.buf_map(bufnr, "n", "<C-d>", ":Trouble document_diagnostics<CR>")
|
||||
|
||||
if client.supports_method("textDocument/formatting") then
|
||||
u.buf_command(bufnr, "LspFormatting", function()
|
||||
lsp_formatting(bufnr, false)
|
||||
end)
|
||||
u.buf_map(bufnr, "n", "<leader>f", function()
|
||||
lsp_formatting(bufnr, true)
|
||||
end)
|
||||
if lsp_utils.is_path_excluded(bufnr, client) == false then
|
||||
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
group = augroup,
|
||||
buffer = bufnr,
|
||||
command = "LspFormatting",
|
||||
})
|
||||
end
|
||||
end
|
||||
|
||||
if client.supports_method("textDocument/rangeFormatting") then
|
||||
u.buf_map(bufnr, "v", "<leader>f", function()
|
||||
local start = vim.api.nvim_buf_get_mark(0, "<")
|
||||
local _end = vim.api.nvim_buf_get_mark(0, ">")
|
||||
local range = { start = start, ["end"] = _end }
|
||||
|
||||
lsp_formatting(bufnr, true, range)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
local capabilities = require("cmp_nvim_lsp").default_capabilities()
|
||||
|
||||
local servers_names = {
|
||||
"bashls",
|
||||
"clangd",
|
||||
"cmake",
|
||||
"csharp_ls",
|
||||
"cssmodules_ls",
|
||||
"dockerls",
|
||||
"elixirls",
|
||||
"html",
|
||||
"hls",
|
||||
"java_language_server",
|
||||
"jsonls",
|
||||
"lua_ls",
|
||||
"null-ls",
|
||||
"pyright",
|
||||
"rust-analyzer",
|
||||
-- "sumneko_lua",
|
||||
"texlab",
|
||||
"tsserver",
|
||||
"yamlls",
|
||||
}
|
||||
|
||||
for _, server_name in ipairs(servers_names) do
|
||||
local success, server = pcall(require, "lsp." .. server_name)
|
||||
|
||||
if success then
|
||||
server.setup(on_attach, capabilities)
|
||||
else
|
||||
-- Load default lsp config
|
||||
require("lspconfig")[server_name].setup({ on_attach, capabilities })
|
||||
end
|
||||
end
|
||||
16
nvim/lua/lsp/jsonls.lua
Normal file
16
nvim/lua/lsp/jsonls.lua
Normal file
@@ -0,0 +1,16 @@
|
||||
local M = {}
|
||||
|
||||
M.setup = function(on_attach, capabilities)
|
||||
require("lspconfig").jsonls.setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
settings = {
|
||||
json = {
|
||||
validate = { enable = true },
|
||||
schemas = require("schemastore").json.schemas(),
|
||||
},
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
37
nvim/lua/lsp/null-ls.lua
Normal file
37
nvim/lua/lsp/null-ls.lua
Normal file
@@ -0,0 +1,37 @@
|
||||
local null_ls = require("null-ls")
|
||||
local b = null_ls.builtins
|
||||
|
||||
-- https://github.com/jose-elias-alvarez/null-ls.nvim/pull/804
|
||||
local buf_path_in_workflow_folder = function()
|
||||
local api = vim.api
|
||||
local path = api.nvim_buf_get_name(api.nvim_get_current_buf())
|
||||
return path:match("github/workflows/") ~= nil
|
||||
end
|
||||
|
||||
local sources = {
|
||||
b.diagnostics.actionlint.with({
|
||||
runtime_condition = buf_path_in_workflow_folder,
|
||||
}),
|
||||
|
||||
function()
|
||||
local nl_utils = require("null-ls.utils").make_conditional_utils()
|
||||
return nl_utils.root_has_file({ ".prettierrc.json", ".prettierrc" })
|
||||
and b.formatting.prettierd.with({ filetypes = { "html", "javascript", "typescript", "svelte" } })
|
||||
or b.formatting.eslint_d
|
||||
end,
|
||||
|
||||
b.formatting.black,
|
||||
b.formatting.stylua,
|
||||
}
|
||||
|
||||
local M = {}
|
||||
|
||||
M.setup = function(on_attach)
|
||||
null_ls.setup({
|
||||
debug = false,
|
||||
sources = sources,
|
||||
on_attach = on_attach,
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
27
nvim/lua/lsp/rust-analyzer.lua
Normal file
27
nvim/lua/lsp/rust-analyzer.lua
Normal file
@@ -0,0 +1,27 @@
|
||||
local M = {}
|
||||
|
||||
M.setup = function(on_attach, capabilities)
|
||||
require("rust-tools").setup({
|
||||
server = {
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
settings = {
|
||||
["rust-analyzer"] = {
|
||||
checkOnSave = {
|
||||
command = "clippy",
|
||||
},
|
||||
cargo = {
|
||||
autoreload = true,
|
||||
},
|
||||
diagnostics = {
|
||||
enable = true,
|
||||
disabled = { "unresolved-proc-macro" },
|
||||
enableExperimental = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
32
nvim/lua/lsp/sumneko_lua.lua
Normal file
32
nvim/lua/lsp/sumneko_lua.lua
Normal file
@@ -0,0 +1,32 @@
|
||||
local runtime_path = vim.split(package.path, ";")
|
||||
table.insert(runtime_path, "lua/?.lua")
|
||||
table.insert(runtime_path, "lua/?/init.lua")
|
||||
|
||||
local M = {}
|
||||
|
||||
M.setup = function(on_attach, capabilities)
|
||||
require("lspconfig").sumneko_lua.setup({
|
||||
capabilities = capabilities,
|
||||
disable_formatting = true,
|
||||
on_attach = on_attach,
|
||||
settings = {
|
||||
Lua = {
|
||||
runtime = {
|
||||
version = "LuaJIT",
|
||||
path = runtime_path,
|
||||
},
|
||||
diagnostics = {
|
||||
globals = { "vim", "use" },
|
||||
},
|
||||
workspace = {
|
||||
library = vim.api.nvim_get_runtime_file("", true),
|
||||
},
|
||||
telemetry = {
|
||||
enable = false,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
28
nvim/lua/lsp/texlab.lua
Normal file
28
nvim/lua/lsp/texlab.lua
Normal file
@@ -0,0 +1,28 @@
|
||||
local M = {}
|
||||
|
||||
M.setup = function(on_attach, capabilities)
|
||||
require("lspconfig").texlab.setup({
|
||||
capabilities = capabilities,
|
||||
on_attach = on_attach,
|
||||
settings = {
|
||||
texlab = {
|
||||
build = {
|
||||
executable = "tectonic",
|
||||
args = {
|
||||
"%f",
|
||||
"--synctex",
|
||||
"--keep-logs",
|
||||
"--keep-intermediates",
|
||||
},
|
||||
},
|
||||
formatterLineLength = 80,
|
||||
latexFormatter = "latexindent",
|
||||
latexindent = {
|
||||
modifyLineBreaks = true,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
18
nvim/lua/lsp/tsserver.lua
Normal file
18
nvim/lua/lsp/tsserver.lua
Normal file
@@ -0,0 +1,18 @@
|
||||
local u = require("utils")
|
||||
|
||||
local M = {}
|
||||
|
||||
M.setup = function(on_attach, capabilities)
|
||||
require("typescript").setup({
|
||||
server = {
|
||||
capabilities = capabilities,
|
||||
on_attach = function(client, bufnr)
|
||||
on_attach(client, bufnr)
|
||||
|
||||
u.buf_map(bufnr, "n", "<leader>h", ":TypescriptOrganizeImports<CR>")
|
||||
end,
|
||||
},
|
||||
})
|
||||
end
|
||||
|
||||
return M
|
||||
24
nvim/lua/lsp/utils.lua
Normal file
24
nvim/lua/lsp/utils.lua
Normal file
@@ -0,0 +1,24 @@
|
||||
local M = {}
|
||||
|
||||
M.is_path_excluded = function(bufnr, client)
|
||||
local buf_path = vim.api.nvim_buf_get_name(bufnr)
|
||||
local excluded_paths = {}
|
||||
local success, custom = pcall(require, "custom")
|
||||
if success then
|
||||
excluded_paths = custom.excluded_paths[client.name]
|
||||
end
|
||||
local is_excluded = false
|
||||
|
||||
if excluded_paths ~= nil then
|
||||
for i = 1, #excluded_paths do
|
||||
if buf_path:find("^" .. excluded_paths[i]) ~= nil then
|
||||
is_excluded = true
|
||||
break
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return is_excluded
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in New Issue
Block a user