Commit graph

963 commits

Author SHA1 Message Date
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
Lukas Wirth
86658c66b4 Parse builtin#asm expressions 2024-09-04 14:09:03 +02:00
DropDemBits
12c62662aa
bundle old root into SyntaxEdit result
useful for `SourceChangeBuilder` so it can still perform a tree diff without having to store the old root separately
2024-09-03 11:20:23 -04:00
DropDemBits
69e8393963
misc fixes 2024-09-02 22:53:54 -04:00
DropDemBits
d929121f7b
handle replace_with_many and replace_all 2024-09-02 22:27:14 -04:00
DropDemBits
41dbaa415a
support replacing root node 2024-09-02 21:42:08 -04:00
DropDemBits
b565d8db74
properly sort changes by depth to sort between nodes that have the same start range 2024-09-02 21:34:00 -04:00
DropDemBits
5fe518361e
fix insert ranges not being excluded from disjointness 2024-09-02 20:45:57 -04:00
DropDemBits
21bb04d3a6
support insert{_all} 2024-09-02 19:11:39 -04:00
DropDemBits
3440408087
propagate annotations to mapped elements 2024-09-02 18:24:47 -04:00
DropDemBits
db649195e9
handle merging two syntax editors together 2024-09-02 00:09:30 -04:00
DropDemBits
883e429179
elaborate SyntaxEdit comments 2024-09-02 00:02:32 -04:00
DropDemBits
ad9595d729
wip: new syntax tree editor 2024-09-02 00:02:32 -04:00
Lukas Wirth
eb64cc8c35 Complete desugared and resugared async fn in trait impls 2024-09-01 11:22:50 +02:00
bors
0ad26e6025 Auto merge of #17941 - ChayimFriedman2:pre-closure-to-fn, r=Veykril
Preliminary work for #17940

I split the PR as requested, and made small commits.
2024-08-26 08:09:15 +00:00
Chayim Refael Friedman
21e6058ab7 Fix Return Type Syntax to include .. (i.e. method(..) and not method()) as specified in the RFC 2024-08-26 01:45:52 +03:00
Chayim Refael Friedman
52462ada22 Impl PartialEq and Eq for IndentLevel
We can impl PartialOrd and Ord too, but I didn't need that.
2024-08-24 23:46:32 +03:00
Chayim Refael Friedman
5c59a718c5 Provide impl From<ast::TypeOrConstParam> for ast::GenericParam 2024-08-24 23:46:32 +03:00
Chayim Refael Friedman
ddbb28daa0 Modify hacks::parse_expr_from_str() to take an edition too
This will be needed as we parse unknown identifiers and want to insert them into source code.
2024-08-24 23:46:32 +03:00
Chayim Refael Friedman
cc07652be5 Add gen modifier to functions
We don't yet lower or maybe even parse them, but blocks already have `gen`, so why not.
2024-08-24 23:46:32 +03:00
Shoyu Vanilla
95470c250a Pin rowan to 0.15.15 2024-08-17 21:35:07 +09:00
bors
c9ee892263 Auto merge of #17905 - ChayimFriedman2:edition-dependent-raw-keyword, r=Veykril
fix: Properly account for editions in names

This PR touches a lot of parts. But the main changes are changing `hir_expand::Name` to be raw edition-dependently and only when necessary (unrelated to how the user originally wrote the identifier), and changing `is_keyword()` and `is_raw_identifier()` to be edition-aware (this was done in #17896, but the FIXMEs were fixed here).

It is possible that I missed some cases, but most IDE parts should properly escape (or not escape) identifiers now.

The rules of thumb are:

 - If we show the identifier to the user, its rawness should be determined by the edition of the edited crate. This is nice for IDE features, but really important for changes we insert to the source code.
 - For tests, I chose `Edition::CURRENT` (so we only have to (maybe) update tests when an edition becomes stable, to avoid churn).
 - For debugging tools (helper methods and logs), I used `Edition::LATEST`.

Reviewing notes:

This is a really big PR but most of it is mechanical translation. I changed `Name` displayers to require an edition, and followed the compiler errors. Most methods just propagate the edition requirement. The interesting cases are mostly in `ide-assists`, as sometimes the correct crate to fetch the edition from requires awareness (there may be two). `ide-completions` and `ide-diagnostics` were solved pretty easily by introducing an edition field to their context. `ide` contains many features, for most of them it was propagated to the top level function and there the edition was fetched based on the file.

I also fixed all FIXMEs from #17896. Some required introducing an edition parameter (usually not for many methods after the changes to `Name`), some were changed to a new method `is_any_identifier()` because they really want any possible keyword.

Fixes #17895.
Fixes #17774.
2024-08-16 13:49:32 +00:00
Chayim Refael Friedman
9d3368f2c2 Properly account for editions in names
This PR touches a lot of parts. But the main changes are changing
`hir_expand::Name` to be raw edition-dependently and only when necessary
(unrelated to how the user originally wrote the identifier),
and changing `is_keyword()` and `is_raw_identifier()` to be edition-aware
(this was done in #17896, but the FIXMEs were fixed here).

It is possible that I missed some cases, but most IDE parts should properly
escape (or not escape) identifiers now.

The rules of thumb are:

 - If we show the identifier to the user, its rawness should be determined
   by the edition of the edited crate. This is nice for IDE features,
   but really important for changes we insert to the source code.
 - For tests, I chose `Edition::CURRENT` (so we only have to (maybe) update
   tests when an edition becomes stable, to avoid churn).
 - For debugging tools (helper methods and logs), I used `Edition::LATEST`.
2024-08-16 16:46:24 +03:00
bors
fc36e0ca16 Auto merge of #17907 - ChayimFriedman2:no-once_cell, r=Veykril
internal: Replace once_cell with std's recently stabilized OnceCell/Lock and LazyCell/Lock

This doesn't get rid of the once_cell dependency, unfortunately, since we have dependencies that use it, but it's a nice to do cleanup. And when our deps will eventually get rid of once_cell we will get rid of it for free.
2024-08-16 07:05:59 +00:00
Chayim Refael Friedman
955e609867 Replace once_cell with std's recently stabilized OnceCell/Lock and LazyCell/Lock
This doesn't get rid of the once_cell dependency, unfortunately, since we have dependencies that use it, but it's a nice to do cleanup. And when our deps will eventually get rid of once_cell we will get rid of it for free.
2024-08-16 09:53:37 +03:00
Lukas Wirth
f90bdfc13d internal: Properly check the edition for edition dependent syntax kinds 2024-08-15 15:57:47 +02:00
Vincent Esche
7dec7e92ea Replace [package.repository] = "…" of published crates with [package.repository.workspace] = true 2024-08-06 00:26:42 +02:00
Vincent Esche
f8de86b308 Apply Veykril's change suggestions 2024-08-06 00:25:02 +02:00
Vincent Esche
b5b0f4bc5a Replace "TBD" with more helpful desciptions in published crates' [package.description] fields 2024-08-06 00:25:02 +02:00
Lukas Wirth
758ad25229 internal: Remove AbsPathBuf::TryFrom impl that checks too many things at once 2024-08-02 11:08:19 +02:00
bors
0ba6f4eda0 Auto merge of #17676 - winstxnhdw:precise-capturing, r=Veykril
feat: add preliminary support for `+ use<..>` `precise_capturing` syntax

## Summary

This PR adds basic support for the following syntax.

```rs
fn captures<'a: 'a, 'b: 'b, T>() -> impl Sized + use<'b, T> {}
//                                  ~~~~~~~~~~~~~~~~~~~~~~~
//                          This opaque type does not capture `'a`.

fn outlives<'o, T: 'o>(_: T) {}

fn caller<'o, 'a, 'b: 'o, T: 'o>() {
    //        ~~
    //        ^ Note that we don't need `'a: 'o`.
    outlives::<'o>(captures::<'a, 'b, T>());
}
```

Related to #17598
2024-07-25 11:10:56 +00:00
Lukas Wirth
200a01adc4 Generate From impls for Any* nodes 2024-07-25 10:21:58 +02:00
winstxnhdw
d42e85758c fix: temporarily use ast::GenericParamList 2024-07-25 07:40:08 +01:00
Winston H.
5af51fa476
fix: use cannot have optional generics
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2024-07-24 10:42:20 +01:00
winstxnhdw
fa3484f39f feat: add use type bound grammar 2024-07-23 22:36:46 +01:00
bors
062822ce91 Auto merge of #17641 - nyurik:optimize-refs, r=Veykril
Avoid ref when using format! in compiler

Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing). Inlining format args prevents accidental `&` misuse.

See https://github.com/rust-lang/rust-clippy/issues/10851
2024-07-20 06:40:27 +00:00
Yuri Astrakhan
cc1aded86c Avoid ref when using format! in compiler
Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing). Inlining format args prevents accidental `&` misuse.
2024-07-19 14:41:59 -04:00
Lukas Wirth
92f5e806f1 Fix edition used for include macro parsing 2024-07-19 20:29:53 +02:00
Lukas Wirth
5264f86242 Encode edition within FileId in the hir layer 2024-07-18 08:49:10 +02:00
Lukas Wirth
b8cac1bb6b string is not a keyword 2024-07-17 11:11:57 +02:00
Lukas Wirth
7011094685 Add always disabled gen parse support 2024-07-17 10:49:12 +02:00
Lukas Wirth
983c9c122e Derive kinds information from ungrammar file 2024-07-17 10:04:45 +02:00
Lukas Wirth
2346a80ab4 Remove Name::to_smol_str 2024-07-16 12:43:58 +02:00
beetrees
d5db933f9d
Add f16 and f128 support 2024-07-10 10:43:14 +01:00
beetrees
320022622c
fix: Fix double rounding of f32 literals 2024-07-08 16:31:32 +01:00
Lukas Wirth
35aa238020 Inline all the things 2024-07-07 11:18:40 +02:00
Lukas Wirth
c08d419fba HasGenericArgs syntax trait 2024-07-07 11:18:28 +02:00
Lukas Wirth
ce5046be50 Run codegen commands as tests if their results are commited 2024-07-07 09:14:50 +02:00
Lukas Wirth
013b6a883f Fix up the syntax tree for macro 2.0 2024-07-03 10:41:19 +02:00
Lukas Wirth
21a3d01875 Remove inline rust_2018_idioms, unused_lifetimes lint warn, Cargo.toml already enforces this 2024-06-30 15:23:54 +02:00
davidsemakula
d6d45a23d3 fix: don't remove parentheses for calls of function-like pointers that are members of a struct or union 2024-06-21 17:57:53 +03:00
abdullathedruid
2592f3168f
Update lib.rs 2024-06-18 00:52:53 +01:00
Wilfred Hughes
27182bb96b chore: Prefer tracing span shorthand macros 2024-06-06 16:52:25 -07:00
bors
cb6b808185 Auto merge of #17315 - hamirmahal:style/simplify-string-interpolation, r=Veykril
style: simplify string interpolation
2024-06-03 12:29:27 +00:00
DropDemBits
a741bb2055
fix typos & formatting 2024-06-02 14:09:36 -04:00
DropDemBits
cf9401049c
Make extract_expressions_from_format_string only use snippets when available 2024-06-02 11:47:05 -04:00
DropDemBits
e989f22015
Add ast::Expr::parse 2024-06-02 11:17:52 -04:00
DropDemBits
c4573b26f6
minor: tidy up Parse a little bit
- Add doc comments to some `Parse` methods
- Uses `Parse::new` more
2024-06-02 11:10:39 -04:00
Hamir Mahal
7c34eb3880
style: simplify string interpolation 2024-05-30 16:18:49 -07:00
bors
e3e22c67e0 Auto merge of #17140 - harrysarson:harry-unused-self, r=Veykril
handle {self} when removing unused imports

Fixes #17139

On master

```rs
mod inner {
    pub struct X();
    pub struct Y();
}

mod z {
    use super::inner::{self, X}$0;

    fn f() {
        let y = inner::Y();
    }
}
```

becomes

```rs
mod inner {
    pub struct X();
    pub struct Y();
}

mod z {
    use super::inner:self;

    fn f() {
        let y = inner::Y();
    }
}
```

with this fix it instead becomes

```

```rs
mod inner {
    pub struct X();
    pub struct Y();
}

mod z {
    use super::inner;

    fn f() {
        let y = inner::Y();
    }
}
```
2024-05-23 08:30:10 +00:00
Lukas Wirth
7c6f31a45b Allow hir::Param to refer to other entity params aside from functions 2024-05-18 12:35:55 +02:00
bors
d28111dce8 Auto merge of #17224 - Veykril:lock-bump, r=Veykril
Bump Cargo.lock
2024-05-14 08:59:34 +00:00
Lukas Wirth
2a4be8d1f7 Bump Cargo.lock 2024-05-14 10:57:02 +02:00
Lukas Wirth
a39c0493a1 Render literal escaping errors in hovers 2024-05-13 12:51:57 +02:00
Lukas Wirth
e1aeed3aed Implement unsafe attribute parsing 2024-05-06 12:11:29 +02:00
Harry Sarson
a653ddf940
braces around {self} in UseTree are not unnecessary
Before this commit `UseTree::remove_unnecessary_braces` removed the braces
around `{self}` in `use x::y::{self};` but `use x::y::self;` is not valid
rust.
2024-04-30 18:17:32 +01:00
bors
4c08e2d32f Auto merge of #16938 - Nilstrieb:dont-panic-tests, r=Veykril
Implement `BeginPanic` handling in const eval

for #16935, needs some figuring out of how to write these tests correctly
2024-04-21 16:22:02 +00:00
roife
3e232bb78a fix: replace unescape fn with the one in ra-ap-rustc_lexer 2024-04-19 20:32:53 +08:00
Lukas Wirth
5df690e13f Fixup some issues with minicore 2024-04-18 12:20:54 +02:00
Lukas Wirth
a483d3bc37 internal: Thread edition through to parsing/tt-to-syntax-tree routines for macros 2024-04-14 16:02:38 +02:00
Lukas Wirth
83370fe5d7 Use Edition::CURRENT 2024-04-14 15:30:29 +02:00
Lukas Wirth
9c75e9fa7d Deduplicate Edition enum 2024-04-14 15:29:01 +02:00
Johann Hemmann
2cf5d8811a Raise edition one more level 2024-04-14 15:11:33 +02:00
Johann Hemmann
454e481422 Add edition to all parse functions of the parser crate 2024-04-14 15:07:43 +02:00
Lukas Wirth
b38d5394bb internal: Move grammar codegen into xtask 2024-03-19 10:57:53 +01:00
Lukas Wirth
4b679f90dd Generate AST in a more stable manner 2024-03-18 09:24:10 +01:00
Lukas Wirth
77607ab99a More precise highlighting rules for constant modifier 2024-03-17 11:26:05 +01:00
Lukas Wirth
c50c4f8bbb internal: Use assoc items as anchors for spans 2024-03-15 09:28:39 +01:00
Niklas Lindorfer
2a4ba4295b
fix: hide destructure_struct_binding assist if no public fields 2024-03-04 21:50:01 +00:00
Lukas Wirth
c3c9f5ffe1 internal: Compute syntax validation errors on demand 2024-03-04 12:06:15 +01:00
Lukas Wirth
4303e741de Cleanup 2024-03-04 11:10:06 +01:00
bors
4ef6a49b44 Auto merge of #16702 - Veykril:intra-doc-links-generic, r=Veykril
fix: Ignore generic arguments in intra doc link path resolution

Fixes https://github.com/rust-lang/rust-analyzer/issues/16699
2024-03-02 09:51:16 +00:00
Niklas Lindorfer
ed230048dc
Add destructure_struct_binding action
Separate into create and apply edit

Rename usages

Hacky name map

Add more tests

Handle non-exhaustive

Add some more TODOs

Private fields

Use todo

Nesting

Improve rest token generation

Cleanup

Doc -> regular comment

Support mut
2024-02-29 13:17:44 +00:00
Lukas Wirth
ab533d887d fix: Ignore generic arguments in intra doc link path resolution 2024-02-28 14:47:47 +01:00
Michael Goulet
36020bb512 Update grammar
Bounds are CONSTNESS ASYNCNESS POLARITY
2024-02-16 16:16:37 +00:00
DropDemBits
eb6d6ba17c
Migrate generate_trait_from_impl to mutable ast 2024-02-15 21:34:29 -05:00
DropDemBits
115646d7d5
Align set_visibility with the rest of the set_ edit-in-place methods 2024-02-15 20:40:14 -05:00
Maybe Waffle
e146139957 Add support for become expr/tail calls 2024-02-14 14:57:18 +00:00
Lukas Wirth
ed57008510 fix: Validate literals in proc-macro-srv FreeFunctions::literal_from_str 2024-02-13 12:33:51 +01:00
bors
925705e0c9 Auto merge of #16446 - Tyrubias:literal_from_str, r=Veykril
Implement `literal_from_str` for proc macro server

Closes #16233

Todos and unanswered questions:

- [x] Is this the correct approach? Can both the legacy and `rust_analyzer_span` servers depend on the `syntax` crate?
- [ ] How should we handle suffixes for string literals? It doesn't seem like `rust-analyzer` preservers suffix information after parsing.
- [x] Why are the `expect` tests failing? Specifically `test_fn_like_macro_clone_literals`
2024-02-13 10:41:36 +00:00
Victor Song
4923b8a74b Return Option<Parse<ast::Literal>> from ast::Literal::parse 2024-02-13 00:00:02 -06:00
Victor Song
1918f9b9e0 Address PR comments 2024-02-13 00:00:02 -06:00
Victor Song
6cd458f3d0 Move raw_delimiter_count to syntax crate 2024-02-13 00:00:02 -06:00
Chengxu Bian
ca64359945 remove eprintln! overwrite 2024-02-12 23:54:32 -05:00
Tavo Annus
a946970e2d Add quantified trees to reduce autocomplete options 2024-02-11 13:33:29 +02:00
Tetsuharu Ohzeki
81c35d1f56 syntax: Fix warnings about clippy str_to_string rule 2024-02-10 01:00:40 +09:00
Tetsuharu Ohzeki
2601d19bac clippy: Enable non_canonical_clone_impl rule 2024-02-09 22:37:42 +09:00
DropDemBits
e28f5514e1
Add AssocItemList::add_item_at_start
Needed to recreate the behavior of `generate_new` addding the `new` method at the start of the impl
2024-02-08 19:13:10 -05:00