kickstart.nvim icon indicating copy to clipboard operation
kickstart.nvim copied to clipboard

[Question] Where to add ruff to init.lua?

Open galenseilisnh opened this issue 10 months ago • 1 comments

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?

galenseilisnh avatar Feb 28 '25 23:02 galenseilisnh

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!

Marc-AnthonyG avatar Mar 01 '25 03:03 Marc-AnthonyG

Nope you're exactly right.

feoh avatar Apr 09 '25 15:04 feoh