Update nvim config to 0.11.1 standards.
This commit is contained in:
parent
fe23a8c0df
commit
ae1489527c
16 changed files with 45 additions and 88 deletions
54
nvim/lsp/clangd.lua
Normal file
54
nvim/lsp/clangd.lua
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
local utils = require("utils")
|
||||
|
||||
-- https://clangd.llvm.org/extensions.html#switch-between-sourceheader
|
||||
local function switch_source_header()
|
||||
local bufnr = utils.validate_bufnr(0)
|
||||
local clangd_client = vim.lsp.get_clients({ bufnr = bufnr, name = "clangd" })[1]
|
||||
if clangd_client then
|
||||
clangd_client.request(
|
||||
"textDocument/switchSourceHeader",
|
||||
{ uri = vim.uri_from_bufnr(bufnr) },
|
||||
function(err, result)
|
||||
if err then
|
||||
error(tostring(err))
|
||||
end
|
||||
if not result then
|
||||
print "Corresponding file cannot be determined"
|
||||
return
|
||||
end
|
||||
vim.api.nvim_command("drop " .. vim.uri_to_fname(result))
|
||||
end, bufnr)
|
||||
else
|
||||
print "method textDocument/switchSourceHeader is not supported by any servers active on the current buffer"
|
||||
end
|
||||
end
|
||||
|
||||
return {
|
||||
cmd = {
|
||||
"clangd",
|
||||
"--background-index", -- Enables background indexing
|
||||
"--clang-tidy", -- Enables clang-tidy diagnostics
|
||||
"--completion-style=bundled", -- Simpler completions for faster performance
|
||||
"--rename-file-limit=0", -- No limit on renaming files
|
||||
"--header-insertion=iwyu", -- Suggest missing includes based on IWYU
|
||||
"--inlay-hints", -- Enable inlay hints for parameter and type information
|
||||
"--limit-results=70", -- Limit autocompletion and symbol results
|
||||
"--suggest-missing-includes", -- Still show missing includes suggestions
|
||||
"--pch-storage=disk", -- Stores precompiled headers on disk (fixes the issue where system ran out of memory when indexing large projects, not a huge performance hit on fast m2 ssds)
|
||||
"--log=error", -- Log only errors
|
||||
},
|
||||
filetypes = { "c", "cpp", "objc", "objcpp", "cuda", "proto" },
|
||||
root_markers = {
|
||||
".clangd",
|
||||
".clang-tidy",
|
||||
".clang-format",
|
||||
"compile_commands.json",
|
||||
"compile_flags.txt",
|
||||
"configure.ac",
|
||||
},
|
||||
on_attach = function()
|
||||
utils.set_keymap_list({
|
||||
{ "<leader>ko", switch_source_header, },
|
||||
})
|
||||
end,
|
||||
}
|
||||
14
nvim/lsp/cmake.lua
Normal file
14
nvim/lsp/cmake.lua
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
return {
|
||||
cmd = { "cmake-language-server" },
|
||||
filetypes = { "cmake" },
|
||||
root_markers = {
|
||||
"CMakeLists.txt",
|
||||
"CMakePresets.json",
|
||||
"CTestConfig.cmake",
|
||||
"build",
|
||||
"cmake",
|
||||
},
|
||||
init_options = {
|
||||
buildDirectory = "build",
|
||||
},
|
||||
}
|
||||
18
nvim/lsp/dartls.lua
Normal file
18
nvim/lsp/dartls.lua
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
return {
|
||||
cmd = { "dart", "language-server", "--protocol=lsp" },
|
||||
filetypes = { "dart" },
|
||||
root_markers = { "pubspec.yaml" },
|
||||
init_options = {
|
||||
onlyAnalyzeProjectsWithOpenFiles = true,
|
||||
suggestFromUnimportedLibraries = true,
|
||||
closingLabels = true,
|
||||
outline = true,
|
||||
flutterOutline = true,
|
||||
},
|
||||
settings = {
|
||||
dart = {
|
||||
completeFunctionCalls = true,
|
||||
showTodos = true,
|
||||
},
|
||||
},
|
||||
}
|
||||
51
nvim/lsp/gopls.lua
Normal file
51
nvim/lsp/gopls.lua
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
local mod_cache = nil
|
||||
|
||||
return {
|
||||
cmd = { "gopls" },
|
||||
filetypes = { "go", "gomod", "gowork", "gotmpl" },
|
||||
settings = {
|
||||
gopls = {
|
||||
analyses = {
|
||||
unusedparams = true,
|
||||
},
|
||||
staticcheck = true,
|
||||
lintTool = "golangci-lint",
|
||||
},
|
||||
},
|
||||
root_dir = function(callback)
|
||||
local path = vim.fn.expand("%:p")
|
||||
if not path or path == "" then
|
||||
callback(nil)
|
||||
return
|
||||
end
|
||||
|
||||
-- Asynchronously fetch GOMODCACHE if not already set
|
||||
if not mod_cache then
|
||||
vim.system({ "go", "env", "GOMODCACHE" }, { text = true }, function(result)
|
||||
if result and result.code == 0 and result.stdout then
|
||||
mod_cache = vim.trim(result.stdout)
|
||||
else
|
||||
vim.notify("[gopls] Unable to fetch GOMODCACHE", vim.log.levels.WARN)
|
||||
mod_cache = nil
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Check if the file is in the module cache
|
||||
if mod_cache and path:sub(1, #mod_cache) == mod_cache then
|
||||
local clients = vim.lsp.get_clients({ name = "gopls" })
|
||||
if #clients > 0 then
|
||||
callback(clients[#clients].config.root_dir)
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- Fallback: Find project root markers
|
||||
local go_mod_root = vim.fs.find({ "go.work", "go.mod", ".git" }, { upward = true, path = path })[1]
|
||||
if go_mod_root then
|
||||
callback(vim.fs.dirname(go_mod_root))
|
||||
else
|
||||
callback(nil)
|
||||
end
|
||||
end,
|
||||
}
|
||||
48
nvim/lsp/lua_ls.lua
Normal file
48
nvim/lsp/lua_ls.lua
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
return {
|
||||
cmd = { "lua-language-server" },
|
||||
filetypes = { "lua" },
|
||||
root_markers = {
|
||||
".luarc.json",
|
||||
".luarc.jsonc",
|
||||
".luacheckrc",
|
||||
".stylua.toml",
|
||||
"stylua.toml",
|
||||
"selene.toml",
|
||||
"selene.yml",
|
||||
".git"
|
||||
},
|
||||
settings = {
|
||||
Lua = {
|
||||
maxPreload = 100000,
|
||||
preloadFileSize = 10000,
|
||||
},
|
||||
},
|
||||
on_init = function(client)
|
||||
local path = vim.tbl_get(client, "workspace_folders", 1, "name")
|
||||
if not path then
|
||||
return
|
||||
end
|
||||
|
||||
-- override the lua-language-server settings for Neovim config
|
||||
client.settings = vim.tbl_deep_extend("force", client.settings, {
|
||||
Lua = {
|
||||
runtime = {
|
||||
version = "LuaJIT"
|
||||
},
|
||||
diagnostics = {
|
||||
globals = { "vim", "Snacks" },
|
||||
},
|
||||
-- Make the server aware of Neovim runtime files
|
||||
workspace = {
|
||||
checkThirdParty = false,
|
||||
library = {
|
||||
vim.env.VIMRUNTIME
|
||||
-- Depending on the usage, you might want to add additional paths here.
|
||||
-- "${3rd}/luv/library"
|
||||
-- "${3rd}/busted/library",
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
end
|
||||
}
|
||||
20
nvim/lsp/nil.lua
Normal file
20
nvim/lsp/nil.lua
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
return {
|
||||
cmd = { "nil" },
|
||||
filetypes = { "nix" },
|
||||
root_markers = {
|
||||
"flake.nix",
|
||||
".git"
|
||||
},
|
||||
settings = {
|
||||
["nil"] = {
|
||||
formatting = {
|
||||
command = { "nixfmt" },
|
||||
},
|
||||
},
|
||||
},
|
||||
on_attach = function(_, bufnr)
|
||||
vim.bo[bufnr].tabstop = 2
|
||||
vim.bo[bufnr].shiftwidth = 2
|
||||
vim.bo[bufnr].softtabstop = 2
|
||||
end
|
||||
}
|
||||
21
nvim/lsp/pyright.lua
Normal file
21
nvim/lsp/pyright.lua
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
return {
|
||||
cmd = { "pyright-langserver", "--stdio" },
|
||||
filetypes = { "python", "py" },
|
||||
root_markers = {
|
||||
"pyproject.toml",
|
||||
"setup.py",
|
||||
"setup.cfg",
|
||||
"requirements.txt",
|
||||
"Pipfile",
|
||||
"pyrightconfig.json",
|
||||
},
|
||||
settings = {
|
||||
python = {
|
||||
analysis = {
|
||||
autoSearchPaths = true,
|
||||
useLibraryCodeForTypes = true,
|
||||
diagnosticMode = "openFilesOnly",
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
10
nvim/lsp/zls.lua
Normal file
10
nvim/lsp/zls.lua
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
return {
|
||||
cmd = { "zls" },
|
||||
on_new_config = function(new_config, new_root_dir)
|
||||
if vim.fn.filereadable(vim.fs.joinpath(new_root_dir, "zls.json")) ~= 0 then
|
||||
new_config.cmd = { "zls", "--config-path", "zls.json" }
|
||||
end
|
||||
end,
|
||||
filetypes = { "zig", "zir" },
|
||||
root_markers = {"zls.json", "build.zig", ".git"},
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue