-
Notifications
You must be signed in to change notification settings - Fork 46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Neovim + Mason + ruff_lsp, trying to pass in a pyproject.toml #177
Comments
Update
but I'm still seeing "Line too long (96 > 88 characters)" |
@dhruvmanila -- Any chance you could take a look? |
Hey, sure. So, I'm assuming you're trying to set a default setting across all projects. As per the PR description, you would want to pass the require("lspconfig").ruff_lsp.setup({
init_options = {
settings = {
-- Any extra CLI arguments for `ruff` go here.
args = {
"--config=~/temp/pyproject.toml",
},
},
},
})
Currently, we don't really have a way to update every setting from the command-line so this won't work as there's no |
Hi, thanks for your replies. You're right that I'm trying to set a default across all projects @dhruvmanila, but I've just tried with "--config=~/temp/pyproject.toml" and it hasn't worked. Is there any logging that I can look at to see what actually got passed to ruff? |
Can you try by expanding the tilde ( require("lspconfig").ruff_lsp.setup({
init_options = {
settings = {
-- Any extra CLI arguments for `ruff` go here.
args = {
"--config=" .. vim.loop.os_homedir() .. "/temp/pyproject.toml",
},
},
},
}) |
Hmmmm, also no luck with that. Still seeing 93 > 88 lines |
Is it possible that your Neovim configuration isn’t being picked up at all? What happens if you add a bogus argument to the args list? |
It's possible, adding a bogus argument seems to have no effect. Other config is being picked up though (for example, pylsp). I'm using LazyVim, but I've bypassed the configuration framework code (to rule that out as the issue) by just placing the ruff_lsp setup into it:
|
Is your config available on GitHub? I could possible take a quick look at it. If not then can you provide some additional context about your setup like the LSP setup, directory structure (to determine if the config is being picked up or not). |
In order to have a default configuration for all your projects, you can use In the Ruff documentation we can read:
And here's my
|
Just a little add on since it took me a while to figure it out.
|
Do you believe there's room for improvement in helping users understand this more quickly? Perhaps through updating the documentation or other means? |
An example config, where the linter and formatter settings are configured, would have helped.
Still not sure what values go into |
Hi, Just chiming in since I also tended to have issues using Mason and it may help others who stumble across here. In my case, I needed to use different version of The issue was that Mason by default will Sorry maybe this information was best put in issue #71 |
It is nice to have it in the same environment so we ensure similar environments for all developers. See astral-sh/ruff-lsp#177 (comment) for reasoning.
I found my way to this issue after similarly struggling to get settings passed into I'm using neovim, mason, mason-lspconfig, and ruff-lsp, and I'm trying to set the lspconfig.ruff_lsp.setup {
on_attach = on_attach,
init_options = {
settings = {
args = {'--config=' .. vim.loop.os_homedir() .. '/.config/ruff/ruff.toml'},
},
},
} The config file is extremely simple and just has this in it: [format]
quote-style = "single" It is definitely reading my
Also, I figured out how to get ruff-lsp to spit out some debug logs — here's a relevant line from it showing the path to the config is being provided correctly:
So it's being passed in, but none of the settings are being respected. I also tried the approach of passing it in directly in the ruff-lsp config, which I had a bit more success with, but still didn't fix my issue. Here was the config I tried for that: lspconfig.ruff_lsp.setup {
on_attach = on_attach,
init_options = {
settings = {
args = { '--config=format.quote-style="single"' },
format = { args = { '--line-length=40' } }, -- length set absurdly low so I can see if the formatter is working
},
},
} With that config it does set the line lengths to 40, but quote-style isn't respected, even though it's definitely being passed correctly:
If there's any guidance on how I can get ruff to do what I'm expecting, I'd appreciate it. |
@naim I'm not familiar with neovim, but it seems that the editor uses the
However, formatting only runs if you run If not, have you tried running the commands from the CLI? E.g. I created a [format]
quote-style="single" and ran |
@naim Can you inform us on what you're expecting from ruff-lsp? The config option you've chosen is only for the formatter and not the linter. Can you tell us how you've configured Neovim on running the Ruff formatter? Are you using any external plugins like |
Ah, I think I see the issue. I wasn't paying close enough attention and grabbed a log message that was for the Edit: And yes, I have configured a command to run vim.keymap.set('n', '<space>x', function()
vim.lsp.buf.format { async = true }
end, opts) Here's the log message when I run that command:
Note that Given that my ruff-lsp config looks like this: lspconfig.ruff_lsp.setup {
on_attach = on_attach,
init_options = {
settings = {
args = {'--config=' .. vim.loop.os_homedir() .. '/.config/ruff/ruff.toml'},
},
},
} and the documentation in this repo says require('lspconfig').ruff_lsp.setup {
init_options = {
settings = {
-- Any extra CLI arguments for `ruff` go here.
args = {},
}
}
} I assumed that my CLI arguments specified there would be passed to any |
That would be settings = {
format = {
args = { '--line-length', '120' }
}
} @naim can you check if that works for you? I can see it being passed in:
|
Seen this thread open while configuring my neovim. I solved it like in the code below. It searches for Lines 6 to 12 do the checks for the toml and set the config path based on the presence of a project local Seems to be working fine so far. The full config is here: https://github.com/pygaiwan/neovim require('mason-lspconfig').setup({
ensure_installed = { 'lua_ls', 'ruff', 'pylsp' },
handlers = {
function(server_name)
if server_name == 'ruff' then
local ruff_config_path = vim.loop.os_homedir() .. '/.config/ruff/ruff.toml'
local project_ruff_config = vim.loop.cwd() .. '/ruff.toml'
local f = io.open(project_ruff_config, 'r')
if f ~= nil then
io.close(f)
ruff_config_path = project_ruff_config
end
require('lspconfig').ruff_lsp.setup({
init_options = {
settings = {
format = {
args = { "--config=" .. ruff_config_path }
},
lint = {
args = { "--config=" .. ruff_config_path }
}
}
}
})
|
Hi, I'm using neovim and getting ruff-lsp from the Mason registry.
I'm trying to pass a pyproject.toml to ruff as suggested in the readme, but find that the line length setting is not applied (still seeing warning about 88 characters):
Lsp config:
pyproject.toml:
ruff version: ruff 0.0.269 (I installed ruff using snap install for testing, but neovim will acutally be using whatever ruff-lsp/ruff is coming from the Mason registry)
ruff-lsp version: 0.0.35
I've tested:
ruff check . --config=/home/xifong/temp/pyproject.toml
, which works as expected, with only lines above 100 being flagged.Not sure if it's relevant but:
ruff check . --config=~/temp/pyproject.toml
is looking in the wrong path, maybe just due to the snap install.error: Failed to parse /home/xifong/snap/ruff/190/temp/pyproject.toml: No such file or directory (os error 2)
Does this setup seem like it should be working?
The text was updated successfully, but these errors were encountered: