diff --git a/after/ftplugin/jsonc.lua b/after/ftplugin/jsonc.lua new file mode 100644 index 0000000..e1833b8 --- /dev/null +++ b/after/ftplugin/jsonc.lua @@ -0,0 +1,9 @@ +local set = vim.opt_local + +set.shiftwidth = 2 +set.tabstop = 2 +set.softtabstop = 2 +set.expandtab = true + +set.number = true +set.relativenumber = true diff --git a/after/ftplugin/man.lua b/after/ftplugin/man.lua new file mode 100644 index 0000000..f21d675 --- /dev/null +++ b/after/ftplugin/man.lua @@ -0,0 +1,8 @@ +local set = vim.opt_local +set.number = true +set.relativenumber = true +set.number = true +set.relativenumber = false +set.wrap = true +set.linebreak = true +set.conceallevel = 0 diff --git a/lua/config/keybinds.lua b/lua/config/keybinds.lua index 1c1b42c..a2979b8 100644 --- a/lua/config/keybinds.lua +++ b/lua/config/keybinds.lua @@ -57,6 +57,9 @@ vim.keymap.set("n", "cn", ":cnextzz") vim.keymap.set("n", "cp", ":cprevzz") vim.keymap.set("n", "li", ":checkhealth vim.lsp", { desc = "LSP Info" }) +-- run make in current working directory +vim.keymap.set("n", "mm", "make") + -- source file vim.keymap.set("n", "", function() vim.cmd("so") diff --git a/lua/config/options.lua b/lua/config/options.lua index 52de0a7..9000cde 100644 --- a/lua/config/options.lua +++ b/lua/config/options.lua @@ -5,6 +5,7 @@ local set = vim.opt set.relativenumber = true set.number = true + -- indentation and tabs set.tabstop = 4 set.shiftwidth = 4 diff --git a/lua/plugins/telescope.lua b/lua/plugins/telescope.lua index 3c10c7e..060de36 100644 --- a/lua/plugins/telescope.lua +++ b/lua/plugins/telescope.lua @@ -9,9 +9,9 @@ return { defaults = { mappings = { i = { - [""] = actions.move_selection_previous, -- move to prev result - [""] = actions.move_selection_next, -- move to next result - [""] = actions.send_selected_to_qflist + actions.open_qflist, -- send selected to quickfixlist + [""] = actions.move_selection_previous, -- move to prev result + [""] = actions.move_selection_next, -- move to next result + [""] = actions.smart_send_to_qflist + actions.open_qflist, -- send selected to quickfixlist } } } diff --git a/lua/plugins/treesitter.lua b/lua/plugins/treesitter.lua index 71cbc58..e6e13e3 100644 --- a/lua/plugins/treesitter.lua +++ b/lua/plugins/treesitter.lua @@ -31,10 +31,14 @@ return { ensure_installed = { "json", "python", + "ron", "javascript", + "haskell", "query", "typescript", "tsx", + "rust", + "zig", "php", "yaml", "html", diff --git a/plugin/lsp.lua b/plugin/lsp.lua index a56c3a2..6b7cb09 100644 --- a/plugin/lsp.lua +++ b/plugin/lsp.lua @@ -21,7 +21,7 @@ vim.diagnostic.config({ }, }, }) --- put early in lsp.lua + local orig = vim.lsp.util.open_floating_preview ---@diagnostic disable-next-line: duplicate-set-field function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...) @@ -33,8 +33,6 @@ function vim.lsp.util.open_floating_preview(contents, syntax, opts, ...) return orig(contents, syntax, opts, ...) end --- 4) Per-buffer behavior on LSP attach (keymaps, auto-format, completion) --- See :help LspAttach for the recommended pattern vim.api.nvim_create_autocmd('LspAttach', { group = vim.api.nvim_create_augroup('my.lsp', {}), callback = function(args) @@ -42,7 +40,6 @@ vim.api.nvim_create_autocmd('LspAttach', { local buf = args.buf local map = function(mode, lhs, rhs) vim.keymap.set(mode, lhs, rhs, { buffer = buf }) end - -- Keymaps (use builtin LSP buffer functions) map('n', 'K', vim.lsp.buf.hover) map('n', 'gd', vim.lsp.buf.definition) map('n', 'gD', vim.lsp.buf.declaration) @@ -55,10 +52,7 @@ vim.api.nvim_create_autocmd('LspAttach', { map({ 'n', 'x' }, '', function() vim.lsp.buf.format({ async = true }) end) map('n', '', vim.lsp.buf.code_action) - -- Put near your LSP on_attach - local excluded_filetypes = { php = true } - - -- Auto-format on save (only if server can't do WillSaveWaitUntil) + local excluded_filetypes = { php = true, c = true, cpp = true } if not client:supports_method('textDocument/willSaveWaitUntil') and client:supports_method('textDocument/formatting') and not excluded_filetypes[vim.bo[buf].filetype] @@ -74,8 +68,6 @@ vim.api.nvim_create_autocmd('LspAttach', { end, }) --- 5) Define the Lua language server config (no mason/lspconfig) --- See :help lsp-new-config and :help vim.lsp.config() local caps = require("cmp_nvim_lsp").default_capabilities() vim.lsp.config['luals'] = { cmd = { 'lua-language-server' }, @@ -136,7 +128,21 @@ vim.lsp.config['ts_ls'] = { }, } --- Nix LSP (nil) +vim.lsp.config['zls'] = { + cmd = { 'zls' }, + filetypes = { 'zig', 'zir' }, + root_markers = { 'zls.json', 'build.zig', '.git' }, + capabilities = caps, + settings = { + zls = { + enable_build_on_save = true, + build_on_save_step = "install", + warn_style = false, + enable_snippets = true, + } + } +} + vim.lsp.config['nil_ls'] = { cmd = { 'nil' }, filetypes = { 'nix' }, @@ -145,15 +151,75 @@ vim.lsp.config['nil_ls'] = { settings = { ['nil'] = { formatting = { - command = { "nixpkgs-fmt" } -- or "alejandra" if you prefer + command = { "alejandra" } } } } } +vim.lsp.config['rust_analyzer'] = { + cmd = { 'rust-analyzer' }, + filetypes = { 'rust' }, + root_markers = { 'Cargo.toml', 'rust-project.json', '.git' }, + capabilities = caps, + settings = { + ['rust-analyzer'] = { + cargo = { allFeatures = true }, + formatting = { + command = { "rustfmt" } + }, + }, + }, +} -vim.lsp.enable('luals') -vim.lsp.enable('cssls') -vim.lsp.enable('ts_ls') -vim.lsp.enable('phpls') -vim.lsp.enable('nil_ls') +-- C / C++ via clangd +vim.lsp.config['clangd'] = { + cmd = { + 'clangd', + '--background-index', + '--clang-tidy', + '--header-insertion=never', + '--completion-style=detailed', + '--query-driver=/nix/store/*-gcc-*/bin/gcc*,/nix/store/*-clang-*/bin/clang*,/run/current-system/sw/bin/cc*', + }, + filetypes = { 'c', 'cpp', 'objc', 'objcpp' }, + root_markers = { 'compile_commands.json', '.clangd', 'configure.ac', 'Makefile', '.git' }, + capabilities = caps, + init_options = { + fallbackFlags = { '-std=c23' }, -- Default to C23 + }, +} + +vim.lsp.config['jsonls'] = { + cmd = { 'vscode-json-languageserver', '--stdio' }, + filetypes = { 'json', 'jsonc' }, + root_markers = { 'package.json', '.git', 'config.jsonc' }, + capabilities = caps, +} + +vim.lsp.config['hls'] = { + cmd = { 'haskell-language-server-wrapper', '--lsp' }, + filetypes = { 'haskell', 'lhaskell' }, + root_markers = { 'stack.yaml', 'cabal.project', 'package.yaml', '*.cabal', 'hie.yaml', '.git' }, + capabilities = caps, + settings = { + haskell = { + formattingProvider = 'fourmolu', + plugin = { + semanticTokens = { globalOn = false } + }, + }, + }, +} + +vim.filetype.add({ + extension = { + h = 'c', + }, +}) + +for name, _ in pairs(vim.lsp.config) do + if name ~= '*' then -- Skip the wildcard config + vim.lsp.enable(name) + end +end