Commit graph

83 commits

Author SHA1 Message Date
bors
855cd5c280 Auto merge of #13418 - lnicola:bump-deps, r=lnicola
Bump deps
2022-10-15 11:27:12 +00:00
Laurențiu Nicola
cbce0cda08 Bump anyhow, arbitrary, itertools, semver, serde 2022-10-15 12:52:34 +03:00
btwotwo
2b2b9f8c73
Formatting 2022-10-11 19:53:22 +02:00
btwotwo
a807cc3afb
Rename get_outer_macro to macro_call_for_string_token 2022-10-11 19:28:42 +02:00
Laurențiu Nicola
df7d39b2ed Bump once_cell 2022-10-08 21:25:11 +03:00
btwotwo
f458ea15d6
Make helper method less specific 2022-10-06 21:34:19 +02:00
btwotwo
8a92910f97
Formatting 2022-10-06 16:53:17 +02:00
btwotwo
386f46a5a1
Use helper method in is_format_string 2022-10-06 16:32:21 +02:00
btwotwo
08b0c92105
Add helper method to get a macro name from passed string 2022-10-06 16:32:19 +02:00
bors
817a6a8609 Auto merge of #12966 - OleStrohm:master, r=Veykril
feat: Display the value of enum variant on hover

fixes #12955

This PR adds const eval support for enums, as well as showing their value on hover, just as consts currently have.

I developed these two things at the same time, but I've realized now that they are separate. However since the hover is just a 10 line change (not including tests), I figured I may as well put them in the same PR. Though if you want them split up into "enum const eval support"  and "show enum variant value on hover", I think that's reasonable too.

Since this adds const eval support for enums this also allows consts that reference enums to have their values computed now too.

The const evaluation itself is quite rudimentary, it doesn't keep track of the actual type of the enum, but it turns out that Rust doesn't actually either, and `E::A as u8` is valid regardless of the `repr` on `E`.

It also doesn't really care about what expression the enum variant contains, it could for example be a string, despite that not being allowed, but I guess it's up to the `cargo check` diagnostics to inform of such issues anyway?
2022-09-20 14:01:16 +00:00
Lukas Wirth
b73fa0be9c Use memmem when searching for usages in ide-db 2022-09-16 16:26:54 +02:00
bors
125d43cb2c Auto merge of #13227 - Veykril:core-pref, r=Veykril
Restructure `find_path` into a separate functions for modules and non-module items

Follow up to https://github.com/rust-lang/rust-analyzer/pull/13212
Also renames `prefer_core` imports config to `prefer_no_std` and changes the behavior of no_std path searching by preferring `core` paths `over` alloc

This PR turned into a slight rewrite, so it unfortunately does a few more things that I initially planned to (including a bug fix for enum variant paths)
2022-09-13 13:16:57 +00:00
Lukas Wirth
a8ecaa1979 Restructure find_path into a separate functions for modules and non-module items
Also renames `prefer_core` imports config to `prefer_no_std` and changes the behavior of no_std path searching by preferring `core` paths `over` alloc
2022-09-13 15:15:27 +02:00
Lukas Wirth
cadb01c315 Move reference imports filtering into to_proto layer 2022-09-13 14:58:50 +02:00
OleStrohm
997fc46efa Implemented basic enum const eval 2022-09-12 20:19:13 +01:00
bors
f64c95600c Auto merge of #13216 - DesmondWillowbrook:move_format_string_arg, r=DesmondWillowbrook
New assist: move_format_string_arg

The name might need some improving.

```rust
fn main() {
    print!("{x + 1}");
}
```
to
```rust
fn main() {
    print!("{}"$0, x + 1);
}
```

fixes #13180

ref to #5988 for similar work

* extracted `format_like`'s parser to it's own module in `ide-db`
* reworked the parser's API to be more direct
* added assist to extract expressions in format args
2022-09-12 15:50:42 +00:00
Kartavya Vashishtha
fb5ae9906b
suggest ExtractRefactor if no expressions found
Added `Ident` variant to arg enum.
2022-09-11 10:39:25 +05:30
Kartavya Vashishtha
cc7200891b
new lint: move_format_string_arg
The name might need some improving.

extract format_like's parser to it's own module in ide-db

reworked the parser's API to be more direct

added assist to extract expressions in format args
2022-09-10 20:13:46 +05:30
Kartavya Vashishtha
2584d48508
wip 2022-09-10 20:13:46 +05:30
Lukas Wirth
7d19971666 Add config to unconditionally prefer core imports over std
Fixes https://github.com/rust-lang/rust-analyzer/issues/12979
2022-09-09 20:04:56 +02:00
bors
5be2e6574d Auto merge of #13185 - ChayimFriedman2:insert-ws-in-static-const-macro, r=Veykril
fix: Insert whitespaces into static & const bodies if they are expanded from macro on hover

Partially fixes #13143.

To resolve the other part we need to expand macros in unevaluated static & const bodies, and I'm not sure we want to. If for example it includes a call to `assert!()`, expanding it will lead to worse hover.
2022-09-05 11:10:40 +00:00
bors
4790916876 Auto merge of #13139 - Austaras:enum, r=Veykril
Suggest struct when completing enum

closes #13107
2022-09-05 10:59:38 +00:00
austaras
748567cba5 complete full struct in enum varaint 2022-09-05 03:36:14 +08:00
Chayim Refael Friedman
26b5f1f92f Do not insert a newline after ; if the next token is a }
This creates double newline.
2022-09-04 14:33:15 +00:00
ice1000
a695e900f6 Create trait Removable, replace ted APIs with builder APIs 2022-09-02 21:18:36 +00:00
Lukas Wirth
192a79c235 Remove hir::Expr::MacroStmts
This hir expression isn't needed and only existed as it was simpler to
deal with at first as it gave us a direct mapping for the ast version of
the same construct. This PR removes it, properly handling the statements
that are introduced by macro call expressions.
2022-08-31 16:58:11 +02:00
Lukas Wirth
d025c5d8d6 Make use of NoHash hashing for FileId and CrateId 2022-08-25 20:41:49 +02:00
bors
82ff740501 Auto merge of #13044 - dzvon:fix-typo, r=Veykril
fix: a bunch of typos

This PR will fix some typos detected by [typos].

There are also some other typos in the function names, variable names, and file
names, which I leave as they are. I'm more certain that typos in comments
should be fixed.

[typos]: https://github.com/crate-ci/typos
2022-08-17 14:59:02 +00:00
Dezhi Wu
23747419ca fix: a bunch of typos
This PR will fix some typos detected by [typos].

There are also some other typos in the function names, variable names, and file
names, which I leave as they are. I'm more certain that typos in comments
should be fixed.

[typos]: https://github.com/crate-ci/typos
2022-08-17 21:44:58 +08:00
bors
d6412b5866 Auto merge of #13034 - lowr:fix/regression-from-12993, r=lowr
fix: escape keywords used as names in earlier editions

Fixes #13030

There are keywords in Rust 2018+ that you can use as names without escaping when your crate is in Rust 2015 e.g. "try". We need to be consistent on how to keep track of the names regardless of how they are actually written in each crate. This patch attempts at it by taking such names into account and storing them uniformly in their escaped form.
2022-08-17 09:55:14 +00:00
Ryo Yoshida
a3409c3a83
fix: escape keywords used as names in earlier editions 2022-08-17 18:46:17 +09:00
Lukas Wirth
557c5b4dc5 minor: Change tracing event level in apply_change 2022-08-17 09:32:25 +02:00
KaDiWa
232176b46a
remove imports that are also in edition 2021's prelude 2022-08-09 01:16:32 +02:00
bors
3805067bf5 Auto merge of #12905 - HKalbasi:master, r=Veykril
Generate rust type from json

fix #10118

Should this be a diagnostic? I made it a diagnostic because of issue label.
2022-08-08 11:46:22 +00:00
hkalbasi
851f6db7f7 Import serde derives on converting json to struct 2022-08-06 20:12:21 +04:30
Lukas Wirth
d6e78b04d0 feat: Handle operators like their trait functions in the IDE 2022-08-05 14:16:36 +02:00
Jonas Schievink
bd7dfac5eb Fix r-a spelling in some places 2022-08-01 13:47:09 +02:00
Lukas Wirth
ddad2847ab Allow name querying for derive helpers 2022-07-26 09:27:22 +02:00
Lukas Wirth
aa1491ecde Record derive helper attributes, resolve them in IDE layer 2022-07-26 09:26:51 +02:00
Lukas Wirth
4e60db2d07 feat: Downmap tokens inside derive helpers 2022-07-26 09:26:47 +02:00
Amos Wenger
7e285e1ef5 Run cargo fmt 2022-07-20 15:06:15 +02:00
Amos Wenger
816f7fe12a Run cargo fix --edition-idioms 2022-07-20 15:02:08 +02:00
Amos Wenger
23d25a3094 Enable extra warnings required by rust-lang/rust 2022-07-20 15:00:17 +02:00
Lukas Wirth
bb4bfae422 fix: Fix search for associated trait items being inconsistent 2022-07-20 13:59:31 +02:00
Amos Wenger
1b416473a3 Upgrade to expect-test@1.4.0
cf. https://github.com/rust-analyzer/expect-test/issues/33
cf. https://github.com/rust-lang/rust/pull/99444#issuecomment-1188844202
2022-07-19 13:00:45 +02:00
bors
22e53f1d33 Auto merge of #12549 - bitgaoshu:goto_where_trait_m_impl, r=Veykril
feat: Go to implementation of trait methods

try goto where the trait method implies,  #4558
2022-07-18 16:29:23 +00:00
Lukas Wirth
38c11bea21 Move convert_to_def_in_trait into ide-db 2022-07-18 18:28:02 +02:00
bors
01d251789f Auto merge of #12539 - soruh:instanciate_empty_structs, r=Veykril
Automatically instaciate trivially instaciable structs in "Generate new" and "Fill struct fields"

As proposed in #12535 this PR changes the "Generate new" and "Fill struct fields" assist/diagnostic to instanciate structs with no fields and enums with a single empty variant.

For example:
```rust
pub enum Bar {
    Bar {},
}
struct Foo<T> {
    a: usize,
    bar: Bar,
    _phantom: std::marker::PhantomData<T>,
}
impl<T> Foo<T> {
    /* generate new */

    fn random() -> Self {
        Self { /* Fill struct fields */ }
    }
}
```

was previously:
```rust
impl<T> Foo<T> {
    fn new(a: usize, bar: Bar, _phantom: std::marker::PhantomData<T>) -> Self {
        Self { a, bar, _phantom }
    }

    fn random() -> Self {
        Self {
            a: todo!(),
            bar: todo!(),
            _phantom: todo!(),
        }
    }
}
```

and is now:
```rust
impl<T> Foo<T> {
  fn new(a: usize) -> Self {
      Self {
          a,
          bar: Bar::Bar {},
          _phantom: std::marker::PhantomData
      }
  }

  fn random() -> Self {
      Self {
          a: todo!(),
          bar: Bar::Bar {},
          _phantom: std::marker::PhantomData,
      }
  }
}
```

I'd be happy about any suggestions.

## TODO
   - [x]  deduplicate `use_trivial_constructor` (unclear how to do as it's used in two separate crates)
   - [x]  write tests

Closes #12535
2022-07-16 16:36:57 +00:00
bors
ac526e029a Auto merge of #12712 - harpsword:fix-rename-crate-root, r=Veykril
fix: ignore renames for crate root

close #12684 . I just ignore renames for crate root in `rename_mod` func.
2022-07-16 16:28:41 +00:00
bors
029184d977 Auto merge of #12765 - Veykril:import-insert-fix, r=Veykril
fix: Fix imports being inserted before doc comments in inline modules

Fixes https://github.com/rust-lang/rust-analyzer/issues/12758
2022-07-14 20:57:22 +00:00