Skip to content
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

ruff server in v0.4.5 doesn't consider the configuration setting in Neovim #11507

Closed
a1401358759 opened this issue May 23, 2024 · 5 comments · Fixed by #11566
Closed

ruff server in v0.4.5 doesn't consider the configuration setting in Neovim #11507

a1401358759 opened this issue May 23, 2024 · 5 comments · Fixed by #11566
Assignees
Labels
bug Something isn't working server Related to the LSP server

Comments

@a1401358759
Copy link

When I updated to version 0.4.5, the E30* checks all failed and nothing changed in my configuration

my pyproject.toml

[tool.ruff]
preview = true
# Exclude a variety of commonly ignored directories.
exclude = [
    ".bzr",
    ".direnv",
    ".eggs",
    ".git",
    ".git-rewrite",
    ".hg",
    ".ipynb_checkpoints",
    ".mypy_cache",
    ".nox",
    ".pants.d",
    ".pyenv",
    ".pytest_cache",
    ".pytype",
    ".ruff_cache",
    ".svn",
    ".tox",
    ".venv",
    ".vscode",
    "__pypackages__",
    "_build",
    "buck-out",
    "build",
    "dist",
    "node_modules",
    "site-packages",
    "venv",
]

# Same as Black.
line-length = 120
indent-width = 4

[tool.ruff.lint]
# Enable Pyflakes (`F`) and a subset of the pycodestyle (`E`)  codes by default.
# Unlike Flake8, Ruff doesn't enable pycodestyle warnings (`W`) or
# McCabe complexity (`C901`) by default.
select = ["E4", "E7", "E9", "F", "I001"]
ignore = ["E402","E501","N802","N803","N806","N801","N813","N815","N816","RUF001","RUF002","RUF003","RUF012","ARG001"]
extend-select = ["E", "N", "W", "ARG", "RUF"]

# Allow fix for all enabled rules (when `--fix`) is provided.
fixable = ["ALL"]
unfixable = []

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

[tool.ruff.format]
# Like Black, use double quotes for strings.
quote-style = "double"

# Like Black, indent with spaces, rather than tabs.
indent-style = "space"

# Like Black, respect magic trailing commas.
skip-magic-trailing-comma = false

# Like Black, automatically detect the appropriate line ending.
line-ending = "auto"

# Enable auto-formatting of code examples in docstrings. Markdown,
# reStructuredText code/literal blocks and doctests are all supported.
#
# This is currently disabled by default, but it is planned for this
# to be opt-out in the future.
docstring-code-format = false

# Set the line length limit used when formatting code snippets in
# docstrings.
#
# This only has an effect when the `docstring-code-format` setting is
# enabled.
docstring-code-line-length = "dynamic"

my ruff config

  init_options = {
    filetypes = { "python" },
    single_file_support = true,
    cmd = { "ruff", "server", "--preview" },
    settings = {
      configuration = "~/.config/nvim/pyproject.toml",
    },
  },
@snowsignal snowsignal added the server Related to the LSP server label May 24, 2024
@snowsignal snowsignal self-assigned this May 24, 2024
@dhruvmanila
Copy link
Member

Can you provide a minimal code snippet on which it's failing? And, just to confirm, by "failing" do you mean that the v0.4.4 wasn't raising any violations but v0.4.5 does?

@a1401358759
Copy link
Author

@dhruvmanila
image
I'm sorry, I wasn't accurate in my description. It's not a failure, it's a non-effect.

@snowsignal
Copy link
Contributor

I haven't been able to reproduce this issue. The pyproject.toml you put in the issue is the one in ~/.config/nvim, right? Do you have any local .toml configuration files?

@a1401358759
Copy link
Author

@snowsignal

image image

I don't have any local .toml configuration files

@dhruvmanila
Copy link
Member

I think I found the bug.

@dhruvmanila dhruvmanila added the bug Something isn't working label May 27, 2024
@dhruvmanila dhruvmanila changed the title When I updated to version 0.4.5, the E30* checks all failed and nothing changed in my configuration ruff server in v0.4.5 doesn't consider the configuration setting in Neovim May 27, 2024
dhruvmanila added a commit that referenced this issue May 27, 2024
…ed (#11566)

## Summary

This PR fixes the bug to avoid flattening the global-only settings for
the new server.

This was added in #11497, possibly
to correctly de-serialize an empty value (`{}`). But, this lead to a bug
where the configuration under the `settings` key was not being read for
global-only variant.

By using #[serde(default)], we ensure that the settings field in the
`GlobalOnly` variant is optional and that an empty JSON object `{}` is
correctly deserialized into `GlobalOnly` with a default `ClientSettings`
instance.

fixes: #11507 

## Test Plan

Update the snapshot and existing test case. Also, verify the following
settings in Neovim:

1. Nothing

```lua
ruff = {
  cmd = {
    '/Users/dhruv/work/astral/ruff/target/debug/ruff',
    'server',
    '--preview',
  },
}
```

2. Empty dictionary

```lua
ruff = {
  cmd = {
    '/Users/dhruv/work/astral/ruff/target/debug/ruff',
    'server',
    '--preview',
  },
  init_options = vim.empty_dict(),
}
```

3. Empty `settings`

```lua
ruff = {
  cmd = {
    '/Users/dhruv/work/astral/ruff/target/debug/ruff',
    'server',
    '--preview',
  },
  init_options = {
    settings = vim.empty_dict(),
  },
}
```

4. With some configuration:

```lua
ruff = {
  cmd = {
    '/Users/dhruv/work/astral/ruff/target/debug/ruff',
    'server',
    '--preview',
  },
  init_options = {
    settings = {
      configuration = '/tmp/ruff-repro/pyproject.toml',
    },
  },
}
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working server Related to the LSP server
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants