Commit graph

112 commits

Author SHA1 Message Date
Benjamin Coenen
f1fda43485 generate_impl assist respect cfg attributes #6312
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-22 09:48:48 +02:00
bors[bot]
c00339509d
Merge #6256
6256: Assist: replace string with char r=bnjjj a=bnjjj

close #6252 

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Co-authored-by: Coenen Benjamin <benjamin.coenen@hotmail.com>
2020-10-20 19:03:25 +00:00
Coenen Benjamin
9883435e4e
Update crates/assists/src/handlers/replace_string_with_char.rs
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-10-20 20:07:39 +02:00
bors[bot]
989de9e309
Merge #6172
6172: Add qualify path assist r=matklad a=Veykril

This implements a `qualify_path` assist which works quite similar to the `auto_import` assist but instead of adding imports to the file it well, qualifies the path. This PR also moves out the `AutoImportAssets` struct and functions from `auto_import` into a utils submodule as most of this is now shared between `auto_import` and `qualify_path`.

Changes made to `AutoImportAssets` are solely in its `search_for_imports` function which now takes a prefixed parameter to discern between using `find_use_path_prefixed` and `find_use_path` as the former is the required behavior by `auto_import` and the latter by this assist.

For missing imported traits instead of importing this will qualify the path with a trait cast as in:
```rust
test_mod::TestStruct::TEST_CONST<|>
```
becomes
```rust
<test_mod::TestStruct as test_mod::TestTrait>::TEST_CONST
```

and for trait methods ideally it would do the following:
```rust
let test_struct = test_mod::TestStruct {};
test_struct.test_meth<|>od()
```
becomes
```rust
let test_struct = test_mod::TestStruct {};
test_mod::TestTrait::test_method(&test_struct)
```

Fixes #4124.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-20 17:03:19 +00:00
Aleksey Kladov
a3a8ad8bc4 Don't rely on display names in inlay_hints 2020-10-20 18:14:14 +02:00
Benjamin Coenen
c22c039578 Assist: replace string with char
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-20 15:57:50 +02:00
Aleksey Kladov
af4e75533f Rename declaration_name -> display_name
Declaration names sounds like a name of declaration -- something you
can use for analysis. It empathically isn't, and is just a label
displayed in various UI. It's important not to confuse the two, least
we accidentally mix semantics with UI (I believe, there's already a
case of this in the FamousDefs at least).
2020-10-20 15:38:11 +02:00
Aleksey Kladov
4fbb602b2d Minor, rename feature 2020-10-19 15:53:48 +02:00
Aleksey Kladov
604caedeb2 Change visibility works for type aliases 2020-10-18 17:04:12 +02:00
Benjamin Coenen
62192cede3 replace_string_with_char #6252
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-16 20:21:16 +02:00
Lukas Wirth
1d612a6ec4 De-duplicate add_group callsite in qualify_path 2020-10-16 16:04:00 +02:00
Lukas Wirth
bc11475a2a Properly qualify trait methods in qualify_path assist 2020-10-15 18:31:33 +02:00
Aleksey Kladov
56e67e3a39 More idiomatic classification API 2020-10-15 17:38:17 +02:00
Lukas Wirth
f8a7cc678d Document auto_import as a feature 2020-10-15 14:57:19 +02:00
Lukas Wirth
d983f18df7 Add mark tests to qualify_path assist 2020-10-14 20:04:57 +02:00
Lukas Wirth
9f41f074be Add qualify path assist 2020-10-14 19:56:20 +02:00
bors[bot]
3e450cf89f
Merge #6207 #6224 #6226 #6227
6207: Extract ImportAssets out of auto_import r=matklad a=Veykril

See https://github.com/rust-analyzer/rust-analyzer/pull/6172#issuecomment-707182140

I couldn't fully pull out `AssistContext` as `find_node_at_offset_with_descend`: 81fa00c5b5/crates/assists/src/assist_context.rs (L90-L92) requires the `SourceFile` which is private in it and I don't think making it public just for this is the right call?

6224: ⬆️ salsa r=matklad a=matklad

bors r+
🤖

6226: Add reminder to update lsp-extensions.md r=matklad a=matklad

bors r+
🤖

6227: Reduce bors timeout r=matklad a=matklad

bors r+
🤖

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-10-14 11:37:51 +00:00
Lukas Wirth
03b77b03fe Fix stackoverflow in insert_use::recursive_merge 2020-10-14 01:43:56 +02:00
Lukas Wirth
01b410c69a Slightly cleanup import_assets module 2020-10-13 20:02:14 +02:00
Lukas Wirth
02b844e9fb Adhere to style guidelines in import_assets 2020-10-13 18:58:37 +02:00
Lukas Wirth
256104d78e Extract ImportAssets out of auto_import 2020-10-13 18:58:37 +02:00
Lukas Wirth
2620b8d42f Fix MergeBehaviour::Full not working when merging nested long paths 2020-10-13 10:44:16 +02:00
bors[bot]
c518fe7f6c
Merge #6130 #6135
6130: Items case quick fix (snake_case / UPPER_SNAKE_CASE / CamelCase) r=matklad a=popzxc

Resolves #4598.

After a third try, it finally works. Boy, it appeared tougher than it seemed.

Initially I thought like "Ha, `rustc` already tells us where idents are named incorrectly. It shouldn't be that hard, should it?".

Well, the problems with the information provided by `rustc` appeared shortly:

- `rustc` warnings are `flycheck` warnings, which are slightly aside from our diagnostics with fixes.
  When we map flycheck diagnostic to LSP, we can convert it into a fix, but only if it's marked as `Applicability::MachineApplicable`.
  Name case fix is marked `Applicability::MaybeIncorrect`, and for a reason: it only suggest to rename symbol under cursor, without tracking any references.
- Warning spawned by `rustc` are identified by string labels rather than enum. It means that if one day the diagnostic will be renamed in `rustc`, `rust-analyzer` code will still compile, but won't find the required diagnostic by name anymore. If by chance this will happen when some unlucky guy will decide to create their first pull request, they'll be confused by suddenly failing tests  (likely) not related to their changes.
- Even if we'll try to build fixes atop of `rustc` warnings, we'll have to do it in the `rust_analyzer::diagnostics::to_proto` module, which is far less
  convenient for that matter than `ide` crate.

That's why I decided that it's worth a separate `rust-analyzer` diagnostic, which will implement `DiagnosticWithFix` trait.

After that, I discovered that currently `hir_ty::diagnostics` only check `DefWithBody` types, like function bodies. I had to add support for diagnostics
which look at any `ModuleDef`.

And of course, since I'd added a lot of new functionality, it required extensive testing.

That explains why the diff is so big for a (looking) relatively small feature.

I hope that this PR doesn't only add a small feature, but also creates a base for building another features.

## Example:

![case_quick_fix](https://user-images.githubusercontent.com/12111581/95008475-e07ee780-0622-11eb-9978-62a9ea0e7782.gif)

P.S. My eyes were bleeding when I had to write the code for the example...


6135: when generating new function, focus on return type instead of body r=matklad a=bnjjj

I made a little change when we use the assist to generate a new function, instead of focusing on the function body, it will focus on return type

Co-authored-by: Igor Aleksanov <popzxc@yandex.ru>
Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-12 16:00:13 +00:00
Jonas Schievink
5dcbf03d0f adt: correctly inherit field visibility from enum
Previously, "find all references" on a variant field wouldn't find any
references outside the defining module. This is because variant fields
were incorrectly assumed to be private, like struct fields without
explicit visibility, but they actually inherit the enum's visibility.
2020-10-09 20:46:45 +02:00
Benjamin Coenen
3bfa3e8123 when generating new function, focus on return type instead of body
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-08 20:57:18 +02:00
Lukas Wirth
783af171f7 Clean up inlay_hints 2020-10-07 13:18:12 +02:00
Lukas Wirth
e106857e80 Shorten iterator hints for std::iter iterators behind references 2020-10-07 12:14:08 +02:00
Lukas Wirth
209e9b9926 Shorten iterator chain hints 2020-10-07 11:30:42 +02:00
Lukas Wirth
c133651e0a Move IntoIterator into FamousDefs 2020-10-07 10:14:42 +02:00
Lukas Wirth
c6f1de6ac5 Use FamousDefs for shorten_iterator hint 2020-10-06 21:25:39 +02:00
Aleksey Kladov
2090b534fc Move ModPath->ast::Path function to IDE layer
closes #6092
2020-10-06 16:19:18 +02:00
bors[bot]
af0e54a566
Merge #6139
6139: Make find_path_prefixed configurable r=matklad a=Veykril

This makes `find_path_prefixed` more configurable allowing one to choose whether it always returns absolute paths, self-prefixed paths or to ignore local imports when building the path. 

The config names are just thrown in here, taking better names if they exist :)

This should fix #6131 as well?

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-06 11:43:08 +00:00
Kirill Bulatov
af4ae86e27 Do not leave braces for colons in dbg! 2020-10-06 14:21:22 +03:00
bors[bot]
dd6a352e64
Merge #6111
6111: Add assist for converting the base of integer literals. r=SomeoneToIgnore a=vlakreeh

This PR adds an assist similar to Intellij's [convert number to](https://i.imgur.com/JH6wstP.png). It also does a small refactor to [assists/src/tests.rs](fc34403018/crates/assists/src/tests.rs) to add the ability to specify the resolved assist for a specific action within an assist group.

## Demo
![Demo of the assist in action](https://i.imgur.com/MBhdPFH.gif)

Co-authored-by: vlakreeh <zeb@zebulon.dev>
2020-10-05 22:00:40 +00:00
Lukas Wirth
8699331014 Make ImportPrefix a configuration option 2020-10-05 17:41:49 +02:00
Aleksey Kladov
3290bb4112 Simplify ast_transform 2020-10-02 20:52:48 +02:00
bors[bot]
40a028c9a8
Merge #6105
6105: Fix path comparison not comparing paths correctly with unequal lengths r=matklad a=Veykril

~~This PR includes the commit from #6102 there as I found a bug while writing that(so either merging this or both in order works) so I included a test there already which was just ignored.~~ This PR fixes that, basically inserting imports didn't consider path length for equality, so depending on the order it might insert the path before or after another import if they only differ in segment length.

~~Diff without the commit of #6102 2d90d3937d~~



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-02 09:30:25 +00:00
bors[bot]
e535489f03
Merge #6104
6104: Minor clippy performance suggestions r=matklad a=kjeremy



Co-authored-by: kjeremy <kjeremy@gmail.com>
2020-10-02 08:07:42 +00:00
Lukas Wirth
95ea23cdef Fix path comparison not comparing paths correctly with unequal lengths 2020-10-01 17:18:34 +02:00
kjeremy
82d6cfd495 Minor clippy performance suggestions 2020-09-30 15:22:49 -04:00
Lukas Wirth
0671bf2d73 Fix MergingBehaviour::Last not working properly 2020-09-30 19:09:17 +02:00
vlakreeh
b2bfadb52c Add tests for convert integer literal assist 2020-09-29 19:05:17 -04:00
vlakreeh
91b4746c01 Add ability to specify ResolvedAssist by label 2020-09-29 18:22:09 -04:00
vlakreeh
c84fdb8b3e Add convert integer literal assist 2020-09-29 14:48:43 -04:00
bors[bot]
18c62c8a39
Merge #6019
6019: Remove make::path_from_text r=matklad a=Veykril

This removes the `make::path_from_text` function, which according to a note should've been private. I removed it since it didn't really serve a purpose as it was simply wrapping `make::ast_from_text`.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-09-29 10:29:33 +00:00
Aleksey Kladov
6ff78962b3 Microoptimize 2020-09-28 19:06:51 +02:00
Lukas Wirth
747f6f64d7 Remove partial import test in insert_use 2020-09-25 15:21:50 +02:00
Lukas Wirth
e1d6981f90 Don't unnecessarily unnest imports for import insertion 2020-09-25 15:19:22 +02:00
Aleksey Kladov
8e3082ff6e Document AstTransformation 2020-09-21 12:36:51 +02:00
Matt Hooper
7d90bb1f47 Rename impl edit method to be more explicit 2020-09-21 10:01:50 +01:00