clean stuff up even more
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
local M = {}
|
||||
|
||||
local float_term = require("util.float").float_terminal
|
||||
|
||||
function M.find_cmake()
|
||||
if vim.g.cmake_path and vim.fn.filereadable(vim.g.cmake_path) == 1 then
|
||||
return vim.g.cmake_path
|
||||
@@ -37,5 +39,27 @@ function M.find_cmake()
|
||||
return "cmake" -- fallback, so termopen still runs even if broken
|
||||
end
|
||||
|
||||
function M.configure_cmake(build_type)
|
||||
vim.fn.mkdir("build", "p")
|
||||
float_term(
|
||||
{ M.find_cmake(), "-DCMAKE_BUILD_TYPE=" .. build_type, "-DCMAKE_EXPORT_COMPILE_COMMANDS=ON", ".." },
|
||||
{ cwd = "build" }
|
||||
)
|
||||
end
|
||||
|
||||
vim.keymap.set("n", "<leader>cd", function() M.configure_cmake("Debug") end, { desc = "CMake Debug" })
|
||||
vim.keymap.set("n", "<leader>cr", function() M.configure_cmake("Release") end, { desc = "CMake Release" })
|
||||
vim.keymap.set("n", "<leader>cp", function() M.configure_cmake("RelWithDebInfo") end, { desc = "CMake RelWithDebInfo" })
|
||||
|
||||
|
||||
vim.api.nvim_create_user_command("Build", function(opts)
|
||||
local t = opts.args
|
||||
if t == "" then print("Usage: :Build <target>"); return end
|
||||
float_term(
|
||||
{ CMAKE, "--build", "build", "--parallel", "20", "--target", t },
|
||||
{ height_ratio = 0.8, width_ratio = 0.8, border = "single" }
|
||||
)
|
||||
end, { nargs = 1 })
|
||||
|
||||
return M
|
||||
|
||||
|
||||
@@ -14,8 +14,7 @@ if not (vim.uv or vim.loop).fs_stat(lazypath) then
|
||||
end
|
||||
vim.opt.rtp:prepend(lazypath)
|
||||
|
||||
vim.g.mapleader = " "
|
||||
vim.g.maplocalleader = "\\"
|
||||
require("config.opts")
|
||||
|
||||
require("lazy").setup({
|
||||
spec = {
|
||||
@@ -26,3 +25,5 @@ require("lazy").setup({
|
||||
install = { colorscheme = { "habamax" } },
|
||||
checker = { enabled = true },
|
||||
})
|
||||
|
||||
require("config.cmake")
|
||||
|
||||
89
nvim/lua/config/lsp.lua
Normal file
89
nvim/lua/config/lsp.lua
Normal file
@@ -0,0 +1,89 @@
|
||||
local cmp = require("cmp")
|
||||
local luasnip = require("luasnip")
|
||||
|
||||
cmp.setup({
|
||||
snippet = {
|
||||
expand = function(args)
|
||||
luasnip.lsp_expand(args.body)
|
||||
end,
|
||||
},
|
||||
mapping = cmp.mapping.preset.insert({
|
||||
["<C-space>"] = cmp.mapping.complete(),
|
||||
["<CR>"] = cmp.mapping.confirm({ select = true }),
|
||||
}),
|
||||
sources = {
|
||||
{ name = "nvim_lsp" },
|
||||
{ name = "luasnip" },
|
||||
}
|
||||
})
|
||||
|
||||
local caps = require("cmp_nvim_lsp").default_capabilities()
|
||||
|
||||
local on_attach = function(client, bufnr)
|
||||
local opts = { noremap=true, silent=true, buffer=bufnr }
|
||||
vim.keymap.set("n", "gd", vim.lsp.buf.definition, opts)
|
||||
vim.keymap.set("n", "K", vim.lsp.buf.hover, opts)
|
||||
end
|
||||
|
||||
-- clangd
|
||||
vim.lsp.config("clangd", {
|
||||
cmd = { "clangd", "--compile-commands-dir=build" },
|
||||
capabilities = caps,
|
||||
on_attach = on_attach,
|
||||
})
|
||||
vim.lsp.enable("clangd")
|
||||
|
||||
-- rust-analyzer
|
||||
vim.lsp.config("rust_analyzer", {
|
||||
settings = {
|
||||
["rust-analyzer"] = {
|
||||
inlayHints = {
|
||||
parameterHints = { enable = true },
|
||||
typeHints = { enable = true },
|
||||
},
|
||||
},
|
||||
},
|
||||
capabilities = caps,
|
||||
on_attach = on_attach,
|
||||
})
|
||||
vim.lsp.enable("rust_analyzer")
|
||||
|
||||
-- typescript
|
||||
vim.lsp.config("ts_ls", {
|
||||
capabilities = caps,
|
||||
on_attach = on_attach,
|
||||
filetypes = { "javascript", "javascriptreact", "typescript", "typescriptreact", "typescript.tsx" },
|
||||
cmd = { "typescript-language-server", "--stdio" },
|
||||
})
|
||||
vim.lsp.enable("ts_ls")
|
||||
|
||||
-- gopls
|
||||
vim.lsp.config("gopls", {
|
||||
settings = {
|
||||
gopls = {
|
||||
gofumpt = true,
|
||||
staticcheck = true,
|
||||
},
|
||||
},
|
||||
capabilities = caps,
|
||||
on_attach = on_attach,
|
||||
})
|
||||
vim.lsp.enable("gopls")
|
||||
|
||||
-- pyright
|
||||
vim.lsp.config("pyright", {
|
||||
capabilities = caps,
|
||||
})
|
||||
|
||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||
group = vim.api.nvim_create_augroup("AutoFormatOnSave", { clear = true }),
|
||||
pattern = "*",
|
||||
callback = function()
|
||||
for _, client in pairs(vim.lsp.get_active_clients({ bufnr = 0 })) do
|
||||
if client.supports_method("textDocument/formatting") then
|
||||
vim.lsp.buf.format({ async = false })
|
||||
return
|
||||
end
|
||||
end
|
||||
end,
|
||||
})
|
||||
19
nvim/lua/config/opts.lua
Normal file
19
nvim/lua/config/opts.lua
Normal file
@@ -0,0 +1,19 @@
|
||||
vim.opt.tabstop = 2
|
||||
vim.opt.shiftwidth = 2
|
||||
vim.opt.softtabstop = 2
|
||||
vim.opt.expandtab = false
|
||||
|
||||
vim.opt.number = true
|
||||
vim.opt.relativenumber = true
|
||||
|
||||
vim.opt.cursorline = true
|
||||
vim.opt.scrolloff = 8
|
||||
vim.opt.autoindent = true
|
||||
|
||||
vim.g.equalalways = false
|
||||
|
||||
vim.g.mapleader = " "
|
||||
vim.g.maplocalleader = "\\"
|
||||
|
||||
vim.keymap.set('t', '<Esc>', '<C-\\><C-n>', { silent = true })
|
||||
vim.opt.shell = "/usr/bin/zsh"
|
||||
Reference in New Issue
Block a user