Commit graph

960 commits

Author SHA1 Message Date
Giga Bowser
27a2f9d594 minor: Add item_const constructor to SyntaxFactory 2024-12-11 09:52:03 -05:00
Lukas Wirth
41f3319173
Merge pull request #18458 from Giga-Bowser/master
feat: Add diagnostic fix to remove unnecessary wrapper in type mismatch
2024-12-11 07:09:15 +00:00
Giga Bowser
547f75a2ce minor: Migrate generate_enum_variant to SyntaxEditor 2024-12-10 13:11:33 -05:00
Giga Bowser
21b376583a minor: Add ty_infer constructor to SyntaxFactory 2024-12-10 12:33:32 -05:00
Giga Bowser
d7d68310c0 minor: Add whitespace constructor to SyntaxFactory 2024-12-10 12:25:13 -05:00
Giga Bowser
c70bf568bb minor: Add item_enum constructor to SyntaxFactory
I recursively added all constructors it depends on. I also changed the old `make::` constructors to support more of the grammar.
2024-12-10 11:12:44 -05:00
Giga Bowser
68b85ce66f minor: Migrate remove_unnecessary_wrapper to SyntaxEditor 2024-12-09 21:16:31 -05:00
Giga Bowser
59cd717602 fix: Handle the final statement in SyntaxFactory::block_expr properly
This caused a bug that was rather tricky to hunt down!
2024-12-09 21:15:15 -05:00
Giga Bowser
e66b4f336d fix: Map new replacement nodes to their mutable equivalents in SyntaxEditor 2024-12-08 15:55:34 -05:00
Giga Bowser
8fd7790eb5 minor: Add token_tree constructor to SyntaxFactory 2024-12-06 10:03:09 -05:00
Giga Bowser
fbb392062a minor: Add expr_bin constructor to SyntaxFactory 2024-12-06 10:02:34 -05:00
Giga Bowser
6406048626 minor: Add token constructor to SyntaxFactory 2024-12-06 10:02:34 -05:00
Giga Bowser
5eb8affdc5 fix: Don't produce ChangedAncestor for SyntaxTokens 2024-12-06 10:01:34 -05:00
Giga Bowser
ff1124918e fix: Properly determine SyntaxEditor replacement intersection
Bordering replacements should not be considered intersecting
2024-12-06 10:01:34 -05:00
Lukas Wirth
4b350f2f11
Merge pull request #18551 from ShoyuVanilla/migrate-turbofish-assist
Migrate `add_turbo_fish` to `SyntaxEditor`
2024-12-06 13:44:54 +00:00
David Barsky
2fd06545a6
Merge pull request #18483 from tareknaser/syntax_factory_introduce_named_generic
Migrate `introduce_named_generic` Assist to Use `SyntaxFactory`
2024-12-05 18:42:27 +00:00
Tarek
8954a7f9e9
fix: rename syntax_editor_add_generic_param to add_generic_param
Signed-off-by: Tarek <tareknaser360@gmail.com>
2024-12-05 13:50:43 +02:00
Tarek
9157761f5d
refactor: move editing for ast using SyntaxEditor to a separate file
Signed-off-by: Tarek <tareknaser360@gmail.com>
2024-12-04 14:51:48 +02:00
Tarek
2fb563f192 fix: refactor introduce_named_generic assist
Signed-off-by: Tarek <tareknaser360@gmail.com>
2024-12-04 14:50:03 +02:00
Tarek
5aaffe6dc9 fix: correct token type for closing angle bracket
Signed-off-by: Tarek <tareknaser360@gmail.com>
2024-12-04 14:50:03 +02:00
Tarek
70ef2f23c2 fix: refactor syntax_editor_add_generic_param
Signed-off-by: Tarek <tareknaser360@gmail.com>
2024-12-04 14:50:03 +02:00
Tarek
54f7ed13f5 fix: refactor syntax_editor_add_generic_param to handle adding new generic parameters
Signed-off-by: Tarek <tareknaser360@gmail.com>
2024-12-04 14:50:03 +02:00
Tarek
98e10d76ca fix: refactor syntax_editor_add_generic_param to handle new generic parameters
Signed-off-by: Tarek <tareknaser360@gmail.com>
2024-12-04 14:50:03 +02:00
Tarek
0990d5956d fix: implement syntax_editor_create_generic_param_list
Signed-off-by: Tarek <tareknaser360@gmail.com>
2024-12-04 14:50:03 +02:00
Tarek
642d4f3385 define syntax_editor_add_generic_param
Signed-off-by: Tarek <tareknaser360@gmail.com>
2024-12-04 14:50:03 +02:00
Tarek
1400aec433 feat: migrate introduce_named_generic assist to use SyntaxFactory
Signed-off-by: Tarek <tareknaser360@gmail.com>
2024-12-04 14:50:03 +02:00
Chayim Refael Friedman
5f25ae3d1b Lay the foundation for diagnostics in ty lowering, and implement a first diagnostic
The diagnostic implemented is a simple one (E0109). It serves as a test for the new foundation.

This commit only implements diagnostics for type in bodies and body-carrying signatures; the next commit will include diagnostics in the rest of the things.

Also fix one weird bug that was detected when implementing this that caused `Fn::(A, B) -> C` (which is a valid, if bizarre, alternative syntax to `Fn(A, B) -> C` to lower incorrectly.

And also fix a maybe-bug where parentheses were sneaked into a code string needlessly; this was not detected until now because the parentheses were removed (by the make-AST family API), but with a change in this commit they are now inserted. So fix that too.
2024-12-04 14:22:56 +02:00
Lukas Wirth
65c0b29720 Fix parsing of parenthesized type args and RTN 2024-12-04 11:48:47 +01:00
Shoyu Vanilla
6aa5ea5411 Migrate add_turbo_fish to SyntaxEditor 2024-11-26 01:47:15 +09:00
Lukas Wirth
bb3239d415
Merge pull request #18385 from Giga-Bowser/master
feat: Add assist to generate a type alias for a function
2024-10-30 09:36:55 +00:00
Lukas Wirth
64f56f458f Move text-edit into ide-db 2024-10-28 14:37:41 +01:00
Chayim Refael Friedman
e12a001b55 Put leading | in patterns under OrPat
Previously it was one level above, and that caused problems with macros that expand to it, because macros expect to get only one top-level node.
2024-10-27 13:11:38 +02:00
Giga Bowser
a87e1aad81 Add ty_fn_ptr function to create function pointer type 2024-10-24 17:46:14 -04:00
Lukas Wirth
c286786888
Merge pull request #18254 from ChayimFriedman2/fix-mut
fix: Nail destructuring assignment once and for all
2024-10-22 17:40:52 +00:00
Lukas Wirth
95298a2e61 fix: Fix incorrect parsing of use bounds
Also lower them a bit more
2024-10-22 13:34:26 +02:00
Lukas Wirth
d878b8caad fix: Fix token downmapping failing for include! inputs 2024-10-21 17:22:18 +02:00
Chayim Refael Friedman
61f162a43d Handle destructuring assignments uniformly
Instead of lowering them to `<expr> = <expr>`, then hacking on-demand to resolve them, we lower them to `<pat> = <expr>`, and use the pattern infrastructure to handle them. It turns out, destructuring assignments are surprisingly similar to pattern bindings, and so only minor modifications are needed.

This fixes few bugs that arose because of the non-uniform handling (for example, MIR lowering not handling slice and record patterns, and closure capture calculation not handling destructuring assignments at all), and furthermore, guarantees we won't have such bugs in the future, since the programmer will always have to explicitly handle `Expr::Assignment`.

Tests don't pass yet; that's because the generated patterns do not exist in the source map. The next commit will fix that.
2024-10-20 19:09:51 +03:00
roife
9f1e450c4f feat: initial support for safe_kw in extern blocks 2024-10-20 17:12:52 +08:00
Noah Bright
4255cae1bb Rename object_safety to dyn_compatibility
Up to a trait implemented by another package, linking to
$CARGO_HOME/registry/cache/index.crates.io-6f17d22bba15001f/
2024-09-29 07:26:45 -04:00
DropDemBits
05b48e4005
internal: Add SyntaxFactory to ease generating nodes with syntax mappings 2024-09-26 16:28:48 -04:00
bors
6dad8c5528 Auto merge of #18146 - ChayimFriedman2:allow-comment, r=Veykril
fix: Remove check that text of `parse_expr_from_str()` matches the produced parsed tree

This check is incorrect when we have comments and whitespace in the text.

We can strip comments, but then we still have whitespace, which we cannot strip without changing meaning for the parser. So instead I opt to remove the check, and wrap the expression in parentheses (asserting what produced is a parenthesized expression) to strengthen verification.

Fixes #18144.
2024-09-19 13:27:21 +00:00
Chayim Refael Friedman
9ef460ba2d Remove check that text of parse_expr_from_str() matches the produced parsed tree
This check is incorrect when we have comments and whitespace in the text.

We can strip comments, but then we still have whitespace, which we cannot strip without changing meaning for the parser. So instead I opt to remove the check, and wrap the expression in parentheses (asserting what produced is a parenthesized expression) to strengthen verification.
2024-09-19 14:18:07 +03:00
Chayim Refael Friedman
cfb701ac78 Get rid of $crate in expansions shown to the user
Be it "Expand Macro Recursively", "Inline macro" or few other things.

We replace it with the crate name, as should've always been.
2024-09-18 18:30:59 +03:00
bors
fd243cd0fb Auto merge of #18099 - ChayimFriedman2:diag-only-necessary, r=Veykril
Use more correct handling of lint attributes

The previous analysis was top-down, and worked on a single file (expanding macros). The new analysis is bottom-up, starting from the diagnostics and climbing up the syntax and module tree.

While this is more efficient (and in fact, efficiency was the motivating reason to work on this), unfortunately the code was already fast enough. But luckily, it also fixes a correctness problem: outline parent modules' attributes were not respected for the previous analysis. Case lints specifically did their own analysis to accommodate that, but it was limited to only them. The new analysis works on all kinds of lints, present and future.

It was basically impossible to fix the old analysis without rewriting it because navigating the module hierarchy must come bottom-up, and if we already have a bottom-up analysis (including syntax analysis because modules can be nested in other syntax elements, including macros), it makes sense to use only this kind of analysis.

Few other bugs (not fundamental to the previous analysis) are also fixed, e.g. overwriting of lint levels (i.e. `#[allow(lint)] mod foo { #[warn(lint)] mod bar; }`.

After this PR is merged I intend to work on an editor command that does workspace-wide diagnostics analysis (that is, `rust-analyzer diagnostics` but from your editor and without having to spawn a new process, which will have to analyze the workspace from scratch). This can be useful to users who do not want to enable check on save because of its overhead, but want to see workspace wide diagnostics from r-a (or to maintainers of rust-analyzer).

Closes #18086.
Closes #18081.
Fixes #18056.
2024-09-12 12:39:27 +00:00
Chayim Refael Friedman
4eb19df5e9 Use more correct handling of lint attributes
The previous analysis was top-down, and worked on a single file (expanding macros). The new analysis is bottom-up, starting from the diagnostics and climbing up the syntax and module tree.

While this is more efficient (and in fact, efficiency was the motivating reason to work on this), unfortunately the code was already fast enough. But luckily, it also fixes a correctness problem: outline parent modules' attributes were not respected for the previous analysis. Case lints specifically did their own analysis to accommodate that, but it was limited to only them. The new analysis works on all kinds of lints, present and future.

It was basically impossible to fix the old analysis without rewriting it because navigating the module hierarchy must come bottom-up, and if we already have a bottom-up analysis (including syntax analysis because modules can be nested in other syntax elements, including macros), it makes sense to use only this kind of analysis.

Few other bugs (not fundamental ti the previous analysis) are also fixed, e.g. overwriting of lint levels (i.e. `#[allow(lint)] mod foo { #[warn(lint)] mod bar; }`.
2024-09-12 15:24:38 +03:00
bors
a91ca0e2fc Auto merge of #18038 - roife:fix-issue-18034, r=Veykril
feat: generate names for tuple-struct in add-missing-match-arms

fix #18034.

This PR includes the following enhancement:

- Introduced a `NameGenerator` in `suggest_name`, which implements an automatic renaming algorithm to avoid name conflicts. Here are a few examples:

```rust
let mut generator = NameGenerator::new();
assert_eq!(generator.suggest_name("a"), "a");
assert_eq!(generator.suggest_name("a"), "a1");
assert_eq!(generator.suggest_name("a"), "a2");

assert_eq!(generator.suggest_name("b"), "b");
assert_eq!(generator.suggest_name("b"), "b1");
assert_eq!(generator.suggest_name("b2"), "b2");
assert_eq!(generator.suggest_name("b"), "b3");
assert_eq!(generator.suggest_name("b"), "b4");
assert_eq!(generator.suggest_name("b3"), "b5");
```

- Updated existing testcases in ide-assists for the new `NameGenerator` (only modified generated names).
- Generate names for tuple structs instead of using wildcard patterns in `add-missing-match-arms`.
2024-09-12 08:21:37 +00:00
bors
f13c776361 Auto merge of #18032 - DropDemBits:sed-tree-edits, r=davidbarsky
internal: Add preliminary `SyntaxEditor` functionality

Related to #15710

Implements a `SyntaxEditor` interface to abstract over the details of modifying syntax trees, to both simplify creating new code fixes and code actions, as well as start on the path of getting rid of mutable syntax nodes.

`SyntaxEditor` relies on `SyntaxMappingBuilder`s to feed in the correct information to map AST nodes created by `make` constructors, as `make` constructors do not guarantee that node identity is preserved. This is to paper over the fact that `make` constructors simply re-parse text input instead of building AST nodes from the ground up and re-using the provided syntax nodes.

`SyntaxAnnotation`s are used to find where syntax elements have ended up after edits are applied. This is primarily useful for the `add_{placeholder,tabstop}` set of methods on `SourceChangeBuilder`, as that currently relies on the nodes provided being in the final syntax tree.

Eventually, the goal should be to move this into the `rowan` crate when we move away from mutable syntax nodes, but for now it'll stay in the `syntax` crate.

---

Closes #14921 as `SyntaxEditor` ensures that all replace changes are disjoint
Closes #9649 by implementing `SyntaxAnnotation`s
2024-09-10 14:13:08 +00:00
roife
825dec8108 refactor: introduce NameGenerator in suggest_name 2024-09-10 00:30:46 +08:00
Lukas Wirth
811905fce8 Give InlineAsmOperand a HIR representation 2024-09-05 12:40:48 +02:00
Lukas Wirth
3b11ff8c4d Lower asm expressions 2024-09-05 09:59:08 +02:00