big updates. added several lsps

This commit is contained in:
tonybtw 2025-11-22 20:37:58 -08:00
commit cd7ef09315
7 changed files with 111 additions and 20 deletions

9
after/ftplugin/jsonc.lua Normal file
View file

@ -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

8
after/ftplugin/man.lua Normal file
View file

@ -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

View file

@ -57,6 +57,9 @@ vim.keymap.set("n", "<leader>cn", ":cnext<CR>zz")
vim.keymap.set("n", "<leader>cp", ":cprev<CR>zz")
vim.keymap.set("n", "<leader>li", ":checkhealth vim.lsp<CR>", { desc = "LSP Info" })
-- run make in current working directory
vim.keymap.set("n", "<leader>mm", "<cmd>make<CR>")
-- source file
vim.keymap.set("n", "<leader><leader>", function()
vim.cmd("so")

View file

@ -5,6 +5,7 @@ local set = vim.opt
set.relativenumber = true
set.number = true
-- indentation and tabs
set.tabstop = 4
set.shiftwidth = 4

View file

@ -9,9 +9,9 @@ return {
defaults = {
mappings = {
i = {
["<C-k>"] = actions.move_selection_previous, -- move to prev result
["<C-j>"] = actions.move_selection_next, -- move to next result
["<C-q>"] = actions.send_selected_to_qflist + actions.open_qflist, -- send selected to quickfixlist
["<C-k>"] = actions.move_selection_previous, -- move to prev result
["<C-j>"] = actions.move_selection_next, -- move to next result
["<C-q>"] = actions.smart_send_to_qflist + actions.open_qflist, -- send selected to quickfixlist
}
}
}

View file

@ -31,10 +31,14 @@ return {
ensure_installed = {
"json",
"python",
"ron",
"javascript",
"haskell",
"query",
"typescript",
"tsx",
"rust",
"zig",
"php",
"yaml",
"html",

View file

@ -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' }, '<F3>', function() vim.lsp.buf.format({ async = true }) end)
map('n', '<F4>', 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