bors [Fri, 3 Jun 2022 07:49:59 +0000 (07:49 +0000)]
Auto merge of #12333 - nolanderc:order-import-assist, r=Veykril
Order auto-imports by relevance
Fixes #10337.
Basically we sort the imports according to how "far away" the imported item is from where we want to import it to. This change makes it so that imports from the current crate are sorted before any third-party crates. Additionally, we make an exception for builtin crates (`std`, `core`, etc.) so that they are sorted before any third-party crates.
There are probably other heuristics that should be added to improve the experience (such as preferring imports that are common elsewhere in the same crate, and ranking crates depending on the dependency graph). However, I think this is a first good step.
PS. This is my first time contributing here, so please be gentle if I have missed something obvious :-)
bors [Fri, 3 Jun 2022 07:40:34 +0000 (07:40 +0000)]
Auto merge of #12452 - iDawer:assist.merge_selected_imports, r=Veykril
feature: `Merge imports` assist can merge multiple selected imports.
The selected imports have to have a common prefix in paths.
Select imports or use trees to merge:
```rust
$0use std::fmt::Display;
use std::fmt::Debug;
use std::fmt::Write;$0
```
Apply `Merge imports`:
```rust
use std::fmt::{Display, Debug, Write};
```
bors [Thu, 2 Jun 2022 12:37:17 +0000 (12:37 +0000)]
Auto merge of #12347 - feniljain:fix_extract_module, r=Veykril
fix(extract_module) resolving import panics and improve import resolution
- Should solve #11766
- While adding a test case for this issue, I observed another issue:
For this test case:
```rust
mod x {
pub struct Foo;
pub struct Bar;
}
use x::{Bar, Foo};
$0type A = (Foo, Bar);$0
```
extract module should yield this:
bors [Wed, 1 Jun 2022 10:18:50 +0000 (10:18 +0000)]
Auto merge of #12431 - Veykril:request-retry, r=Veykril
fix: Fix completions disappearing when typing two keys in quick succession
With this PR we now retry requests if they get cancelled due to document changes.
This fixes the completions problem we have where completions seem to randomly disappear, see https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Completions.20not.20always.20appearing
bors [Mon, 30 May 2022 11:29:55 +0000 (11:29 +0000)]
Auto merge of #12387 - 00nktk:fix-mod-rename, r=Veykril
fix(ide-db): correct single-file module rename
Fixes a bug where rust-analyzer would emit `WorkspaceEdit`s with paths to dirs instead of files for the following project layout.
lib.rs
```rust
mod foo;
```
foo.rs
```rust
mod bar {
struct Bar;
}
```
Also fixes emitted paths for modules with mod.rs.
The bug resulted in panic in helix editor when attempting to rename a module.
bors [Mon, 30 May 2022 11:22:10 +0000 (11:22 +0000)]
Auto merge of #12412 - yue4u:fix/visibility-completion, r=Veykril
fix: Retrigger visibility completion after parentheses
close #12390
This PR add `(` to trigger_characters as discussed in original issue.
Some questions:
1. Is lsp's `ctx.trigger_character` from `params.context` is the same as `ctx.original_token` inside actually completions?
1. If not what's the difference?
2. if they are the same, it's unnecessary to pass it down from handler at all.
3. if they are the same, maybe we could parse it from fixture directly instead of using the `check_with_trigger_character` I added.
2. Some completion fixtures written as `($0)` ( https://github.com/rust-lang/rust-analyzer/blob/master/crates/ide-completion/src/tests/fn_param.rs#L105 as an example), If I understand correctly they are not invoked outside tests at all?
1. using `ctx.original_token` directly would break these tests as well as parsing trigger_character from fixture for now.
2. I think it make sense to allow `(` triggering these cases?
3. I hope this line up with #12144
bors [Sun, 29 May 2022 08:45:15 +0000 (08:45 +0000)]
Auto merge of #12409 - lowr:fix/usize-overflow, r=Veykril
fix overflow during type inference for tuple struct patterns
The following code causes integer overflow during type inference for (malformed) tuple struct patterns.
```rust
struct S(usize);
let S(.., a, b) = S(1);
```
It has been panicking only in debug builds, and working in a way in release builds but it was inconsistent with type inference for tuple patterns:
```rust
struct S(usize);
let S(.., a, b) = S(1); // a -> unknown, b -> usize
let (.., a, b) = (1,); // a -> usize, b -> unknown
```
With this PR, the overflow no longer happens by utilizing `saturating_sub()` like in other places and type inference for tuple struct patterns is in line with that for tuple patterns.
bors [Fri, 27 May 2022 12:35:48 +0000 (12:35 +0000)]
Auto merge of #12341 - vemoo:exclude_dirs, r=Veykril
make `files.excludeDirs` work
There's a small issue because if all projects are excluded, this: https://github.com/rust-lang/rust-analyzer/blob/01d412f4d7bd7ef21a7e8f0461e9ba3439e3c4bf/crates/rust-analyzer/src/main_loop.rs#L114 will be shown.
I thought about not showing it if `files.excludeDirs` is set, but that is not necessarily correct.