Commit graph

6609 commits

Author SHA1 Message Date
Galilée 'Bill' Enguehard
910ac5a213 Fix formatting error when no modpath is present 2020-05-22 20:10:37 +02:00
Florian Diebold
ea265aad64 Provide missing Chalk debug methods 2020-05-22 19:52:06 +02:00
Florian Diebold
27fe68ad5c Use TypeCtorId as AdtId directly, and rename the type alias StructId -> AdtId 2020-05-22 19:52:06 +02:00
Florian Diebold
1d0e27254d Split up chalk module a bit 2020-05-22 19:52:06 +02:00
bors[bot]
b38f9a5810
Merge #4570
4570: Use Chalk's built-in impls r=matklad a=flodiebold

This contains two changes:
 - Chalk has begun adding built-in representations of primitive types; use these in our type conversion logic. There's one somewhat 'iffy' part here, namely references; we don't keep track of lifetimes, but Chalk does, so it will expect a lifetime parameter on references. If we didn't provide that, it could cause crashes in Chalk code that expects the lifetime, so I rather hackily add an (always the same) lifetime placeholder during conversion. I expect that we'll fully switch to using Chalk's types everywhere before we add lifetime support, so I think this is the best solution for now.
 - let Chalk know about well-known traits (from lang items), so it can apply its built-in impls.

Before:
```
Total expressions: 181485
Expressions of unknown type: 2940 (1%)
Expressions of partially unknown type: 2884 (1%)
Type mismatches: 901
Inference: 37.821210245s, 0b allocated 0b resident
Total: 53.399467609s, 0b allocated 0b resident
```

After:
```
Total expressions: 181485
Expressions of unknown type: 2923 (1%)
Expressions of partially unknown type: 2879 (1%)
Type mismatches: 734
Inference: 39.157752509s, 0b allocated 0b resident
Total: 54.110767621s, 0b allocated 0b resident
```

(I will start splitting up `chalk.rs` in a separate PR, since it's getting pretty big...)

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
Co-authored-by: Florian Diebold <florian.diebold@freiheit.com>
2020-05-22 17:31:39 +00:00
Galilée 'Bill' Enguehard
5043c9ce9c Modify hover info to show module path separated by a line 2020-05-22 19:04:39 +02:00
Florian Diebold
e0f978018a Add some tests for Chalk built-in trait impls 2020-05-22 18:52:07 +02:00
bors[bot]
a95bb1355d
Merge #4571
4571: KISS SourceChange r=matklad a=matklad

The idea behind requiring the label is a noble one, but we are not
really using it consistently anyway, and it should be easy to retrofit
later, should we need it.

bors r+

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-05-22 16:09:37 +00:00
Aleksey Kladov
2c04aad2d2 KISS SourceChange
The idea behind requiring the label is a noble one, but we are not
really using it consistently anyway, and it should be easy to retrofit
later, should we need it.
2020-05-22 18:04:26 +02:00
bors[bot]
2a36a2a3cc
Merge #4569
4569: CodeAction groups r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-05-22 15:33:12 +00:00
Florian Diebold
02c2beaa8c Provide Chalk well-known traits 2020-05-22 17:32:49 +02:00
Florian Diebold
e81c76a95a Use Chalk's built-in representations of primitive types
For references, we make sure Chalk actually gets a lifetime here.
2020-05-22 17:32:49 +02:00
Aleksey Kladov
2075e77ee5 CodeAction groups 2020-05-22 17:32:46 +02:00
Florian Diebold
06ed140fc7 Update Chalk
As always, this just makes compilation work, we don't use the newly available
functionality yet.
2020-05-22 16:40:42 +02:00
bors[bot]
5aa3a4c04f
Merge #4516
4516: LSP: Two stage initialization r=kjeremy a=kjeremy

Fills in server information.

Derives CodeAction capabilities from the client. If code action literals
are unsupported we fall back to the "simple support" which just sends back
commands (this is already supported in our config). The difference being
that we did not adjust our server capabilities so that if the client was
checking for `CodeActionProvider: "true"` in the response that would have failed.

Part of #144
Fixes #4130 (the specific case called out in that issue)

Co-authored-by: kjeremy <kjeremy@gmail.com>
2020-05-22 13:12:57 +00:00
Benjamin Coenen
43339058e3 add support of feature flag for runnables #4464
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-05-22 09:23:31 +02:00
Aleksey Kladov
5ef4ebff20 Use WorkspaceEdit for ssr 2020-05-22 00:28:49 +02:00
Galilée 'Bill' Enguehard
7fece3bdd2 Merge branch 'master' of github.com:rust-analyzer/rust-analyzer into modname_spacing 2020-05-21 23:27:38 +02:00
Galilée 'Bill' Enguehard
db926218b2 Add extra newline after module path in hover info
Closes issue #3813
2020-05-21 23:26:09 +02:00
Aleksey Kladov
5b5ebec440 Formalize JoinLines protocol extension 2020-05-21 20:05:33 +02:00
Aleksey Kladov
ef0da3bbec Cleanup 2020-05-21 16:11:37 +02:00
Aleksey Kladov
5f57491c98 Cleanup TextEdit 2020-05-21 15:56:18 +02:00
Aleksey Kladov
ff28c79ebd Remove dead code for handling cursor positions 2020-05-21 15:08:03 +02:00
Aleksey Kladov
4b495da368 Transition OnEnter to WorkspaceSnippetEdit
This also changes our handiling of snippet edits on the client side.
`editor.insertSnippet` unfortunately forces indentation, which we
really don't want to have to deal with. So, let's just implement our
manual hacky way of dealing with a simple subset of snippets we
actually use in rust-analyzer
2020-05-21 15:08:03 +02:00
Benjamin Coenen
a7c8aa7c60 add support of feature flag for runnables #4464
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-05-21 10:53:29 +02:00
Benjamin Coenen
c6143742bd add support of feature flag for runnables #4464
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-05-21 10:48:42 +02:00
Aleksey Kladov
4fdb1eac08 Remove unused cursor positions 2020-05-21 10:37:11 +02:00
bors[bot]
42dd0ce51f
Merge #4506
4506: Make `find_path_inner` a query r=matklad a=jonas-schievink

This eliminates the remaining performance problems in the "Implement default members" assist (at least those that I've found).

Closes https://github.com/rust-analyzer/rust-analyzer/issues/4498

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-05-20 23:48:02 +00:00
Aleksey Kladov
04a8daaa33 Remove unused cursor positions 2020-05-21 00:46:08 +02:00
Aleksey Kladov
70930d3bb2 Remove set_cursor 2020-05-21 00:03:42 +02:00
Aleksey Kladov
4ac0abd296 Snippetify unwrap -> match 2020-05-21 00:01:08 +02:00
Jonas Schievink
6cdfd1c3cf Make find_path_inner a query
This eliminates any remaining performance problems in the
"Implement default members" assist (at least that I've found).
2020-05-20 23:54:50 +02:00
Aleksey Kladov
8300132ed0 More snippets 2020-05-20 23:50:42 +02:00
bors[bot]
4677cea719
Merge #4540
4540: More snippets r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-05-20 21:33:36 +00:00
Aleksey Kladov
5e13e4eba1 More snippets 2020-05-20 23:33:03 +02:00
bors[bot]
64afbf8d95
Merge #4526
4526: Use a flat play icon instead of the blue emoji with test code lens r=kjeremy a=aloucks

@lnicola 

Restores this commit:
55e914a2a1

That was effectively wiped out by this code formatting commit:
dc217bdf90
3d445256fe

Co-authored-by: Aaron Loucks <aloucks@cofront.net>
2020-05-20 21:23:13 +00:00
Aleksey Kladov
fd77170718 Snippetify introduce/inline var 2020-05-20 23:07:17 +02:00
Aleksey Kladov
65fa586410 Relax cursor position tests in assists
Those will be replaced with snippets anyway
2020-05-20 22:55:37 +02:00
vain0x
e18f00882d Add call postfix completion
To make it easier to wrap an expression with Ok/Some/Rc::new etc.
2020-05-20 22:05:37 +09:00
Aleksey Kladov
ba3a58d1b2 Snippetify fix_visibility 2020-05-20 14:13:17 +02:00
Aleksey Kladov
c446fd76a2 Snippetify fill_match_arms 2020-05-20 14:01:10 +02:00
Aleksey Kladov
a622b54ac0 Don't set cursor in change_visibility 2020-05-20 13:48:31 +02:00
Aleksey Kladov
74da16f6f9 Cleanup imports 2020-05-20 13:45:00 +02:00
Aleksey Kladov
cec773926f Split change_ and fix_ visibility assists 2020-05-20 13:33:13 +02:00
Aleksey Kladov
ecac5d7de2 Switch to new magic marks 2020-05-20 13:02:53 +02:00
Aleksey Kladov
5258c817f7 Remove cross-crate marks
They create quite a bit of friction. Really, we should just move the
tests to the same crate, rather than paper over existing split.
2020-05-20 13:00:50 +02:00
Aleksey Kladov
d18d1c0594 Significantly more glorious marks 2020-05-20 13:00:50 +02:00
bors[bot]
4d3fd62f89
Merge #4530
4530: Use snippets in change_return_type_to_result r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-05-20 09:10:52 +00:00
Aleksey Kladov
33e111483f Use snippets in change_return_type_to_result 2020-05-20 11:10:15 +02:00
Aleksey Kladov
d8881d98d3 Fix Some|None order in fill_match_arms 2020-05-20 10:51:48 +02:00
Aleksey Kladov
d790a443f3 wip 2020-05-20 10:30:18 +02:00
Aleksey Kladov
2e74df4e2b Cleanup 2020-05-20 10:28:58 +02:00
Aleksey Kladov
36a5ca9a84 Minor 2020-05-20 10:26:14 +02:00
Aleksey Kladov
45e343a0ef Minor 2020-05-20 10:20:21 +02:00
Aleksey Kladov
9b2bd022dc Snippetify add_new 2020-05-20 10:17:46 +02:00
bors[bot]
c0bcaea466
Merge #4505
4505: Infer return type of loops with value breaks r=flodiebold a=ruabmbua

Creates a type variable to represent the return value of the loop.
Uses `coerce_merge_branch` on each break with the previous value, to determine the actual return value of the loop.

Resolves: https://github.com/rust-analyzer/rust-analyzer/issues/4492 , https://github.com/rust-analyzer/rust-analyzer/issues/4512

Co-authored-by: Roland Ruckerbauer <roland.rucky@gmail.com>
2020-05-20 07:22:53 +00:00
Aaron Loucks
63ffc17733 Use a flat play icon instead of the blue emoji with test code lens 2020-05-19 20:29:49 -04:00
bors[bot]
efac093093
Merge #4525
4525: Better cursor placement when adding impl members r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-05-20 00:11:25 +00:00
Aleksey Kladov
767d169a2a Better cursor placement when adding impl members 2020-05-20 02:07:21 +02:00
bors[bot]
b26dbf8009
Merge #4524
4524: Use snippets in add_missing_members r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-05-19 23:54:08 +00:00
Aleksey Kladov
a04cababaa Use snippets in add_missing_members 2020-05-20 01:53:21 +02:00
bors[bot]
a36202390c
Merge #4521 #4522
4521: Use snippets in add_function r=matklad a=matklad

bors r+
🤖

4522: Explain the purpose of `ast::make` module more clearly r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-05-19 23:30:48 +00:00
Aleksey Kladov
e6fc0bdffb Moderate cleanup of add_function 2020-05-20 01:30:12 +02:00
Aleksey Kladov
4de2749db8 Explain the purpose of ast::make module more clearly 2020-05-20 01:28:46 +02:00
Aleksey Kladov
8eb3272ad6 Use snippets in add function 2020-05-20 01:23:05 +02:00
Aleksey Kladov
9c3acd3028 Cleanup 2020-05-20 01:23:05 +02:00
Aleksey Kladov
0146a95a39 Cleanup 2020-05-20 01:23:05 +02:00
Aleksey Kladov
4a3a525ea9 Use new format for all assists that don't change cursor positon 2020-05-20 01:23:05 +02:00
Aleksey Kladov
80545e5d3a New assist: add turbo fish 2020-05-20 00:27:10 +02:00
kjeremy
acc5e8d64b Add version 2020-05-19 18:12:07 -04:00
kjeremy
e3ae298e78 Fill code action capabilities with a function 2020-05-19 17:22:38 -04:00
Roland Ruckerbauer
45021cae55 Apply suggestion of @flodiebold: Get rid of multiple unwraps 2020-05-19 22:53:19 +02:00
Roland Ruckerbauer
da09f96746 loop return value inference: add tests 2020-05-19 21:52:43 +02:00
Roland Ruckerbauer
6e36ad3d91 Move false negative expr_diverges_missing_arm() to working tests 2020-05-19 21:18:43 +02:00
Roland Ruckerbauer
6eaa669da0 loop return value inference: coerce_merge branches 2020-05-19 21:06:47 +02:00
Aleksey Kladov
3e9bf7ebab Update test data 2020-05-19 20:29:18 +02:00
Aleksey Kladov
2bf6b16a7f Server side of SnippetTextEdit 2020-05-19 20:28:27 +02:00
Aleksey Kladov
a752853350 Add snippetTextEdit protocol extension 2020-05-19 20:28:27 +02:00
Aleksey Kladov
fa2e5299c3 Add snippet support for some assists 2020-05-19 20:28:27 +02:00
Aleksey Kladov
c847c079fd Add AssistConfig 2020-05-19 20:28:27 +02:00
bors[bot]
131849f2ab
Merge #4491
4491: fix doctest inside impl block r=matklad a=bnjjj

close #4449 

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Co-authored-by: Coenen Benjamin <benjamin.coenen@hotmail.com>
2020-05-19 18:16:20 +00:00
kjeremy
6bf4fc27d9 LSP: Two stage initialization
Fills in server information.

Derives CodeAction capabilities from the client. If code action literals
are unsupported we fall back to the "simple support" which just sends back
commands (this is already supported in our config). The difference being
that we did not adjust our server capabilities so that if the client was
checking for `CodeActionProvider: "true"` in the response that would have failed.
2020-05-19 11:56:51 -04:00
Aleksey Kladov
dce31efdde Cleanup query fn naming 2020-05-19 16:54:45 +02:00
Aleksey Kladov
01bd1e1296 Move public API to the top 2020-05-19 16:46:33 +02:00
Aleksey Kladov
908da9ac1b Simplify 2020-05-19 16:45:57 +02:00
Aleksey Kladov
5c9ebbeaa4 Cleanup imports 2020-05-19 16:43:26 +02:00
George Fraser
47ce5ea581 Color attribute functions 2020-05-18 22:55:46 -07:00
Roland Ruckerbauer
0fe876925e Infer return type of loops with value breaks. 2020-05-18 23:39:10 +02:00
bors[bot]
38e8f35855
Merge #4501
4501: Querify `importable_locations_in_crate` r=jonas-schievink a=jonas-schievink

This brings the time needed to compute the `add_missing_impl_members` assist down from ~5 minutes to 20 seconds on my test workload (which is editing within an impl of a MIR [`MutVisitor`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/mir/visit/trait.MutVisitor.html))

cc #4498

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-05-18 19:43:12 +00:00
Jonas Schievink
8f80df1117 Querify importable_locations_in_crate
This brings the time needed to compute the `add_missing_impl_members`
assist down from ~5 minutes to 20 seconds
2020-05-18 21:42:39 +02:00
bors[bot]
9bdedbbcaf
Merge #4497
4497: Create LowerCtx on the fly r=matklad a=edwin0cheng

Previously we create `LowerCtx` at the beginning of lowering, however, the hygiene content is in fact changing between macro expression expanding. 

This PR change it to create the `LowerCtx` on the fly to fix above bug.

However, #4465 is not fixed by this PR, the goto-def is still not work yet. It only fixed the infer part. 

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-05-18 11:03:44 +00:00
bors[bot]
ad03e4de18
Merge #4493
4493: Provide builtin impls of Fn traits for fn-pointers r=flodiebold a=hban

Meant to be, but isn't actually a fix for #2880.

Consider this snippet:

```rust
use std::marker::PhantomData;
use std::ops::Deref;

struct Lazy<T, F/* = fn() -> T*/>(F, PhantomData<T>);

impl<T, F> Lazy<T, F> {
    pub fn new(f: F) -> Lazy<T, F> {
        Lazy(f, PhantomData)
    }
}

impl<T, F: FnOnce() -> T> Deref for Lazy<T, F> {
    type Target = T;

    fn deref(&self) -> &T { todo!() }
}

fn test() {
    let lazy1: Lazy<u32, _> = Lazy::new(|| 0u32);
    let r1 = lazy1.to_string();

    fn make_u32_fn() -> u32 { todo!() }
    let make_u32_fn_ptr: fn() -> u32 = make_u32_fn;
    let lazy2: Lazy<u32, _> = Lazy::new(make_u32_fn_ptr);
    let r2 = lazy2.to_string();
}
```

* On current master:
  * When type default is commented-out, `r1` is correctly inferred, `r2` in _{unknown}_.
  * When type default is not commented-out, both `r1`  and `r2` are _{unknown}_.
* With this PR:
  * When type default is commented-out, both `r1` and `r2` are correctly inferred.
  * When type default is not commented-out, both `r1`  and `r2` are _{unknown}_.

Well, it's a improvement at least. I guess this thing with type defaults is a different problem.

I also tried add Fn impls for fn items, but wasn't successful. So this PR only adds those impls for fn pointers.

Co-authored-by: Hrvoje Ban <hban@users.noreply.github.com>
2020-05-18 07:44:44 +00:00
vsrs
78817a3194 Add "rust-analyzer.lens.enable" 2020-05-18 10:27:00 +03:00
Hrvoje Ban
68db49c853 Add more tests for Fn traits 2020-05-18 08:07:31 +02:00
vsrs
3d445256fe code formatting 2020-05-17 20:38:50 +03:00
vsrs
dc217bdf90 CodeLens configuration options. 2020-05-17 19:51:44 +03:00
Edwin Cheng
12a3bf3c31 Create LowerCtx on the fly 2020-05-17 23:37:30 +08:00
Coenen Benjamin
01688f8d4f
Fix doctests in an Impl block 2020-05-17 12:10:35 +02:00
Benjamin Coenen
947f95193a fix doctest inside impl block #4449
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-05-17 11:16:31 +02:00
bors[bot]
1afdc57929
Merge #4489
4489: Memory allocation optimization r=matklad a=simonvandel

I did some profiling using DHAT, and this was what I could easily optimize without much knowledge of the codebase.

This speeds up analysis-stats on rust-analyser by ~4% on my local machine.

**Benchmark**
➜  rust-analyzer-base git:(master) hyperfine --min-runs=2 '/home/simon/Documents/rust-analyzer/target/release/rust-analyzer analysis-stats .' '/home/simon/Documents/rust-analyzer-base/target/release/rust-analyzer analysis-stats .'
Benchmark #1: /home/simon/Documents/rust-analyzer/target/release/rust-analyzer analysis-stats .
  Time (mean ± σ):     49.621 s ±  0.317 s    [User: 48.725 s, System: 0.792 s]
  Range (min … max):   49.397 s … 49.846 s    2 runs
 
Benchmark #2: /home/simon/Documents/rust-analyzer-base/target/release/rust-analyzer analysis-stats .
  Time (mean ± σ):     51.764 s ±  0.045 s    [User: 50.882 s, System: 0.756 s]
  Range (min … max):   51.733 s … 51.796 s    2 runs
 
Summary
  '/home/simon/Documents/rust-analyzer/target/release/rust-analyzer analysis-stats .' ran
    1.04 ± 0.01 times faster than '/home/simon/Documents/rust-analyzer-base/target/release/rust-analyzer analysis-stats .'

Co-authored-by: Simon Vandel Sillesen <simon.vandel@gmail.com>
2020-05-16 23:06:23 +00:00