This commit is contained in:
dlond 2025-05-09 13:16:17 +12:00
parent 2639f27f84
commit 06037c9bb4
4 changed files with 51 additions and 61 deletions

View File

@ -1,5 +1,3 @@
-- Autocompletion configuration (nvim-cmp)
return { return {
{ {
'hrsh7th/nvim-cmp', 'hrsh7th/nvim-cmp',
@ -11,7 +9,7 @@ return {
{ -- LuaSnip and its potential build step { -- LuaSnip and its potential build step
'L3MON4D3/LuaSnip', 'L3MON4D3/LuaSnip',
-- Follow latest V2 release. -- Follow latest V2 release.
version = 'v2.*', -- <--- REVERTED TO USING VERSION version = 'v2.*',
-- tag = '<your-desired-luasnip-tag>', -- Removed tag specification -- tag = '<your-desired-luasnip-tag>', -- Removed tag specification
-- install jsregexp (optional!:). -- install jsregexp (optional!:).
build = (function() build = (function()

View File

@ -14,7 +14,10 @@ return {
lua = { 'stylua' }, lua = { 'stylua' },
c = { 'clang_format' }, c = { 'clang_format' },
cpp = { 'clang_format' }, cpp = { 'clang_format' },
python = { 'isort', 'black' }, -- Use ruff for Python formatting (includes isort and is faster than black
-- Ensure 'ruff' is installed via Home Manager (pkgs.ruff)
python = { 'ruff_format', 'ruff_fix' },
-- python = { 'isort', 'black' },
nix = { 'nixpkgs-fmt' }, -- Add nix formatter nix = { 'nixpkgs-fmt' }, -- Add nix formatter
-- Add other filetypes and formatters, e.g.: -- Add other filetypes and formatters, e.g.:
-- javascript = { "prettier" }, -- javascript = { "prettier" },

View File

@ -18,8 +18,8 @@ return {
'pyright', -- Your addition 'pyright', -- Your addition
-- Add others like 'bashls', 'yamlls', 'nixd', 'gopls', 'rust_analyzer' etc. if needed -- Add others like 'bashls', 'yamlls', 'nixd', 'gopls', 'rust_analyzer' etc. if needed
}, },
-- You can add other mason-lspconfig options here if needed -- Optional: Configure automatic setup (might replace manual loop below)
-- automatic_installation = true, -- Example: if you want auto-install -- automatic_installation = false, -- v2 uses different approach
}, },
}, },
-- Optional: Tool installer for linters/formatters not handled by LSP -- Optional: Tool installer for linters/formatters not handled by LSP
@ -37,30 +37,22 @@ return {
-- Get LSP capabilities from nvim-cmp -- Get LSP capabilities from nvim-cmp
local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities()) local capabilities = require('cmp_nvim_lsp').default_capabilities(vim.lsp.protocol.make_client_capabilities())
--
-- Call mason-lspconfig's setup function (mainly for ensure_installed)
require('mason-lspconfig').setup(opts)
-- Setup LSP servers using mason-lspconfig -- Manually iterate through the servers list and set them up with lspconfig
-- This iterates through the servers listed in `ensure_installed` above local servers_to_setup = require('mason-lspconfig').get_ensure_installed()
-- and calls lspconfig's setup function for each.
require('mason-lspconfig').setup_handlers { for _, server_name in ipairs(servers_to_setup) do
function(server_name) -- Default handler -- print('Setting up LSP server: ' .. server_name) -- Debug print
require('lspconfig')[server_name].setup { require('lspconfig')[server_name].setup {
capabilities = capabilities, -- Pass cmp capabilities to the server capabilities = capabilities, -- Pass augmented capabilities
-- Add any server-specific overrides here if needed, e.g.: -- Add any server-specific overrides here if needed
-- on_attach = function(client, bufnr) ... end, }
-- settings = { ... }, end
}
end,
-- Example of specific setup for a server if needed:
-- ['lua_ls'] = function()
-- require('lspconfig').lua_ls.setup {
-- capabilities = capabilities,
-- settings = { Lua = { completion = { callSnippet = 'Replace' } } },
-- }
-- end,
}
-- Setup keymaps and diagnostics based on kickstart's original init.lua LSP section -- Setup keymaps and diagnostics based on kickstart's original init.lua LSP section
-- This ensures the standard LSP keymaps (gd, gr, etc.) are set on attach.
vim.api.nvim_create_autocmd('LspAttach', { vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('kickstart-lsp-attach-override', { clear = true }), group = vim.api.nvim_create_augroup('kickstart-lsp-attach-override', { clear = true }),
callback = function(event) callback = function(event)
@ -69,7 +61,7 @@ return {
vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc }) vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
end end
-- Standard LSP keymaps (copy these from kickstart init.lua or customize) -- Standard LSP keymaps
map('grn', vim.lsp.buf.rename, '[R]e[n]ame') map('grn', vim.lsp.buf.rename, '[R]e[n]ame')
map('gra', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' }) map('gra', vim.lsp.buf.code_action, '[G]oto Code [A]ction', { 'n', 'x' })
map('grr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences') map('grr', require('telescope.builtin').lsp_references, '[G]oto [R]eferences')
@ -80,21 +72,25 @@ return {
map('gW', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Open Workspace Symbols') map('gW', require('telescope.builtin').lsp_dynamic_workspace_symbols, 'Open Workspace Symbols')
map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definition') map('grt', require('telescope.builtin').lsp_type_definitions, '[G]oto [T]ype Definition')
-- Highlight references (optional, from kickstart) -- Highlight references
local client = vim.lsp.get_client_by_id(event.data.client_id) local client = vim.lsp.get_client_by_id(event.data.client_id)
if client and client.supports_method 'textDocument/documentHighlight' then local function client_supports_method(client, method, bufnr)
if vim.fn.has 'nvim-0.11' == 1 then
return client:supports_method(method, { bufnr = bufnr })
else
return client.supports_method(method, { bufnr = bufnr })
end
end
if client and client_supports_method(client, 'textDocument/documentHighlight', event.buf) then
local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight-override', { clear = false }) local highlight_augroup = vim.api.nvim_create_augroup('kickstart-lsp-highlight-override', { clear = false })
vim.api.nvim_create_autocmd({ 'CursorHold', 'CursorHoldI' }, { vim.api.nvim_create_autocmd(
buffer = event.buf, { 'CursorHold', 'CursorHoldI' },
group = highlight_augroup, { buffer = event.buf, group = highlight_augroup, callback = vim.lsp.buf.document_highlight }
callback = vim.lsp.buf.document_highlight, )
}) vim.api.nvim_create_autocmd(
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, { { 'CursorMoved', 'CursorMovedI' },
buffer = event.buf, { buffer = event.buf, group = highlight_augroup, callback = vim.lsp.buf.clear_references }
group = highlight_augroup, )
callback = vim.lsp.buf.clear_references,
})
-- Ensure highlight group is cleared on detach
vim.api.nvim_create_autocmd('LspDetach', { vim.api.nvim_create_autocmd('LspDetach', {
group = vim.api.nvim_create_augroup('kickstart-lsp-detach-override', { clear = true }), group = vim.api.nvim_create_augroup('kickstart-lsp-detach-override', { clear = true }),
callback = function(event2) callback = function(event2)
@ -104,8 +100,8 @@ return {
}) })
end end
-- Inlay hints toggle (optional, from kickstart) -- Inlay hints toggle
if client and client.supports_method 'textDocument/inlayHint' then if client and client_supports_method(client, 'textDocument/inlayHint', event.buf) then
map('<leader>th', function() map('<leader>th', function()
vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf }) vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled { bufnr = event.buf })
end, '[T]oggle Inlay [H]ints') end, '[T]oggle Inlay [H]ints')
@ -113,26 +109,23 @@ return {
end, end,
}) })
-- Diagnostic configuration (can be kept from kickstart or customized) -- Diagnostic configuration
vim.diagnostic.config { vim.diagnostic.config {
severity_sort = true, severity_sort = true,
float = { border = 'rounded', source = 'if_many' }, float = { border = 'rounded', source = 'if_many' },
underline = { severity = vim.diagnostic.severity.ERROR }, underline = { severity = vim.diagnostic.severity.ERROR },
signs = vim.g.have_nerd_font signs = vim.g.have_nerd_font and {
and { text = {
text = { [vim.diagnostic.severity.ERROR] = '󰅚 ',
[vim.diagnostic.severity.ERROR] = '󰅚 ', -- Error icon [vim.diagnostic.severity.WARN] = '󰀪 ',
[vim.diagnostic.severity.WARN] = '󰀪 ', -- Warning icon [vim.diagnostic.severity.INFO] = '󰋽 ',
[vim.diagnostic.severity.INFO] = '󰋽 ', -- Info icon [vim.diagnostic.severity.HINT] = '󰌶 ',
[vim.diagnostic.severity.HINT] = '󰌶 ', -- Hint icon },
}, } or {},
}
or {}, -- Use kickstart's sign definitions
virtual_text = { virtual_text = {
source = 'if_many', source = 'if_many',
spacing = 2, spacing = 2,
format = function(diagnostic) format = function(diagnostic)
-- Map diagnostic severity to the message itself (simple format)
local diagnostic_message = { local diagnostic_message = {
[vim.diagnostic.severity.ERROR] = diagnostic.message, [vim.diagnostic.severity.ERROR] = diagnostic.message,
[vim.diagnostic.severity.WARN] = diagnostic.message, [vim.diagnostic.severity.WARN] = diagnostic.message,
@ -146,14 +139,12 @@ return {
end, -- End of config function end, -- End of config function
}, },
-- Add the lazydev setup here as well, as it relates to LSP for Lua development -- lazydev setup
{ {
'folke/lazydev.nvim', 'folke/lazydev.nvim',
ft = 'lua', ft = 'lua',
opts = { opts = {
library = { library = { { path = 'luvit-meta/library', words = { 'vim%.uv' } } },
{ path = 'luvit-meta/library', words = { 'vim%.uv' } }, -- Corrected path if using luvit types
},
}, },
}, },
} }

View File

@ -1,5 +1,3 @@
-- Treesitter configuration override
return { return {
-- ======================================== -- ========================================
-- Treesitter Configuration Override -- Treesitter Configuration Override