888 Commits

Author SHA1 Message Date
Jane Lewis
77c93fd63c Bump version to 0.4.2 (#11151) 2024-04-25 17:31:38 +00:00
Ibraheem Ahmed
1c8849f9a8 Use Matchit to Resolve Per-File Settings (#11111)
## Summary

Continuation of https://github.com/astral-sh/ruff/pull/9444.

> When the formatter is fully cached, it turns out we actually spend
meaningful time mapping from file to `Settings` (since we use a
hierarchical approach to settings). Using `matchit` rather than
`BTreeMap` improves fully-cached performance by anywhere from 2-5%
depending on the project, and since these are all implementation details
of `Resolver`, it's minimally invasive.

`matchit` supports escaping routing characters so this change should now
be fully compatible.

## Test Plan

On my machine I'm seeing a ~3% improvement with this change.

```
hyperfine --warmup 20 -i "./target/release/main format ../airflow" "./target/release/ruff format ../airflow"
Benchmark 1: ./target/release/main format ../airflow
  Time (mean ± σ):      58.1 ms ±   1.4 ms    [User: 63.1 ms, System: 66.5 ms]
  Range (min … max):    56.1 ms …  62.9 ms    49 runs
 
Benchmark 2: ./target/release/ruff format ../airflow
  Time (mean ± σ):      56.6 ms ±   1.5 ms    [User: 57.8 ms, System: 67.7 ms]
  Range (min … max):    54.1 ms …  63.0 ms    51 runs
 
Summary
  ./target/release/ruff format ../airflow ran
    1.03 ± 0.04 times faster than ./target/release/main format ../airflow
```
2024-04-24 10:25:46 -04:00
Micha Reiser
92814fd99b Use crossbeam-channel instead of crossbeam (#11129) 2024-04-24 13:56:55 +00:00
Nolan
7c8c1c71a3 Implement hover menu support for ruff-server; Issue #10595 (#11096)
<!--
Thank you for contributing to Ruff! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title?
- Does this pull request include references to any relevant issues?
-->

## Summary

Add support for hover menu to ruff_server, as requested in
[10595](https://github.com/astral-sh/ruff/issues/10595).
Majority of new code is in hover.rs.
I reused the regex from ruff-lsp's implementation. Also reused the
format_rule_text function from ruff/src/commands/rule.rs
Added capability registration in server.rs, and added the handler to
api.rs.

## Test Plan

Tested in NVIM v0.10.0-dev-2582+g2a8cef6bd, configured with lspconfig
using the default options (other than cmd pointing to my test build,
with options "server" and "--preview"). OS: Ubuntu 24.04, kernel
6.8.0-22.

---------

Co-authored-by: Jane Lewis <me@jane.engineering>
2024-04-23 20:16:02 +00:00
Dhruv Manilawala
c30735d4a7 Add ExpressionContext for expression parsing (#11055)
## Summary

This PR adds a new `ExpressionContext` struct which is used in
expression parsing.

This solves the following problem:
1. Allowing starred expression with different precedence
2. Allowing yield expression in certain context
3. Remove ambiguity with `in` keyword when parsing a `for ... in`
statement

For context, (1) was solved by adding `parse_star_expression_list` and
`parse_star_expression_or_higher` in #10623, (2) was solved by by adding
`parse_yield_expression_or_else` in #10809, and (3) was fixed in #11009.
All of the mentioned functions have been removed in favor of the context
flags.

As mentioned in #11009, an ideal solution would be to implement an
expression context which is what this PR implements. This is passed
around as function parameter and the call stack is used to automatically
reset the context.

### Recovery

How should the parser recover if the target expression is invalid when
an expression can consume the `in` keyword?

1. Should the `in` keyword be part of the target expression?
2. Or, should the expression parsing stop as soon as `in` keyword is
encountered, no matter the expression?

For example:
```python
for yield x in y: ...

# Here, should this be parsed as
for (yield x) in (y): ...
# Or
for (yield x in y): ...
# where the `in iter` part is missing
```

Or, for binary expression parsing:
```python
for x or y in z: ...

# Should this be parsed as
for (x or y) in z: ...
# Or
for (x or y in z): ...
# where the `in iter` part is missing
```

This need not be solved now, but is very easy to change. For context
this PR does the following:
* For binary, comparison, and unary expressions, stop at `in`
* For lambda, yield expressions, consume the `in`

## Test Plan

1. Add test cases for the `for ... in` statement and verify the
snapshots
2. Make sure the existing test suite pass
3. Run the fuzzer for around 3000 generated source code
4. Run the updated logic on a dozen or so open source repositories
(codename "parser-checkouts")
2024-04-23 04:19:05 +00:00
renovate[bot]
0b92f450ca Update Rust crate codspeed-criterion-compat to v2.5.0 (#11087)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-22 08:33:05 +02:00
renovate[bot]
d3ed0ad68c Update Rust crate thiserror to v1.0.59 (#11080)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-22 08:31:51 +02:00
renovate[bot]
01678a990c Update Rust crate syn to v2.0.60 (#11079)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-22 08:31:33 +02:00
renovate[bot]
45692ce89f Update Rust crate quick-junit to 0.4.0 (#11084) 2024-04-22 07:13:09 +01:00
renovate[bot]
4246111f67 Update Rust crate proc-macro2 to v1.0.81 (#11076) 2024-04-22 07:10:37 +01:00
renovate[bot]
9924bd774a Update Rust crate serde to v1.0.198 (#11077) 2024-04-21 22:50:35 -05:00
renovate[bot]
fc7f07bca7 Update Rust crate serde_json to v1.0.116 (#11078) 2024-04-21 22:50:29 -05:00
Dhruv Manilawala
0ff25a540c Bump version to 0.4.1 (#11035)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-04-19 17:42:02 +05:30
Zanie Blue
e751b4ea82 Bump version to 0.4.0 (#11011)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
2024-04-18 19:10:28 +00:00
Dhruv Manilawala
13ffb5bc19 Replace LALRPOP parser with hand-written parser (#10036)
(Supersedes #9152, authored by @LaBatata101)

## Summary

This PR replaces the current parser generated from LALRPOP to a
hand-written recursive descent parser.

It also updates the grammar for [PEP
646](https://peps.python.org/pep-0646/) so that the parser outputs the
correct AST. For example, in `data[*x]`, the index expression is now a
tuple with a single starred expression instead of just a starred
expression.

Beyond the performance improvements, the parser is also error resilient
and can provide better error messages. The behavior as seen by any
downstream tools isn't changed. That is, the linter and formatter can
still assume that the parser will _stop_ at the first syntax error. This
will be updated in the following months.

For more details about the change here, refer to the PR corresponding to
the individual commits and the release blog post.

## Test Plan

Write _lots_ and _lots_ of tests for both valid and invalid syntax and
verify the output.

## Acknowledgements

- @MichaReiser for reviewing 100+ parser PRs and continuously providing
guidance throughout the project
- @LaBatata101 for initiating the transition to a hand-written parser in
#9152
- @addisoncrump for implementing the fuzzer which helped
[catch](https://github.com/astral-sh/ruff/pull/10903)
[a](https://github.com/astral-sh/ruff/pull/10910)
[lot](https://github.com/astral-sh/ruff/pull/10966)
[of](https://github.com/astral-sh/ruff/pull/10896)
[bugs](https://github.com/astral-sh/ruff/pull/10877)

---------

Co-authored-by: Victor Hugo Gomes <labatata101@linuxmail.org>
Co-authored-by: Micha Reiser <micha@reiser.io>
2024-04-18 17:57:39 +05:30
Jane Lewis
cffc55576f ruff server: Resolve configuration for each document individually (#10950)
## Summary

Configuration is no longer the property of a workspace but rather of
individual documents. Just like the Ruff CLI, each document is
configured based on the 'nearest' project configuration. See [the Ruff
documentation](https://docs.astral.sh/ruff/configuration/#config-file-discovery)
for more details.

To reduce the amount of times we resolve configuration for a file, we
have an index for each workspace that stores a reference-counted pointer
to a configuration for a given folder. If another file in the same
folder is opened, the configuration is simply re-used rather than us
re-resolving it.

## Guide for reviewing

The first commit is just the restructuring work, which adds some noise
to the diff. If you want to quickly understand what's actually changed,
I recommend looking at the two commits that come after it.
f7c073d441 makes configuration a property
of `DocumentController`/`DocumentRef`, moving it out of `Workspace`, and
it also sets up the `ConfigurationIndex`, though it doesn't implement
its key function, `get_or_insert`. In the commit after it,
fc35618f17, we implement `get_or_insert`.

## Test Plan

The best way to test this would be to ensure that the behavior matches
the Ruff CLI. Open a project with multiple configuration files (or add
them yourself), and then introduce problems in certain files that won't
show due to their configuration. Add those same problems to a section of
the project where those rules are run. Confirm that the lint rules are
run as expected with `ruff check`. Then, open your editor and confirm
that the diagnostics shown match the CLI output.

As an example - I have a workspace with two separate folders, `pandas`
and `scipy`. I created a `pyproject.toml` file in `pandas/pandas/io` and
a `ruff.toml` file in `pandas/pandas/api`. I changed the `select` and
`preview` settings in the sub-folder configuration files and confirmed
that these were reflected in the diagnostics. I also confirmed that this
did not change the diagnostics for the `scipy` folder whatsoever.
2024-04-16 18:15:02 +00:00
renovate[bot]
49d9ad4c7e Update Rust crate chrono to v0.4.38 (#10953)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-15 14:50:22 +02:00
renovate[bot]
cdbd754870 Update Rust crate syn to v2.0.59 (#10941) 2024-04-15 06:38:18 +01:00
renovate[bot]
91efca1837 Update Rust crate codspeed-criterion-compat to v2.4.1 (#10931) 2024-04-14 21:49:31 -04:00
renovate[bot]
f07af6fb63 Update Rust crate insta-cmd to 0.6.0 (#10937) 2024-04-14 21:48:46 -04:00
renovate[bot]
b11d17f65c Update Rust crate pep440_rs to 0.6.0 (#10938) 2024-04-14 21:48:37 -04:00
renovate[bot]
b4c7c55ddd Update Rust crate argfile to 0.2.0 (#10936) 2024-04-14 21:48:30 -04:00
renovate[bot]
0f01713257 Update Rust crate proc-macro2 to v1.0.80 (#10932) 2024-04-14 21:48:15 -04:00
renovate[bot]
ed9a92d915 Update Rust crate quote to v1.0.36 (#10933) 2024-04-14 21:48:09 -04:00
renovate[bot]
6da4ea6116 Update Rust crate anyhow to v1.0.82 (#10930) 2024-04-14 21:47:54 -04:00
Dhruv Manilawala
2e37cf6b3b Bump version to v0.3.7 (#10895) 2024-04-12 03:39:45 +00:00
Dhruv Manilawala
4e8a84617c Bump version to v0.3.6 (#10883)
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2024-04-11 15:53:01 +00:00
Charlie Marsh
ac14d187c6 Update clearscreen to v3.0.0 (#10869)
## Summary

Closes https://github.com/astral-sh/ruff/issues/10627.
2024-04-11 00:41:35 -04:00
renovate[bot]
a188ba5c26 chore(deps): update rust crate quick-junit to v0.3.6 (#10834)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-08 11:48:46 +01:00
renovate[bot]
a9ebfe6ec0 chore(deps): update rust crate libcst to v1.3.1 (#10824) 2024-04-07 22:20:48 -04:00
renovate[bot]
0a50874c01 chore(deps): update rust crate syn to v2.0.58 (#10823) 2024-04-07 22:20:40 -04:00
Boshen
d467aa78c2 Remove an unused dependency (#10747)
## Summary

Continuation of #10475, I improved [`cargo
shear`](https://github.com/Boshen/cargo-shear) even more.

We can put this in CI once I test it a bit more, given that [ignoring
false
positives](https://github.com/Boshen/cargo-shear?tab=readme-ov-file#ignore-false-positives)
has been implemented.

## Test Plan

`cargo check --all-features --all-targets`
2024-04-03 09:57:19 +01:00
renovate[bot]
6e1c061e5f chore(deps): update rust crate lsp-types to v0.95.1 (#10686)
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [lsp-types](https://togithub.com/gluon-lang/lsp-types) |
workspace.dependencies | patch | `0.95.0` -> `0.95.1` |

---

### Release Notes

<details>
<summary>gluon-lang/lsp-types (lsp-types)</summary>

###
[`v0.95.1`](https://togithub.com/gluon-lang/lsp-types/blob/HEAD/CHANGELOG.md#v0951-2024-03-18)

[Compare
Source](https://togithub.com/gluon-lang/lsp-types/compare/v0.95.0...v0.95.1)

##### v0.95.1 (2024-03-18)

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "on Monday" (UTC), Automerge - At any
time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/astral-sh/ruff).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4yNjkuMiIsInVwZGF0ZWRJblZlciI6IjM3LjI2OS4yIiwidGFyZ2V0QnJhbmNoIjoibWFpbiJ9-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-03 06:37:03 +00:00
renovate[bot]
b90e6df5cc chore(deps): update rust crate env_logger to 0.11.0 (#10700)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-02 15:03:54 +02:00
Charlie Marsh
200ebeebdc Bump version to v0.3.5 (#10717) 2024-04-01 13:15:32 -04:00
renovate[bot]
221b3236a8 chore(deps): update strum to 0.26.0 (#10715) 2024-04-01 16:06:51 +00:00
renovate[bot]
a0e1544848 chore(deps): update rust crate pep440_rs to 0.5.0 (#10703) 2024-04-01 16:02:18 +00:00
renovate[bot]
7042b9b16d fix(deps): update rust crate similar to v2.5.0 (#10711) 2024-04-01 11:54:58 -04:00
renovate[bot]
4047d456b6 chore(deps): update rust crate insta to v1.38.0 (#10701) 2024-04-01 15:44:30 +00:00
renovate[bot]
d021cac0c9 chore(deps): update rust crate tracing-tree to 0.3.0 (#10709)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-01 14:21:50 +01:00
renovate[bot]
46369d48fe chore(deps): update rust crate uuid to v1.8.0 (#10710)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-01 14:20:05 +01:00
renovate[bot]
20a2e25cb0 chore(deps): update rust crate serde_with to v3.7.0 (#10706) 2024-04-01 12:37:41 +00:00
renovate[bot]
a32e70d449 chore(deps): update rust crate insta-cmd to 0.5.0 (#10702) 2024-04-01 11:55:05 +00:00
renovate[bot]
76d0edbbaa chore(deps): update rust crate toml to v0.8.12 (#10696) 2024-04-01 11:53:43 +00:00
renovate[bot]
d7a6978e05 chore(deps): update rust crate syn to v2.0.57 (#10694)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-01 11:24:48 +00:00
renovate[bot]
786ff403b1 chore(deps): update rust crate serde_json to v1.0.115 (#10693)
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
2024-04-01 11:24:15 +00:00
renovate[bot]
b9dfa7845f chore(deps): update rust crate memchr to v2.7.2 (#10688) 2024-04-01 08:25:05 +01:00
renovate[bot]
090f6580d3 Update rust crate regex to v1.10.4 (#10689) 2024-04-01 08:24:13 +01:00
renovate[bot]
eb884c8f76 chore(deps): update rust crate indoc to v2.0.5 (#10685) 2024-04-01 01:10:27 +00:00
renovate[bot]
9f2127bf04 Update rust crate clap to v4.5.4 (#10684) 2024-04-01 01:16:02 +01:00