Commit graph

1103 commits

Author SHA1 Message Date
Lukas Wirth
a3910c6f14 syntax: Drop Parse on separate thread
Rowan's green nodes are super drop heavy and as lru eviction happens on cancellation this can block for quite some time, especially after cache priming
2025-11-17 11:19:43 +01:00
A4-Tacks
8549afe4a6
Add ide-assist: convert_range_for_to_while
Convert for each range into while loop.

```rust
fn foo() {
    $0for i in 3..7 {
        foo(i);
    }
}
```
->
```rust
fn foo() {
    let mut i = 3;
    while i < 7 {
        foo(i);
        i += 1;
    }
}
```
2025-11-04 13:31:41 +08:00
Johannes Altmanninger
70f972c2fd Fix rustfmt for files that use 2024-edition syntax
"cargo fmt" works fine but "rustfmt" fails to format some files.

	$ rustfmt crates/ide-db/src/search.rs
	error: let chains are only allowed in Rust 2024 or later
	   --> /home/johannes/git/rust-analyzer/crates/ide-db/src/search.rs:298:12
	    |
	298 |         if let &Definition::Module(module) = self
	    |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I guess I could work around this by setting my format command to
"cargo fmt -- $filename" instead of "rustfmt $filename".

But it'd be nice if this worked OOTB. Make it so by adding specifying
the edition in rustfmt.toml.  We already have several other places
specifying the edition.

changelog internal
2025-10-23 23:13:13 +02:00
Chayim Refael Friedman
7a7ab993bb
Revert "internal: Rewrite attribute handling" 2025-10-22 19:19:13 +03:00
Chayim Refael Friedman
455ca02f17 Rewrite attribute handling
Basically, we switch to expanding cfg_attr in AST form, filter irrelevant attributes from the item tree, and move hir-def attributes (non-item-tree) to be flag-based.

The main motivation is memory usage, although this also simplifies the code, and fixes some bugs around handling of `cfg_attr`s.
2025-10-22 11:47:01 +03:00
Chayim Refael Friedman
81e621af0b Improve fixture support
Support more features beside highlighting, and support items from minicore.
2025-10-16 22:06:16 +03:00
A4-Tacks
e4cceca607
Fix not applicable c-str and byte-str for raw_string
Example
---

Assist: `make_raw_string`

```rust
fn f() {
    let s = $0b"random\nstring";
}
```
->
```rust
fn f() {
    let s = br#"random
string"#;
}
```

---

Assist: `make_raw_string`

```rust
fn f() {
    let s = $0c"random\nstring";
}
```
->
```rust
fn f() {
    let s = cr#"random
string"#;
}
```

---

Assist: `add_hash`

```rust
fn f() {
    let s = $0cr"random string";
}
```
->
```rust
fn f() {
    let s = cr#"random string"#;
}
```

---

Assist: `remove_hash`

```rust
fn f() {
    let s = $0cr#"random string"#;
}
```
->
```rust
fn f() {
    let s = cr"random string";
}
```

---

Assist: `make_usual_string`

```rust
fn f() {
    let s = $0cr#"random string"#;
}
```
->
```rust
fn f() {
    let s = c"random string";
}
```
2025-10-10 19:04:48 +08:00
Chayim Refael Friedman
e3287fc878 Impl std::error::Error for SyntaxError 2025-09-30 15:40:54 +03:00
Chayim Refael Friedman
6da1ce7869
Merge pull request #20624 from A4-Tacks/fix-syn-lifetime-bounds
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
Fix LifetimeParam::lifetime_bounds invalid implement
2025-09-09 07:35:19 +00:00
A4-Tacks
080f2b3f71
Fix LifetimeParam::lifetime_bounds invalid implement
Lifetime node example:

```
LIFETIME_PARAM@15..21
  LIFETIME@15..17
    LIFETIME_IDENT@15..17 "'a"
  COLON@17..18 ":"
  WHITESPACE@18..19 " "
  TYPE_BOUND_LIST@19..21
    TYPE_BOUND@19..21
      LIFETIME@19..21
        LIFETIME_IDENT@19..21 "'b"
```
2025-09-09 15:22:12 +08:00
A4-Tacks
7e2dc40642
Improve make::struct_ field_list whitespace
Example
---
**Before this PR**:

```rust
struct Variant{
    field: u32
}
```

**After this PR**:

```rust
struct Variant {
    field: u32
}
```
2025-09-07 22:19:52 +08:00
Deadbeef
82f174fbd9 Merge Trait and TraitAlias handling 2025-08-13 15:28:08 +08:00
Hmikihiro
fcd4010b03 In extract_module.rs, generate ast::Module instead of String 2025-08-07 02:29:59 +09:00
Hmikihiro
c57a42acf3 remvoe add_attr edit_in_place.rs because it use ted. 2025-08-04 21:52:49 +09:00
Hmikihiro
1fea875fb1 Remove unused functions from edit_in_place 2025-08-03 19:40:54 +09:00
Hmikihiro
85f7112c0e Migrate generate_delegate_methods assist to use SyntaxEditor 2025-08-03 02:17:56 +09:00
Shoyu Vanilla (Flint)
68e7ec90bf
Merge pull request #20345 from Hmikihiro/Migrate_add_trait_assoc_items_to_impl
Some checks failed
metrics / build_metrics (push) Has been cancelled
rustdoc / rustdoc (push) Has been cancelled
metrics / other_metrics (diesel-1.4.8) (push) Has been cancelled
metrics / other_metrics (hyper-0.14.18) (push) Has been cancelled
metrics / other_metrics (ripgrep-13.0.0) (push) Has been cancelled
metrics / other_metrics (self) (push) Has been cancelled
metrics / other_metrics (webrender-2022) (push) Has been cancelled
metrics / generate_final_metrics (push) Has been cancelled
add `SyntaxEditor::delete_all` to migrate utils.rs `add_trait_assoc_items_to_impl`
2025-07-31 15:11:22 +00:00
Lukas Wirth
8ce30264c8 cargo clippy --fix 2025-07-31 10:55:10 +02:00
Hmikihiro
e600060680 add SyntaxEditor::delete_all to migrate utils.rs add_trait_assoc_items_to_impl 2025-07-30 23:53:05 +09:00
Hmikihiro
ec02abf97a add SyntaxFactory::record_expr to hide clone_for_update 2025-07-29 21:49:03 +09:00
Hayashi Mikihiro
82dfdacb78 Modify around add_trait_assoc_items_to_impl to migrate add_missing_impl_members
Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
2025-07-26 00:22:29 +09:00
Shoyu Vanilla (Flint)
fa64d3b720
Merge pull request #20281 from ChayimFriedman2/parse-hrtb-const
Some checks are pending
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
fix: Parse `for<'a> [const]`
2025-07-23 01:50:16 +00:00
Chayim Refael Friedman
c7ceb39f67 Parse for<'a> [const]
And also refactor parsing of HRTB.
2025-07-22 16:24:42 +03:00
Shoyu Vanilla (Flint)
bdfc7709bf
Merge pull request #20269 from Hmikihiro/migrate_indent_mapping
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
Migrate AstNodeEdit::Indent to SyntaxEditor
2025-07-22 04:07:47 +00:00
Hayashi Mikihiro
9cc03e01c5 migrate generate new 2025-07-21 17:22:03 +09:00
Hayashi Mikihiro
6f101d9cc7 Migrate AstNodeEdit 2025-07-21 15:26:48 +09:00
Hayashi Mikihiro
435b2962a0 remove remove_default 2025-07-13 02:03:56 +09:00
Shoyu Vanilla (Flint)
e9968fc555
Merge pull request #20210 from ChayimFriedman2/naked-asm-safe
fix: Inline asm fixes
2025-07-10 06:28:49 +00:00
Chayim Refael Friedman
95c04c4503 Make global_asm!() work
Because apparently, we were not accepting inline asm in item position, completely breaking it.
2025-07-09 18:55:27 +03:00
Chayim Refael Friedman
bd8087e86e Differentiate between asm!(), global_asm!() and naked_asm!(), and make only asm!() unsafe 2025-07-09 17:37:27 +03:00
Hayashi Mikihiro
c6ce2abd47 Migrate pull_assignment_up assist to SyntaxEditor
Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
2025-07-09 00:58:58 +09:00
Lukas Wirth
2c01609d6d minor: Handle match arm commas in make::match_arm
Co-authored-by: Giga Bowser <45986823+Giga-Bowser@users.noreply.github.com>
2025-07-04 11:08:28 +02:00
Hayashi Mikihiro
0b7ad9cd0f Migrate wrap_unwrap_cfg_attr assist to use SyntaxEditor
Signed-off-by: Hayashi Mikihiro <34ttrweoewiwe28@gmail.com>
2025-07-02 01:18:22 +09:00
Lukas Wirth
5924b38e3d Parse new const trait syntax 2025-06-26 11:08:30 +02:00
Lukas Wirth
70cbf8332a
Merge pull request #20012 from lnicola/bump-literal-escaper
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run
Update to literal-escaper 0.0.4
2025-06-24 08:21:36 +00:00
Chayim Refael Friedman
de312d0c71 Don't run doctests 2025-06-23 00:50:22 +03:00
Lukas Wirth
8661c59a7f
Merge pull request #19939 from ChayimFriedman2/fill-arms-self
feat: In "Fill match arms", allow users to prefer `Self` to the enum name when possible
2025-06-17 08:20:02 +00:00
Marijn Schouten
13a46eab7d update to literal-escaper 0.0.4 for better API without unreachable and faster string parsing 2025-06-16 15:12:24 +03:00
Lukas Wirth
23712aea06 cargo upgrade 2025-06-13 10:08:20 +02:00
Chayim Refael Friedman
4bcf03e28b Use stable AST IDs
Instead of simple numbering, we hash important bits, like the name of the item.

This will allow for much better incrementality, e.g. when you add an item. Currently, this invalidates the IDs of all following items, which invalidates pretty much everything.
2025-06-12 08:47:22 +03:00
Chayim Refael Friedman
25a7b2480e In "Fill match arms", allow users to prefer Self to the enum name when possible
But default to not to.

I chose to have a more generic config name because maybe other assists could also use the same approach.
2025-06-06 16:34:53 +03:00
Lukas Wirth
7c3de05e3a Give path segment type anchors their own grammar rule 2025-06-04 11:40:05 +02:00
Lukas Wirth
38bf4b1fe1 internal: Restructure some semantics APIs for virtual macro files 2025-05-30 22:03:04 +02:00
Lukas Wirth
1f0052a496 fix: Fix import insertion not being fully cfg aware 2025-05-29 14:55:09 +02:00
Lukas Wirth
751ca9ec0d feat: Desugar assist for let pat = expr?; -> let else 2025-05-28 11:12:28 +02:00
Laurențiu Nicola
9e86544698 Merge from rust-lang/rust 2025-05-20 10:01:00 +03:00
Stuart Cook
9f4e2cc51d
Rollup merge of #140035 - fee1-dead-contrib:push-oszwkkvmpkks, r=jieyouxu,wesleywiser
Implement RFC 3503: frontmatters

Tracking issue: #136889

Supercedes #137193. This implements [RFC 3503](https://github.com/rust-lang/rfcs/blob/master/text/3503-frontmatter.md).

This might break rust-analyzer. Will look into how to fix that.

Suggestions welcome for how to improve diagnostics.
2025-05-06 16:28:39 +10:00
Deadbeef
9fce1dfac5 Implement RFC 3503: frontmatters
Supercedes #137193
2025-05-05 23:10:08 +08:00
Lukas Wirth
f9c83edf12 fix: Fix move_bounds assists not working for lifetimes 2025-05-05 15:07:36 +02:00
Lukas Wirth
5d43e752ad refactor: Simplify macro call id construction 2025-05-02 17:26:48 +02:00