[Question] Where to add ruff to init.lua?
I am using this kickstarter but with a few added packages and small adjustments like
I am reading ruff's docs. It says I can add this to the init.lua (somewhere):
require('lspconfig').ruff.setup({
init_options = {
settings = {
-- Ruff language server settings go here
}
}
})
Since I am also using PyRight, I am considering following the docs' instruction to turn off some functionality related to hover:
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup('lsp_attach_disable_ruff_hover', { clear = true }),
callback = function(args)
local client = vim.lsp.get_client_by_id(args.data.client_id)
if client == nil then
return
end
if client.name == 'ruff' then
-- Disable hover in favor of Pyright
client.server_capabilities.hoverProvider = false
end
end,
desc = 'LSP: Disable hover capability from Ruff',
})
I tried adding these lines to my init.lua beside some other code that pertained to LSP servers and it gave an error saying it could not find lspconfig.
My config is still quite similar to the kickstarter. Assuming it were the same, where could I add these lines to configure ruff?
Hi @galenseilisnh,
I suggest adding both code snippets to the config function of neovim/nvim-lspconfig. In an unmodified Kickstart configuration, this function starts near line 500. There is already a callback created to perform actions when an LSP attaches. You can either integrate the Pyright and Ruff setup into the existing setup or create two separate autocmd events for LspAttach.
vim.api.nvim_create_autocmd('LspAttach', {
group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }),
callback = function(event)
...
end,
})
For your first snippet, in the current Kickstart config at line 668, there is a variable called servers. You can add your configuration there as follows:
local servers = {
ruff = {
init_options = {
settings = {
-- Ruff language server settings go here
}
}
},
-- REST OF THE EXISTING CONFIG
}
I might be wrong, tho! I invite other to correct me if I am wrong!
Nope you're exactly right.