Commit graph

6464 commits

Author SHA1 Message Date
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
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
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
bors[bot]
8944a9b35a
Merge #4484
4484: Allow calling dyn trait super trait methods without the super trait in scope r=flodiebold a=flodiebold

This also removes some vestiges of the old impl trait support which I think aren't currently in use.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2020-05-16 21:59:26 +00:00
Simon Vandel Sillesen
1e9172d70c Reuse Vec allocations 2020-05-16 22:20:44 +02:00
Simon Vandel Sillesen
b606399095 Reduce reallocations in ra_tt::buffer::TokenBuffer::new_inner 2020-05-16 22:20:44 +02:00
Simon Vandel Sillesen
ef6d53521f Shrink ra_parser::Event from 32 bytes to 16 bytes
This boxes the Error variant with the assumption that it is rarely constructed
2020-05-16 22:20:44 +02:00
bors[bot]
ebaa05a447
Merge #4472
4472: Fix path resolution for module and function with same name r=hasali19 a=hasali19

This fixes #3970 and also fixes completion for the same issue.

Co-authored-by: Hasan Ali <git@hasali.co.uk>
2020-05-16 19:49:01 +00:00
Hasan Ali
bb78d314e1 Add doc comment for resolve_hir_path_qualifier 2020-05-16 20:40:58 +01:00
Florian Diebold
811d25b723 Allow calling dyn trait super trait methods without the super trait in scope
This also removes some vestiges of the old impl trait support which I think
aren't currently in use.
2020-05-16 18:37:05 +02:00
Florian Diebold
050601ef7b Chalk upgrade 2020-05-16 11:43:48 +02:00
zbsz
d7d8bfc472 Add 'self to parameter' renaming. 2020-05-15 19:05:59 -07:00
Hasan Ali
001a86dc03 Fix completion and hover for module and function of same name 2020-05-16 01:09:04 +01:00
Florian Diebold
3f42b2e837 Handle Self in values and patterns
I.e.
 - `Self(x)` or `Self` in tuple/unit struct impls
 - `Self::Variant(x)` or `Self::Variant` in enum impls
 - the same in patterns

Fixes #4454.
2020-05-15 17:25:28 +02:00
bors[bot]
d51c1f6217
Merge #4448
4448: Generate configuration for launch.json r=vsrs a=vsrs

This PR adds two new commands: `"rust-analyzer.debug"` and `"rust-analyzer.newDebugConfig"`. The former is a supplement to the existing `"rust-analyzer.run"` command and works the same way: asks for a runnable and starts new debug session. The latter allows adding a new configuration to **launch.json** (or to update an existing one).

If the new option `"rust-analyzer.debug.useLaunchJson"` is set to true then `"rust-analyzer.debug"` and Debug Lens will first look for existing debug configuration in **launch.json**. That is, it has become possible to specify startup arguments, env variables, etc.

`"rust-analyzer.debug.useLaunchJson"` is false by default, but it might be worth making true the default value. Personally I prefer true, but I'm not sure if it is good for all value.

----
I think that this PR also solves https://github.com/rust-analyzer/rust-analyzer/issues/3441.
Both methods to update launch.json mentioned in the issue do not work:
1. Menu. It is only possible to add a launch.json configuration template via a debug adapter. And anyway it's only a template and it is impossible to specify arguments from an extension.

2. DebugConfigurationProvider. The exact opposite situation: it is possible to specify all debug session settings, but it is impossible to export these settings to launch.json.

Separate `"rust-analyzer.newDebugConfig"` command looks better for me.

----
Fixes #4450
Fixes #3441

Co-authored-by: vsrs <vit@conrlab.com>
Co-authored-by: vsrs <62505555+vsrs@users.noreply.github.com>
2020-05-15 14:29:01 +00:00
bors[bot]
982b92f966
Merge #4431
4431: Store proc-macro result in salsa db r=matklad a=edwin0cheng

Fixed #4315 

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-05-15 10:17:42 +00:00
Aleksey Kladov
08027c3075 Cleanups 2020-05-15 02:09:30 +02:00
Aleksey Kladov
f1a5c489fd Better structure 2020-05-15 01:58:39 +02:00
Aleksey Kladov
220813dcb0 Move LSP bits from flycheck to rust-analyzer
There should be only one place that knows about LSP, and that place is
right before we spit JSON on stdout.
2020-05-15 01:52:25 +02:00
bors[bot]
12d82687cd
Merge #4273
4273: Trigger add_vis assist on paths/record fields as well r=flodiebold a=TimoFreiberg

Resolves #4037.

- [x] Function defs
- [x] ADT defs
- [x] Enum variants
- [x] Consts
- [x] Statics
- [x] Traits
- [x] Type aliases
- [x] Modules
- [x] Record fields (using different implementation)
    - [x] struct fields
    - [x] enum variant fields
    -   union fields (`Semantics::resolve_record_field` seems to not work for union fields, so I think this can be handled in a future PR)
- [x] More tests? 
- [x] Improve test fixture code and documentation a bit (see [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Fwg-rls-2.2E0/topic/resolve_path.20between.20fixture.20files))

Co-authored-by: Timo Freiberg <timo.freiberg@gmail.com>
2020-05-14 14:29:22 +00:00
Aleksey Kladov
acedad8134 Minor 2020-05-14 15:36:15 +02:00
Aleksey Kladov
fc0c5dfcd1 Put preselect items on top 2020-05-14 15:33:56 +02:00
vsrs
51d5a08255
Better label for a runnable.
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-05-14 16:28:18 +03:00
Aleksey Kladov
90c62bcee9 Prioritize locals with correct types 2020-05-14 15:15:52 +02:00
vsrs
20fdd14c62 Multiple binaries support for launch.json.
Generate unique names on the LSP side.
2020-05-14 16:02:01 +03:00
bors[bot]
f1587ac263
Merge #4445
4445: Correctly fill default type parameters r=flodiebold a=montekki

Fixes #3877 

So, basically even if the parameters are omitted from the `impl` block, check the parameters in `trait` if they have a default type, and if they do go from `hir` to `ast::TypeArg`. I've added a helper for that but I am not sure that it's a proper way to go from `hir` to `ast` here.

Co-authored-by: Fedor Sakharov <fedor.sakharov@gmail.com>
2020-05-14 11:20:42 +00:00
Fedor Sakharov
ccd5268374
Ty -> Type 2020-05-14 13:53:45 +03:00
Fedor Sakharov
12bf008ab1
Adds a param_idx helper 2020-05-14 13:47:36 +03:00
Edwin Cheng
20f7068b68 Store proc-macro result in salsa db 2020-05-14 17:57:51 +08:00
bors[bot]
5148d6dc66
Merge #4405
4405: Make some stuff public so that they can be reused by other tools r=pksunkara a=pksunkara

So, my little experiment of building a code analysis tool using rust-analyzer is successful. I am going to proceed to build the tool now. This PR makes the needed things public.

I know there were some things about trying to change stuff regarding loading workspaces, which would make it more easier for other tools to reuse. But, until then, it should be okay using this `load_cargo` fn.

Btw, if I were publish my tool, I would need the `ra` crates to be released. Since @matklad told me that he doesn't want to care about breaking stuff, I would propose the following.

Every monday, during the weekly release, we release a new pre v1 minor version of all the crates. That way, we don't need to care about breaking stuff but still have rust-analyzer on crates.io.

I made https://github.com/pksunkara/cargo-workspaces to help release workspace crates easily.

So, coming week, we start with `0.1.0`, then week after that, we release `0.2.0` and then `0.3.0` etc.. until we decide on `1.0.0` which is probably when the compiler team also starts using the crates. There is no limit to the minor versions (we can even have `0.150.0` or `0.1500.0`), so I don't see anything wrong with this strategy.

Co-authored-by: Pavan Kumar Sunkara <pavan.sss1991@gmail.com>
2020-05-14 09:23:34 +00:00
Pavan Kumar Sunkara
9f0a7eb97b Make some stuff public so that they can be reused by other tools 2020-05-14 11:14:46 +02:00
Fedor Sakharov
2dfbec149f
Fix formatting 2020-05-14 10:31:34 +03:00
Fedor Sakharov
7e9396c7eb
Change type_arg to type_ref func 2020-05-14 10:14:04 +03:00
Fedor Sakharov
a55ad20388
Use generic_defaults and display_source_code 2020-05-14 09:56:20 +03:00
Trevor Spiteri
2d0a949236 Use back ticks instead of single quotes around code 2020-05-14 01:06:07 +02:00
Laurențiu Nicola
55e914a2a1 Remove hidden VARIATION SELECTOR-16 2020-05-13 17:26:57 +03:00
Fedor Sakharov
00f3b6c59a
Correctly fill default type parameters 2020-05-13 16:07:44 +03:00
bors[bot]
a84bd9e18c
Merge #4434
4434: add more specific match postfix for Result and Option r=matklad a=bnjjj

In order to have the same behavior than `if let` and `while let`

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-05-13 09:25:01 +00:00
bors[bot]
9594fe33fa
Merge #4083
4083: Smol documentation for ast nodes r=matklad a=Veetaha

There is a tremendous amount of TODOs to clarify the topics I am not certain about.
Please @matklad, @edwin0cheng review carefully, I even left some mentions of your names in todos to put your attention where you most probably can give comments.

In order to simplify the review, I separated the codegen (i.e. changes in `ast/generated/nodes.rs`) from `ast_src` changes (they in fact just duplicate one another) into two commits.

Also, I had to hack a little bit to let the docs be generated as doc comments and not as doc attributes because it's easier to read them this way and IIRC we don't support hints for `#[doc = ""]` attributes for now...

Closes #3682 

Co-authored-by: veetaha <veetaha2@gmail.com>
2020-05-13 09:09:46 +00:00
Trevor Spiteri
3583e0fe2b fix typo unimplementated -> unimplemented
Pretty harmless typo, but it does get exposed in
lsp-rust-analyzer-expand-macro.
2020-05-12 23:51:38 +02:00