Commit graph

7407 commits

Author SHA1 Message Date
vsrs
d4e75312ba Add associated type test. 2020-06-18 10:15:43 +03:00
vsrs
283ec13fc0 Fix type "items" order. 2020-06-18 10:15:43 +03:00
vsrs
c50157f330 Add Go to Type Definition hover action. 2020-06-18 10:15:43 +03:00
vsrs
102b7f0f56 Fix empty hover action group for a runnable. 2020-06-18 10:15:42 +03:00
bors[bot]
28077f971a
Merge #4872
4872: Reduce the usage of bare subscript operator r=matklad a=Veetaha



Co-authored-by: Veetaha <veetaha2@gmail.com>
2020-06-18 06:48:12 +00:00
bors[bot]
99e3acd1fe
Merge #4934
4934: Remove special casing for library symbols r=matklad a=matklad

We might as well handle them internally, via queries.

I am not sure, but it looks like the current LibraryData setup might
even predate salsa? It's not really needed and creates a bunch of
complexity.



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-06-18 06:31:24 +00:00
Aleksey Kladov
d1d0b5a88c Remove special casing for library symbols
We might as well handle them internally, via queries.

I am not sure, but it looks like the current LibraryData setup might
even predate salsa? It's not really needed and creates a bunch of
complexity.
2020-06-18 08:29:34 +02:00
Veetaha
9bb028189a Simplify 2020-06-18 02:00:48 +03:00
Jonas Schievink
4d6d7aec50 Avoid all unchecked indexing in match checking 2020-06-17 21:41:07 +02:00
unexge
ce29d172a5 Fix renaming mod in use tree 2020-06-17 20:16:04 +03:00
bors[bot]
1ce8c2b5a0
Merge #4927
4927: Better encapsulate reverse-mapping of files to cargo targets r=matklad a=matklad

We need to find a better way to do it...

CrateGraph by itself is fine, CargoWorkspace as well, but the mapping
between the two seems arbitrary...



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-06-17 15:53:07 +00:00
Aleksey Kladov
dc90e0b5a5 Better encapsulate reverse-mapping of files to cargo targets
We need to find a better way to do it...

CrateGraph by itself is fine, CargoWorkspace as well, but the mapping
between the two seems arbitrary...
2020-06-17 17:51:46 +02:00
Paul Daniel Faria
a951108173 Ensure all existing doctest code highlights have documentation modifier 2020-06-17 09:33:21 -04:00
Leander Tentrup
2145e2d878 Syntax highlighting for escape sequences in strings 2020-06-17 15:27:13 +02:00
Paul Daniel Faria
aae26bc5b8 Add highlighting support for doc comments 2020-06-17 08:29:13 -04:00
bors[bot]
931f317399
Merge #4913 #4915 #4916
4913: Remove debugging code for incremental sync r=matklad a=lnicola



4915: Inspect markdown code fences to determine whether to apply syntax highlighting r=matklad a=ltentrup

Fixes #4904 

4916: Warnings as hint or info r=matklad a=GabbeV

Fixes #4229 

This PR is my second attempt at providing a solution to the above issue. My last PR(#4721) had to be rolled back(#4862) due to it overriding behavior many users expected. This PR solves a broader problem while trying to minimize surprises for the users. 

### Problem description
The underlying problem this PR tries to solve is the mismatch between [Rustc lint levels](https://doc.rust-lang.org/rustc/lints/levels.html) and [LSP diagnostic severity](https://microsoft.github.io/language-server-protocol/specification#diagnostic). Rustc currently doesn't have a lint level less severe than warning forcing the user to disable warnings if they think they get to noisy. LSP however provides two severitys below warning, information and hint. This allows editors like VSCode to provide more fine grained control over how prominently to show different diagnostics.

Info severity shows a blue squiggly underline in code and can be filtered separately from errors and warnings in the problems panel.
![image](https://user-images.githubusercontent.com/13839236/84830640-0bb8d900-b02a-11ea-9e2f-0561b0e8f1ef.png)
![image](https://user-images.githubusercontent.com/13839236/84826931-ffca1880-b023-11ea-8080-5e5b91a6ac0d.png)

Hint severity doesn't show up in the problems panel at all and only show three dots under the affected code or just faded text if the diagnostic also has the unnecessary tag.
![image](https://user-images.githubusercontent.com/13839236/84827165-55062a00-b024-11ea-8bd6-bdbf1217c4c5.png)

### Solution
The solution provided by this PR allows the user to configure lists of of warnings to report as info severity and hint severity respectively. I purposefully only convert warnings and not errors as i believe it's a good idea to have the editor show the same severity as the compiler as much as possible.
![image](https://user-images.githubusercontent.com/13839236/84829609-50437500-b028-11ea-80a8-1bbd05680ba7.png)

### Open questions
#### Discoverability
How do we teach this to new and existing users? Should a section be added to the user manual? If so  where and what should it say?

#### Defaults
Other languages such as TypeScript report unused code as hint by default. Should rust-analyzer similarly report some problems as hint/info by default?

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
Co-authored-by: Leander Tentrup <leander.tentrup@gmail.com>
Co-authored-by: Gabriel Valfridsson <gabriel.valfridsson@gmail.com>
2020-06-17 11:01:37 +00:00
bors[bot]
09c5cfedff
Merge #4914
4914: Fix panic in match checking r=flodiebold a=jonas-schievink

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/4416

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-06-17 10:53:22 +00:00
David Lattimore
ac9166a7af Remove :expr from placeholders
Reasoning discussed at #3186
2020-06-17 18:28:24 +10:00
Gabriel Valfridsson
656e95211e Warnings as hint or info 2020-06-17 00:00:43 +02:00
Leander Tentrup
8ff91cf6b6 Inspect markdown code fences to determine whether to apply syntax highlighting 2020-06-16 23:03:59 +02:00
Jonas Schievink
d8af7983b1 Use ra_fixture and reformat tests 2020-06-16 22:54:41 +02:00
Jonas Schievink
9ecbadcedb Fix index-out-of-bounds panic in match checking 2020-06-16 22:45:34 +02:00
Laurențiu Nicola
2fa0b20ce0 Remove debugging code for incremental sync 2020-06-16 22:06:24 +03:00
Aleksey Kladov
3c72fc0573 Anchor file-system operations to the file, and not to the source root.
Anchoring to the SourceRoot wont' work if the path is absolute:

  #[path = "/tmp/foo.rs"]
  mod foo;

Anchoring to a file will.

However, we *should* anchor, instead of just producing an abs path.

I can imagine a situation where, for example, rust-analyzer processes
crates from different machines (or, for example, from in-memory git
branch), where the same absolute path in different crates might refer
to different files in the end!
2020-06-16 18:45:58 +02:00
bors[bot]
6b2175878d
Merge #4891
4891: New VFS API r=matklad a=matklad

cc @flodiebold , @jonas-schievink 

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-06-16 11:48:36 +00:00
Aleksey Kladov
c002322bde New VFS API 2020-06-16 13:42:29 +02:00
bors[bot]
4342b71715
Merge #4876
4876: Syntactic highlighting of NAME_REF for injections r=matklad a=ltentrup

This commit adds a function that tries to determine the syntax highlighting class of NAME_REFs based on the usage.
It is used for highlighting injections (such as highlighting of doctests) as the semantic logic will most of the time result in unresolved references.
It also adds a color to unresolved references in HTML encoding.

Follow up of #4683.
Fixes #4809.

Co-authored-by: Leander Tentrup <leander.tentrup@gmail.com>
2020-06-16 11:40:51 +00:00
bors[bot]
83a16e825d
Merge #4878
4878: Make "Replace qualified name with use" replace *all* mentions of the path r=matklad a=jonas-schievink

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/4836

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-06-16 05:29:05 +00:00
Jonas Schievink
4295a004ed Operate only on AST paths instead of HIR 2020-06-16 00:49:59 +02:00
Benjamin Coenen
9aad07dbea don't complete top level attrs inside nested attrs and add better labels #4890
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-06-15 23:11:08 +02:00
Jonas Schievink
aaaa68b56c Simplify 2020-06-15 22:59:49 +02:00
Jonas Schievink
71c002e589 It's fookin' raw 2020-06-15 22:39:26 +02:00
Leander Tentrup
c4b3db0c2f Syntactic highlighting of NAME_REF for injections
This commit adds a function that tries to determine the syntax highlighting class of NAME_REFs based on the usage.
It is used for highlighting injections (such as highlighting of doctests) as the semantic logic will most of the time result in unresolved references.
It also adds a color to unresolved references in HTML encoding.
2020-06-15 22:13:53 +02:00
bors[bot]
f4f51171ca
Merge #4860
4860: Accept relative paths in rust-project.json r=matklad a=tweksteen

If a relative path is found as part of Crate.root_module or Root.path, interpret it as relative to the location of the rust-project.json file.

Fixes: #4816 

Co-authored-by: Thiébaud Weksteen <tweek@google.com>
2020-06-15 15:03:31 +00:00
bors[bot]
5b013e5665
Merge #4877
4877: Fix syntax highlighting of recursive macros r=matklad a=ltentrup

Add syntax highlighting for the BANG (`!`) token if the parent is `MACRO_CALL`.

Before:
<img width="514" alt="before" src="https://user-images.githubusercontent.com/201808/84595030-11f65c00-ae56-11ea-9bb2-b1abe2236990.png">

After:
<img width="516" alt="recursive-macro" src="https://user-images.githubusercontent.com/201808/84594981-d196de00-ae55-11ea-8636-f877d5d795ff.png">


Fixes #4694.

Co-authored-by: Leander Tentrup <leander.tentrup@gmail.com>
2020-06-15 13:44:46 +00:00
Leander Tentrup
06f89e5f3a Fix syntax highlighting of recursive macros
Add syntax highlighting for the BANG (`!`) token if the parent is `MACRO_CALL`.
2020-06-15 15:03:13 +02:00
David Lattimore
fe7d35d477 Make ra_syntax::{SyntaxNodeChildren, SyntaxElementChildren} public.
SyntaxNode::children and SyntaxNode::children_with_tokens return these types, but there's currently no way AFAIK to name them.
2020-06-15 21:36:30 +10:00
Thiébaud Weksteen
44f28f65af Accept relative paths in rust-project.json
If a relative path is found as part of Crate.root_module or Root.path,
interpret it as relative to the location of the rust-project.json file.
2020-06-15 13:11:53 +02:00
bors[bot]
db6100dbaa
Merge #4889
4889: Deprecate hir::Path::from_ast r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-06-15 09:02:53 +00:00
Aleksey Kladov
b5c4f2faa2 Update parser tests with env var 2020-06-15 11:02:17 +02:00
Aleksey Kladov
d739731830 Allow attributes on expressions
https://github.com/rust-lang/rust/pull/69201/
2020-06-15 10:59:05 +02:00
Aleksey Kladov
52a220cece Deprecate hir::Path::from_ast 2020-06-15 10:55:48 +02:00
bors[bot]
6609e71b16
Merge #4882
4882: _match.rs: improve comment formatting r=matklad a=jonas-schievink

This results in much nicer rustdoc output

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-06-15 08:25:05 +00:00
Toby Dimmick
41f5471f3e fill_match_arms bind pattern implementation 2020-06-14 22:44:51 +01:00
Toby Dimmick
34db4edb80 fill_match_arms bind pattern test 2020-06-14 22:43:16 +01:00
Benjamin Coenen
36d9105d0e display Doctest code lens before comment #4785
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-06-14 21:50:24 +02:00
Jonas Schievink
4ebafb9005 _match.rs: improve comment formatting 2020-06-14 15:56:02 +02:00
Aleksey Kladov
a32cff333d Introduce paths crate
It's a good idea to distinguish between absolute and relative paths at
the type level, to avoid accidental dependency on the cwd, which
really shouldn't matter for rust-analyzer service
2020-06-14 14:15:36 +02:00
Veetaha
667d224fcc Reduce the usage of bare subscript operator 2020-06-14 13:12:52 +03:00
Jonas Schievink
5d66bfe163 Shorten *all* qualified paths when adding use 2020-06-13 19:12:05 +02:00
Jonas Schievink
b65c0a5893 Expose find_insert_use_container 2020-06-13 19:05:46 +02:00
Jonas Schievink
e9eb54c617 Fix rewrite_root when there's only 1 replacement 2020-06-13 19:05:46 +02:00
bors[bot]
246c66a7f7
Merge #4867
4867: Cleanup URL handling r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-06-13 12:35:44 +00:00
Aleksey Kladov
50bbf7233d Cleanup URL handling 2020-06-13 14:15:38 +02:00
bors[bot]
d00ca86da4
Merge #4868
4868: Fix if and while postfix completions r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-06-13 12:12:08 +00:00
Aleksey Kladov
7dafe951d4 Fix if and while postfix completions 2020-06-13 14:06:13 +02:00
bors[bot]
c87c4a0a40
Merge #4700
4700: Add top level keywords completion r=matklad a=mcrakhman

This fixes the following issue: https://github.com/rust-analyzer/rust-analyzer/issues/4566. 

Also added simple logic which filters the keywords which can be used with unsafe on the top level.   

Co-authored-by: Mikhail Rakhmanov <rakhmanov.m@gmail.com>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-06-13 12:02:59 +00:00
Aleksey Kladov
b99b4953c9 More concise completion tests 2020-06-13 13:57:18 +02:00
Aleksey Kladov
ef70076f1d Cleanup 2020-06-13 13:47:30 +02:00
Mikhail Rakhmanov
912f38200f Add keywords completions on source file position 2020-06-13 10:43:39 +02:00
Mikhail Rakhmanov
16bbf4ab7f Merge branch 'master' into keyword_completion
# Conflicts:
#	docs/user/generated_features.adoc
2020-06-13 08:42:15 +02:00
Mikhail Rakhmanov
eeb8b9e236 Fix tests and remove unused methods 2020-06-13 01:21:48 +02:00
Mikhail Rakhmanov
6feb52c12a Add more patterns, tests and fix keywords 2020-06-13 00:55:21 +02:00
Mikhail Rakhmanov
3576671043 Rewrite snapshot checks 2020-06-12 20:30:57 +02:00
Timo Freiberg
f5ac313000 Add quickfix to add a struct field 2020-06-12 18:52:44 +02:00
Gabriel Valfridsson
66291d19f9 Revert "Hide squiggly for unused and unnecessary"
This reverts commit 599c105e6f.
2020-06-12 18:39:50 +02:00
bors[bot]
b56ad148db
Merge #4857
4857: Fix invalid shorthand initialization diagnostic for tuple structs r=jonas-schievink a=OptimalStrategy

Initializing tuple structs explicitly, like in the example below, produces a "Shorthand struct initialization" diagnostic that leads to a compilation error when applied:
```rust
struct S(usize);

fn main() { 
    let s = S { 0: 0 };  // OK, but triggers the diagnostic
    // let s = S { 0 };  // Compilation error
}
```

This PR adds a check that the field name is not a literal.

Co-authored-by: OptimalStrategy <george@usan-podgornov.com>
Co-authored-by: OptimalStrategy <17456182+OptimalStrategy@users.noreply.github.com>
2020-06-12 14:28:40 +00:00
OptimalStrategy
591b5ec2c1 simplify determining whether the field is a tuple field 2020-06-12 10:16:19 -04:00
bors[bot]
f3d73865d6
Merge #4855
4855: Use more idiomatic style for lifetimes in generated code r=matklad a=Veetaha



Co-authored-by: Veetaha <veetaha2@gmail.com>
2020-06-12 12:49:30 +00:00
bors[bot]
1906655070
Merge #4856
4856: Simplify r=matklad a=Veetaha



Co-authored-by: Veetaha <veetaha2@gmail.com>
2020-06-12 12:41:52 +00:00
Mikhail Rakhmanov
42a719ad25 Remove comment and incorrect assert 2020-06-12 13:14:53 +02:00
Mikhail Rakhmanov
d38bf1624d Return snapshots to tests 2020-06-12 13:09:42 +02:00
Jonas Schievink
0231e4ac77 find_path: return shorter paths for external items
If a containing module is already in scope, there's no need to
use the full path to the item.
2020-06-12 13:01:20 +02:00
Mikhail Rakhmanov
f123539ad2 More assert refactoring 2020-06-12 12:15:53 +02:00
Mikhail Rakhmanov
4c92f2d190 Add more pattern tests 2020-06-12 10:12:15 +02:00
Mikhail Rakhmanov
396167eadb New testing approach for keywords 2020-06-12 08:49:12 +02:00
OptimalStrategy
59f195a323 Fix invalid shorthand initialization diagnostic for tuple structs 2020-06-12 01:11:54 -04:00
Veetaha
4fefc7d06c Simplify 2020-06-12 02:56:06 +03:00
Veetaha
c514060600 Apply codegen with idiomatic lifetimes 2020-06-12 01:26:58 +03:00
Mikhail Rakhmanov
a2b4385f16 Add few smoke tests for patterns and refactoring 2020-06-12 00:17:30 +02:00
Mikhail Rakhmanov
f46bc12199 Add more patterns and keywords 2020-06-11 23:25:58 +02:00
bors[bot]
36353bb182
Merge #4833
4833: Separating parsing of `for` in predicates and types r=matklad a=matthewjasper

We now correctly accept `for<'a> (&'a F): Fn(&'a str)` in a where clause and correctly reject `for<'a> &'a u32` as a type.

Co-authored-by: Matthew Jasper <mjjasper1@gmail.com>
2020-06-11 17:33:20 +00:00
Matthew Jasper
8622e4cc1b Add example of old trait object syntax 2020-06-11 18:15:03 +01:00
Matthew Jasper
879693e63c Move complex inline test to own file 2020-06-11 18:14:57 +01:00
bors[bot]
bd61ad756c
Merge #4849
4849: Make known paths use `core` instead of `std` r=matklad a=jonas-schievink

I'm not sure if this causes problems today, but it seems like it easily could, if rust-analyzer processes the libstd sources for the right `--target` and that target is a `#![no_std]`-only target.

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2020-06-11 15:30:05 +00:00
Jonas Schievink
215e229dd1 Update wrap return tests
Update "no diagnostic" tests, use `()` instead of `String`
2020-06-11 17:28:32 +02:00
bors[bot]
7c617000b8
Merge #4850
4850: Indent chain `.` even if there's more stuff afterwards r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-06-11 15:20:24 +00:00
Aleksey Kladov
279a1ae564 Indent chain . even if there's more stuff afterwards 2020-06-11 17:13:24 +02:00
Jonas Schievink
90331ea035 Make known paths use core instead of std 2020-06-11 16:23:20 +02:00
Mikhail Rakhmanov
eb4004fdb8 Add todo 2020-06-11 14:32:14 +02:00
Mikhail Rakhmanov
9f91901f7e Add more keywords 2020-06-11 14:16:35 +02:00
Aleksey Kladov
663ce0e99d Remove dead code 2020-06-11 13:34:09 +02:00
bors[bot]
32157d48f4
Merge #4843
4843: Don't guess macro expansion crate r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-06-11 10:18:53 +00:00
Aleksey Kladov
fac7b0e252 Don't guess macro expansion crate 2020-06-11 12:13:14 +02:00
bors[bot]
f320c38aec
Merge #4819
4819: Add an FST index to `ImportMap` and use it to speed up auto import r=matklad a=jonas-schievink

For the importing crate, we still use the symbol index, but I've modified it to only look at files that comprise that crate (instead of the whole workspace).

Oh, and since now the symbol query limit is respected correctly, it's possible that some results from the local crate now disappear if there are many matches.

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/4763

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2020-06-11 10:07:52 +00:00
Jonas Schievink
6766a6b0e1 Add symbol index FIXME 2020-06-11 12:03:08 +02:00
Aleksey Kladov
d8a5d39c2d Make relevant_crates return a Set 2020-06-11 11:30:06 +02:00
Jonas Schievink
dd22657407 ImportMap: use IndexMap internally
It iterates in insertion order, which makes the ordering more
predictable.
2020-06-10 16:15:49 +02:00
Jonas Schievink
7e83ed99a8 Respect casing when searching for imports 2020-06-10 16:04:55 +02:00
Jonas Schievink
ed2817e599 Move limit check down 2020-06-10 12:40:33 +02:00
Jonas Schievink
56c7145993 Limit import map queries 2020-06-10 12:40:33 +02:00
Jonas Schievink
bcf875f46a Clean up import_map.rs 2020-06-10 12:38:58 +02:00
Jonas Schievink
781b514e58 Add test for macro generated items 2020-06-10 12:38:58 +02:00
Jonas Schievink
a70a0ca73c ImportsLocator: use ImportMap for non-local crates 2020-06-10 12:38:58 +02:00
Jonas Schievink
b01fb22494 ra_hir: expose import_map::search_dependencies 2020-06-10 12:38:58 +02:00
Jonas Schievink
6463d3ac63 symbol_index: allow querying a single crate 2020-06-10 12:38:58 +02:00
Jonas Schievink
4bcf8c8c68 Add an FST index to ImportMap 2020-06-10 12:38:58 +02:00
Jonas Schievink
54936e8aa2 Fix the symbol query limit 2020-06-10 12:38:58 +02:00
Jonas Schievink
d50a1a0fe9 Profile world_symbols 2020-06-10 12:38:58 +02:00
bors[bot]
f632727b2a
Merge #4834
4834: In field patterns, don't highlight local binding as a field r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-06-10 10:37:27 +00:00
Aleksey Kladov
db1cadd444 In field patterns, don't highlight local binding as a field 2020-06-10 12:34:23 +02:00
Matthew Jasper
506e1ddbfa Separating parsing of for in predicates and types 2020-06-10 11:30:58 +01:00
Aleksey Kladov
27ebe5d33e Reduce OUT_DIR special casing 2020-06-10 12:08:35 +02:00
bors[bot]
560b98bc50
Merge #4822
4822: Let checkOnSafe default to some of the options of cargo r=matklad a=clemenswasser

This will fix #4631
The implementation works (as far as I have tested) but is suboptimal because I am copying the "cargo.features".

Co-authored-by: Clemens Wasser <clemens.wasser@gmail.com>
2020-06-10 07:39:44 +00:00
Clemens Wasser
fe21fc2d25 checkOnSafe.features and checkOnSafe.allFeatures now work identically. 2020-06-10 09:37:26 +02:00
Clemens Wasser
33b9058838 Most of the checkOnSafe options now default to the cargo equivalent. 2020-06-10 09:27:25 +02:00
Clemens Wasser
47ef544fa5 Added the rust-analyzer.checkOnSave.features option. 2020-06-10 08:51:11 +02:00
bors[bot]
c9fc7251ca
Merge #4824
4824: Correct "debug_assertion" to "debug_assertions" to match the cfg that the rust debug assert macros use. r=matklad a=woody77

This is for #4823.

Co-authored-by: Aaron Wood <aaronwood@google.com>
2020-06-10 05:24:18 +00:00
Aaron Wood
f4ed2da966 Correct "debug_assertion" to "debug_assertions" to match the cfg
option that the rust debug assert macros use.
2020-06-09 19:58:39 -07:00
Clemens Wasser
684b6fa1b8 flycheck now uses the configured features 2020-06-09 21:47:54 +02:00
Benjamin Coenen
9d0a6aaee3 display Doctest code lens before comment #4785
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-06-09 21:28:51 +02:00
Aleksey Kladov
e8d50578ab Correctly parse <_> paths in patterns
closes #3659
2020-06-09 13:45:18 +02:00
Aleksey Kladov
16943e533c Minor, use T! 2020-06-09 13:45:11 +02:00
bors[bot]
d4d384e4c8
Merge #4813
4813: Simplify r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-06-09 11:22:38 +00:00
Aleksey Kladov
d8571e076c Simplify 2020-06-09 13:17:22 +02:00
bors[bot]
eb53f5a9e5
Merge #4812
4812: Use correct indent when replacing with match r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-06-09 11:14:30 +00:00
Aleksey Kladov
8cad7d1a2b Use correct indent when replacing with match 2020-06-09 12:38:47 +02:00
bors[bot]
382d10ea60
Merge #4811
4811: Unwrap block works with match arms r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-06-09 10:12:50 +00:00
Aleksey Kladov
53cc2c16e7 Unwrap block works with match arms 2020-06-09 11:52:45 +02:00
bors[bot]
4cacedd3de
Merge #4810
4810: Simplify unwrapping of blocks r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-06-09 09:33:56 +00:00
Aleksey Kladov
5233766ce5 Simplify unwrapping of blocks 2020-06-09 11:33:28 +02:00
bors[bot]
6f0cc91c88
Merge #4803
4803: Parse default unsafe fn r=matklad a=Avi-D-coder



Co-authored-by: Avi Dessauer <avi.the.coder@gmail.com>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-06-09 08:56:28 +00:00
Aleksey Kladov
2785362a1f
Update crates/ra_parser/src/grammar/items.rs 2020-06-09 10:50:25 +02:00
Aaron Wood
055b9b64bc Finish transition to cfgs from the separate atoms and features. 2020-06-08 16:19:39 -07:00
Aleksey Kladov
38fa4d17fb Simplify API 2020-06-09 00:01:53 +02:00
Avi Dessauer
e38685cb48 Parse default unsafe fn 2020-06-08 17:49:06 -04:00
Aleksey Kladov
2a42904680 Simplify 2020-06-08 21:48:23 +02:00
bors[bot]
3a7c218fd4
Merge #4576
4576: Add implementation of extract struct from enum variant r=matklad a=mcrakhman

Hi guys! I implemented the extraction functionality including modifying multiple files. The only thing I didn't change the cursor position. I've done it with a previous API, but now snippets have been introduced and I need to figure out how to do it.

Please bear in mind that I am a newcomer in the rust-analyzer (and also Rust) world, so I tried to implement the feature to the best of my knowledge, but the API is very new to me, so I am very welcome to introducing changes etc. 

Co-authored-by: Mikhail Rakhmanov <rakhmanov.m@gmail.com>
2020-06-08 16:28:48 +00:00
bors[bot]
38ac331f7d
Merge #4784
4784: Change management of test cfg to better support json projects r=Nashenas88 a=Nashenas88

This helps support json projects where they can decide whether to add the `test` cfg or not. One alternative is to add support for marking json project crates as a sysroot crate, and adding logic to remove the `test` cfg in those cases. In my opinion, that option gives less flexibility to json projects and leads to more functionality that needs to be maintained.

Fixes #4508 
cc @woody77 

Co-authored-by: Paul Daniel Faria <Nashenas88@users.noreply.github.com>
Co-authored-by: Paul Daniel Faria <nashenas88@users.noreply.github.com>
2020-06-08 16:20:45 +00:00
Paul Daniel Faria
dbceaf522b Use Option<&str> for target instead of Option<&String> 2020-06-08 12:10:23 -04:00
Paul Daniel Faria
9c35f135b9 Remove default_cfg_options, pass target instead so it can be used for building cargo workspaces 2020-06-08 10:23:29 -04:00
Aleksey Kladov
3b4d000250 Better unsafe highlihgting tests 2020-06-08 15:23:03 +02:00
Aleksey Kladov
c476f71bdf Highlight only the unsafe operator itself 2020-06-08 15:03:14 +02:00
bors[bot]
83fd0fb355
Merge #4775
4775: Add goto def for enum variant field r=matklad a=unexge

Closes #4764. I'm not familiar with ra codebase, there might be better ways to do that 😄 

Co-authored-by: unexge <unexge@gmail.com>
2020-06-08 12:46:12 +00:00
unexge
48b6dd0b33 Use explicit match for extracting def from classify_name 2020-06-08 15:38:10 +03:00
unexge
4edf736eb2 Swap into_definition and definition semantics for FieldShorthand variant 2020-06-08 15:37:12 +03:00
bors[bot]
db36a25839
Merge #4683
4683: Implement syntax highlighting for doctests r=ltentrup a=ltentrup

The implementation is more complicated than the previous injection logic as the doctest comments consist of multiple ranges. The implementation extracts the doctests together with an offset-mapping, applies the syntax highlighting, and updates the text ranges.

<img width="478" alt="Bildschirmfoto 2020-06-01 um 15 45 25" src="https://user-images.githubusercontent.com/201808/83415249-1f0b5800-a41f-11ea-8fa6-c282434d6ff7.png">

Part of #4170.

Co-authored-by: Leander Tentrup <leander.tentrup@gmail.com>
2020-06-08 12:26:33 +00:00
Leander Tentrup
4a2efb2f42 Implement syntax highlighting for doctests 2020-06-08 14:18:16 +02:00
unexge
c5d5d21858 Add FieldShorthand variant to NameClass 2020-06-08 14:46:58 +03:00
bors[bot]
6e4fca5882
Merge #4773
4773: Run|Debug hover actions. r=matklad a=vsrs

![hover_actions_run](https://user-images.githubusercontent.com/62505555/83335644-dfc1f780-a2b6-11ea-820b-ccaa82290e7d.gif)

This hover actions work exactly like corresponding lenses.

Co-authored-by: vsrs <vit@conrlab.com>
2020-06-08 11:29:35 +00:00
vsrs
b7db9f058a Apply suggestions from code review 2020-06-08 14:19:40 +03:00
bors[bot]
d8552d114c
Merge #4781
4781: Remove redundancy in syntax highlighting tests r=matklad a=ltentrup

Follow up from #4683. Improves syntax highlighting testing by introducing a function that contains the boilerplate comparison code. Keeps the `ra_fixture` argument in the first position, thus, the editor syntax highlighting injection still works.

Co-authored-by: Leander Tentrup <leander.tentrup@gmail.com>
2020-06-08 09:48:38 +00:00
bors[bot]
bb0d4600ff
Merge #4770
4770: Clean up handling of int/float literal types r=matklad a=flodiebold

'Unknown' int/float types actually never exist as such, they get replaced by type variables immediately. So the whole `Uncertain<IntTy>` thing was unnecessary and just led to a bunch of match branches that were never hit.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2020-06-08 09:37:37 +00:00
Leander Tentrup
3aaaf924cb Fix bug in lexer for format specifier where the type and width were not correctly distinguished 2020-06-07 22:57:24 +02:00
Paul Daniel Faria
3937b225e7 Change management of test cfg to better support json projects 2020-06-07 10:29:03 -04:00
Leander Tentrup
65943c0585 Remove redundancy in syntax highlighting tests 2020-06-07 14:50:02 +02:00
unexge
73684a4ae2 Add goto def for enum variant field 2020-06-06 22:16:59 +03:00
vsrs
9b4256dc4d Add lib target filtering. 2020-06-06 22:11:17 +03:00
vsrs
46084f8a96 Disable runnables lookup in macro-generated code. 2020-06-06 20:10:36 +03:00
Florian Diebold
d66daee849 Clean up handling of int/float literal types
'Unknown' int/float types actually never exist as such, they get replaced by
type variables immediately. So the whole `Uncertain<IntTy>` thing was
unnecessary and just led to a bunch of match branches that were never hit.
2020-06-06 17:52:00 +02:00
vsrs
3434f1dd2c Add Run|Debug hover actions 2020-06-06 18:17:52 +03:00
vsrs
de74c0dcab Preliminary runnables refactoring 2020-06-06 18:17:52 +03:00
Florian Diebold
a4a4a1854e Fix type parameter defaults
They should not be applied in expression or pattern contexts, unless there are
other explicitly given type args.
2020-06-05 20:09:13 +02:00
bors[bot]
02f7b5d7ab
Merge #4761
4761: Upgrade Chalk to published version r=matklad a=flodiebold

CC @pksunkara 

Co-authored-by: Florian Diebold <florian.diebold@freiheit.com>
2020-06-05 16:05:06 +00:00
bors[bot]
2a3ab7f3b4
Merge #4689
4689: Implement return position impl trait / opaque type support r=matklad a=flodiebold

This is working, but I'm not that happy with how the lowering works. We might need an additional representation between `TypeRef` and `Ty` where names are resolved and `impl Trait` bounds are separated out, but things like inference variables don't exist and `impl Trait` is always represented the same way.

Also note that this doesn't implement correct handling of RPIT *inside* the function (which involves turning the `impl Trait`s into variables and creating obligations for them). That intermediate representation might help there as well.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
Co-authored-by: Florian Diebold <florian.diebold@freiheit.com>
2020-06-05 15:46:28 +00:00
Florian Diebold
0d2328f3ea Review fixes 2020-06-05 17:41:58 +02:00
bors[bot]
f133159ec0
Merge #4760
4760: Minimize FileLoader interface r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-06-05 15:23:22 +00:00
Aleksey Kladov
bbb40d7463 Minimize FileLoader interface 2020-06-05 17:22:56 +02:00
bors[bot]
4029628f15
Merge #4729 #4748
4729: Hover actions r=matklad a=vsrs

This PR adds a `hoverActions` LSP extension and a `Go to Implementations` action as an example:
![hover_actions_impl](https://user-images.githubusercontent.com/62505555/83335732-6d9de280-a2b7-11ea-8cc3-75253d062fe0.gif)



4748: Add an `ImportMap` and use it to resolve item paths in `find_path` r=matklad a=jonas-schievink

Removes the "go faster" queries I added in https://github.com/rust-analyzer/rust-analyzer/pull/4501 and https://github.com/rust-analyzer/rust-analyzer/pull/4506. I've checked this PR on the rustc code base and the assists are still fast.

This should fix https://github.com/rust-analyzer/rust-analyzer/issues/4515.

Note that this does introduce a change in behavior: We now always refer to items defined in external crates using paths through the external crate. Previously we could also use a local path (if for example the extern crate was reexported locally), as seen in the changed test. If that is undesired I can fix that, but the test didn't say why the previous behavior would be preferable.

Co-authored-by: vsrs <vit@conrlab.com>
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2020-06-05 15:14:35 +00:00
Florian Diebold
02962b374e Implement return position impl trait / opaque type support
This is working, but I'm not that happy with how the lowering works. We might
need an additional representation between `TypeRef` and `Ty` where names are
resolved and `impl Trait` bounds are separated out, but things like inference
variables don't exist and `impl Trait` is always represented the same
way.

Also note that this doesn't implement correct handling of RPIT *inside* the
function (which involves turning the `impl Trait`s into variables and creating
obligations for them). That intermediate representation might help there as
well.
2020-06-05 17:08:27 +02:00
Florian Diebold
69854f7795 Upgrade Chalk to published version 2020-06-05 17:06:07 +02:00
Aleksey Kladov
c9a41bd92d Actually test include!(concant!(env!()));
It triggered index-based goto definition before :-(
2020-06-05 15:49:12 +02:00
Aleksey Kladov
cb9d9040f7 Cleanup test 2020-06-05 15:14:47 +02:00
Aleksey Kladov
bba374bab2 More direct signature for resolve_path 2020-06-05 15:07:30 +02:00
Aleksey Kladov
e63c00f100 Rename resolve_relative_path -> resolve_path
For things like `concant!(env!("OUT_DIR"))`, we need to support abs paths
2020-06-05 14:58:30 +02:00
vsrs
bd9d7b6ad8 Remove hover actions heavy tests. 2020-06-05 15:26:46 +03:00
vsrs
78c9223b7b Remove hover contents marking as trusted.
Hover contents might be extracted from raw
doc comments and need some validation.
2020-06-05 15:25:01 +03:00
Jonas Schievink
bc2d172995 Clarify when we visit modules multiple times 2020-06-05 14:24:51 +02:00
vsrs
0fe43a124b Add capabilities tests. 2020-06-05 15:00:31 +03:00
vsrs
e35418ceb9 Apply suggestions from @kjeremy review 2020-06-05 15:00:31 +03:00
vsrs
92cfc0f2a1 Add enum hover action test. 2020-06-05 15:00:31 +03:00
vsrs
5d0c1aa162 Rebase on the latest master. 2020-06-05 15:00:30 +03:00
vsrs
b147e6eb95 Code formatting 2020-06-05 15:00:30 +03:00
vsrs
7d0dd17b09 Add hover actions as LSP extension 2020-06-05 14:59:26 +03:00
Aleksey Kladov
522d24a607 Inlay Hints: more directly account for self param 2020-06-05 13:58:52 +02:00
Jonas Schievink
2fb3d87bf7 impl Debug for ImportMap 2020-06-05 13:36:19 +02:00
Mikhail Rakhmanov
5dda995538 Fix review comments 2020-06-05 13:17:17 +02:00
Jonas Schievink
8395396782 Reorder imports 2020-06-05 13:15:16 +02:00
Jonas Schievink
5f23f8ca44 Make find_path_inner private again 2020-06-05 13:11:53 +02:00
Jonas Schievink
f085e592fe Measure memory usage of ImportMap 2020-06-05 13:10:43 +02:00
Jonas Schievink
86fbd8cc2b defining_crate -> krate 2020-06-05 13:05:19 +02:00
Jonas Schievink
e0e9c6d1a4 Fix wrong comment 2020-06-05 13:04:35 +02:00
Mikhail Rakhmanov
74c3e7a1ad Remove unnecessary return 2020-06-05 11:45:41 +02:00
bors[bot]
913a623281
Merge #4750
4750: introduce_named_lifetime assist wasn't applicable when type parameter r=matklad a=jbalint

followed anonymous lifetime token

(fixes #4684)

Co-authored-by: Jess Balint <jbalint@gmail.com>
2020-06-05 07:56:11 +00:00
Jess Balint
921306757b introduce_named_lifetime assist wasn't applicable when type parameter
followed anonymous lifetime token

(fixes #4684)
2020-06-04 17:31:21 -05:00
bors[bot]
e66c7b3a45
Merge #4737
4737: Parse default unsafe & default const r=matklad a=Avi-D-coder

Closes: #4718 #4264

Co-authored-by: Avi Dessauer <avi.the.coder@gmail.com>
2020-06-04 17:51:03 +00:00
Jonas Schievink
3c496f7fa7 Use ImportMap in find_path, remove old queries 2020-06-04 19:33:01 +02:00
Jonas Schievink
d08c63cb9e Add an ImportMap 2020-06-04 19:33:01 +02:00
Avi Dessauer
c4fd463981 Move default const test out of line 2020-06-04 13:06:57 -04:00
Avi Dessauer
3ec2dcfc0d Address review 2020-06-04 13:00:21 -04:00
bors[bot]
c19496f845
Merge #4740
4740: Remove unneeded "./" prefix affecting error messages r=kjeremy a=dtolnay

I noticed this in the error in the commit message of https://github.com/rust-analyzer/rust-analyzer/pull/4739.

Before:

```console
error[E0599]: no method named `initialize_finish` found for struct `lsp_server::Connection` in the current scope
  --> crates/rust-analyzer/./src/bin/main.rs:99:16
   |
99 |     connection.initialize_finish(initialize_id, initialize_result)?;
   |                ^^^^^^^^^^^^^^^^^ method not found in `lsp_server::Connection`
```

After:

```console
error[E0599]: no method named `initialize_finish` found for struct `lsp_server::Connection` in the current scope
  --> crates/rust-analyzer/src/bin/main.rs:99:16
   |
99 |     connection.initialize_finish(initialize_id, initialize_result)?;
   |                ^^^^^^^^^^^^^^^^^ method not found in `lsp_server::Connection`
```

```diff
-   --> crates/rust-analyzer/./src/bin/main.rs:99:16
+   --> crates/rust-analyzer/src/bin/main.rs:99:16
```

Co-authored-by: David Tolnay <dtolnay@gmail.com>
2020-06-04 13:04:24 +00:00
bors[bot]
a1ca1e7598
Merge #4739
4739: Declare required lsp-server dependency of rust-analyzer crate r=jonas-schievink a=dtolnay

My codebase already depended on lsp-server and introducing a dependency on rust-analyzer failed at first because it assumes some functions that were first present in lsp-server 0.3.2.

Without this change:

```console
error[E0599]: no method named `initialize_start` found for struct `lsp_server::Connection` in the current scope
  --> crates/rust-analyzer/./src/bin/main.rs:83:57
   |
83 |     let (initialize_id, initialize_params) = connection.initialize_start()?;
   |                                                         ^^^^^^^^^^^^^^^^ method not found in `lsp_server::Connection`

error[E0599]: no method named `initialize_finish` found for struct `lsp_server::Connection` in the current scope
  --> crates/rust-analyzer/./src/bin/main.rs:99:16
   |
99 |     connection.initialize_finish(initialize_id, initialize_result)?;
   |                ^^^^^^^^^^^^^^^^^ method not found in `lsp_server::Connection`
```

Co-authored-by: David Tolnay <dtolnay@gmail.com>
2020-06-04 10:45:06 +00:00
Mikhail Rakhmanov
b0c8a2be7b Remove AsName import 2020-06-04 10:03:44 +02:00
David Tolnay
4461796f33
Fix type inference failure when built with log/kv_unstable
This code is broken by an `impl From<kv::Error> for fmt::Error` in the
log crate when building in a codebase that has the log/kv_unstable
feature enabled.

    $ cargo check --manifest-path crates/ra_hir_def/Cargo.toml
        Checking ra_hir_def v0.1.0
        Finished dev [unoptimized] target(s) in 0.75s

    $ cargo check --manifest-path crates/ra_hir_def/Cargo.toml --features log/kv_unstable
        Checking ra_hir_def v0.1.0
    error[E0282]: type annotations needed for the closure `fn(&str) -> std::result::Result<(), _>`
       --> crates/ra_hir_def/src/path.rs:278:17
        |
    278 |                 f.write_str("::")?;
        |                 ^^^^^^^^^^^^^^^^^^ cannot infer type
        |
    help: give this closure an explicit return type without `_` placeholders
        |
    276 |         let mut add_segment = |s| -> std::result::Result<(), _> {
        |                                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2020-06-03 19:06:02 -07:00
David Tolnay
7348040944
Remove unneeded "./" prefix affecting error messages
Before:

    error[E0599]: no method named `initialize_finish` found for struct `lsp_server::Connection` in the current scope
      --> crates/rust-analyzer/./src/bin/main.rs:99:16
       |
    99 |     connection.initialize_finish(initialize_id, initialize_result)?;
       |                ^^^^^^^^^^^^^^^^^ method not found in `lsp_server::Connection`

After:

    error[E0599]: no method named `initialize_finish` found for struct `lsp_server::Connection` in the current scope
      --> crates/rust-analyzer/src/bin/main.rs:99:16
       |
    99 |     connection.initialize_finish(initialize_id, initialize_result)?;
       |                ^^^^^^^^^^^^^^^^^ method not found in `lsp_server::Connection`
2020-06-03 18:02:09 -07:00
David Tolnay
19b27f2ec9
Declare required lsp-server dependency of rust-analyzer crate
My codebase already depended on lsp-server and introducing a dependency
on rust-analyzer failed at first because it assumes some functions that
were first present in lsp-server 0.3.2.

Without this change:

    error[E0599]: no method named `initialize_start` found for struct `lsp_server::Connection` in the current scope
      --> crates/rust-analyzer/./src/bin/main.rs:83:57
       |
    83 |     let (initialize_id, initialize_params) = connection.initialize_start()?;
       |                                                         ^^^^^^^^^^^^^^^^ method not found in `lsp_server::Connection`

    error[E0599]: no method named `initialize_finish` found for struct `lsp_server::Connection` in the current scope
      --> crates/rust-analyzer/./src/bin/main.rs:99:16
       |
    99 |     connection.initialize_finish(initialize_id, initialize_result)?;
       |                ^^^^^^^^^^^^^^^^^ method not found in `lsp_server::Connection`
2020-06-03 17:55:48 -07:00
Avi Dessauer
a5588b9e19 Update tests 2020-06-03 20:39:57 -04:00
Avi Dessauer
fb632c747d Parse default unsafe & default const 2020-06-03 20:16:38 -04:00
Mikhail Rakhmanov
a6d3c77bdd Fixed tests 2020-06-03 20:43:57 +02:00
Mikhail Rakhmanov
eefa10bc6b Merge branch 'master' into assists_extract_enum 2020-06-03 20:10:54 +02:00
Mikhail Rakhmanov
a9d5675848 Fix incorrect behaviour if not resolved 2020-06-03 20:10:33 +02:00
Mikhail Rakhmanov
6cd2e04bd2 Fix more comments 2020-06-03 19:33:57 +02:00
Mikhail Rakhmanov
6a0083a519 Merge branch 'master' into compute-lazy-assits
# Conflicts:
#	crates/rust-analyzer/src/main_loop/handlers.rs
#	crates/rust-analyzer/src/to_proto.rs
2020-06-03 19:26:01 +02:00
Mikhail Rakhmanov
bacd0428fa Fix review comments 2020-06-03 18:39:01 +02:00
bors[bot]
a33cfcb55d
Merge #4502
4502: Mark fixes from diagnostics as quick fixes r=kjeremy a=kjeremy

Populates the diagnostic UI with fixes:

Before: 
![quickfix-before](https://user-images.githubusercontent.com/4325700/82165183-0e38df00-9882-11ea-96cf-7dab5faec4d4.PNG)

After:
![image](https://user-images.githubusercontent.com/4325700/82165193-1a24a100-9882-11ea-97d7-be1b64b135e0.png)


Co-authored-by: Jeremy Kolb <kjeremy@gmail.com>
2020-06-03 13:39:30 +00:00
Jeremy Kolb
9e71fc0314 Mark fixes from diagnostics as quick fixes 2020-06-03 09:31:32 -04:00
bors[bot]
1edf6d2d4f
Merge #4730
4730: Document rust-project.json r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-06-03 13:18:12 +00:00
Aleksey Kladov
fa019c8f56 Document rust-project.json 2020-06-03 15:17:26 +02:00
bors[bot]
e644f64f2a
Merge #4678
4678: Unsquish parameter types in tooltips for macro-generated functions r=aloucks a=aloucks

Note the missing whitespace between `:` and the parameter type.

Before:
![image](https://user-images.githubusercontent.com/221559/83364680-faf13d80-a370-11ea-96b7-a041969a4954.png)

After:
![image](https://user-images.githubusercontent.com/221559/83364685-03e20f00-a371-11ea-9668-4e6ebcb81947.png)


Co-authored-by: Aaron Loucks <aloucks@cofront.net>
2020-06-03 11:27:10 +00:00
Aaron Loucks
f06b2bcd91 Use split1 when formatting function signature params 2020-06-03 07:26:15 -04:00
bors[bot]
c6b739bad0
Merge #4660
4660: Enable hover and autocomplete docs on macro generated items r=aloucks a=aloucks

Enable hover and autocomplete docs on macro generated items. This de-sugars doc comments into `doc` attributes in some cases, but not all. Comments and `doc` attributes are then merged together. 

This PR is essentially a partial implementation of what's being suggested #3182, but it's not all the way there yet. ~I still need to add unit tests~, but I wanted to first get feedback on whether or not this was an acceptable path forward.

Fixes #4564
Fixes #3984
Fixes #3180
Related #3182

![macro_item_docs](https://user-images.githubusercontent.com/221559/83336760-15012200-a284-11ea-8d0d-b6a615850044.gif)



Co-authored-by: Aaron Loucks <aloucks@cofront.net>
2020-06-03 11:05:52 +00:00
Aaron Loucks
85c4edb0af Consolidate documentation expansion and merging
Removes the duplicated `expand_doc_attrs` and `merge_doc_comments_and_attrs`
functions from `ra_ide` and exposes the same functionality via
`ra_hir::Documentation::from_ast`.
2020-06-03 06:54:41 -04:00
Aaron Loucks
5837acce53 Add basic hover and completion doc tests for macro generated items 2020-06-03 06:46:07 -04:00
Aaron Loucks
4c655c01f3 Enable hover and autocomplete docs on macro generated items 2020-06-03 06:46:07 -04:00
Aleksey Kladov
2e7d12d2f3 Drop test for old format 2020-06-03 12:39:11 +02:00
Aleksey Kladov
8baa4c5d07 Groundwork for specifying the set of projects via config 2020-06-03 12:22:01 +02:00
Aleksey Kladov
03a76191a1 Rename ProjectRoot -> ProjectManifest 2020-06-03 12:05:50 +02:00
Aleksey Kladov
0a88de809f Move project discovery 2020-06-03 12:04:27 +02:00
Aleksey Kladov
a87cd8ecc6 Rename WorldState -> GlobalState 2020-06-03 11:20:01 +02:00
Aleksey Kladov
ee181cf683 Drop no-project test
Eventually, we should support "just open random rust file" use case,
we don't really do this now, so let's avoid spending time on it until
we fix it properly.
2020-06-03 11:07:04 +02:00
Aleksey Kladov
d4b21476a8 Derive local roots from Workspaces 2020-06-03 10:52:35 +02:00
Aleksey Kladov
ca80544f4b Put important things on top 2020-06-03 10:33:01 +02:00
Aleksey Kladov
ac4782ef11
Merge pull request #4382 from woody77/json_cfgs
Begin transition to new fields for JsonProject crate cfgs
2020-06-03 10:28:15 +02:00
bors[bot]
68f26dc1bb
Merge #4679
4679: Update a comment for the new source organization r=matklad a=nelhage



Co-authored-by: Nelson Elhage <nelhage@nelhage.com>
2020-06-03 06:47:18 +00:00
bors[bot]
6d38351db4
Merge #4721
4721: Hide squiggly for unused and unnecessary diagnostics r=matklad a=GabbeV

Fixes #4229 

When working with JavaScript or TypeScript in VSCode unused valiables are faded but don't have a squiggle. This PR makes rust-analyzer work similarly by setting the severity to hint when applying the unnecessary tag.

VSCode usually shows a squiggle for error, warning and information and shows three dots for hint. When the unnecessary tag is present the squiggles will still show up but the three dots will not.

This is my first contribution to open source. Please tell me if i need to do anything more to get this PR considered.

Co-authored-by: Gabriel Valfridsson <gabriel.valfridsson@gmail.com>
2020-06-03 06:16:45 +00:00
Gabriel Valfridsson
599c105e6f Hide squiggly for unused and unnecessary 2020-06-03 01:57:28 +02:00
Paul Daniel Faria
a9cb2933fb Add highlight support for unsafe fn calls and raw ptr deref 2020-06-02 18:54:00 -04:00
Mikhail Rakhmanov
cb482e6351 Merge remote-tracking branch 'upstream/master' into compute-lazy-assits
# Conflicts:
#	crates/rust-analyzer/src/to_proto.rs
2020-06-02 23:22:45 +02:00
Mikhail Rakhmanov
57cd936c52 Preliminary implementation of lazy CodeAssits 2020-06-02 23:10:53 +02:00
bors[bot]
2f6ab77708
Merge #4710
4710: New runnables r=matklad a=matklad

bors d=@vsrs

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-06-02 20:44:56 +00:00
bors[bot]
0035dafbfa
Merge #4711
4711: Disable rust-analyzer.{cargo,checkOnSave}.allFeatures by default r=matklad a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-06-02 16:16:38 +00:00
Laurențiu Nicola
7a66d99897 Disable rust-analyzer.{cargo,checkOnSave}.allFeatures by default 2020-06-02 19:14:34 +03:00
Aleksey Kladov
bc3db7c1de Fix tests 2020-06-02 18:09:12 +02:00
Aleksey Kladov
a83ab820a4 Spec better runnables 2020-06-02 17:34:18 +02:00
Aleksey Kladov
0303982119 New runnables API 2020-06-02 17:22:42 +02:00
Aleksey Kladov
31f282636b Minor 2020-06-02 16:30:47 +02:00
bors[bot]
fe6508bd78
Merge #4658
4658: Fix problem with format string tokenization r=matklad a=ruabmbua

Fixed by just not handling closing curlybrace escaping.

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

Co-authored-by: Roland Ruckerbauer <roland.rucky@gmail.com>
2020-06-02 12:13:02 +00:00
bors[bot]
131ccd9540
Merge #4580
4580: Fix invoking cargo without consulting CARGO env var or standard installation paths r=matklad a=Veetaha

Followup for #4329

The pr essentially fixes [this bug](https://youtu.be/EzQ7YIIo1rY?t=2189)

cc @lefticus

Co-authored-by: veetaha <veetaha2@gmail.com>
2020-06-02 11:58:28 +00:00
veetaha
fb971c3bce Simplify 2020-06-02 02:50:05 +03:00
Mikhail Rakhmanov
b4af02d110 Add top level keywords completion 2020-06-02 01:29:54 +02:00
Aleksey Kladov
285717de33 Rename assist 2020-06-01 15:41:16 +02:00
Aleksey Kladov
d08232b10d Cleanup imports 2020-06-01 15:35:41 +02:00
Nelson Elhage
8101ea0fdc Update a comment for the new source organization 2020-05-31 16:04:52 -07:00
Aaron Loucks
1211a46826 Unsquish parameter types in tooltips for macro-generated functions 2020-05-31 18:58:54 -04:00
veetaha
ddd811601e Small refactor 2020-05-31 21:39:19 +03:00
Brennan Vincent
d39cbeef91 add test 2020-05-31 12:21:45 -04:00
Brennan Vincent
8ef9703740 recursively search submodules 2020-05-31 12:05:54 -04:00
bors[bot]
5579ba8af5
Merge #4667
4667: Infer labelled breaks correctly r=flodiebold a=robojumper

Fixes #4663.

Co-authored-by: robojumper <robojumper@gmail.com>
2020-05-31 12:03:24 +00:00
bors[bot]
09df51dab8
Merge #4664
4664: Generate feature documentation from code r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-05-31 10:50:11 +00:00
robojumper
cc6ba84c40 fmt 2020-05-31 12:06:22 +02:00
robojumper
1cd78a3355 correctly infer labelled breaks 2020-05-31 11:40:18 +02:00
Aleksey Kladov
1c6a2eb14a Move the rest of the features to generated docs 2020-05-31 11:29:19 +02:00
robojumper
fb469c3b31 labelled break test 2020-05-31 11:24:53 +02:00
Aleksey Kladov
b795a07320 Doc more features 2020-05-31 10:14:36 +02:00
Aleksey Kladov
8915183d7d Don't require module docs for Features and Assists 2020-05-31 09:59:38 +02:00
Aleksey Kladov
f593393ebb Specify actions 2020-05-31 09:45:41 +02:00
veetaha
d605ec9c32 Change Runnable.bin -> Runnable.kind
As per matklad, we now pass the responsibility for finding the binary to the frontend.
Also, added caching for finding the binary path to reduce
the amount of filesystem interactions.
2020-05-31 05:21:45 +03:00
veetaha
a419cedb1c Fix tests, apply code review proposals 2020-05-31 03:10:23 +03:00
veetaha
030d78345f Fix invoking cargo without consulting CARGO or standard installation paths 2020-05-31 03:10:23 +03:00
Aleksey Kladov
c8f27a4a88 Generate features docs from source 2020-05-31 01:54:54 +02:00
Roland Ruckerbauer
780c89959a Test case for format string highlighting of closing curlybrace 2020-05-30 18:35:11 +02:00
Roland Ruckerbauer
a27ede88a3 Fix problem with format string tokenization
Fixed by just not handling closing curlybrace escaping.
2020-05-30 14:09:10 +02:00
bors[bot]
07060b3daa
Merge #4654
4654: Add semantic highlight to ? operator r=matklad a=ruabmbua

Made it an operator with controlFlow modifier.

To highlight in vscode as red:

```json
"editor.semanticTokenColorCustomizations": {
        "enabled": true,
        "rules": {
            "operator.controlFlow": "#ff0000",
        }
}
```

![Bildschirmfoto von 2020-05-29 21-32-06](https://user-images.githubusercontent.com/2522373/83297998-f3585a00-a1f3-11ea-9d14-4ef04b9b6b9a.png)

https://github.com/rust-analyzer/rust-analyzer/issues/4597


Co-authored-by: Roland Ruckerbauer <roland.rucky@gmail.com>
2020-05-30 08:26:04 +00:00
bors[bot]
5d84028170
Merge #4562
4562: Assist: replace anonymous lifetime with a named one r=matklad a=jbalint

(fixes #4523)

Co-authored-by: Jess Balint <jbalint@gmail.com>
2020-05-30 08:01:00 +00:00
bors[bot]
11f74f2827
Merge #4653
4653: Fix match ergonomics in closure parameters r=matklad a=flodiebold

Fixes #4476.

Co-authored-by: Florian Diebold <florian.diebold@freiheit.com>
2020-05-30 07:52:07 +00:00
bors[bot]
f7f01dd5f0
Merge #4651
4651: Use first match branch in case of type mismatch, not last r=kjeremy a=flodiebold

The comment says this was intentional, but I do agree with #4304 that it makes
more sense the other way around (for if/else as well).

Fixes #4304.

Co-authored-by: Florian Diebold <florian.diebold@freiheit.com>
2020-05-29 21:07:43 +00:00
bors[bot]
3689c8c3f6
Merge #4652
4652: Upgrade Chalk r=kjeremy a=flodiebold

Fixes #4072.

Co-authored-by: Florian Diebold <florian.diebold@freiheit.com>
2020-05-29 19:33:52 +00:00
Roland Ruckerbauer
18aa4bcb03 Add semantic highlight to QUESTION token
Made it an operator with controlFlow modifier.
2020-05-29 21:17:14 +02:00
Florian Diebold
6f67a46a6a Fix match ergonomics in closure parameters
Fixes #4476.
2020-05-29 17:36:43 +02:00
Florian Diebold
ab28f6c249 Upgrade Chalk
Fixes #4072.
2020-05-29 16:49:52 +02:00
Florian Diebold
7d0586cb15 Use first match branch in case of type mismatch, not last
The comment says this was intentional, but I do agree with #4304 that it makes
more sense the other way around (for if/else as well).

Fixes #4304.
2020-05-29 16:04:56 +02:00
Jess Balint
bd8aa04bae add support for naming anon lifetimes in function return type 2020-05-28 15:10:14 -05:00
robojumper
367487fe88 Support raw_ref_op's raw reference operator 2020-05-28 21:42:22 +02:00
bors[bot]
fc29d0e924
Merge #4641
4641: Upgrade Chalk r=matklad a=flodiebold

Chalk newly added TypeName::Never and Array; I implemented the conversion for
Never, but not Array since that expects a const argument.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2020-05-28 09:34:33 +00:00
Florian Diebold
c8a4bb1445 Upgrade Chalk
Chalk newly added TypeName::Never and Array; I implemented the conversion for
Never, but not Array since that expects a const argument.
2020-05-27 21:07:08 +02:00
Cadu
c011f04f55 Fixed missing newline on each field on "Missing structure fields". 2020-05-27 13:15:19 -03:00
bors[bot]
94889b6472
Merge #4592
4592: fix textedit range returned for completion when left token is a keyword r=bnjjj a=bnjjj

close #4545

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-05-27 13:22:26 +00:00
Benjamin Coenen
846cefa491 fix textedit range returned for completion when left token is a keyword
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-05-27 15:15:19 +02:00
bors[bot]
59adc7bfb6
Merge #4596
4596: Strip leading underscores of argument names in function/method r=matklad a=kuy

Closes #4510 

### Goal

When I select a function/method from completions, I get a snippet that doesn't contain leading underscores of argument names.

### Solution

- Option 1: All signatures don't contain underscores
- Option 2: Keep same signature, but inserted snippet doesn't contain underscores

I choose Option 2 because I think that leading underscores is a part of "signature". Users should get correct signatures. On the other hand, trimming underscores is an assist by IDE.

### Other impls.

rls: Complete argument names with underscores (same as actual ra)
IntelliJ Rust: Doesn't complete argument names
VSCode (TypeScript): Doesn't complete argument names

### Working example

![Screen Shot 2020-05-25 at 0 03 21](https://user-images.githubusercontent.com/151614/82757771-a05e5b80-9e1d-11ea-9dbc-1263c960e2ae.png)


Co-authored-by: Yuki Kodama <endflow.net@gmail.com>
2020-05-27 12:41:38 +00:00
bors[bot]
3c5112b079
Merge #4625 #4629
4625: Partially fix displaying inlay hints in Github PR diff views r=matklad a=Veetaha

See the comment in https://github.com/rust-analyzer/rust-analyzer/issues/4608#issuecomment-63424257

It partially fixes the left side of diff view (the one where old code is displayed), but the diff editor with new code changes still has `file` scheme and will proceed displaying inlay hints...

4629: Fix the `should_panic` snippet r=matklad a=eminence

Closes #4628

Co-authored-by: veetaha <veetaha2@gmail.com>
Co-authored-by: Andrew Chin <achin@eminence32.net>
2020-05-27 12:34:03 +00:00
bors[bot]
64a1c77ab2
Merge #4622
4622: Pass trivially copy types as copy r=matklad a=kjeremy



Co-authored-by: kjeremy <kjeremy@gmail.com>
2020-05-27 06:42:04 +00:00
Andrew Chin
36f97d39a4 Fix the should_panic snippet
Closes #4628
2020-05-26 18:45:14 -04:00
kjeremy
9a0353a81e Update lexer 2020-05-26 14:35:09 -04:00
kjeremy
bee4f8f9fe Pass trivially copy types as copy 2020-05-26 14:12:13 -04:00
bors[bot]
e3280eb4ae
Merge #4534
4534: Add call postfix completion r=matklad a=vain0x

To make it easier to wrap an expression with Ok/Some/Rc::new etc.

Note I agree with conclusion of the discussion in #1431 that adding many completions is not the way to go. However, this PR still could be justified due to versatility of use.

Co-authored-by: vain0x <vainzerox@gmail.com>
2020-05-26 12:12:52 +00:00
Aaron Loucks
a047f10839 Hover tooltip module name is monospace once again
The line separator is moved below the function signature to split
regions between the docs. This is very similar to how IntelliJ
displays tooltips. Adding an additional separator between the module
name and function signature currently has rendering issues.

Fixes #4594
Alternative to #4615
2020-05-25 23:18:45 -04:00
Jeremy Kolb
a5cc9a8a9b Fix some clippy perf warnings 2020-05-25 13:35:52 -04:00
Yuki Kodama
fd83f469e9 Trim at presentation layer 2020-05-26 01:06:25 +09:00
Yuki Kodama
41d0f7f24e Fix test to consider multiple underscores 2020-05-26 01:06:25 +09:00
Yuki Kodama
408d04764c Use built-in method 2020-05-26 01:06:25 +09:00
Yuki Kodama
378bfc3c8f Separate assertions 2020-05-26 01:06:25 +09:00
Yuki Kodama
4d13691ad1 Reflect test case 2020-05-26 01:06:25 +09:00
Yuki Kodama
6c676909dd Strip leading underscore 2020-05-26 01:06:25 +09:00
bors[bot]
30f058dfea
Merge #4602 #4603
4602: Add boolean literal semantic token type to package.json r=matklad a=lnicola

Closes #4583.

CC @GrayJack

4603: Add self keyword semantic token type r=matklad a=lnicola

Not sure if this is warranted a new token type or just a modifier.

---

CC #4583, @GrayJack

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-05-25 14:08:21 +00:00
Aleksey Kladov
0ebb25b29b Document parentModule experimental LSP request 2020-05-25 15:59:49 +02:00
Aleksey Kladov
a30bdd9795 Cleanup lsp extensions on the client side 2020-05-25 14:56:26 +02:00
Aleksey Kladov
76e170c3d0 Less rust-analyzer specific onEnter 2020-05-25 14:28:47 +02:00
Laurențiu Nicola
c2358365ad Add self keyword semantic token type 2020-05-25 12:08:58 +03:00
bors[bot]
fbb8b884a2
Merge #4593
4593: Document some rust-analyzer specific protocol extensions r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-05-24 15:05:20 +00:00
Aleksey Kladov
5276bfff81 Fix formatting 2020-05-24 17:04:17 +02:00
Aleksey Kladov
dec4ba8023 Document some rust-analyzer specific protocol extensions 2020-05-24 17:01:40 +02:00
Aleksey Kladov
9342273616 Document matchingBrace LSP request 2020-05-24 16:53:18 +02:00
Benjamin Coenen
0e814a3b5f fix textedit range returned for completion when left token is a keyword #4545
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-05-24 16:47:35 +02:00
Matthew Jasper
1895888aec Handle more cases in highlight_name_by_syntax 2020-05-24 15:12:17 +01:00
Matthew Jasper
e2d36cb692 Highlight true and false as literals 2020-05-24 15:12:17 +01:00
Aleksey Kladov
d1ff0145a9 Fix tests 2020-05-24 15:47:05 +02:00
Aleksey Kladov
130318b823
Merge pull request #4548 from bnjjj/fix_4464
add support of feature flag for runnables
2020-05-24 15:34:35 +02:00
Aleksey Kladov
f26b7928e0
Merge pull request #4495 from vsrs/fixture_meta
Test fixtures parsing improvements
2020-05-24 15:32:52 +02:00
Aleksey Kladov
ce7144a93d
Merge pull request #4474 from georgewfraser/color_attrs
Color attribute functions
2020-05-24 15:32:31 +02:00
Mikhail Rakhmanov
08aa8e1de7 Further refactoring under review comments 2020-05-24 14:53:12 +02:00
Benjamin Coenen
27ed376bc4 add support of feature flag for runnables #4464
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-05-24 13:34:34 +02:00
Julian Wollersberger
ff9d553fe3 Some FIXMEs were outdated:
* Done at line 243: "Add validation of `crate` keyword not appearing in the middle of the symbol path"
* Already happened: "Remove validation of unterminated literals (it is already implemented in `tokenize()`)"
* Happens in `unescape()`: "Add validation of character literal containing only a single char"
* Missing: "raw string literals and raw byte string literals"
2020-05-24 13:17:16 +02:00
Julian Wollersberger
cd4ffc1945 Update to rustc_lexer version 660.
Change `unescape_*()` to `unescape_literal()`.
2020-05-24 13:12:16 +02:00
Benjamin Coenen
48d7c61e26 add support of feature flag for runnables #4464
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-05-23 20:59:18 +02:00
bors[bot]
4cc2ff6e39
Merge #4555 #4575
4555: VSCode: added patchelf after download for NixOS support r=matklad a=cab404

This adds Nix support, and fixes #4542 

4575: Use Chalk's built-in representations for fn items and pointers r=matklad a=flodiebold

The `TypeName::FnDef` was just added; the function pointer variant has existed for a while, I just forgot about it because it's special (because fn pointers can be higher-ranked over lifetimes).

We *could* also make `FnPtr` a separate `Ty` variant instead of a `TypeCtor` variant, which would make the conversion code a bit less special-casey, but it doesn't seem worth doing right now.

Co-authored-by: Vladimir Serov <me@cab404.ru>
Co-authored-by: Cabia Rangris <me@cab404.ru>
Co-authored-by: Florian Diebold <florian.diebold@freiheit.com>
2020-05-23 11:32:26 +00:00
bors[bot]
ca5e4596a0
Merge #4578
4578: Remove unnecessary clone that prevented clippy from moving on r=matklad a=kjeremy



Co-authored-by: kjeremy <kjeremy@gmail.com>
2020-05-23 11:24:28 +00:00
bors[bot]
88c292b1c2
Merge #4559
4559: Module name on hover shows another newline after it r=matklad a=Arthamys

This changes the display of hover information to add a newline between the module path of the item and the signature of the item, as suggested in #3813 

**Before**

![before_3813](https://user-images.githubusercontent.com/11710698/82609224-5d517d80-9bbc-11ea-9a08-0a1558409c6b.png)

**After**

![after_3813](https://user-images.githubusercontent.com/11710698/82609208-562a6f80-9bbc-11ea-8cb6-4430269c5800.png)

Co-authored-by: Galilée 'Bill' Enguehard <galilee.enguehard@gmail.com>
2020-05-23 11:09:24 +00:00
Mikhail Rakhmanov
e2974ba8f7 Remove unnecessary set_file and change variable positions for better readability 2020-05-23 11:57:12 +02:00
Mikhail Rakhmanov
3a244e02b5 Remove unwraps where possible 2020-05-23 11:53:02 +02:00
Galilée 'Bill' Enguehard
6197a960df Fix resolve_proc_macro heavy test 2020-05-23 08:59:51 +02:00
Jess Balint
4967b811dd tweak syntax 2020-05-22 19:09:37 -05:00
Mikhail Rakhmanov
6ee1c60c9c Further review fixes 2020-05-23 01:41:08 +02:00
Mikhail Rakhmanov
4984520ef5 Use default instead of new in AssistDirector 2020-05-23 01:27:11 +02:00
Mikhail Rakhmanov
fce10200a0 Better naming and fix some review comments 2020-05-23 01:23:40 +02:00
kjeremy
7a46a99490 And a few drive-bys 2020-05-22 17:26:31 -04:00
kjeremy
d8af45472e Remove unnecessary clone that prevented clippy from moving on 2020-05-22 17:13:14 -04:00
Mikhail Rakhmanov
ef1aaeb595 More formatting 2020-05-22 22:59:17 +02:00
Mikhail Rakhmanov
97ffe3c6e8 Refactor AssistDirector 2020-05-22 22:47:25 +02:00
Mikhail Rakhmanov
04a35784df Formatting and remove unused imports 2020-05-22 22:43:52 +02:00
Mikhail Rakhmanov
5cd4eb6dd6 Add preliminary implementation of extract struct from enum variant 2020-05-22 22:28:30 +02:00
Florian Diebold
194dd9eb0d Use Chalk's Ty::Function for function pointer types
Function pointers can be 'higher-ranked' over lifetimes, which is why they're
not an application type in Chalk, but since we don't model lifetimes it doesn't
matter for us yet.
2020-05-22 21:05:28 +02:00
Florian Diebold
bfbc210bc1 Use Chalk's built-in representation of function item types 2020-05-22 21:05:13 +02:00
Galilée 'Bill' Enguehard
d688215f25 Update tests to accept new hover formatting 2020-05-22 20:11:24 +02:00
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
Jess Balint
d42fd8efb6 use char range 2020-05-22 10:15:59 -05: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
Jess Balint
1f9e02c74e fix generated docs issue 2020-05-22 09:25:55 -05:00
Jess Balint
1fae96a8d4 handle the case of conflicting lifetime param name
- and clean/format code
2020-05-22 08:51:37 -05: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
Jess Balint
2ab79c6f4d Assist: replace anonymous lifetime with a named one
(fixes #4523)
2020-05-21 21:04:02 -05: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
Benjamin Coenen
03735be317 fix doctest inside impl block #4449
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-05-17 00:43:42 +02: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
vsrs
cd45c73b66 JFF, ra_fixture arg name for a code highlighting 2020-05-16 17:27:23 +03:00
vsrs
7e9c7ac4ee smoke test 2020-05-16 16:56:41 +03:00
vsrs
2c00bd8c6a Propogate fixture meta to AnalysisHost
Except crate name.
2020-05-16 15:23:43 +03:00
vsrs
2dde9b1994 Use FixtureMeta in MockAnalysis 2020-05-16 13:17:21 +03:00
Florian Diebold
050601ef7b Chalk upgrade 2020-05-16 11:43:48 +02:00
vsrs
256fb7556e Remove temporary FixtureEntry parsed_meta field. 2020-05-16 12:25:26 +03:00
vsrs
d901e0e709 Reimplement ra_db::fixture::ParsedMeta
in terms of test_utils::FixtureMeta
2020-05-16 11:57:41 +03:00
vsrs
eeb98237d1 parse fixture meta in test_utils crate 2020-05-16 11:16:32 +03: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
veetaha
8d4c11625a Remove an equals sign from ConstArg (this probably pertains only to ConstParam)
(As per matklad)
2020-05-12 23:57:04 +03:00
veetaha
51edfbaffe Convert TODO to a Note(matklad) 2020-05-12 23:50:52 +03:00
veetaha
65b380fa8d Convert to TODOs to FIXMEs as per matklad 2020-05-12 23:48:04 +03:00
veetaha
55a29982c0 Revert "Remove MacroStmts as per edwin0cheng" (cc @edwin0cheng) and add a fixme to document it.
This reverts commit 7a49165f5d.
MacroStmts ast node is not used by itself, but it pertains
to SyntaxNodeKind MACRO_STMTS that is used by ra_paser, so
even tho the node itself is not used, it is better to keep it
with a FIXME to actually add a doc comment when it becomes useful.
2020-05-12 23:45:29 +03:00
veetaha
24b27abf9f Add a doc comment on the difference between Name and NameRef ast nodes 2020-05-12 23:31:37 +03:00
Benjamin Coenen
df33022408 add more specific match postfix for Result and Option
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-05-12 11:48:58 +02:00
bors[bot]
2c9878a2fc
Merge #4423
4423: add tests module snippet r=bnjjj a=bnjjj

Request from a friend coming from intellij Rust

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-05-11 18:15:31 +00:00
bors[bot]
0063ad970d
Merge #4358
4358: add if let and while let postfix for Option and Result #4348 r=matklad a=bnjjj

close #4348 

I also added `while let` for iterator or stream it could be useful 

![iflet](https://user-images.githubusercontent.com/5719034/81278000-676c6b80-9055-11ea-87ad-6b8476dd983f.gif)


Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-05-11 18:08:26 +00:00
Benjamin Coenen
72e3d2260b add tests module snippet
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-05-11 19:59:58 +02:00
bors[bot]
848aa56df5
Merge #4397
4397: Textmate cooperation r=matklad a=georgewfraser

This PR tweaks the fallback TextMate scopes to make them more consistent with the existing grammar and other languages, and edits the builtin TextMate grammar to align with semantic coloring. Before is on the left, after is on the right:

<img width="855" alt="Screen Shot 2020-05-10 at 1 45 51 PM" src="https://user-images.githubusercontent.com/1369240/81512320-a8be7e80-92d4-11ea-8940-2c03f6769015.png">

**Use keyword.other for regular keywords instead of keyword**. This is a really peculiar quirk of TextMate conventions, but virtually *all* TextMate grammars use `keyword.other` (colored blue in VSCode Dark+) for regular keywords and `keyword.control` (colored purple in VSCode Dark+) for control keywords. The TextMate scope `keyword` is colored like control keywords, not regular keywords. It may seem strange that the `keyword` scope is not the right fallback for the `keyword` semantic token, but TextMate has a long and weird history. Note how keywords change from purple back to blue (what they were before semantic coloring was added):

**(1) Use punctuation.section.embedded for format specifiers**. This aligns with how Typescript colors formatting directives:

<img width="238" alt="Screen Shot 2020-05-09 at 10 54 01 AM" src="https://user-images.githubusercontent.com/1369240/81481258-93b5f280-91e3-11ea-99c2-c6d258c5bcad.png">

**(2) Consistently use `entity.name.type.*` scopes for type names**. Avoid using `entity.name.*` which gets colored like a keyword.

**(3) Use Property instead of Member for fields**. Property and Member are very similar, but if you look at the TextMate fallback scopes, it's clear that Member is intended for function-like-things (methods?) and Property is intended for variable-like-things.

**(4) Color `for` as a regular keyword when it's part of `impl Trait for Struct`**. 

**(5) Use `variable.other.constant` for constants instead of `entity.name.constant`**. In the latest VSCode insiders, variable.other.constant has a subtly different color that differentiates constants from ordinary variables. It looks close to the green of types but it's not the same---it's a new color recently added to take advantage of semantic coloring.

I also made some minor changes that make the TextMate scopes better match the semantic scopes. The effect of this for the user is you observe less of a change when semantic coloring "activates". You can see the changes I made relative to the built-in TextMate grammar here:

a91d15c80c..97428b6d52 (diff-6966c729b862f79f79bf7258eb3e0885)


Co-authored-by: George Fraser <george@fivetran.com>
2020-05-11 17:33:38 +00:00
bors[bot]
de1fe23c1e
Merge #4403
4403: Check client capabilities before sending progress notifications r=kjeremy a=kjeremy

Fixes #4384

Co-authored-by: Jeremy Kolb <kjeremy@gmail.com>
2020-05-11 17:25:34 +00:00
Jeremy Kolb
d4471dccfe Check client capabilities before sending progress notifications
Fixes #4384
2020-05-11 13:16:46 -04:00
Aleksey Kladov
72e229fcb3 Use RA_LOG instead of RUST_LOG for logging
RUST_LOG might be set up for debugging the user's problem, slowing
down rust-analyzer considerably. That's the same reason why rustc uses
RUSTC_LOG.
2020-05-11 19:16:00 +02:00
Benjamin Coenen
4e54b1ca46 add tests module snippet
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-05-11 18:11:23 +02:00
bors[bot]
05399250d4
Merge #4421
4421: Find references to a function outside module r=flodiebold a=montekki

Fixes #4188 

Yet again, it looks like although the code in 
da1f316b02/crates/ra_ide_db/src/search.rs (L128-L132)

may be wrong, it is not hit since the `vis` is `None` at this point. The fix is similar to the #4237 case: just add another special case to `Definition::visibility()`.

Co-authored-by: Fedor Sakharov <fedor.sakharov@gmail.com>
2020-05-11 12:21:08 +00:00
Fedor Sakharov
3d66aa0542
New definition_visibility method 2020-05-11 14:28:14 +03:00
Fedor Sakharov
753e1e679c
Also for consts and type aliases 2020-05-11 13:52:20 +03:00
Fedor Sakharov
762ec9581a
Find references to a function outside module 2020-05-11 12:25:18 +03:00
George Fraser
63b75a40c8 Color for as a regular keyword when it's part of impl _ for _ 2020-05-10 13:11:14 -07:00
George Fraser
3f1c73633e Color in as a control keyword 2020-05-10 13:07:28 -07:00
George Fraser
cff0d6b6e6 Use Property instead of Member for fields 2020-05-10 13:07:28 -07:00
veetaha
2a5ab9f5dd Resolve TODO about macro 2.0 def 2020-05-10 22:08:06 +03:00
veetaha
73c6bc4dbd Fix typo 2020-05-10 21:59:15 +03:00
veetaha
33f240960d Carify on a semicolon in macro call 2020-05-10 21:57:49 +03:00
veetaha
a1dc28f236 Resolve TODO about curly-braced constructions in expression statement 2020-05-10 21:51:53 +03:00
veetaha
8a298eed7a Resolve todos about refs and empty statements 2020-05-10 21:44:14 +03:00
veetaha
f5e2e02aa9 Converted TODO about MacroItems to FIXME as per edwin0cheng 2020-05-10 21:06:12 +03:00
veetaha
71f2be968b Verified ConstArg example, waiting for response on what = sign pertains to 2020-05-10 21:02:21 +03:00
bors[bot]
bfb40a698d
Merge #4396
4396: Improve panic message for ast_from_text r=jonas-schievink a=edwin0cheng

Related: #4368

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-05-10 18:01:20 +00:00
veetaha
f6fd4c4a74 Correcy use tree and type args docs 2020-05-10 20:52:25 +03:00
bors[bot]
74e72e9afa
Merge #4394 #4414
4394: Simplify r=matklad a=Veetaha



4414: Highlighting improvements r=matklad a=matthewjasper

- `static mut`s are highlighted as `mutable`.
- The name of the macro declared by `macro_rules!` is now highlighted.

Co-authored-by: veetaha <veetaha2@gmail.com>
Co-authored-by: Matthew Jasper <mjjasper1@gmail.com>
2020-05-10 17:47:27 +00:00
bors[bot]
a3dbd272e0
Merge #4406 #4410 #4411 #4417
4406: Update cargo-metadata r=matklad a=edwin0cheng

This PR update `cargo-metadata` to  0.10.0 and it also relax the` serde-derive` deps to 1.0 for tests in `proc-macro-srv`.

cc @robojumper 

r= @matklad  , I think you would have something to say related to https://github.com/serde-rs/json/issues/647#issue-593788429 ?





4410: Improve wording in comment r=matklad a=edwin0cheng



4411: do not remove then block when you unwrap else block #4361 r=matklad a=bnjjj

close #4361 

4417: Omit default types in HirDisplay SourceCode mode r=matklad a=TimoFreiberg

Closes #4390

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Co-authored-by: Timo Freiberg <timo.freiberg@gmail.com>
2020-05-10 17:37:07 +00:00
bors[bot]
348cbc054c
Merge #4418
4418: Refactor protocol handling r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-05-10 17:28:59 +00:00
Aleksey Kladov
3bec2be9de req -> lsp_ext 2020-05-10 19:27:12 +02:00
Aleksey Kladov
bec3bf701c Don't re-export lsp_types 2020-05-10 19:24:02 +02:00
veetaha
2af6b4b67e Correct use cannot have type args as per flodiebold 2020-05-10 20:23:29 +03:00
veetaha
a19b164661 Correct path docs and add colon2 token to Path ast node 2020-05-10 20:21:46 +03:00
Aleksey Kladov
a78e1573b1 Better fn signature 2020-05-10 19:14:02 +02:00
Aleksey Kladov
bd8422643a to_proto::semantic_tokens 2020-05-10 19:09:22 +02:00
Aleksey Kladov
1586bab0b9 Simplify proto conversion
Trait based infra in conv.rs is significantly more complicated than
what we actually need here.
2020-05-10 19:01:26 +02:00
veetaha
eedf11ae88 Add example with const in TypeBound as per flodiebold 2020-05-10 19:24:06 +03:00
veetaha
09c438b47e Properly document const impl as per flodiebold 2020-05-10 19:17:46 +03:00
veetaha
7a49165f5d Remove MacroStmts as per edwin0cheng 2020-05-10 19:11:22 +03:00
Timo Freiberg
cbbbd48325 Omit default types in HirDisplay SourceCode mode 2020-05-10 18:10:15 +02:00
veetaha
258a3461b4 Add proper docs for TokenTree as per edwin0cheng 2020-05-10 19:09:36 +03:00
veetaha
3554866d67 Run codegen of ast types with documentation 2020-05-10 19:06:28 +03:00
Matthew Jasper
22b75c4cea Highlight the name in macro declarations 2020-05-10 16:25:51 +01:00
Matthew Jasper
11c0a5bb60 Highlight mutable statics as mutable 2020-05-10 16:25:51 +01:00
Timo Freiberg
e17193dc51 Expand fixture documentation a little 2020-05-10 16:51:12 +02:00
Timo Freiberg
66db88d226 Trigger change_visibility assist when on an invisible struct field
Union fields apparently don't work :(
2020-05-10 16:51:12 +02:00
Emil Lauridsen
85d44cad45 infer: Make expected rhs type for plain assign the lhs type
This fixes an issue where the following code sample would fail to infer
the type contained in the option:
```rust
fn main() {
    let mut end = None; // TODO: Fix inference for this in RA
    loop {
        end = Some(true);
    }
}
```
2020-05-10 16:24:04 +02:00
Benjamin Coenen
98a7bb2435 do not remove then block when you unwrap else block #4361
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-05-10 15:31:51 +02:00
Timo Freiberg
7568d07709 Trigger change_visibility assist when on a path to an invisible def 2020-05-10 13:54:04 +02:00
Benjamin Coenen
92b2230fef add if let and while let postfix for Option and Result
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-05-10 12:45:35 +02:00
Benjamin Coenen
e80903a965 Merge branch 'master' of github.com:rust-analyzer/rust-analyzer into feat_4348 2020-05-10 12:31:55 +02:00
Edwin Cheng
a3375c1a88 Remove dbg 2020-05-10 18:03:44 +08:00
Edwin Cheng
9405116d51 Hot fix panic for function_signature 2020-05-10 16:27:31 +08:00
Edwin Cheng
3de3b52f10 Remove dbg 2020-05-10 06:39:36 +08:00