remember to enable lsp

This commit is contained in:
2025-11-19 13:13:50 +01:00
parent c80db2417e
commit 883c4cabb0

View File

@@ -5,28 +5,29 @@ require("neodev").setup()
require("fidget").setup({ require("fidget").setup({
notification = { notification = {
redirect = -- Conditionally redirect notifications to another backend redirect = -- Conditionally redirect notifications to another backend
function(msg, level, opts) function(msg, level, opts)
if opts and opts.on_open then if opts and opts.on_open then
return require("fidget.integration.nvim-notify").delegate(msg, level, opts) return require("fidget.integration.nvim-notify").delegate(msg, level, opts)
end end
end, end,
}, },
}) })
require('mason').setup({}) require('mason').setup({})
require('mason-lspconfig').setup({ require('mason-lspconfig').setup({
ensure_installed = {'bashls', 'clangd', 'marksman', 'pylsp', 'ruff', 'texlab'}, ensure_installed = { 'bashls', 'clangd', 'lua_ls', 'marksman', 'pylsp', 'ruff', 'texlab' },
automatic_enable = false, automatic_enable = false,
}) })
require('mason-nvim-dap').setup({ require('mason-nvim-dap').setup({
ensure_installed = {'bash', 'cppdbg', 'python'}, ensure_installed = { 'bash', 'cppdbg', 'python' },
}) })
require('dap-python').setup("python") require('dap-python').setup("python")
local servers = { local servers = {
bashls = {}, bashls = {},
clangd = {}, clangd = {},
lua_ls = {},
marksman = {}, marksman = {},
pylsp = { pylsp = {
settings = { settings = {
@@ -49,19 +50,19 @@ local servers = {
filetypes = { "python" }, filetypes = { "python" },
init_options = { init_options = {
settings = { settings = {
configuration = "~/.local/share/nvim/ruff.toml", -- Custom config for ruff to use configuration = "~/.local/share/nvim/ruff.toml", -- Custom config for ruff to use
exclude = { "__about__.py" }, -- Files to be excluded by ruff checking exclude = { "__about__.py" }, -- Files to be excluded by ruff checking
lineLength = 160, -- Line length to pass to ruff checking and formatting lineLength = 160, -- Line length to pass to ruff checking and formatting
organizeImports = true, organizeImports = true,
format = { format = {
preview = false, -- Whether to enable the preview style linting and formatting. preview = false, -- Whether to enable the preview style linting and formatting.
}, },
lint = { lint = {
enable = true, -- Enable linting enable = true, -- Enable linting
-- select = { "F" }, -- Rules to be enabled by ruff -- select = { "F" }, -- Rules to be enabled by ruff
extendSelect = { "F", "I" }, -- Rules that are additionally used by ruff extendSelect = { "F", "I" }, -- Rules that are additionally used by ruff
ignore = { "D210", "E741", "E743" }, -- Rules to be ignored by ruff ignore = { "D210", "E741", "E743" }, -- Rules to be ignored by ruff
extendIgnore = { "C90" }, -- Rules that are additionally ignored by ruff extendIgnore = { "C90" }, -- Rules that are additionally ignored by ruff
}, },
}, },
}, },
@@ -87,7 +88,7 @@ local servers = {
ignoredPatterns = { ignoredPatterns = {
"Unused label", "Unused label",
-- "Unused entry", -- "Unused entry",
}, },
}, },
formatterLineLength = -1, formatterLineLength = -1,
latexFormatter = "latexindent", latexFormatter = "latexindent",
@@ -96,7 +97,7 @@ local servers = {
}, },
forwardSearch = { forwardSearch = {
executable = "zathura", executable = "zathura",
args = { "--synctex-forward", "%l:1:%f", "%p"} args = { "--synctex-forward", "%l:1:%f", "%p" }
}, },
}, },
}, },
@@ -124,13 +125,15 @@ local on_attach = function(_client, buffer_number)
-- Use Prettier to format TS/JS if it's available -- Use Prettier to format TS/JS if it's available
return format_client.name ~= "tsserver" or not null_ls.is_registered("prettier") return format_client.name ~= "tsserver" or not null_ls.is_registered("prettier")
end, end,
async = false,
timeout_ms = 10000,
}) })
end, { desc = "LSP: Format current buffer with LSP" }) end, { desc = "LSP: Format current buffer with LSP" })
end end
-- Iterate over our servers and set them up -- Iterate over our servers and set them up
for name, config in pairs(servers) do for name, config in pairs(servers) do
vim.lsp.config(name,{ vim.lsp.config(name, {
capabilities = default_capabilities, capabilities = default_capabilities,
filetypes = config.filetypes, filetypes = config.filetypes,
handlers = vim.tbl_deep_extend("force", {}, default_handlers, config.handlers or {}), handlers = vim.tbl_deep_extend("force", {}, default_handlers, config.handlers or {}),
@@ -138,6 +141,7 @@ for name, config in pairs(servers) do
settings = config.settings, settings = config.settings,
init_options = config.init_options, init_options = config.init_options,
}) })
vim.lsp.enable(name)
end end
vim.diagnostic.config({ vim.diagnostic.config({
@@ -156,48 +160,48 @@ vim.diagnostic.config({
}) })
-- Autoformat on save -- Autoformat on save
local fmt_group = vim.api.nvim_create_augroup('autoformat_cmds', {clear = true}) local fmt_group = vim.api.nvim_create_augroup('autoformat_cmds', { clear = true })
local function setup_autoformat(event) local function setup_autoformat(event)
local id = vim.tbl_get(event, 'data', 'client_id') local id = vim.tbl_get(event, 'data', 'client_id')
local client = id and vim.lsp.get_client_by_id(id) local client = id and vim.lsp.get_client_by_id(id)
if client == nil then if client == nil then
return return
end end
vim.api.nvim_clear_autocmds({group = fmt_group, buffer = event.buf}) vim.api.nvim_clear_autocmds({ group = fmt_group, buffer = event.buf })
local buf_format = function(e) local buf_format = function(e)
vim.lsp.buf.format({ vim.lsp.buf.format({
bufnr = e.buf, bufnr = e.buf,
async = false, async = false,
timeout_ms = 10000, timeout_ms = 10000,
})
end
vim.api.nvim_create_autocmd('BufWritePre', {
buffer = event.buf,
group = fmt_group,
desc = 'Format current buffer',
callback = buf_format,
}) })
end
vim.api.nvim_create_autocmd('BufWritePre', {
buffer = event.buf,
group = fmt_group,
desc = 'Format current buffer',
callback = buf_format,
})
end end
vim.api.nvim_create_autocmd('LspAttach', { vim.api.nvim_create_autocmd('LspAttach', {
desc = 'Setup format on save', desc = 'Setup format on save',
callback = setup_autoformat, callback = setup_autoformat,
}) })
-- Enable inlay hints -- Enable inlay hints
vim.api.nvim_create_autocmd('LspAttach', { vim.api.nvim_create_autocmd('LspAttach', {
desc = 'Enable inlay hints', desc = 'Enable inlay hints',
callback = function(event) callback = function(event)
local id = vim.tbl_get(event, 'data', 'client_id') local id = vim.tbl_get(event, 'data', 'client_id')
local client = id and vim.lsp.get_client_by_id(id) local client = id and vim.lsp.get_client_by_id(id)
if client == nil or not client:supports_method('textDocument/inlayHint') then if client == nil or not client:supports_method('textDocument/inlayHint') then
return return
end end
vim.lsp.inlay_hint.enable(true, {bufnr = event.buf}) vim.lsp.inlay_hint.enable(true, { bufnr = event.buf })
end, end,
}) })