Commit graph

6887 commits

Author SHA1 Message Date
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
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
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
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
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