ruff/crates/ruff_server/src
Dhruv Manilawala 1f82731856
Use CWD to resolve settings from ruff.configuration (#14352)
## Summary

This PR fixes a bug in the Ruff language server where the
editor-specified configuration was resolved relative to the
configuration directory and not the current working directory.

The existing behavior is confusing given that this config file is
specified by the user and is not _discovered_ by Ruff itself. The
behavior of resolving this configuration file should be similar to that
of the `--config` flag on the command-line which uses the current
working directory:
3210f1a23b/crates/ruff/src/resolve.rs (L34-L48)

This creates problems where certain configuration options doesn't work
because the paths resolved in that case are relative to the
configuration directory and not the current working directory in which
the editor is expected to be in. For example, the
`lint.per-file-ignores` doesn't work as mentioned in the linked issue
along with `exclude`, `extend-exclude`, etc.

fixes: #14282 

## Test Plan

Using the following directory tree structure:
```
.
├── .config
│   └── ruff.toml
└── src
    └── migrations
        └── versions
            └── a.py
```

where, the `ruff.toml` is:
```toml
# 1. Comment this out to test `per-file-ignores`
extend-exclude = ["**/versions/*.py"]

[lint]
select = ["D"]

# 2. Comment this out to test `extend-exclude`
[lint.per-file-ignores]
"**/versions/*.py" = ["D"]

# 3. Comment both `per-file-ignores` and `extend-exclude` to test selection works
```

And, the content of `a.py`:
```py
"""Test"""
```

And, the VS Code settings:
```jsonc
{
  "ruff.nativeServer": "on",
  "ruff.path": ["/Users/dhruv/work/astral/ruff/target/debug/ruff"],
  // For single-file mode where current working directory is `/`
  // "ruff.configuration": "/tmp/ruff-repro/.config/ruff.toml",
  // When a workspace is opened containing this path
  "ruff.configuration": "./.config/ruff.toml",
  "ruff.trace.server": "messages",
  "ruff.logLevel": "trace"
}
```

I also tested out just opening the file in single-file mode where the
current working directory is `/` in VS Code. Here, the
`ruff.configuration` needs to be updated to use absolute path as shown
in the above VS Code settings.
2024-11-15 13:45:00 +05:30
..
edit Fix server panic when undoing an edit (#14010) 2024-11-01 08:16:53 +01:00
server Avoid indexing the workspace for single-file mode (#13770) 2024-10-18 10:51:43 +05:30
session Use CWD to resolve settings from ruff.configuration (#14352) 2024-11-15 13:45:00 +05:30
edit.rs Add support for extensionless Python files for server (#13326) 2024-09-12 00:35:26 +05:30
fix.rs Detect empty implicit namespace packages (#14236) 2024-11-09 22:03:34 -05:00
format.rs ruff server: Formatting a document with syntax problems no longer spams a visible error popup (#11745) 2024-06-04 17:18:21 -07:00
lib.rs Avoid indexing the workspace for single-file mode (#13770) 2024-10-18 10:51:43 +05:30
lint.rs Detect empty implicit namespace packages (#14236) 2024-11-09 22:03:34 -05:00
message.rs Ignore non-file workspace URL (#12725) 2024-08-07 09:15:55 +00:00
resolve.rs Add support for extensionless Python files for server (#13326) 2024-09-12 00:35:26 +05:30
server.rs Upgrade to Rust 1.82 (#13816) 2024-10-19 16:05:50 +02:00
session.rs Avoid indexing the workspace for single-file mode (#13770) 2024-10-18 10:51:43 +05:30
trace.rs Use $/logTrace for server trace logs in Zed and VS Code (#12564) 2024-07-30 08:32:20 +05:30