Commit graph

6303 commits

Author SHA1 Message Date
Laurențiu Nicola
1a2d4e2921 Add support for incremental text synchronization 2020-04-30 21:26:57 +03:00
John Renner
513a3615f6 Report invalid, nested, multi-segment crate-paths
Specifically, things like:

use foo::{crate::bar};

Are now being caught, when before we only caught:

use foo::{crate};
2020-04-30 11:16:09 -07:00
Edwin Cheng
45c4f620b1 Special-case try macro_rules 2020-04-30 22:07:46 +08:00
Aleksey Kladov
c51c8bfb84 Special-case try macro to better support 2015 edition 2020-04-30 14:17:14 +02:00
bors[bot]
fdaddb98b5
Merge #4210
4210: Include function qualifiers in signature r=matklad a=oxalica

Fixes #2450

It seems there's no test for `ra_ide/display/{short_label,function_signature}`. I'm not sure how to setup it.

Manually tested:
<img width="428" alt="Screenshot_20200430_004434" src="https://user-images.githubusercontent.com/14816024/80622769-d6f1c200-8a7b-11ea-91f3-e94bfb2703c5.png">


Co-authored-by: oxalica <oxalicc@pm.me>
2020-04-30 11:09:57 +00:00
bors[bot]
95e8766db6
Merge #4178
4178: Validate the location of `crate` in paths r=matklad a=djrenren

**This solution does not fully handle `use` statements. See below**

This pull requests implements simple validation of usages of the `crate` keyword in `Path`s. Specifically it validates that:

- If a `PathSegment` is starts with the `crate` keyword, it is also the first segment of the `Path`
- All other usages of `crate` in `Path`s are considered errors.

This aligns with `rustc`'s rules. Unlike rustc this implementation does not issue a special error message in the case of `::crate` but it does catch the error.

Furthermore, this change does not cover all error cases. Specifically the following is not caught:

```rust
use foo::{crate}
```

This is because this check is context sensitive. From an AST perspective, `crate` is the root of the `Path`. Only by inspecting the full `UseItem` do we see that it is not in fact the root. This problem becomes worse because `UseTree`s are allowed to be arbitrarily nested:

```rust
use {crate, {{crate, foo::{crate}}}
```

So this is a hard problem to solve without essentially a breadth-first search. In a traditional compiler, I'd say this error is most easily found during the AST -> HIR conversion pass but within rust-analyzer I'm not sure where it belongs.  

Under the implementation in this PR, such errors are ignored so we're *more correct* just not *entirely correct*. 

Co-authored-by: John Renner <john@jrenner.net>
2020-04-30 10:17:40 +00:00
oxalica
b9b342ff93
Add tests of showing function qualifiers 2020-04-30 12:54:16 +08:00
Jonas Schievink
0cd6a88cf6 if let -> match 2020-04-30 00:10:30 +02:00
Jonas Schievink
15233a467d ? 2020-04-30 00:10:30 +02:00
Jonas Schievink
cafa7a780a Use or-patterns more 2020-04-30 00:10:30 +02:00
Jonas Schievink
3e41483932 Remove .clone() 2020-04-30 00:10:30 +02:00
Jonas Schievink
3cb73da949 Rename to associated_type_shorthand_candidates 2020-04-30 00:10:30 +02:00
Jonas Schievink
8c2670026a Complete assoc. items on type parameters 2020-04-30 00:10:30 +02:00
John Renner
0af727da91 Validate the location of crate in paths 2020-04-29 11:06:51 -07:00
oxalica
414d8d9c38
Include function qualifiers in signature 2020-04-30 00:34:46 +08:00
bors[bot]
1cde354c35
Merge #4119
4119: Cache proc-macro dlls r=matklad a=edwin0cheng

This PR try to fix a deadlock in proc-macro srv by not unloading dlls.

Currently we load and unload dlls for each request, however rustc TLS is leaky , such that if we do it a lot of times, all TLS index will be consumed and it will be deadlocked inside panic (it is because panic itself is using TLS too).


Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-04-29 13:28:57 +00:00
Benjamin Coenen
bbe22640b8 Add unwrap block assist #4156
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-04-29 14:53:47 +02:00
Aleksey Kladov
b4dd475257 More principled approach for finding From trait 2020-04-29 14:51:44 +02:00
Benjamin Coenen
76733f0cd4 Add unwrap block assist #4156
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-04-29 14:08:30 +02:00
bors[bot]
c3dfeba165
Merge #4204
4204: Use specific pattern when translating if-let-else to match r=matklad a=matklad

We *probably* should actually use the same machinery here, as we do
for fill match arms, but just special-casing options and results seems
to be a good first step.



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-04-29 10:01:26 +00:00
Aleksey Kladov
7c3c289dab Use specific pattern when translating if-let-else to match
We *probably* should actually use the same machinery here, as we do
for fill match arms, but just special-casing options and results seems
to be a good first step.
2020-04-29 11:59:11 +02:00
Aleksey Kladov
041aea2263 Better filtering of qualified enum variants in completion 2020-04-29 11:26:21 +02:00
Aleksey Kladov
73bef854ab Move shared assist code to utils 2020-04-29 10:38:51 +02:00
Jonas Schievink
8cb139090f Complete union fields after dot 2020-04-28 22:45:46 +02:00
bors[bot]
07f690ddf6
Merge #4161
4161: lsp-types 0.74 r=kjeremy a=kjeremy

* Fixes a bunch of param types to take partial progress into account.
* Will allow us to support insert/replace text in completions

Co-authored-by: kjeremy <kjeremy@gmail.com>
2020-04-28 20:12:44 +00:00
bors[bot]
db441de0a8
Merge #4193
4193: Make it impossible to forget to add a semantic token type / modifier r=kjeremy a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-04-28 20:05:08 +00:00
bors[bot]
2096db90b4
Merge #4184
4184: Treat comments beginning with four slashes as regular line comments r=kjeremy a=adamrk

Addresses https://github.com/rust-analyzer/rust-analyzer/issues/4040

Co-authored-by: adamrk <ark.email@gmail.com>
2020-04-28 19:57:23 +00:00
adamrk
0bd7d81805 Fix comment prefix method for four slash comments 2020-04-28 21:13:37 +02:00
bors[bot]
9230ae5492
Merge #4148
4148: Simplify profiler impl (bubble up Option) r=matklad a=Veetaha



Co-authored-by: veetaha <veetaha2@gmail.com>
2020-04-28 18:44:34 +00:00
Aleksey Kladov
890938a48c Make it impossible to forget to add a semantic token type / modifier 2020-04-28 17:14:05 +02:00
Leander Tentrup
052e9faa90 Introduce new semantic highlight token for format specifier 2020-04-28 11:13:12 +02:00
adamrk
b6560e3ebb Treat comments beginning with four slashes as regular line comments 2020-04-28 10:23:45 +02:00
Christophe MASSOLIN
e7523511ce [config] remove RustcConfig 2020-04-28 00:17:23 +02:00
Christophe MASSOLIN
ed5af989f4 [config] rename cargo.defaultTarget 2020-04-28 00:15:54 +02:00
bors[bot]
da1f316b02
Merge #4173
4173: Use core instead of std for builtin derive macros r=edwin0cheng a=edwin0cheng

Fixed #4087.

We can't use `$crate` here right now because : 

1. We have to able to detect `macro` 2.0 in collecting phase for finding `rustc_builtin_macro` attrs.
2. And we have to make hygiene works for builtin derive macro.

r= @flodiebold 

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-04-27 20:12:27 +00:00
Edwin Cheng
c69f9c1b0a Check dep name to detect it is core 2020-04-28 04:11:24 +08:00
Edwin Cheng
6d3b0af900 Use empty-deps tricks to detect it is core 2020-04-28 03:32:47 +08:00
Edwin Cheng
213d208e2d Add test 2020-04-28 02:10:17 +08:00
Edwin Cheng
6a5014329a Use core instead of std for builtin derive macros 2020-04-28 01:48:55 +08:00
Christophe MASSOLIN
b7edffe244 Started rust-analyzer.cargo.defaultTarget implementation 2020-04-27 00:11:04 +02:00
kjeremy
61f1c0a990 lsp-types 0.74
* Fixes a bunch of param types to take partial progress into account.
* Will allow us to support insert/replace text in completions
2020-04-26 16:05:22 -04:00
Florian Diebold
497073abc6 For associated type shorthand (T::Item), use the substs from the where clause
So e.g. if we have `fn foo<T: SomeTrait<u32>>() -> T::Item`, we want to lower
that to `<T as SomeTrait<u32>>::Item` and not `<T as SomeTrait<_>>::Item`.
2020-04-26 16:58:08 +02:00
Edwin Cheng
bfce657377 Generate uniq name 2020-04-26 18:59:09 +08:00
Edwin Cheng
183673655f Simpify code 2020-04-26 17:58:56 +08:00
Edwin Cheng
fb996cae6b Fix 2020-04-26 17:17:37 +08:00
Edwin Cheng
3bad5587c8 Compare timestamp 2020-04-26 17:17:37 +08:00
Edwin Cheng
5a5bba5a46 Copy dylib to temp directory 2020-04-26 17:17:37 +08:00
Edwin Cheng
3e24444aee Cacheproc-macro dlls 2020-04-26 17:17:37 +08:00
bors[bot]
ef67e0a497
Merge #4155
4155: Precompute expected type during completion r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-04-26 08:54:42 +00:00
Aleksey Kladov
05cdc87158 Precompute expected type during completion 2020-04-26 10:54:08 +02:00
Aleksey Kladov
5ef0f44499 Add cargo test to the list of Run commands 2020-04-26 10:40:34 +02:00
veetaha
24d18d92f6 Simplify profiler impl (bubble up Option and shorten code 2020-04-26 00:55:49 +03:00
Jonas Schievink
5a355ff52b Fix broken test 2020-04-25 22:23:56 +02:00
Jonas Schievink
76d6f54471 Don't add call parens when an fn type is expected 2020-04-25 22:18:57 +02:00
bors[bot]
45832b990c
Merge #4145
4145: Remove dead code r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-04-25 19:30:04 +00:00
bors[bot]
7021352dc2
Merge #4113 #4136 #4141 #4142
4113: Support returning non-hierarchical symbols r=matklad a=kjeremy

If `hierarchicalDocumentSymbolSupport` is not true in the client capabilites
then it does not support the `DocumentSymbol[]` return type from the
`textDocument/documentSymbol` request and we must fall back to `SymbolInformation[]`.

This is one of the few requests that use the client capabilities to
differentiate between return types and could cause problems for clients.

See https://github.com/microsoft/language-server-protocol/pull/538#issuecomment-442510767 for more context.

Found while looking at #144

4136: add support for cfg feature attributes on expression #4063 r=matklad a=bnjjj

close issue #4063

4141: Fix typo r=matklad a=Veetaha



4142: Remove unnecessary async from vscode language client creation r=matklad a=Veetaha



Co-authored-by: kjeremy <kjeremy@gmail.com>
Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Co-authored-by: veetaha <veetaha2@gmail.com>
2020-04-25 19:23:15 +00:00
Aleksey Kladov
bd9ede0ec9 Extract messy tree handling out of profiling code 2020-04-25 21:22:40 +02:00
Aleksey Kladov
0f099ead88 Fix panic in NoSuchField diagnostic 2020-04-25 21:09:33 +02:00
Aleksey Kladov
95b989ec30 Simplify 2020-04-25 19:50:42 +02:00
veetaha
f52e2f6840 Fix typo 2020-04-25 20:49:51 +03:00
Aleksey Kladov
726938f598 Simplify hprof 2020-04-25 19:30:00 +02:00
Aleksey Kladov
b3e9f3d143 Move hprof to a separate file 2020-04-25 19:30:00 +02:00
Aleksey Kladov
7623db1106 minor clenup 2020-04-25 19:30:00 +02:00
bors[bot]
5671bacfa6
Merge #4139
4139: Add check for rules that no repetition which could match an empty token r=matklad a=edwin0cheng

Fix #4103

for `/ui/issues/issue-57597.rs`

This is `ParseError` of the macro rules , because it is how rustc handle it : 

a58b1ed44f/src/librustc_expand/mbe/macro_rules.rs (L558)


Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-04-25 16:26:51 +00:00
bors[bot]
67afeebaf5
Merge #4137
4137: Prefer core/alloc paths on #![no_std] r=matklad a=jonas-schievink



Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-04-25 16:19:21 +00:00
Edwin Cheng
d5eb43f246 Checks no repetition for an empty token 2020-04-25 23:30:10 +08:00
bors[bot]
fc57358efd
Merge #4133
4133: main: eagerly prime goto-definition caches r=matklad a=BurntSushi

This commit eagerly primes the caches used by goto-definition by
submitting a "phantom" goto-definition request. This is perhaps a bit
circuitous, but it does actually get the job done. The result of this
change is that once RA is finished its initial loading of a project,
goto-definition requests are instant. There don't appear to be any more
surprise latency spikes.

This _partially_ addresses #1650 in that it front-loads the latency of the
first goto-definition request, which in turn makes it more predictable and
less surprising. In particular, this addresses the use case where one opens
the text editor, starts reading code for a while, and only later issues the
first goto-definition request. Before this PR, that first goto-definition request
is guaranteed to have high latency in any reasonably sized project. But
after this PR, there's a good chance that it will now be instant.

What this _doesn't_ address is that initial loading time. In fact, it makes it
longer by adding a phantom goto-definition request to the initial startup
sequence. However, I observed that while this did make initial loading
slower, it was overall a somewhat small (but not insignificant) fraction
of initial loading time.

-----

At least, the above is what I _want_ to do. The actual change in this PR is just a proof-of-concept. I came up with after an evening of printf-debugging. Once I found the spot where this cache priming should go, I was unsure of how to generate a phantom input. So I just took an input I knew worked from my printf-debugging and hacked it in. Obviously, what I'd like to do is make this more general such that it will always work.

I don't know whether this is the "right" approach or not. My guess is that there is perhaps a cleaner solution that more directly primes whatever cache is being lazily populated rather than fudging the issue with a phantom goto-definition request.

I created this as a draft PR because I'd really like help making this general. I think whether y'all want to accept this patch is perhaps a separate question. IMO, it seems like a good idea, but to be honest, I'm happy to maintain this patch on my own since it's so trivial. But I would like to generalize it so that it will work in any project.

My thinking is that all I really need to do is find a file and a token somewhere in the loaded project, and then use that as input. But I don't quite know how to connect all the data structures to do that. Any help would be appreciated!

cc @matklad since I've been a worm in your ear about this problem. :-)

Co-authored-by: Andrew Gallant <jamslam@gmail.com>
2020-04-25 14:30:10 +00:00
Jonas Schievink
3cf2c3b943 Prefer core/alloc paths on #![no_std] 2020-04-25 16:27:34 +02:00
Andrew Gallant
0c12b7e8c8
main: fix bug where thread pool isn't joined
Pointed out here:
https://github.com/rust-analyzer/rust-analyzer/pull/4133#issuecomment-619386272
2020-04-25 10:26:33 -04:00
Benjamin Coenen
b87b335e68 add support for cfg feature attributes on expression #4063
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-04-25 15:48:04 +02:00
Andrew Gallant
c1a31d4261
main: eagerly prime goto-definition caches
This commit makes RA more aggressive about eagerly priming the caches.
In particular, this fixes an issue where even after RA was done priming
its caches, an initial goto-definition request would have very high
latency. This fixes that issue by requesting syntax highlighting for
everything. It is presumed that this is a tad wasteful, but not overly
so.

This commit also tweaks the logic that determines when the cache is
primed. Namely, instead of just priming it when the state is loaded
initially, we attempt to prime it whenever some state changes. This
fixes an issue where if a modification notification is seen before cache
priming is done, it would stop the cache priming early.
2020-04-25 09:28:34 -04:00
Aleksey Kladov
970dbf8717 Rename StructField -> Field 2020-04-25 14:23:34 +02:00
bors[bot]
7bc7173230
Merge #4134
4134: Special case for empty comments in doc comment kind  r=matklad a=edwin0cheng

Part of #4103

Fix `ui/empty/empty-comment.rs macros`

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-04-25 10:53:40 +00:00
Edwin Cheng
f0fece4be0 Fix whitespaces 2020-04-25 18:49:46 +08:00
bors[bot]
f654f49435
Merge #4125
4125: Avoid lossy OsString conversions r=matklad a=lnicola

This is a bit invasive, and perhaps for not much benefit since non-UTF-8 environment variables don't work anyway.

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-04-25 10:35:14 +00:00
Aleksey Kladov
e873469500 text-size 1.0.0 2020-04-25 12:15:32 +02:00
Aleksey Kladov
63a462f37c Switch to TryFrom 2020-04-25 11:59:18 +02:00
Aleksey Kladov
dc2151085e Cleanups 2020-04-25 11:59:18 +02:00
Aleksey Kladov
8843588fca Convert tests to text-size 2020-04-25 11:59:18 +02:00
Aleksey Kladov
b1d5817dd1 Convert code to text-size 2020-04-25 11:59:18 +02:00
Edwin Cheng
d20eea073e Special case for empty comments 2020-04-25 17:37:34 +08:00
Laurențiu Nicola
58dde891f8 Avoid lossy OsString conversions 2020-04-25 12:19:23 +03:00
bors[bot]
27a7718880
Merge #4128
4128: Include correct item path for variant completions r=matklad a=jonas-schievink

The test would previously suggest `E::V`, which is not enough to name the variant as the enum is in a module. Now it correctly suggests the full path `m::E::V`.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-04-24 21:11:19 +00:00
Aleksey Kladov
aa669c5ba5 Don't print cargo version to stdout, breaking everything 2020-04-24 23:02:10 +02:00
Jonas Schievink
e131763fb8 Include correct item path for variant completions 2020-04-24 22:18:59 +02:00
bors[bot]
51a0058d4c
Merge #3998 #4006
3998: Make add_function generate functions in other modules via qualified path r=matklad a=TimoFreiberg

Additional feature for #3639 

- [x] Add tests for paths with more segments
- [x] Make generating the function in another file work
- [x] Add `pub` or `pub(crate)` to the generated function if it's generated in a different module
- [x] Make the assist jump to the edited file
- [x] Enable file support in the `check_assist` helper

4006: Syntax highlighting for format strings r=matklad a=ltentrup

I have an implementation for syntax highlighting for format string modifiers `{}`.
The first commit refactors the changes in #3826 into a separate struct.
The second commit implements the highlighting: first we check in a macro call whether the macro is a format macro from `std`. In this case, we remember the format string node. If we encounter this node during syntax highlighting, we check for the format modifiers `{}` using regular expressions.

There are a few places which I am not quite sure:
- Is the way I extract the macro names correct?
- Is the `HighlightTag::Attribute` suitable for highlighting the `{}`?

Let me know what you think, any feedback is welcome!

Co-authored-by: Timo Freiberg <timo.freiberg@gmail.com>
Co-authored-by: Leander Tentrup <leander.tentrup@gmail.com>
Co-authored-by: Leander Tentrup <ltentrup@users.noreply.github.com>
2020-04-24 20:10:54 +00:00
bors[bot]
e55b1833ff
Merge #4127
4127: More helpful error message if toolchain is not in PATH r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-04-24 20:03:33 +00:00
Aleksey Kladov
6c400b3e33 More helpful error message if toolchain is not in PATH 2020-04-24 22:01:32 +02:00
Jonas Schievink
7b9553a703 Don't omit methods with self from path completion 2020-04-24 21:46:18 +02:00
Roberto Vidal
0dab5d5879 Adds attribute completions (#3941) 2020-04-24 17:54:52 +02:00
kjeremy
0619c67ac6 Support returning non-hierarchical symbols
If `hierarchicalDocumentSymbolSupport` is not true in the client capabilites
then it does not support the `DocumentSymbol[]` return type from the
`textDocument/documentSymbol` request and we must fall back to `SymbolInformation[]`.

This is one of the few requests that use the client capabilities to
differentiate between return types and could cause problems for clients.

See https://github.com/microsoft/language-server-protocol/pull/538#issuecomment-442510767 for more context.

Found while looking at #144
2020-04-24 10:11:57 -04:00
kjeremy
ae1f77e5e9 Add hierarchical symbols client capability 2020-04-24 10:08:45 -04:00
Aleksey Kladov
62e08fa53d Better label for macros completion 2020-04-24 13:25:37 +02:00
bors[bot]
44e6c2cb54
Merge #4101
4101: Panic proc macro srv if read request failed r=matklad a=edwin0cheng

This PR fixed a bug when the rust-analyzer is killed suddenly, the `rust-analyzer proc-macro` will become stale.

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-04-24 01:28:53 +00:00
Edwin Cheng
a83d1743a5 Refactor a bit 2020-04-24 09:27:37 +08:00
Aleksey Kladov
440cd05edb Honor snippet capability
closes #2518
2020-04-24 02:41:07 +02:00
Aleksey Kladov
5fd5de4061 Make sure that adding a snippet requires corresponding capability 2020-04-24 02:26:38 +02:00
Aleksey Kladov
b3050bded1 Introduce internal snippet cap 2020-04-24 02:06:12 +02:00
Aleksey Kladov
bd3b239390 Move CompletionConfig to a separate module 2020-04-24 02:01:23 +02:00
Aleksey Kladov
88d243c742 Don't set sortText
I might be reading this wrong, but it looks like we are setting it to
essentially arbitrary string at the moment, as there are no defined
order on the items in the *set* of completions.
2020-04-24 01:53:37 +02:00
Aleksey Kladov
647683b9bb Add test marks 2020-04-24 01:48:32 +02:00
Aleksey Kladov
09a4b78775 Introduce ActiveParameter 2020-04-24 01:46:00 +02:00
Aleksey Kladov
4b8e9d5483 Move tests to where they belong 2020-04-24 01:26:27 +02:00
Aleksey Kladov
174952e89b Refactor 2020-04-24 01:24:08 +02:00
Aleksey Kladov
953b5f23cc Restore CompletionItem immutability 2020-04-24 01:17:33 +02:00
Aleksey Kladov
6654b9aff3 More functional 2020-04-24 01:08:27 +02:00
Aleksey Kladov
75cb1c1806 Move 2020-04-24 00:11:33 +02:00
bors[bot]
5eb51c1e60
Merge #4106
4106: Fix wrong substitution code r=matklad a=flodiebold

We need to shift in when we're substituting inside a binder.

This should fix #4053 (it doesn't fix the occasional overflow that also occurs on the Diesel codebase though).

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2020-04-23 21:58:52 +00:00
Florian Diebold
0c01b4eb6a Fix wrong substitution code
We need to shift in when we're substituting inside a binder.

This should fix #4053 (it doesn't fix the occasional overflow that also occurs
on the Diesel codebase though).
2020-04-23 23:53:08 +02:00
bors[bot]
e833e03783
Merge #3954
3954: Improve autocompletion by looking on the type and name r=matklad a=bnjjj

This tweet (https://twitter.com/tjholowaychuk/status/1248918374731714560) gaves me the idea to implement that in rust-analyzer.

Basically for this first example I made some examples when we are in a function call definition. I look on the parameter list to prioritize autocompletions for the same types and if it's the same type + the same name then it's displayed first in the completion list.

So here is a draft, first step to open a discussion and know what you think about the implementation. It works (cf tests) but maybe I can make a better implementation at some places. Be careful the code needs some refactoring to be better and concise.

PS: It was lot of fun writing this haha

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-04-23 21:48:45 +00:00
bors[bot]
01f1f10fec
Merge #4111 #4112
4111: Record definitions in `extern` blocks r=jonas-schievink a=jonas-schievink

Enables completion of extern functions and statics.

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

4112: Add Launch configuration for release build r=matklad a=jonas-schievink

The debug build takes very long until I can test anything useful, with the release build it's much quicker. Add another Run configuration for it.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-04-23 21:37:06 +00:00
Jonas Schievink
5cc9546ca0 Record definitions in extern blocks 2020-04-23 23:36:23 +02:00
Aleksey Kladov
dd59237e0c minor 2020-04-23 23:18:18 +02:00
Aleksey Kladov
27dd0086ea Fully get rid of SyntaxNodePtr::range 2020-04-23 21:23:36 +02:00
Edwin Cheng
1627b55028 Bubble up error 2020-04-24 01:38:58 +08:00
Aleksey Kladov
ca6d7bfe61 Cleanup proc_macro config
In general, there should be no reason to call `.to_string_lossy`.
If you want to display the path, use `.display()`.
If you want to pass the path to an OS API (like std::process::Command)
than use `PathBuf` or `OsString`.
2020-04-23 18:55:26 +02:00
Edwin Cheng
25e8f5ded9 Fix typo 2020-04-24 00:16:17 +08:00
Edwin Cheng
0744497699 Panic proc macro srv if read request failed 2020-04-24 00:06:01 +08:00
bors[bot]
278bf351e3
Merge #4065
4065: Complete unqualified enum names in patterns and expressions r=matklad a=nathanwhit

This PR implements the completion described in #4014.
The result looks like so for patterns:
<img width="542" alt="Screen Shot 2020-04-20 at 3 53 55 PM" src="https://user-images.githubusercontent.com/17734409/79794010-8f529400-831f-11ea-9673-f838aa9bc962.png">

and for `expr`s:
<img width="620" alt="Screen Shot 2020-04-21 at 3 51 24 PM" src="https://user-images.githubusercontent.com/17734409/79908784-d73ded80-83e9-11ea-991d-921f0cb27e6f.png">


I'm not confident that the completion text itself is very robust, as it will unconditionally add completions for enum variants with the form `Enum::Variant`. This means (I believe) it would still suggest `Enum::Variant` even if the local name is changed i.e. `use Enum as Foo` or the variants are brought into scope such as through `use Enum::*`.

Co-authored-by: nathanwhit <nathan.whitaker01@gmail.com>
2020-04-23 15:35:31 +00:00
Aleksey Kladov
4176c03d12 Remove SyntaxPtr::range from more places 2020-04-23 16:33:01 +02:00
bors[bot]
0502be3bf4
Merge #4093
4093: Simplify config r=matklad a=Veetaha



Co-authored-by: veetaha <veetaha2@gmail.com>
2020-04-23 09:49:03 +00:00
bors[bot]
6ec64805e3
Merge #4094
4094: proc_macro: add ability to log to stderr and view output in vscode r=matklad a=Veetaha

r? @edwin0cheng 

Co-authored-by: veetaha <veetaha2@gmail.com>
2020-04-23 09:32:45 +00:00
bors[bot]
604b936ca0
Merge #4092
4092: feat: run ignored tests r=matklad a=hdevalke

I started making some exercices on https://exercism.io/ and a lot of test have the `#[ignore]` attribute.
The `Run Test|Debug` code lens show up, but running the test results in:

```
running 1 test
test test_one_piece ... ignored

test result: ok. 0 passed; 0 failed; 1 ignored; 0 measured; 5 filtered out
```

This pull request adds the `--ignored` flag if needed.

Co-authored-by: Hannes De Valkeneer <hannes@de-valkeneer.be>
2020-04-23 09:24:15 +00:00
veetaha
a3a8d10191 Fix typo 2020-04-23 02:00:56 +03:00
veetaha
b5620341fc proc_macro: add ability to log to stderr and view output in vscode 2020-04-23 01:57:02 +03:00
veetaha
364fbd7fc7 Simplify config 2020-04-23 01:30:55 +03:00
Hannes De Valkeneer
380a2870c7 feat: run ignored tests 2020-04-22 23:54:09 +02:00
nathanwhit
dfde73ef90 Update tests to reflect new completions 2020-04-22 12:21:22 -04:00
nathanwhit
18ad86fdda Add tests for enum completion
Adds tests for completion of enum variants in match arms, if-let statements, and basic expressions.
2020-04-22 12:21:22 -04:00
nathanwhit
8664509745 Complete unqualified enum variants when possible 2020-04-22 12:21:14 -04:00
nathanwhit
6c61a7b22f Add utility fn for expected type of a node
Adds `expected_type_of` to `CompletionContext` to return the expected type of a
node, if it is known.
2020-04-22 12:20:18 -04:00
bors[bot]
3f1f3a835a
Merge #4090
4090: Fix config naming r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-04-22 15:26:47 +00:00
Aleksey Kladov
9e16e2b279 Align the name of proc-macro enabling flag
We use `enable`, not `enabled` elsewhere
2020-04-22 17:22:59 +02:00
Aleksey Kladov
d436beeb04 Match implementation of diagnostics flag to the docs 2020-04-22 17:22:18 +02:00
Leander Tentrup
445052f6d4 Adapt format specifier highlighting to support escaped squences and unicode identifiers 2020-04-22 15:28:35 +02:00
Leander Tentrup
b2829a5216 Apply suggestions from code review
Co-Authored-By: bjorn3 <bjorn3@users.noreply.github.com>
2020-04-22 10:18:46 +02:00
Andrew Chin
165f5c6577 Don't panic on rust-analyzer --help
Special case handling for `-h` and `--help` if no subcommand is given.

Closes #4068
2020-04-21 20:23:01 -04:00
Timo Freiberg
f2f882bc44 Add pub(crate) to functions generated in other module 2020-04-21 23:04:44 +02:00
Timo Freiberg
74780a15f6 Jump to sourceChanges in other files 2020-04-21 23:04:44 +02:00
Timo Freiberg
ba8faf3efc Add target file information to AssistAction 2020-04-21 23:04:44 +02:00
Timo Freiberg
317fc650d5 Make add_function generate functions in other modules via qualified path 2020-04-21 23:04:44 +02:00
Kirill Bulatov
ce06a6b422 Do not add default and closure types in 'add explicit type' assist 2020-04-21 22:56:40 +03:00
bors[bot]
7ab28cacbb
Merge #4076
4076: Improve remove derive attrs r=matklad a=edwin0cheng

This PR implemented a proper `remove_derive_attrs` function which **merely** remove  any `#[derive(*)]` attributes.

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-04-21 18:50:53 +00:00
Edwin Cheng
4a303366c8 Improve remove dervie attrs 2020-04-22 01:44:21 +08:00
Benjamin Coenen
da6b136ea5 Improve autocompletion by looking on the type and name
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-04-21 17:19:18 +02:00
bors[bot]
4a250021b1
Merge #4038
4038: Group generated ast boilerplate apart from the interesting part r=matklad a=Veetaha

Boilerplate `AstNode` and `From` impls are moved to the end further from the interesting part in `generated.rs`

Co-authored-by: veetaha <veetaha2@gmail.com>
2020-04-21 12:58:27 +00:00
Benjamin Coenen
b6a7be19d9 Improve autocompletion by looking on the type and name
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-04-21 14:36:56 +02:00
Benjamin Coenen
7f143b154e Merge branch 'master' of github.com:rust-analyzer/rust-analyzer 2020-04-21 14:32:02 +02:00
Benjamin Coenen
1c3a1385a5 Improve autocompletion by looking on the type and name
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-04-21 14:31:57 +02:00
bors[bot]
a88887df07
Merge #4071
4071: Cleanup args a bit r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-04-21 10:10:22 +00:00
Aleksey Kladov
d9bed8aa45 Cleanup args a bit 2020-04-21 12:06:25 +02:00
Edwin Cheng
ce382e6a79 Refactor a bit 2020-04-21 05:22:17 +08:00
Edwin Cheng
bd350108b0 Fix restart missing arguments in proc-macro-srv 2020-04-21 04:57:55 +08:00
bors[bot]
0ad6b6d407
Merge #4061
4061: ra_proc_macro: cleanups here and there r=edwin0cheng a=Veetaha

r? @edwin0cheng 

Co-authored-by: veetaha <veetaha2@gmail.com>
Co-authored-by: Veetaha <veetaha2@gmail.com>
2020-04-20 20:25:33 +00:00
veetaha
fc460b1e42 Migrate to Result<T, io::Error> -> io::Result<T> 2020-04-20 22:42:36 +03:00
veetaha
d8ca817456 Fix doc comment 2020-04-20 22:24:10 +03:00
Veetaha
834960d841
Fix typo
Co-Authored-By: Laurențiu Nicola <lnicola@users.noreply.github.com>
2020-04-20 22:07:47 +03:00
Veetaha
0f5b1fef5e Display path not debug it
Co-Authored-By: Laurențiu Nicola <lnicola@users.noreply.github.com>
2020-04-20 22:06:41 +03:00
Veetaha
982af2286a
Display path not debug it
Co-Authored-By: Laurențiu Nicola <lnicola@users.noreply.github.com>
2020-04-20 21:50:06 +03:00
veetaha
d3019164dc ra_proc_macro: cleanups here and there 2020-04-20 21:37:02 +03:00
Florian Diebold
0be68a4825 Update Chalk, and cache Chalk env elaboration through a query
This should fix some of the worst performance problems.
2020-04-20 19:16:01 +02:00
Aleksey Kladov
8a04372fec Fix panic in split_imports assist
The fix is admittedly quit literally just papering over.

Long-term, I see two more principled approaches:

* we switch to a fully tree-based impl, without parse . to_string
  step; with this approach, there shouldn't be any panics. The results
  might be nonsensical, but so was the original input.

* we preserve the invariant that re-parsing constructed node is an
  identity, and make all the `make_xxx` method return an `Option`.

closes #4044
2020-04-20 16:34:01 +02:00
Leander Tentrup
ac798e1f7c Implement syntax highlighting for format strings
Detailed changes:
1) Implement a lexer for string literals that divides the string in format specifier `{}` including the format specifier modifier.
2) Adapt syntax highlighting to add ranges for the detected sequences.
3) Add a test case for the format string syntax highlighting.
2020-04-20 11:19:15 +02:00
Jeremy Kolb
d7f3d858ad Some clippy fixes 2020-04-19 15:15:49 -04:00
veetaha
972d3b2ba3 Group generated ast boilerplate apart from the interesting part 2020-04-18 23:51:13 +03:00
bors[bot]
36840bd6c7
Merge #4036
4036: Fix a bunch of unresovled references r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-04-18 20:18:57 +00:00
Aleksey Kladov
b79fd82559 Correctly infer types in guard expressions
The root cause was that we forgot to add bindings from the arm to the
guard expression

closes #3980
2020-04-18 22:16:04 +02:00
Aleksey Kladov
fa2ea8f494 Fix goto definition for record patterns 2020-04-18 22:11:49 +02:00
bors[bot]
7a59cd49ff
Merge #4035
4035: Convert bool to ident instead of literal in mbe r=matklad a=edwin0cheng

Fixed #1249

Currently we treat boolean literal as `tt::Literal` , which makes parsing $lit:lit matcher easily.
However, proc-macro2 treat boolean literal as `ident` :

4173a21dc4/src/lib.rs (L939)

OT: I am quite happy we finally need to fix this bug :)

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-04-18 19:36:37 +00:00
bors[bot]
b95b77f92f
Merge #4034
4034: Add semantic tag for unresolved references r=matklad a=matklad

This is a quick way to implement unresolved reference diagnostics.
For example, adding to VS Code config

    "editor.tokenColorCustomizationsExperimental": {
        "unresolvedReference": "#FF0000"
    },

will highlight all unresolved refs in red.

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-04-18 19:29:17 +00:00
Aleksey Kladov
ca61356b01 Add semantic tag for unresolved references
This is a quick way to implement unresolved reference diagnostics.
For example, adding to VS Code config

    "editor.tokenColorCustomizationsExperimental": {
        "unresolvedReference": "#FF0000"
    },

will highlight all unresolved refs in red.
2020-04-18 21:28:51 +02:00
Edwin Cheng
a1b5cf81eb Convert bool to ident instead of literal in mbe 2020-04-19 03:24:17 +08:00
bors[bot]
b949500126
Merge #4032
4032: Add mbe lifetime split test r=matklad a=edwin0cheng



Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-04-18 18:57:14 +00:00
Edwin Cheng
ce674be217 Add mbe lifetime split test 2020-04-19 02:45:17 +08:00
bors[bot]
6f60e646fc
Merge #3894
3894: Match check enum record r=flodiebold a=JoshMcguigan

This PR implements match statement exhaustiveness checking for record type enums.

It also make a minor addition to the test infrastructure to allow testing against a single diagnostic, so you can be sure your test is triggering (or not) whichever diagnostic you expect.

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2020-04-18 18:42:07 +00:00
bors[bot]
98819d8919
Merge #4029
4029: Fix various proc-macro bugs r=matklad a=edwin0cheng

This PRs does the following things:

1. Fixed #4001 by splitting `LIFETIME` lexer token to two mbe tokens. It is because rustc token stream expects `LIFETIME` as a combination of punct and ident, but RA `tt:TokenTree` treats it as a single `Ident` previously.
2. Fixed #4003, by skipping `proc-macro` for completion. It is because currently we don't have `AstNode` for `proc-macro`. We would need to redesign how to implement `HasSource` for `proc-macro`.
3.  Fixed a bug how empty `TokenStream` merging in `proc-macro-srv` such that no L_DOLLAR and R_DOLLAR will be emitted accidentally. 


Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-04-18 17:56:54 +00:00
Benjamin Coenen
af3c19e85f Merge branch 'master' of github.com:rust-analyzer/rust-analyzer 2020-04-18 17:14:24 +02:00
Leander Tentrup
29a846464b Refactor flattening logic for highlighted syntax ranges 2020-04-18 15:02:51 +02:00
Josh Mcguigan
7adb681b1f missing match arm diagnostic support enum record type 2020-04-18 05:54:56 -07:00
Edwin Cheng
72bba98828 Merge empty delim subtree in proc-macro 2020-04-18 19:29:04 +08:00
Edwin Cheng
da18f11307 Split LIFETIME to two tokens in mbe 2020-04-18 19:28:07 +08:00
Edwin Cheng
f78de3bb95 Ignore proc-macro in completion 2020-04-18 19:26:54 +08:00
Florian Diebold
b49ecafd40 find_path: Builtins are always in scope
Fixes #3977.
2020-04-18 12:06:22 +02:00
bors[bot]
0948932145
Merge #4026
4026: Omit more parameter hints in the presence of underscores r=matklad a=lnicola

Fixes #4017.

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-04-18 09:01:41 +00:00
bors[bot]
162481d5ce
Merge #4023
4023: Fix another crash from wrong binders r=matklad a=flodiebold

Basically, if we had something like `dyn Trait<T>` (where `T` is a type parameter) in an impl we lowered that to `dyn Trait<^0.0>`, when it should be `dyn Trait<^1.0>` because the `dyn` introduces a new binder. With one type parameter, that's just wrong, with two, it'll lead to crashes.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2020-04-18 08:48:08 +00:00
Laurențiu Nicola
8a51a74556 Omit more parameter hints in the presence of underscores 2020-04-18 10:53:48 +03:00
Florian Diebold
d3cb9ea0bf Fix another crash from wrong binders
Basically, if we had something like `dyn Trait<T>` (where `T` is a type
parameter) in an impl we lowered that to `dyn Trait<^0.0>`, when it should be
`dyn Trait<^1.0>` because the `dyn` introduces a new binder. With one type
parameter, that's just wrong, with two, it'll lead to crashes.
2020-04-18 00:01:09 +02:00
Leander Tentrup
2e2c03ee2d Fix incorrect order of syntax highlight ranges 2020-04-17 22:50:30 +02:00
Florian Diebold
6a7fc76b89 Fix type equality for dyn Trait
Fixes a lot of false type mismatches.

(And as always when touching the unification code, I have to say I'm looking
forward to replacing it by Chalk's...)
2020-04-17 19:42:36 +02:00
Florian Diebold
fbd95785a6 Add two more tests for associated types 2020-04-17 18:27:38 +02:00
Aleksey Kladov
f178df1a5e Don't use SyntaxNodePtr::range when determining scope for offset 2020-04-17 18:04:49 +02:00
bors[bot]
179d983535
Merge #4012
4012: fix panic on ellipsis in pattern r=flodiebold a=JoshMcguigan

fixes #3999

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2020-04-17 12:39:20 +00:00
Josh Mcguigan
408f914bf4 fix panic on ellipsis in pattern 2020-04-17 05:36:44 -07:00
Aleksey Kladov
028f1e2e3a Don\t suggest import itself as a completion for import 2020-04-17 14:28:20 +02:00
bors[bot]
0262c9b9c0
Merge #4010
4010: Fix handling of ranges in diagnostics r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-04-17 11:57:29 +00:00
Aleksey Kladov
146f6f5a45 Simplify Diagnostic structure
It's not entirely clear what subnode ranges should mean in the
presence of macros, so let's leave them out for now. We are not using
them heavily anyway.
2020-04-17 13:56:42 +02:00
Aleksey Kladov
a8196ffe84 Correctly highlight ranges of diagnostics from macros
closes #2799
2020-04-17 13:56:38 +02:00
Aleksey Kladov
302bf97bbf Don't expose impl details of SyntaxPtr 2020-04-17 12:25:41 +02:00
bors[bot]
bd6b532224
Merge #4009
4009: Better snippet when completing trait method r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-04-17 10:06:01 +00:00
Aleksey Kladov
3b75bc154f Better snippet when completing trait method 2020-04-17 12:05:35 +02:00