Use real file path when available in ruff server (#11800)

## Summary

As-is, we're using the URL path for all files, leading us to use paths
like:

```
/c%3A/Users/crmar/workspace/fastapi/tests/main.py
```

This doesn't match against per-file ignores and other patterns in Ruff
configuration.

This PR modifies the LSP to use the real file path if available, and the
virtual file path if not.

Closes https://github.com/astral-sh/ruff/issues/11751.

## Test Plan

Ran the LSP on Windows. In the FastAPI repo, added:

```toml
[tool.ruff.lint.per-file-ignores]
"tests/**/*.py" = ["F401"]
```

And verified that an unused import was ignored in `tests` after this
change, but not before.
This commit is contained in:
Charlie Marsh 2024-06-07 22:48:53 -07:00 committed by GitHub
parent 32ca704956
commit ee1621b2f9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 13 additions and 9 deletions

View file

@ -113,7 +113,7 @@ pub(crate) fn check(query: &DocumentQuery, encoding: PositionEncoding) -> Diagno
// Generate checks.
let LinterResult { data, .. } = check_path(
query.virtual_file_path(),
&query.virtual_file_path(),
package,
&locator,
&stylist,
@ -127,7 +127,7 @@ pub(crate) fn check(query: &DocumentQuery, encoding: PositionEncoding) -> Diagno
);
let noqa_edits = generate_noqa_edits(
query.virtual_file_path(),
&query.virtual_file_path(),
data.as_slice(),
&locator,
parsed.comment_ranges(),