Move files out of their respective fs structure into program dirs in root and symlink dotfils using HM.

This commit is contained in:
Martin Larsson 2025-01-16 23:49:38 +00:00
parent 10bab010b7
commit fb2adb4547
72 changed files with 9 additions and 0 deletions

View file

@ -0,0 +1,62 @@
local utils = require("utils")
-- https://clangd.llvm.org/extensions.html#switch-between-sourceheader
local function switch_source_header(bufnr)
bufnr = utils.validate_bufnr(bufnr)
local clangd_client = vim.lsp.get_clients({ bufnr = bufnr, name = "clangd" })[1]
local params = { uri = vim.uri_from_bufnr(bufnr) }
if clangd_client then
clangd_client.request("textDocument/switchSourceHeader", params, 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(_, bufnr)
local lsp_maps = {
{
"<leader>ko",
function() switch_source_header(0) end,
},
}
local keymaps = { n = {} }
for i, _ in ipairs(lsp_maps) do
local binding, cmd = unpack(lsp_maps[i])
keymaps.n[binding] = { cmd = cmd, opts = { buffer = bufnr } }
end
utils.add_keymaps(keymaps)
end,
}

View 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",
},
}

View file

@ -0,0 +1,56 @@
local mod_cache = nil
return {
cmd = { "gopls" },
filetypes = { "go", "gomod", "gowork", "gotmpl" },
settings = {
gopls = {
["ui.inlayhints.hints"] = {
compositeLiteralFields = true,
constantValues = true,
parameterNames = true,
},
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,
}

View file

@ -0,0 +1,39 @@
return {
cmd = { "lua-language-server" },
filetypes = { "lua" },
root_markers = {
".luarc.json",
".luarc.jsonc",
".luacheckrc",
".stylua.toml",
"stylua.toml",
"selene.toml",
"selene.yml",
".git"
},
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"
},
-- 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
}

View 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",
},
},
},
}