Commit graph

8528 commits

Author SHA1 Message Date
Igor Aleksanov
70157f07d9 Remove redundant completions 2020-10-17 10:27:59 +03:00
bors[bot]
1af6275f20
Merge #6246
6246: Follow symlinks when walking project trees r=lnicola a=dfoxfranke

Fixes #3691.

~~WIP pending further testing~~:

- [X] Verify that symlinked files get indexed.
- [x] Verify that files in symlinked directories get indexed.
- [x] Verify that inotify events are properly received and handled when the target of a symlink resides outside the project tree.

Co-authored-by: Daniel Fox Franke <dfoxfranke@gmail.com>
2020-10-16 12:53:10 +00:00
Daniel Fox Franke
e821aa842b Follow symlinks when walking project trees
Fixes #3691
2020-10-15 14:22:36 -04:00
bors[bot]
0d45802d67
Merge #6220
6220: implement binary operator overloading type inference r=flodiebold a=ruabmbua

Extend type inference of *binary operator expression*, by adding support for operator overloads.

Before this merge request, the type inference of binary expressions could only resolve operations done on built-in primitive types. This merge requests adds a code path, which is executed in case the built-in inference could not get any results. It resolves the proper operator overload trait in *core::ops* via lang items, and then resolves the associated *Output* type.

```rust
struct V2([f32; 2]);

#[lang = "add"]
pub trait Add<Rhs = Self> {
    /// The resulting type after applying the `+` operator.
    type Output;

    /// Performs the `+` operation.
    #[must_use]
    fn add(self, rhs: Rhs) -> Self::Output;
}

impl Add<V2> for V2 {
    type Output = V2;

    fn add(self, rhs: V2) -> V2 {
        let x = self.0[0] + rhs.0[0];
        let y = self.0[1] + rhs.0[1];
        V2([x, y])
    }
}

fn test() {
    let va = V2([0.0, 1.0]);
    let vb = V2([0.0, 1.0]);

    let r = va + vb; // This infers to V2 now
}
```

There is a problem with operator overloads, which do not explicitly set the *Rhs* type parameter in the respective impl block. 

**Example:**

```rust
impl Add for V2 {
    type Output = V2;

    fn add(self, rhs: V2) -> V2 {
        let x = self.0[0] + rhs.0[0];
        let y = self.0[1] + rhs.0[1];
        V2([x, y])
    }
}
```

In this case, the trait solver does not realize, that the *Rhs* type parameter is actually self in the context of the impl block. This stops type inference in its tracks, and it can not resolve the associated *Output* type.

I guess we can still merge this back, because it increases the amount of resolved types, and does not regress anything (in the tests).

Somewhat blocked by https://github.com/rust-analyzer/rust-analyzer/issues/5685
Resolves  https://github.com/rust-analyzer/rust-analyzer/issues/5544

Co-authored-by: Roland Ruckerbauer <roland.rucky@gmail.com>
2020-10-15 18:02:27 +00:00
Aleksey Kladov
c5868a4879 Clarify the names one more time 2020-10-15 17:38:51 +02:00
Aleksey Kladov
56e67e3a39 More idiomatic classification API 2020-10-15 17:38:17 +02:00
Aleksey Kladov
f9c1336873 More clarifications 2020-10-15 17:37:55 +02:00
Aleksey Kladov
bc287b8f9b Unconfuse expression and pattern field init shorthands 2020-10-15 17:37:36 +02:00
Aleksey Kladov
fa3c449d8f Clarify NameClass names a bit 2020-10-15 17:37:36 +02:00
bors[bot]
7fadc78ebb
Merge #6242
6242: Diagnost shorthand in patterns r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-10-15 15:11:36 +00:00
Aleksey Kladov
3086fb2ef4 Move field_shorthand to a separate module 2020-10-15 17:10:06 +02:00
Aleksey Kladov
1022672af0 Diagnose shorthand in patterns as well 2020-10-15 17:03:52 +02:00
Aleksey Kladov
e9903a91cd flatten 2020-10-15 16:51:55 +02:00
Aleksey Kladov
c8cbd398e4 Prepare for pat_field_shorthand 2020-10-15 16:48:25 +02:00
bors[bot]
8090799aa2
Merge #6234
6234: Fix hover over field pattern shorthand r=matklad a=Vlad-Shcherbina

Instead of the information about the field, it now shows the information
about the local.

Fixes #6146

Co-authored-by: Vlad Shcherbina <vlad.shcherbina@gmail.com>
2020-10-15 13:09:27 +00:00
Lukas Wirth
f8a7cc678d Document auto_import as a feature 2020-10-15 14:57:19 +02:00
bors[bot]
3a38554f86
Merge #6231
6231: Factor macro_rules and format-string highlighting out into submodules r=Veykril a=Veykril

This moves `format`-like macro string highlighting and macro_rules highlight skipping out of the main module.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-14 20:52:41 +00:00
Lukas Wirth
bab29e65eb Default::default the highlighters 2020-10-14 22:50:26 +02:00
Vlad Shcherbina
e6fbb94edd Fix hover over field pattern shorthand
Instead of the information about the field, it now shows the information
about the local.

Fixes #6146
2020-10-14 21:22:00 +03:00
Lukas Wirth
8c6dc5f28a Factor macro_rules! highlighting out 2020-10-14 19:23:59 +02:00
Lukas Wirth
df87be88d8 Factor format string highlighting out 2020-10-14 19:23:45 +02:00
Roland Ruckerbauer
0e9d1e17d6 binary operator overload type inference: add test mark 2020-10-14 19:00:04 +02:00
Aleksey Kladov
1b3b8c7fda Log around sysroot discovery 2020-10-14 17:22:07 +02:00
Laurențiu Nicola
8cc175ee9b Add docs for dbgr and call 2020-10-14 16:23:51 +03: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
Aleksey Kladov
41e2639f35 ⬆️ salsa 2020-10-14 12:40:48 +02:00
bors[bot]
b62f48f535
Merge #6217
6217: Bump pulldown-cmark r=matklad a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-10-14 10:26:13 +00:00
Lukas Wirth
03b77b03fe Fix stackoverflow in insert_use::recursive_merge 2020-10-14 01:43:56 +02:00
Roland Ruckerbauer
4e49b2f731 Implement binary operator overloading type inference 2020-10-13 20:48:08 +02:00
Lukas Wirth
01b410c69a Slightly cleanup import_assets module 2020-10-13 20:02:14 +02:00
Laurențiu Nicola
e559066bed Bump pulldown-cmark 2020-10-13 20:41:49 +03: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
bors[bot]
0fb069c5b0
Merge #6216
6216: Bump deps r=matklad a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-10-13 15:13:55 +00:00
Laurențiu Nicola
9937c0d50a Bump rustc_lexer 2020-10-13 18:06:23 +03:00
Laurențiu Nicola
017a04f424 Bump crossbeam-channel and lsp-server in rust-analyzer 2020-10-13 18:05:06 +03:00
Laurențiu Nicola
db7813ef2c Bump crossbeam-channel in crates 2020-10-13 16:57:01 +03: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
bors[bot]
ef33953c70
Merge #6205
6205: Fix iterator hint shortening heuristic r=SomeoneToIgnore a=Veykril

Turns out I made a mistake with the heuristic check which is always true, so all iterators exposed from `core` were shortened, including things like ranges. 😅 

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-12 15:53:32 +00:00
bors[bot]
05faeb50f3
Merge #6153
6153: Improve prime_caches and display its progress r=matklad a=jonas-schievink

It now computes the `CrateDefMap` of all crates, which is generally a reasonable approximation for "IDE features ready". There is still some delay after this finishes, I suspect mostly due to impl collection, which takes a while, but this should be an improvement already.

For more accurate progress reports, this topologically sorts all crates before starting this operation. ~~Because that is also the ordering in which parallelization makes sense (which was previously attempted in https://github.com/rust-analyzer/rust-analyzer/pull/3529), I decided to throw that into the mix as well. It still doesn't provide *that* much of a performance boost, but it does scale beyond the current single-core architecture, and adding it was very easy.~~

~~Unfortunately, as written, this will not tell the user which crate is actually causing slowdowns, since the displayed crate is the last one that was *started*, not the one we are currently *blocked* on, but that seems fairly difficult to implement unless I'm missing something.~~

(I have removed rayon for now since it does not work correctly with cancellation.)

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2020-10-12 15:21:39 +00:00
Lukas Wirth
ed59512d02 Fix iterator hint shortening heuristic 2020-10-12 17:18:21 +02:00
bors[bot]
fac59f4f28
Merge #6195
6195: Shorten iterators in associated params r=matklad a=SomeoneToIgnore

Applies the same iterator-shortening logic to the iterator associated types, recursively.

Before: 
![image](https://user-images.githubusercontent.com/2690773/95662735-e6ecf200-0b41-11eb-8e54-28493ad4e644.png)

After:
<img width="1192" alt="image" src="https://user-images.githubusercontent.com/2690773/95662894-e9038080-0b42-11eb-897d-527571ccac58.png">


Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2020-10-12 15:06:45 +00:00
bors[bot]
44df0e2a9f
Merge #6198
6198: Skip macro matcher fragment name semantic highlighting r=matklad a=Veykril

Implements a small state-machine for macro_rules! highlighting to separate out the matcher part of its rules. This skips semantically highlighting names of metavariables in the matcher and expander. This might even allow for more fun macro highlighting things in the future.

Fixes #4380.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-12 14:44:34 +00:00
bors[bot]
93de4918ea
Merge #6199
6199: Fix `mut self` not emitting mutable binding on `self` use r=matklad a=Veykril

Prior to this, when `self` in a function is taken by value and bound mutably, its use inside of the method body won't be marked `mutably`. 

Fixes #5461

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-12 14:24:18 +00:00
Jonas Schievink
cde7392ec8 Improve prime_caches and display its progress 2020-10-12 13:35:01 +02:00
Igor Aleksanov
991d019096 Use TextRange::contains_inclusive in fixes check 2020-10-12 11:32:22 +03:00
Igor Aleksanov
fb0ab9f745 Keep SyntaxNodePtr::range private 2020-10-12 11:05:00 +03:00
Igor Aleksanov
66cea8cbaa Replace 'if let' with 'match' in decl_check.rs 2020-10-12 11:05:00 +03:00
Igor Aleksanov
559cc97073 Add to_upper_snake_case function to stdx 2020-10-12 11:05:00 +03:00