Commit Graph

5457 Commits

Author SHA1 Message Date
Aleksey Kladov
1a6f51da66 Simplify: remove couple of useless functions 2020-03-02 19:03:46 +01:00
bors[bot]
7928ac4bbd
Merge #3405
3405: More principled approach for gotodef for field shorhand r=matklad a=matklad

Callers can now decide for themselves if they should prefer field or
local definition. By default, it's the local.



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-03-02 18:01:50 +00:00
Aleksey Kladov
2716a1fa3f More principled approach for gotodef for field shorhand
Callers can now decide for themselves if they should prefer field or
local definition. By default, it's the local.
2020-03-02 19:00:38 +01:00
kjeremy
c6f4e8de5e lsp-types 0.72 2020-03-02 11:52:46 -05:00
bors[bot]
02f761ba4b
Merge #3397 #3398
3397: Minimal viable meta r=matklad a=matklad



bors r+
🤖

3398: Reformat? r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-03-02 13:31:56 +00:00
Aleksey Kladov
62e62d1c23 Reformat? 2020-03-02 14:28:34 +01:00
bors[bot]
79c874803b
Merge #3385
3385: Fix #3373 r=matklad a=flodiebold

Basically, we need to allow variables in the caller self type to unify with the
impl's declared self type. That requires some more contortions in the variable
handling. I'm looking forward to (hopefully) handling this in a cleaner way when
we switch to Chalk's types and unification code.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2020-03-02 13:23:24 +00:00
Aleksey Kladov
503ffb4893 One more assert 2020-03-02 13:59:35 +01:00
Aleksey Kladov
8f8980cedf Tighten up an assert 2020-03-02 13:45:26 +01:00
bors[bot]
b71fc18abe
Merge #3387
3387: Type inference for slice patterns r=flodiebold a=JoshMcguigan

Fixes #3043 

Notes to reviewer:

1. This only works if `expected` is `Ty::Apply`. I'm not sure of the implications of this.
1. This only works if the slice pattern only has a prefix. I think this means it doesn't work for subslice patterns, which are currently only available behind a feature flag.

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2020-03-01 22:36:47 +00:00
Josh Mcguigan
f5efa17515 handle array pattern matching type inference 2020-03-01 14:02:32 -08:00
Josh Mcguigan
b9ef7a6b98 remove match statement, handle suffix 2020-03-01 12:13:05 -08:00
Josh Mcguigan
d0e282f6b1 handle arbitrary length slices 2020-03-01 07:35:15 -08:00
Josh Mcguigan
f353625705 match single prefix slice 2020-03-01 06:25:38 -08:00
bors[bot]
ea67e2346e
Merge #3384
3384: fix #2377 super::super::* r=flodiebold a=JoshMcguigan

Thanks @matklad for the detailed explanation on #2377. I believe this fixes it.

One thing I'm not sure about is you said the fix would involve changing `crates/ra_hir_def/src/path/lower/lower.rs`, but I only changed `crates/ra_hir_def/src/path/lower/lower_use.rs`. I'm not sure what kind of test code I'd have to write to expose the issue in `lower.rs`, but I'd be happy to add it if you are able to provide additional guidance. 

closes #2377

Co-authored-by: Josh Mcguigan <joshmcg88@gmail.com>
2020-03-01 13:36:44 +00:00
Florian Diebold
336a3c6121 Fix #3373
Basically, we need to allow variables in the caller self type to unify with the
impl's declared self type. That requires some more contortions in the variable
handling. I'm looking forward to (hopefully) handling this in a cleaner way when
we switch to Chalk's types and unification code.
2020-03-01 14:31:35 +01:00
Josh Mcguigan
0057d1e10d fix completion for super::super:: 2020-02-29 21:04:21 -08:00
Josh Mcguigan
69faf81e0d fix #2377 super::super::* 2020-02-29 19:48:55 -08:00
bors[bot]
6db2da4993
Merge #3383
3383: Slightly refactor inlay hints r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-02-29 22:32:27 +00:00
Aleksey Kladov
584c8d9875 Slightly refactor inlay hints 2020-02-29 23:24:50 +01:00
bors[bot]
61fe34b709
Merge #3382
3382: ra_project_model: migrate to Sysroot::alloc() r=matklad a=Veetaha



Co-authored-by: Veetaha <gerzoh1@gmail.com>
2020-02-29 22:24:21 +00:00
Veetaha
9f1adf8498 ra_project_model: migrate to Sysroot::alloc() 2020-03-01 00:16:57 +02:00
bors[bot]
6ee3470975
Merge #3381
3381: Remove debug print r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-02-29 22:10:14 +00:00
Aleksey Kladov
2e0d89401a Remove debug print 2020-02-29 23:03:49 +01:00
Florian Diebold
31171eed5e Do autoderef for indexing 2020-02-29 22:48:53 +01:00
Florian Diebold
e313efb992 Do array unsizing for method receivers
It turns out rustc actually only unsizes array method receivers, so we don't
need to do any trait solving for this (at least for now).

Fixes #2670.
2020-02-29 22:48:53 +01:00
Aleksey Kladov
a1e1869554 Rename ast::ImplBlock -> ast::ImplDef 2020-02-29 21:33:15 +01:00
Aleksey Kladov
f316e074d2 Add a FIXME 2020-02-29 21:23:16 +01:00
Aleksey Kladov
7f09083c6f Handle tuple fields as well 2020-02-29 18:35:45 +01:00
Aleksey Kladov
14ea21617a Minor 2020-02-29 18:34:34 +01:00
Aleksey Kladov
28332d9b63 Simplify SourceBinder 2020-02-29 18:32:18 +01:00
Aleksey Kladov
a6a623dfbb Small cleanup 2020-02-29 16:57:56 +01:00
bors[bot]
099a8f37f5
Merge #3309
3309: Find cargo toml up the fs r=matklad a=not-much-io

Currently rust-analyzer will look for Cargo.toml in the root of the project and if failing that then go down the filesystem until root.

This unfortunately wouldn't work automatically with (what I imagine is) a fairly common project structure. As an example with multiple languages like:
```
js/
  ..
rust/
  Cargo.toml
  ...
```

Added this small change so rust-analyzer would glance one level up if not found in root or down the filesystem.

## Why not go deeper?

Could be problematic with large project vendored dependencies etc.

## Why not add a Cargo.toml manual setting option?

Loosely related and a good idea, however the convenience of having this automated also is hard to pass up. 

## Testing?

Build a binary with various logs and checked it in a project with such a structure:

```
[ERROR ra_project_model] find_cargo_toml()
[ERROR ra_project_model] find_cargo_toml_up_the_fs()
[ERROR ra_project_model] entities: ReadDir("/workspaces/my-project")
[ERROR ra_project_model] candidate: "/workspaces/my-project/rust/Cargo.toml", exists: true
```

## Edge Cases?

If you have multiple Cargo.toml files one level deeper AND not in the root, will get whatever comes first (order undefined), example:
```
crate1/
    Cargo.toml
crate2/
     Cargo.toml
... (no root Cargo.toml)
```

However this is quite unusual and wouldn't have worked before either. This is only resolvable via manually choosing.

Co-authored-by: nmio <kristo.koert@gmail.com>
2020-02-29 15:36:03 +00:00
Florian Diebold
5fe220b987 Fix a common false-positive type mismatch
E.g. for `&{ some_string() }` in a context where a `&str` is expected, we
reported a mismatch inside the block. The problem is that we're passing an
expectation of `str` down, but the expectation is more of a hint in this case.
There's a long comment in rustc about this, which I just copied.

Also, fix reported location for type mismatches in macros.
2020-02-29 15:31:07 +01:00
nmio
b9fbb3da17 lint warn fix 2020-02-29 13:14:31 +00:00
nmio
e15424c1b7 keep one CargoTomlNotFoundError 2020-02-29 13:05:10 +00:00
Aleksey Kladov
9abcab1669 Fix typo 2020-02-29 13:51:23 +01:00
Aleksey Kladov
5f8b37563e Cleanup editing API 2020-02-29 13:51:23 +01:00
Aleksey Kladov
ca713e462b More orthogonal API for building paths 2020-02-29 11:55:36 +01:00
Aleksey Kladov
067cb928f0 Simplify 2020-02-28 22:43:13 +01:00
Aleksey Kladov
ff42008679 Move insert_use util to utils 2020-02-28 21:53:20 +01:00
Aleksey Kladov
e7c82eab21 Reduce visibility 2020-02-28 17:28:29 +01:00
bors[bot]
c692e07b4f
Merge #3367
3367: Fix highlighting of const patterns r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-02-28 15:56:07 +00:00
Aleksey Kladov
56ce34c6a7 Correctly flag 'lifetime definitions as definitions 2020-02-28 16:53:12 +01:00
Aleksey Kladov
5ebfcb9cb7 Fix highlighting of const patterns 2020-02-28 16:38:36 +01:00
bors[bot]
93f632ca4e
Merge #3366
3366: Simpilfy original_range logic r=matklad a=edwin0cheng

This PR fixed another [bug](https://github.com/rust-analyzer/rust-analyzer/issues/3000#issuecomment-592474844) which incorrectly map the wrong range of `punct` in macro_call and simplify the logic a little bit by introducing an `ascend_call_token` function.



Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-02-28 15:07:33 +00:00
Edwin Cheng
7a5ff0f37c Simpilfy origin_range logic 2020-02-28 22:53:59 +08:00
Aleksey Kladov
209eb32796 Classify name takes const patterns into account 2020-02-28 15:27:52 +01:00
Aleksey Kladov
da40149572 Fix union classification 2020-02-28 15:03:09 +01:00
bors[bot]
2995fd2c87
Merge #3363
3363: Cleanup highlighting tags r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-02-28 13:48:42 +00:00
Aleksey Kladov
9464ca97c9 Fix highlighting test 2020-02-28 14:47:33 +01:00
Aleksey Kladov
701cf43606 Cleanup highlighting tags 2020-02-28 12:13:37 +01:00
Aleksey Kladov
996e18846d add more tags 2020-02-28 10:39:31 +01:00
bors[bot]
553353e316
Merge #3360
3360: Parse attribues in RHS of let statments r=matklad a=edwin0cheng

Fixed #3315

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-02-28 09:23:41 +00:00
bors[bot]
4741ae7852
Merge #3359
3359: Remove AnalysisHost::type_of  r=matklad a=edwin0cheng

This PR remove ` AnalysisHost::type_of` (It is subsume by hover now) and use `Semantics::type_of_x` to infer the type inside `hover` directly. 

And this also solved a bug : Right now hovering on a string literal inside a macro will show up a `&str` popup correctly. (Except if that involved builtin macro, e.g. `println`)

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-02-28 07:53:19 +00:00
Edwin Cheng
cda04d2077 Fix typo 2020-02-28 15:39:34 +08:00
Edwin Cheng
f4e48ad3e4 Parse attr in rhs of let stmts 2020-02-28 13:08:47 +08:00
Edwin Cheng
5f30dd6f72 Remove hover::type_of 2020-02-28 11:37:22 +08:00
Douglas Campos
34a7e4fbaf introduce const visibility assist 2020-02-28 01:15:17 +00:00
nmio
12b595e817 remove code used for testing 2020-02-27 22:06:51 +00:00
nmio
f9f8edfb06 fix unneeded body 2020-02-27 22:03:29 +00:00
nmio
9391b1c8ce fixes and improvements 2020-02-27 21:52:10 +00:00
Aleksey Kladov
e74484e133 Refactor string literals 2020-02-27 17:19:53 +01:00
Aleksey Kladov
fedab39011
Merge pull request #3350 from edwin0cheng/give-up-hover-in-builtin-macro
Ignore hover on builtin macro
2020-02-27 16:48:22 +01:00
Aleksey Kladov
c6247f74c7 Basic injections 2020-02-27 16:16:13 +01:00
Aleksey Kladov
8ed7e751b6 Ensure that semantic tokens are single-line 2020-02-27 16:06:46 +01:00
Edwin Cheng
c42bbc5e37 Ignore hover on builtin macro 2020-02-27 23:03:18 +08:00
Aleksey Kladov
8215b74032 Move tests to a new file 2020-02-27 14:20:22 +01:00
Aleksey Kladov
695460fbf5 More cleanup 2020-02-27 14:14:24 +01:00
Aleksey Kladov
a2dbdbba00 Split loop into orthogonal phases 2020-02-27 11:56:42 +01:00
Aleksey Kladov
9bb1718639 Cleanup 2020-02-27 11:39:54 +01:00
Aleksey Kladov
819bbd0864 Minor cleanup 2020-02-27 11:37:21 +01:00
bors[bot]
50956f89fc
Merge #3285
3285: Handle trivia in Structural Search and Replace r=matklad a=adamrk

Addresses the second point of https://github.com/rust-analyzer/rust-analyzer/issues/3186.

Structural search and replace will now match code that has varies from the pattern in whitespace or comments.

One issue is that it's not clear where comments in the matched code should go in the replacement. With this change they're just tacked on at the end, which can cause some unexpected moving of comments (see the last test example).

Co-authored-by: adamrk <ark.email@gmail.com>
2020-02-27 08:54:18 +00:00
Aleksey Kladov
2374f8ddd8 Renam module 2020-02-27 09:46:41 +01:00
bors[bot]
2180591593
Merge #3335
3335: Refactor highlighting a bit r=matklad a=matklad

bors r+

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-02-27 08:32:44 +00:00
Aleksey Kladov
a8e68ff814 Color constants 2020-02-27 09:32:00 +01:00
Aleksey Kladov
9784ab9f39 Move html highlightig to a separate module 2020-02-27 09:32:00 +01:00
Aleksey Kladov
995c46024b Fix html tests 2020-02-27 09:32:00 +01:00
Aleksey Kladov
f7db49bfc6 Better highlightign API 2020-02-27 09:32:00 +01:00
Shotaro Yamada
33de107ed9 Remove unused dependencies 2020-02-27 14:04:13 +09:00
Edwin Cheng
61fd6c6270 Use text_range::extend_to 2020-02-27 10:06:48 +08:00
kjeremy
bc1985037f Update lsp-types 2020-02-26 16:50:47 -05:00
Aleksey Kladov
c88ba9c4bd Fix 2020-02-26 22:10:23 +01:00
Aleksey Kladov
d1e7a20c00
Merge pull request #3327 from matklad/bitsetoops
Fix bitset ops
2020-02-26 18:32:13 +01:00
Aleksey Kladov
2a2d289e5f Fix bitset ops 2020-02-26 18:09:49 +01:00
Aleksey Kladov
913cdcee8f
Merge pull request #3325 from edwin0cheng/skip-trival-token
Skip trival token in original_range
2020-02-26 17:58:32 +01:00
Aleksey Kladov
f38bac48e5 More type safety for highlighting 2020-02-26 17:17:15 +01:00
Edwin Cheng
553254973e Skip trival token in original_range 2020-02-27 00:12:26 +08:00
Edwin Cheng
871dc2bd3c Remove duplicate comment 2020-02-26 20:55:11 +08:00
Edwin Cheng
ffdc740446 Add recursive support in original_range 2020-02-26 20:53:00 +08:00
Aleksey Kladov
ade0176c20 Remove dead code 2020-02-26 13:26:53 +01:00
Aleksey Kladov
09bc7ca74d Reduce visibility 2020-02-26 13:22:46 +01:00
Aleksey Kladov
c3a4c4429d Refactor primary IDE API
This introduces the new type -- Semantics.
Semantics maps SyntaxNodes to various semantic info, such as type,
name resolution or macro expansions.

To do so, Semantics maintains a HashMap which maps every node it saw
to the file from which the node originated. This is enough to get all
the necessary hir bits just from syntax.
2020-02-26 12:55:50 +01:00
Aleksey Kladov
04deae3dba
Merge pull request #3317 from matklad/no-unicase
Actually drop unicase dependency
2020-02-26 12:00:33 +01:00
Aleksey Kladov
8046622871 Actually drop unicase dependency 2020-02-26 11:38:33 +01:00
Aleksey Kladov
52fd19621c Remove code duplication in tests 2020-02-26 11:25:07 +01:00
adamrk
b1ee6d17a4 get matches from code.descendants 2020-02-25 23:53:29 +01:00
adamrk
94603d9848 save comments as ra_syntax::ast::Comment 2020-02-25 23:35:16 +01:00
nmio
f1b7349e7a clean up 2020-02-25 20:56:24 +00:00
kjeremy
fa355d6339 Rename back to highlight and check event's again highlight range 2020-02-25 14:44:47 -05:00
nmio
39bd3b2bd7 Merge branch 'master' of https://github.com/rust-analyzer/rust-analyzer into find-cargo-toml-up-the-fs 2020-02-25 18:01:59 +00:00
Jeremy Kolb
8f6f864547 Semantic Ranges 2020-02-25 11:37:43 -05:00
bors[bot]
d3040c0deb
Merge #3305
3305: Simplify r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-02-25 13:59:44 +00:00
Aleksey Kladov
d7da42bd40 Simplify 2020-02-25 14:59:13 +01:00
Aleksey Kladov
469011169b ⬆️ rowan 2020-02-25 14:44:51 +01:00
Aleksey Kladov
6542ab89ce Simplify 2020-02-25 13:49:34 +01:00
bors[bot]
3853a3b643
Merge #3298
3298: Bump chalk and replace TypeFamily with Interner r=flodiebold a=lnicola



Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-02-25 11:59:47 +00:00
Aleksey Kladov
136151515a Replace generic with a concrete type 2020-02-25 12:43:08 +01:00
Jeremy Kolb
17ffdf9c27 Add docs 2020-02-24 21:17:20 -05:00
kjeremy
9f0cfb7ad2 Teach the server about Semantic Tokens proposed LSP 2020-02-24 20:59:58 -05:00
Laurențiu Nicola
ed69482d90 Bump chalk and replace TypeFamily with Interner 2020-02-24 22:36:57 +02:00
nmio
34e3ef61bd Initial debugging code 2020-02-24 16:38:59 +00:00
Aleksey Kladov
f551e50c16 When joining lines, unwrap trivial diverging blocks 2020-02-24 17:17:05 +01:00
Kirill Bulatov
7f3c0e8564 Omit type hints for enum variant bind pats 2020-02-24 10:32:46 +03:00
adamrk
4f1d90e73b Handle trivia in strucural search and replace 2020-02-23 22:14:47 +01:00
Yoshua Wuyts
b4970b0fe9 Add suggestion for failed path resolution
This adds https://github.com/rust-analyzer/rust-analyzer/issues/3245 as an inline help text for when path resolution fails.
2020-02-23 15:51:32 +01:00
Kirill Bulatov
b2a7b29bb9 Style fixes 2020-02-23 13:02:00 +03:00
Kirill Bulatov
c200dba167 Add basic parameter name hints heuristics 2020-02-23 12:49:53 +03:00
Kirill Bulatov
ca4557ac52 Fix the tests 2020-02-23 01:44:15 +03:00
Kirill Bulatov
6670868d09 Show more parameter name hints 2020-02-23 01:44:15 +03:00
Kirill Bulatov
4ca22f3a88 Simplify inlay hints processing 2020-02-23 01:44:15 +03:00
Aleksey Kladov
fda118f4e9 Simplify 2020-02-22 16:59:31 +01:00
bors[bot]
46dbe4dc80
Merge #3272
3272: ra_db: removed a couple of explicit lifetimes r=matklad a=Veetaha



Co-authored-by: Veetaha <gerzoh1@gmail.com>
2020-02-22 15:07:36 +00:00
Veetaha
4255bc70e8 ra_db: removed a couple of explicit lifetimes 2020-02-22 17:00:39 +02:00
bors[bot]
2cbe8a4c4b
Merge #3263
3263: Implement unsizing coercions using Chalk r=matklad a=flodiebold

These are coercions like `&[T; n] -> &[T]`, which are handled by the `Unsize` and `CoerceUnsized` traits. The impls for `Unsize` are all built in to the compiler and require special handling, so we need to provide them to Chalk.

This adds the following `Unsize` impls:
 - `Unsize<[T]> for [T; _]`
 - `Unsize<dyn Trait> for T where T: Trait`
 - `Unsize<dyn SuperTrait> for dyn SubTrait`

Hence we are still missing the 'unsizing the last field of a generic struct' case.

Co-authored-by: Florian Diebold <florian.diebold@freiheit.com>
Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2020-02-22 12:31:30 +00:00
Veetaha
59dc797eb3
Fix dat comment 2020-02-22 14:16:13 +02:00
Florian Diebold
5a6e770f99 Shorten some code 2020-02-22 13:15:54 +01:00
Florian Diebold
3e106c77ff Rework find_super_trait_path to protect against cycles 2020-02-22 13:14:39 +01:00
bors[bot]
f9acb4333f
Merge #3260
3260: Refactor how builtins are resolved r=matklad a=flodiebold

This fixes autocompletion suggesting e.g. `self::usize`. (I thought we had a bug for that, but I didn't find it.)

Co-authored-by: Florian Diebold <florian.diebold@freiheit.com>
2020-02-22 11:25:09 +00:00
Veetaha
5f15e3aeb0
ra_mbe: Remove explicit type annotation 2020-02-22 13:14:46 +02:00
Veetaha
28bdb65407 ra_mbe: added test for malformed token in macro invokation
There was a panic where lexer returned None on malformed tokens.
But now we just ignore tokenization errors in mbe.
2020-02-22 13:10:54 +02:00
Veetaha
93a19bda17 ra_mbe: convert_literal now works with malformed tokens 2020-02-22 13:10:54 +02:00
Florian Diebold
c200025794 Fix shift_bound_vars
It should only shift free vars (maybe the name isn't the best...)
2020-02-22 11:09:21 +01:00
Florian Diebold
463df6720c Fix wrong handling of bare dyn Trait exposed by canonicalizer fix
The self type in the `dyn Trait` trait ref should always be ^0, but we didn't
put that in there in the bare case.
2020-02-22 11:09:21 +01:00
Florian Diebold
2d5ab63247 Add &dyn Trait -> &dyn SuperTrait coercion, and fix &T -> &dyn Trait 2020-02-22 11:09:21 +01:00
Florian Diebold
f126808b2e Fix handling of binders in canonicalization
I'm looking forward to getting rid of this in favor of Chalk's implementation.
2020-02-22 11:09:21 +01:00
Florian Diebold
0dfbbaf03b Implement dyn Trait unsizing as well 2020-02-22 11:09:21 +01:00
Florian Diebold
de39d221a1 Implement unsize coercion using proper trait solving 2020-02-22 11:09:21 +01:00
bors[bot]
baf832d6d9
Merge #3262
3262: Fix handling of const patterns r=matklad a=flodiebold

E.g. in `match x { None => ... }`, `None` is a path pattern (resolving to the
option variant), not a binding. To determine this, we need to try to resolve the
name during lowering. This isn't too hard since we already need to resolve names
for macro expansion anyway (though maybe a bit hacky).

Fixes #1618.

Co-authored-by: Florian Diebold <florian.diebold@freiheit.com>
2020-02-22 00:27:09 +00:00
adamrk
fe8ce4c41d remove unneeded collect 2020-02-21 23:51:30 +01:00
Adam Bratschi-Kaye
7be1044104 use Vec::extend instead of Vec::push in loop
Co-Authored-By: Laurențiu Nicola <lnicola@users.noreply.github.com>
2020-02-21 23:51:30 +01:00
adamrk
8b3f449b5f rename module references 2020-02-21 23:51:30 +01:00
Florian Diebold
f1f45f9191 Fix handling of const patterns
E.g. in `match x { None => ... }`, `None` is a path pattern (resolving to the
option variant), not a binding. To determine this, we need to try to resolve the
name during lowering. This isn't too hard since we already need to resolve names
for macro expansion anyway (though maybe a bit hacky).

Fixes #1618.
2020-02-21 17:01:19 +01:00
Florian Diebold
31af774254 Refactor how builtins are resolved
This fixes autocompletion suggesting e.g. self::usize.
2020-02-21 15:39:51 +01:00
Florian Diebold
e50201345e Normalize associated types in types coming from Chalk
Fixes #3232.
2020-02-21 14:06:19 +01:00
Edwin Cheng
d70ddec746 Remove unused placeholder 2020-02-21 18:33:45 +08:00
Edwin Cheng
4e48a73f9c Improve server version info 2020-02-21 18:33:45 +08:00
Aleksey Kladov
7f4b205b72 Better errorse 2020-02-20 18:41:12 +01:00
Laurențiu Nicola
5cd311d64e Fix off by one in onEnter 2020-02-20 11:24:47 +02:00
bors[bot]
e00b9ca3c9
Merge #3215
3215: Exclude methods from non-parameter types introduced by generic constraints r=flodiebold a=lnicola

Fixes #3184.

r? @flodiebold

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-02-19 19:46:37 +00:00
Aleksey Kladov
9549aad525 Fill missing fields of enum variants 2020-02-19 18:17:09 +01:00
Aleksey Kladov
7db7c86881
Merge pull request #3239 from matklad/opt-backtrace
Make backtrace optional
2020-02-19 17:13:27 +01:00
Aleksey Kladov
2ff23c172e Make backtrace optional 2020-02-19 16:28:25 +01:00
kjeremy
044180847a Bump lsp-types 2020-02-19 09:14:05 -05:00
bors[bot]
27587f3501
Merge #3236
3236: Merge NameDefinition and NameKind r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-02-19 13:57:03 +00:00
Aleksey Kladov
372439dec8 Merge NameDefinition and NameKind 2020-02-19 14:56:22 +01:00
bors[bot]
ff41558296
Merge #3235
3235: Derive visibility as well r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-02-19 13:46:48 +00:00
Aleksey Kladov
0d5ae89948 Derive visibility as well 2020-02-19 14:45:49 +01:00
bors[bot]
b560de4117
Merge #3234
3234: Don't store deriveable Module info in NameDefinition r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-02-19 13:33:30 +00:00
Aleksey Kladov
86b66067f6 Don't store deriveable Module info in NameDefinition 2020-02-19 14:32:22 +01:00
Aleksey Kladov
bcb5f1b65c Extend selection handles commas in tuple pats 2020-02-19 13:59:19 +01:00
bors[bot]
624a9978e2
Merge #3231
3231: Add `remove_mut` assist r=matklad a=matklad



bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-02-19 11:49:52 +00:00
Aleksey Kladov
312a779610 Add remove_mut assist 2020-02-19 12:44:54 +01:00
bors[bot]
eb804261dc
Merge #3228
3228: Use proper range for hover on macro arguments r=matklad a=edwin0cheng

This PR use `original_range` to remap the range of found syntax node in `hover` and thus it should return the proper text range now.

fixed #3000 
fixed #3135 


Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-02-19 10:46:00 +00:00
Laurențiu Nicola
5b05209744 Exclude methods from non-parameter types introduced by generic constraints 2020-02-19 10:46:13 +02:00
Shotaro Yamada
d06733efeb Cleanup 2020-02-19 13:36:59 +09:00
Shotaro Yamada
dd0c3c41b9 Fix a crash with non-ascii whitespace in doc-comments 2020-02-19 13:13:29 +09:00
Edwin Cheng
b9d94d73a2 Use proper range for hover on macro arguments 2020-02-19 11:56:27 +08:00
Aleksey Kladov
b4450b1043 Cleanup imports 2020-02-18 23:52:53 +01:00
Aleksey Kladov
97ab471b6d Minor simplification 2020-02-18 18:52:33 +01:00
Kirill Bulatov
f6816c253b Update versions 2020-02-18 16:12:40 +02:00
Kirill Bulatov
eceaf94f19 More manual clippy fixes 2020-02-18 16:12:37 +02:00
Kirill Bulatov
b8ddcb0652 Run cargo +nightly fix --clippy -Z unstable-options 2020-02-18 16:03:08 +02:00
bors[bot]
eab80cd961
Merge #3218
3218: Cut some deps r=matklad a=matklad



Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-02-18 13:46:54 +00:00
Aleksey Kladov
039f2039a4 Remove unicase dependency 2020-02-18 14:44:52 +01:00
Aleksey Kladov
b643ccfaed Drop extra deps 2020-02-18 14:44:52 +01:00
Veetaha
583b1e155a
Remove dat FIXME 2020-02-18 15:19:49 +02:00
bors[bot]
c447fe9bc0
Merge #3026
3026: ra_syntax: reshape SyntaxError for the sake of removing redundancy r=matklad a=Veetaha

Followup of #2911, also puts some crosses to the todo list of #223.

**AHTUNG!** A big part of the diff of this PR are test data files changes.

Simplified `SyntaxError` that was `SyntaxError { kind: { /* big enum */  }, location: Location }` to `SyntaxError(String, TextRange)`. I am not sure whether the tuple struct here is best fit, I am inclined to add names to the fields, because I already provide getters `SyntaxError::message()`, `SyntaxError::range()`.
I also removed `Location` altogether ...

This is currently WIP, because the following is not done:
- [ ] ~~Add tests to `test_data` dir for unescape errors *// I don't know where to put these errors in particular, because they are out of the scope of the lexer and parser. However, I have an idea in mind that we move all validators we have right now to parsing stage, but this is up to discussion...*~~ **[UPD]** I came to a conclusion that tree validation logic, which unescape errors are a part of, should be rethought of, we currently have no tests and no place to put tests for tree validations. So I'd like to extract potential redesign (maybe move of tree validation to ra_parser) and adding tests for this into a separate task.

Co-authored-by: Veetaha <gerzoh1@gmail.com>
Co-authored-by: Veetaha <veetaha2@gmail.com>
2020-02-18 12:57:26 +00:00
Aleksey Kladov
865759925b Rename folder 2020-02-18 12:37:45 +01:00
Aleksey Kladov
c0fa5e2246 Rename the binary to rust-analyzer 2020-02-18 12:33:16 +01:00
Aleksey Kladov
4d307ff802 Fully document ra_lsp_server 2020-02-18 12:25:26 +01:00
Aleksey Kladov
1f142d79ed Refactor 2020-02-18 12:17:47 +01:00
Aleksey Kladov
42c766b2bd Reduce visibility 2020-02-18 12:16:40 +01:00
Aleksey Kladov
b6740060f6 Refactor 2020-02-18 12:15:12 +01:00
Aleksey Kladov
93b969003d Some docs 2020-02-18 12:11:32 +01:00
Aleksey Kladov
59e1207dac Better folder structure 2020-02-18 11:56:18 +01:00
Veetaha
053ccf4121 ra_syntax: fix reparsing merging errors, also now reparse_token() reports errors 2020-02-18 02:11:16 +02:00
Kirill Bulatov
e29dbdb139 Simplify the command execution 2020-02-18 00:38:01 +02:00
Kirill Bulatov
67d30312d0 Simplify the code further 2020-02-18 00:18:26 +02:00
Kirill Bulatov
addb61df36 Idempotent location and installation of rust src 2020-02-18 00:07:15 +02:00
Kirill Bulatov
5cea8a37b7 Install rust-src when it is not found 2020-02-17 23:40:34 +02:00
Veetaha
fc5e7b8807 ra_syntax: migrate test data to 0-length text-range of SyntaxError when constructed from TextUnit 2020-02-17 23:14:31 +02:00
Veetaha
cd8e56c580 ra_syntax: remove message() method and use only Display trait in SyntaxError as per matklad 2020-02-17 23:13:38 +02:00
Veetaha
e05eb631d4 ra_syntax: change module-level documentation for syntax_error to "see X" as per matklad 2020-02-17 22:50:58 +02:00
Veetaha
b510e77fbe ra_syntax: followup fix for making SyntaxError::range() to return by value 2020-02-17 22:24:38 +02:00
Veetaha
e00922d113 ra_syntax: SyntaxError::range() now returns by value 2020-02-17 22:24:38 +02:00
Veetaha
acdab6f0f2 ra_syntax: moved reexport declaration after imports as per matklad 2020-02-17 22:24:38 +02:00
Veetaha
6ae4850c89 ra_syntax: Apply Aleksei Kladov suggestion about TextRange of TextUnit
Co-Authored-By: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-02-17 22:24:33 +02:00
Veetaha
c58276673a Change semmantical analyzis to tree validation as per @matklad
Co-Authored-By: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-02-17 22:24:33 +02:00
Veetaha
9fdf984958 ra_syntax: reshape SyntaxError for the sake of removing redundancy 2020-02-17 22:24:33 +02:00
Laurențiu Nicola
b6b8fd9525 Replace ra_cli mentions 2020-02-17 22:07:24 +02:00
Aleksey Kladov
2c9b91ad32 Merge ra_vfs_glob and ra_lsp_server 2020-02-17 19:07:30 +01:00
Aleksey Kladov
659b0e73cf Merge cli and ra_lsp_server 2020-02-17 19:03:03 +01:00
Aleksey Kladov
2d1b3da5fb Use anyhow 2020-02-17 18:19:25 +01:00
Aleksey Kladov
8e86d12771 Cleanup 2020-02-17 18:15:19 +01:00
Aleksey Kladov
06e37b273e Better name 2020-02-17 18:10:15 +01:00
Aleksey Kladov
3ef916061b More precise types 2020-02-17 18:09:07 +01:00
Aleksey Kladov
c818f5c65e Unify verbosity handling 2020-02-17 18:05:45 +01:00
Aleksey Kladov
fa482a9fee Move interesting stuff to main 2020-02-17 18:03:48 +01:00
Aleksey Kladov
a51b2603f9 Stronger Types 2020-02-17 18:02:59 +01:00
Aleksey Kladov
017f0e4e53 Refactor arg parsing 2020-02-17 18:02:10 +01:00
Aleksey Kladov
90e61ac75d Sort deps 2020-02-17 17:41:53 +01:00
Aleksey Kladov
d7be1da8df Inline ra_batch 2020-02-17 17:32:17 +01:00
Aleksey Kladov
559c5f37f6 Cleanup imports 2020-02-17 17:19:55 +01:00
Aleksey Kladov
d5371b5dec Inline help 2020-02-17 17:18:45 +01:00
Aleksey Kladov
0353e1c6f4 Use Arguments::from_os 2020-02-17 17:12:37 +01:00
Aleksey Kladov
57140f1730 Drop proptest tests
It takes waaay to long to compile.

We should add quickcheck tests when we touch the relevant code next
time.
2020-02-17 16:57:06 +01:00
bors[bot]
fcf15cc05a
Merge #3169
3169: Show record field names in Enum completion r=flodiebold a=adamrk

Adresses https://github.com/rust-analyzer/rust-analyzer/issues/2947.
Previously the details shown when autocompleting an Enum variant would look like the variant was a tuple even if it was a record:
![2020-02-16-15:59:32_crop](https://user-images.githubusercontent.com/16367467/74607233-64f21980-50d7-11ea-99db-e973e29c71d7.png)

This change will show the names of the fields for a record and use curly braces instead of parentheses:
![2020-02-16-15:33:00_crop](https://user-images.githubusercontent.com/16367467/74607251-8ce17d00-50d7-11ea-9d4d-38d198a4aec0.png)

This required exposing the type `adt::StructKind` from `ra_hir` and adding a function 
```
kind(self, db: &impl HirDatabase) -> StructKind
```
in the `impl` of `EnumVariant`. 

There was also a previously existing function `is_unit(self, db: &impl HirDatabase) -> bool` for `EnumVariant` which I removed because it seemed redundant after adding `kind`.

Co-authored-by: adamrk <ark.email@gmail.com>
2020-02-17 10:54:32 +00:00
adamrk
0e260aa6b1 use 'if let' instead of match on kind in lower.rs 2020-02-17 11:53:12 +01:00
bors[bot]
93d28fb50c
Merge #3099
3099: Init implementation of structural search replace r=matklad a=mikhail-m1

next steps:
* ignore space and other minor difference
* add support to ra_cli
* call rust parser to check pattern
* documentation

original issue #2267 

Co-authored-by: Mikhail Modin <mikhailm1@gmail.com>
2020-02-17 10:02:54 +00:00
bors[bot]
8d8d542dfa
Merge #3108
3108: Magic Completion for `impl Trait for` Associated Items r=matklad a=kdelorey

# Summary
This PR adds a set of magic completions to auto complete associated trait items (functions/consts/types). 

![Associated Trait Impl](https://user-images.githubusercontent.com/2295721/74493144-d8f1af00-4e96-11ea-93a4-82725bf89646.gif)

## Notes
Since the assist and completion share the same logic when figuring out the associated items that are missing, a shared utility was created in the `ra_assists::utils` module.

Resolves #1046 

As this is my first PR to the rust-analyzer project, I'm new to the codebase, feedback welcomed!

Co-authored-by: Kevin DeLorey <2295721+kdelorey@users.noreply.github.com>
2020-02-17 09:34:08 +00:00
bors[bot]
953dbe3e02
Merge #3181
3181: Add ability to pass additional arguments to rustfmt. r=matklad a=Leonqn

relates to #2848

Co-authored-by: Ilya Titkov <ilya@titkov.me>
2020-02-17 09:05:01 +00:00
bors[bot]
c9989a524c
Merge #3153
3153: When a single test is run, do not run others with overlapping names r=matklad a=SomeoneToIgnore



Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2020-02-17 08:52:45 +00:00
Ilya Titkov
a2b0bdcc24 Add arguments to rustfmt 2020-02-17 11:44:58 +03:00
bors[bot]
daffdd8674
Merge #3179
3179: Introduce AsMacroCall trait r=matklad a=edwin0cheng

This PR introduce `AsMacroCall` trait to help convert `ast::MacroCall` to `MacroCallId`. The main goal here is to centralize various conversions to single place and make implementing eager macro calls without further ado.

```rust
pub trait AsMacroCall {
    fn as_call_id(
        &self,
        db: &(impl db::DefDatabase + AstDatabase),
        resolver: impl Fn(path::ModPath) -> Option<MacroDefId>,
    ) -> Option<MacroCallId>;
}
```

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-02-17 08:38:09 +00:00
Edwin Cheng
2d4e79e1e6 Introduce AsMacroCall trait 2020-02-17 12:57:24 +08:00
Aleksey Kladov
ca7e9ab0da 1-based columns 2020-02-16 18:30:48 +01:00
Aleksey Kladov
0f79ec76d6 Support goto def in bences 2020-02-16 18:24:06 +01:00
Aleksey Kladov
6a3ec2dfa5 Refactor arg parsing 2020-02-16 18:20:22 +01:00
Aleksey Kladov
2ba918775c Refactor position parsing 2020-02-16 18:17:35 +01:00
Aleksey Kladov
98cc51580d Enable profiling for bench 2020-02-16 18:04:08 +01:00
Kirill Bulatov
f0338cea5b Fix a slow test 2020-02-16 18:55:52 +02:00
Kirill Bulatov
dabdb57067 Simplify module retrieval 2020-02-16 18:44:46 +02:00
Aleksey Kladov
28fa5edbce Add module colors to css 2020-02-16 17:06:01 +01:00
adamrk
e88eb89132 add space before/after wrapping braces 2020-02-16 16:33:15 +01:00
adamrk
68d3743faf replace uses of VariantData::is_unit with VariantData::kind 2020-02-16 16:10:32 +01:00
adamrk
04aff742b1 show names for record fields in enum completion 2020-02-16 16:10:23 +01:00
Florian Diebold
e14e7ffa34 Fix coercion of &T to itself
The autoderef coercion logic did not handle matching placeholders. This led to
some type mismatches.
2020-02-16 12:58:20 +01:00
bors[bot]
d976772716
Merge #3157
3157: Extend analysis-stats a bit r=matklad a=flodiebold

This adds some tools helpful when debugging nondeterminism in analysis-stats:
 - a `--randomize` option that analyses everything in random order
 - a `-vv` option that prints even more detail

Also add a debug log if Chalk fuel is exhausted (which would be a source of
nondeterminism, but didn't happen in my tests).

I found one source of nondeterminism (rust-lang/chalk#331), but there are still
other cases remaining.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2020-02-15 22:35:44 +00:00
Aleksey Kladov
11dda31941 Remove extra dep 2020-02-15 23:23:44 +01:00
Florian Diebold
3484d727c3 Extend analysis-stats a bit
This adds some tools helpful when debugging nondeterminism in analysis-stats:
 - a `--randomize` option that analyses everything in random order
 - a `-vv` option that prints even more detail

Also add a debug log if Chalk fuel is exhausted (which would be a source of
nondeterminism, but didn't happen in my tests).

I found one source of nondeterminism (rust-lang/chalk#331), but there are still
other cases remaining.
2020-02-15 18:04:01 +01:00
Kevin DeLorey
057d0bee55 Added module doc comment to explain the purpose of the completion. 2020-02-15 10:27:04 -06:00
Kevin DeLorey
ae8ae650fc Fixed bug that allowed for completion in a nested method. 2020-02-15 09:50:07 -06:00
Kevin DeLorey
fc13b7fc9a Reordered the use items. 2020-02-14 18:54:00 -06:00
Kirill Bulatov
426c0f26fe If possible, use --exact flag when running tests 2020-02-15 01:06:14 +02:00
Mikhail Modin
f8f454ab5c Init implementation of structural search replace 2020-02-14 21:45:42 +00:00
Benjamin Brittain
843f03a3d2 Bump crate resolution limit for large projects
Change-Id: Ie0221e5bcfd1779cd5e241f96b4489e5bd3854c1
2020-02-14 16:15:59 -05:00
bors[bot]
b2b94cbf71
Merge #3147
3147: Check that impl self type matches up with expected self type in path mode r=matklad a=flodiebold

Fixes #3144.

Co-authored-by: Florian Diebold <flodiebold@gmail.com>
2020-02-14 20:32:55 +00:00
bors[bot]
6fb36dfdcb
Merge #3145
3145: Make Self implement the trait inside trait default methods r=matklad a=flodiebold



Co-authored-by: Florian Diebold <florian.diebold@freiheit.com>
2020-02-14 20:26:08 +00:00
Florian Diebold
f47dc4de8d Check that impl self type matches up with expected self type in path mode
Fixes #3144.
2020-02-14 21:08:25 +01:00