Commit graph

317 commits

Author SHA1 Message Date
Aleksey Kladov
05729fd3c4 For unresolved macros, hightlight only the last segment 2021-02-28 14:29:10 +03:00
Lukas Wirth
5183c9f083 Introduce TypeCtor::Scalar 2021-02-28 01:20:04 +01:00
Lukas Wirth
0799288f01 Don't write trailing whitespace when formatting empty GenericPredicates 2021-02-20 20:43:04 +01:00
Kirill Bulatov
4fe5786c0c Consider import prefix config settings during flyimports 2021-02-20 13:53:50 +02:00
Vladyslav Katasonov
37a8cec638 expose hir::Type::type_paramters
Used to get E parameter from `Result<T, E>`
2021-02-13 22:04:52 +03:00
Jonas Schievink
216dc856c5 Wrap BuiltinType in code model 2021-02-11 19:52:33 +01:00
Lukas Wirth
a195711df0 Resolve TupleStructPat in SourceAnalyzer::resolve_path 2021-02-10 09:37:22 +01:00
Lukas Wirth
e3eeccf8ef Prefer ValueNS when resolving hir path for PathExpressions 2021-01-29 15:59:52 +01:00
Lukas Wirth
426ad8e165 Classify function calls as functions when shadowed by types 2021-01-28 19:08:55 +01:00
Jonas Schievink
5c241b0766 Create all ModuleIds through a DefMap method
`ModuleId` needs to be able to represent blocks, and only the
associated `DefMap` will know how to construct that `ModuleId`
2021-01-25 15:21:33 +01:00
Phil Ellison
1ff860b93c Implement fix, add tests 2021-01-23 07:40:25 +00:00
Phil Ellison
1316422a7c Add diagnostic for filter_map followed by next 2021-01-23 07:40:24 +00:00
Jonas Schievink
3de8f57c51 Make ModuleId's krate field private 2021-01-22 18:09:55 +01:00
Jonas Schievink
ce29730bc7 Obtain ModuleId's DefMap through a method 2021-01-22 16:33:58 +01:00
Daiki Ihara
f5b97e52c9 Fix broken link in intra-doc 2021-01-22 20:06:45 +09:00
Jonas Schievink
896dfacfc4 Add name resolution query for block expressions 2021-01-21 15:22:17 +01:00
Jonas Schievink
0587b99fde Make public DefMap fields private 2021-01-20 15:41:18 +01:00
bors[bot]
f647e134a7
Merge #7351
7351: Show const params in completions r=Veykril a=Veykril

bors r+
![image](https://user-images.githubusercontent.com/3757771/105080872-bba76680-5a91-11eb-91cd-0910da4c8312.png)


Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-01-19 19:07:33 +00:00
Lukas Wirth
bed12833cc Show const params in completions 2021-01-19 20:06:39 +01:00
Kirill Bulatov
ca65488276 Show deprecated completions for deprecated traits 2021-01-19 01:08:59 +02:00
Kirill Bulatov
db335a1bbf Add flyimport completion for trait assoc items 2021-01-16 20:44:12 +02:00
Lukas Wirth
cb863390f2 Handle self/super/crate in PathSegment as NameRef 2021-01-15 19:21:23 +01:00
bors[bot]
607b9ea160
Merge #7218
7218: Fix typos r=Veykril a=regexident

Apart from the very last commit on this PR (which fixes a public type's name) all changes are non-breaking.

Co-authored-by: Vincent Esche <regexident@gmail.com>
2021-01-10 18:16:29 +00:00
Lukas Wirth
b795128dde Use hir::GenericParam in ide_db::Definition instead of relisting all 3 2021-01-10 12:33:47 +01:00
Vincent Esche
21f8239ac8 Fixed typos in code comments 2021-01-09 15:41:29 +01:00
bors[bot]
1a29934c37
Merge #7145
7145: Proper handling $crate Take 2 [DO NOT MERGE] r=edwin0cheng a=edwin0cheng

Similar to previous PR (#7133) , but improved the following things :

1. Instead of storing the whole `ExpansionInfo`, we store a similar but stripped version `HygieneInfo`.
2. Instread of storing the `SyntaxNode` (because every token we are interested are IDENT), we store the `TextRange` only.
3. Because of 2, we now can put it in Salsa.
4. And most important improvement: Instead of computing the whole frames every single time, we compute it recursively through salsa: (Such that in the best scenario, we only need to compute the first layer of frame)

```rust
        let def_site = db.hygiene_frame(info.def.file_id);
        let call_site = db.hygiene_frame(info.arg.file_id);

        HygieneFrame { expansion: Some(info), local_inner, krate, call_site, def_site }
```

The overall speed compared to previous PR is much faster (65s vs 45s) :
```
[WITH old PR]
Database loaded 644.86ms, 284mi
Crates in this dir: 36
Total modules found: 576
Total declarations: 11153
Total functions: 8715
Item Collection: 15.78s, 91562mi
Total expressions: 240721
Expressions of unknown type: 2635 (1%)
Expressions of partially unknown type: 2064 (0%)
Type mismatches: 865
Inference: 49.84s, 250747mi
Total: 65.62s, 342310mi
rust-analyzer -q analysis-stats .  66.72s user 0.57s system 99% cpu 1:07.40 total

[WITH this PR]
Database loaded 665.83ms, 284mi
Crates in this dir: 36
Total modules found: 577
Total declarations: 11188
Total functions: 8743
Item Collection: 15.28s, 84919mi
Total expressions: 241229
Expressions of unknown type: 2637 (1%)
Expressions of partially unknown type: 2064 (0%)
Type mismatches: 868
Inference: 30.15s, 135293mi
Total: 45.43s, 220213mi   
rust-analyzer -q analysis-stats .  46.26s user 0.74s system 99% cpu 47.294 total
```

*HOWEVER*,  it is still a perf regression (35s vs 45s):
```
[WITHOUT this PR]
Database loaded 657.42ms, 284mi
Crates in this dir: 36
Total modules found: 577
Total declarations: 11177
Total functions: 8735
Item Collection: 12.87s, 72407mi
Total expressions: 239380
Expressions of unknown type: 2643 (1%)
Expressions of partially unknown type: 2064 (0%)
Type mismatches: 868
Inference: 22.88s, 97889mi
Total: 35.74s, 170297mi
rust-analyzer -q analysis-stats .  36.71s user 0.63s system 99% cpu 37.498 total
```



Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-01-08 03:57:11 +00:00
Phil Ellison
b2dbe6e43a Add fix to wrap return expression in Some 2021-01-07 19:01:33 +00:00
Edwin Cheng
76f2b9d2ef Proper handling $crate Take 2 2021-01-07 13:08:32 +08:00
Aleksey Kladov
f9707cde68 Rename expr -> tail_expr 2021-01-05 15:51:13 +03:00
Arnaud
052404565e Remove RetType 2021-01-04 20:34:23 +01:00
Arnaud
2f0969b873 Document hir::Function::ret_type
This adds documentation for the newly added function. It might be a bit too
detailed, but I like it that way :)
2021-01-04 19:14:44 +01:00
Arnaud
a6dc7cf36d Make it possible to retrieve hir::Function's return type
This is done by adding a `ret_type` method to `hir::Function`.
I followed `assoc_fn_params` convention by creating a new `RetType` type,
that contains the actual return type accessible via a `ty` method.
2021-01-04 19:14:44 +01:00
Lukas Wirth
54b9b03ca2 Show GotoTypeAction for TypeParam 2021-01-04 15:54:45 +01:00
Lukas Wirth
bd47e140b6 Show GotoTypeAction for ConstParam 2021-01-04 15:19:09 +01:00
Lukas Wirth
47900dd3bc Impl hovering for TypeParams 2021-01-04 12:24:47 +01:00
bors[bot]
1cc73d60bb
Merge #7068
7068: Add VSCode command to view the hir of a function body r=theotherphil a=theotherphil

Will fix https://github.com/rust-analyzer/rust-analyzer/issues/7061. Very rough initial version just to work out where I needed to wire everything up.

@matklad would you be happy merging a hir visualiser of some kind? If so, do you have any thoughts on what you'd like it show, and how?

I've spent very little time on this thus far, so I'm fine with throwing away the contents of this PR, but I want to avoid taking the time to make this more polished/interactive/useful only to discover that no-one else has any interest in this functionality.

![image](https://user-images.githubusercontent.com/1974256/103236081-bb58f700-493b-11eb-9d12-55ae1b870f8f.png)


Co-authored-by: Phil Ellison <phil.j.ellison@gmail.com>
2021-01-03 09:03:15 +00:00
bors[bot]
520b8a5a4d
Merge #7115
7115: Migrate HasSource::source to return Option r=matklad a=nick96

I've made a start on fixing #6913 based on the provided work plan, migrating `HasSource::source` to return an `Option`. The simple cases are migrated but there are a few that I'm unsure exactly how they should be handled:

- Logging the processing of functions in `AnalysisStatsCmd::run`: In verbose mode it includes the path to the module containing the function and the syntax range. I've handled this with an if-let but would it be better to blow up here with `expect`? I'm not 100% on the code paths but if we're processing a function definition then the source should exist.

I've handled `source()` in all code paths as `None` being a valid return value but are there some cases where we should just blow up? Also, all I've done is bubble up the returned `None`s, there may be some places where we can recover and still provide something.

Co-authored-by: Nick Spain <nicholas.spain@stileeducation.com>
Co-authored-by: Nick Spain <nicholas.spain96@gmail.com>
2021-01-03 08:56:17 +00:00
Phil Ellison
ee7c3f79e2 Use stdx::format_to instead of writeln 2021-01-03 08:54:33 +00:00
Lukas Wirth
68336fdb61 Implement HasAttrs for Type-, Const- and LifetimeParam 2021-01-02 12:11:46 +01:00
Nick Spain
40cd6cdf67 Fix ConstParam HasSource impl and implement TryToNav not Nav 2021-01-02 22:11:25 +11:00
Nick Spain
887028fcf5 Remove old_source now we've fully migrated
Fixes #6913
2021-01-02 21:53:52 +11:00
Nick Spain
c936e4b86f source_old -> source for cases that can be handled by simple bubbling 2021-01-02 21:53:52 +11:00
Nick Spain
14d0db0759 HasSource::source_old -> HasSource::source for places where proc-macros were special cased
In #6901 some special case handling for proc-macros was introduced to
prevent panicing as they have no AST. Now the new HasSource::source
method is used that returns an option.

Generally this was a pretty trivial change, the only thing of much
interest is that `hir::MacroDef` now implements `TryToNav` not `ToNav`
as this allows us to handle `HasSource::source` now returning an option.
2021-01-02 21:53:52 +11:00
Nick Spain
ea4708c444 Mark HasSource::source_old as deprecated but allow at all call sites 2021-01-02 21:53:51 +11:00
Nick Spain
2de2b1eca3 Implement new HasSource::source for all implementors of HasSource 2021-01-02 21:53:51 +11:00
Nick Spain
27cadcd531 HasSource::source -> HasSource::source_old
To start migrating HasSource::source to return an Option.
2021-01-02 21:53:51 +11:00
Lukas Wirth
ec448ca4b3 Impl HasAttrs for GenericParam 2021-01-02 00:44:59 +01:00
Phil Ellison
db53db8046 Address review suggestion, fix tidy tests 2021-01-01 19:25:18 +00:00
bors[bot]
0e5fe47153
Merge #7080
7080: Implement ConstParams for HIR r=Veykril a=Veykril

r? @flodiebold 

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-01-01 13:45:10 +00:00
Lukas Wirth
0acdb73076 Add ConstParams to the HIR 2021-01-01 10:06:42 +01:00
kjeremy
dc1396eec7 Update crates 2020-12-30 10:39:50 -05:00
Phil Ellison
077592a12f Initial implementation of view-hir command 2020-12-28 18:29:58 +00:00
bors[bot]
06320015af
Merge #7021
7021: Track labels in the HIR r=matklad a=Veykril

Groundwork for #6966

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-24 12:04:28 +00:00
Lukas Wirth
262b9c3982 Track labels in the HIR 2020-12-24 12:49:40 +01:00
unexge
bfae2634b4 Prevent multiple incorrect case diagnostics in functions 2020-12-23 22:18:31 +03:00
bors[bot]
4a2f60cb7b
Merge #6964
6964: Add full pattern completions for Struct and Variant patterns r=matklad a=Veykril


Just gonna call it full pattern completion as pattern completion is already implemented in a sense by showing idents in pattern position. What this does is basically complete struct and variant patterns where applicable(function params, let statements and refutable pattern locations).

This does not replace just completing the corresponding idents of the structs and variants, instead two completions are shown for these, a completion for the ident itself and a completion for the pattern(if the pattern make sense to be used that is). I figured in some cases one would rather type out the pattern manually if it has a lot of fields but you only care about one since this completion would cause one more work in the end since you would have to delete all the extra matched fields again.

These completions are tagged as `CompletionKind::Snippet`, not sure if that is the right one here.
<details>
  <summary>some gifs</summary>

![dx2lxgzhj3](https://user-images.githubusercontent.com/3757771/102719967-6987ef80-42f1-11eb-8ae0-8aff53777860.gif)
![EP2E7sJLkB](https://user-images.githubusercontent.com/3757771/102785777-c7264580-439e-11eb-8a64-f142e19fb65b.gif)
![JMNHHWknr9](https://user-images.githubusercontent.com/3757771/102785796-d1e0da80-439e-11eb-934b-218ada31b51c.gif)
</details>

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-22 18:03:51 +00:00
Lukas Wirth
b184bfad7a Add completions for patterns 2020-12-20 18:19:23 +01:00
bors[bot]
eefbae7ed4
Merge #6921
6921: Higher-ranked trait bounds for where clauses r=flodiebold a=Veykril

There is a slight problem with this which is also noted in a FIXME now but `LifetimeParameters` of these ForLifetime where clauses allocate the lifetimes in the corresponding arena as if they were lifetimes of the item itself and not just the clause they belong to. I wasn't entirely sure what I could do about this but given nothing really uses lifetimes like that currently I figured it might be fine? Open to suggestions for that problem.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-20 11:47:01 +00:00
Aleksey Kladov
f6ed16674c Align code_model name with ungrammar 2020-12-20 10:05:24 +03:00
bors[bot]
f4929fa9cc
Merge #6901
6901: Temp fixes panic caused by no ast for proc-macro r=maklad a=edwin0cheng

There are some panic when hover/goto definition for proc-macro. It is because in current design, we don't have `ast-node` for proc-macro and then it trigger [this](479d1f7eec/crates/hir/src/has_source.rs (L116)) line to panic.

This PR is a temp fix for all of these similar to bd4c352831/crates/completion/src/render/macro_.rs (L42)

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-12-18 02:30:51 +00:00
Edwin Cheng
60a3785ac2 Temp fixes panic caused by no ast for proc-macro 2020-12-18 10:26:17 +08:00
Aleksey Kladov
30216880c4 Minor API cleanup 2020-12-17 20:14:13 +03:00
Jonas Schievink
9231821c03 Make Attrs::from_attrs_owner private 2020-12-17 15:45:26 +01:00
Lukas Wirth
c8c58d81ec Remove obsolete FIXME 2020-12-17 13:40:11 +01:00
Aleksey Kladov
2ae31e34b1 Rename ImplDef -> Impl
We used to have `Def` suffix for all symbols, but we moved off from
that. `FunctionDef` isn't better than `Function`. Looks like we've
forgot to change `Impl` though!
2020-12-17 14:36:15 +03:00
Jonas Schievink
6615fda695 decl_check: don't pass db around so often 2020-12-17 01:19:56 +01:00
Jonas Schievink
21b68a328c Remove module_lang_items
It isn't used anywhere except in `crate_lang_items`. Remove it to
slightly reduce memory usage and simplify the code.
2020-12-17 00:26:01 +01:00
bors[bot]
067067a6c1
Merge #6896
6896: Node-ify lifetimes r=jonas-schievink a=Veykril

Let's see if this passes the tests 🤞 

Depends on https://github.com/rust-analyzer/ungrammar/pull/15

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-16 17:08:03 +00:00
bors[bot]
63bbdb31e5
Merge #6897
6897: Basic support for macros 2.0 r=jonas-schievink a=jonas-schievink

This adds support for (built-in-only) macros 2.0, and removes some hacks used for builtin derives, which are declared via macros 2.0 in libcore.

First steps for https://github.com/rust-analyzer/rust-analyzer/issues/2248.

Blocked on https://github.com/rust-analyzer/ungrammar/pull/16.

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2020-12-16 16:52:46 +00:00
Lukas Wirth
dd496223f5 Node-ify lifetimes 2020-12-16 14:16:09 +01:00
Jonas Schievink
b238ddd21a Make macro def krate mandatory
Refactors builtin derive support to go through proper name resolution
2020-12-15 20:33:05 +01:00
Jonas Schievink
c31c3246a8 Basic support for decl macros 2.0 2020-12-15 18:43:34 +01:00
bors[bot]
eb9ba457b0
Merge #6879
6879: Change HasChildSource::ChildId assoc item to generic param r=matklad a=Veykril



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-15 17:22:03 +00:00
Lukas Wirth
2c67a4abe4 Change HasChildSource::ChildId assoc item to generic param 2020-12-15 18:21:01 +01:00
Jonas Schievink
c1cb595382 Move to upstream macro_rules! model 2020-12-15 15:37:37 +01:00
Lukas Wirth
c6172f3f6d Add LifetimeParam resolving to Semantics 2020-12-14 16:04:28 +01:00
bors[bot]
479d1f7eec
Merge #6818
6818: Add Lifetimes to the HIR r=matklad a=Veykril

This doesn't handle resolve yet as I don't know yet how that will be used. I'll get to that once I start moving the lifetime reference PR to the hir.

This also adds a new `hir` name type for lifetimes and labels, `hir::LifetimeName`.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-12 14:35:38 +00:00
Lukas Wirth
11f8664182 Add Lifetimes to the HIR 2020-12-12 00:56:52 +01:00
Aleksey Kladov
4015ff0e0b Improve code structure
Make sure that there's only one entry point, analyze, remove awkard
analyzer2 name
2020-12-11 17:06:21 +03:00
bors[bot]
44978acf51
Merge #6769
6769: Add native "remove this semicolon" diagnostics r=matklad a=ivan770

Closes #6739 
![demo2](https://user-images.githubusercontent.com/14003886/101530533-b76c3180-399a-11eb-9d18-5c8457721655.gif)


Co-authored-by: ivan770 <leshenko.ivan770@gmail.com>
2020-12-10 16:18:49 +00:00
ivan770
7738467e0a Format code 2020-12-08 19:25:21 +00:00
ivan770
cb66bb8ff9
Remove this semicolon 2020-12-08 20:47:20 +02:00
Jonas Schievink
4943ef085d Make original_range a method on InFile<&SyntaxNode> 2020-12-08 19:01:27 +01:00
Lukas Wirth
1caaa201fa Remove hir_def/docs.rs module 2020-12-07 19:58:17 +01:00
Lukas Wirth
b3652ef288 Remove documentation query 2020-12-07 19:58:17 +01:00
Jonas Schievink
b9d947cc6f Add slightly more profiling details 2020-12-04 20:26:28 +01:00
Aleksey Kladov
9d94ffad44 Place cursor correctly when completing assoc fns with self 2020-12-01 14:28:50 +03:00
Aleksey Kladov
6f51f728a1 Type-safer API for dealing with parameter lists with optional self 2020-12-01 13:53:39 +03:00
Jonas Schievink
0432aa0ed7 Publish diagnostics for macro expansion errors 2020-11-27 13:50:22 +01:00
Lukas Wirth
6501c9445e Don't use raw identifiers 2020-11-26 21:44:17 +01:00
Jonas Schievink
6a9338e979 Use ExpandResult instead of MacroResult
`MacroResult` is redundant
2020-11-26 16:48:17 +01:00
Jonas Schievink
9559bce311 Rename parse_macro to parse_macro_expansion
This does not parse macros, it expands a macro and parses the *result*
2020-11-24 21:57:51 +01:00
Jonas Schievink
d5e9bf80f9 hir_expand: propagate expansion errors 2020-11-24 19:00:23 +01:00
bors[bot]
156f7d6963
Merge #6553
6553: Auto imports in completion r=matklad a=SomeoneToIgnore

![completion](https://user-images.githubusercontent.com/2690773/99155339-ae4fb380-26bf-11eb-805a-655b1706ce70.gif)

Closes https://github.com/rust-analyzer/rust-analyzer/issues/1062 but does not handle the completion order, since it's a separate task for https://github.com/rust-analyzer/rust-analyzer/issues/4922 , https://github.com/rust-analyzer/rust-analyzer/issues/4922 and maybe something else.

2 quirks in the current implementation:

* traits are not auto imported during method completion

If I understand the current situation right, we cannot search for traits by a **part** of a method name, we need a full name with correct case to get a trait for it.

* VSCode (?) autocompletion is not as rigid as in Intellij Rust as you can notice on the animation.

Intellij is able to refresh the completions on every new symbol added, yet VS Code does not query the completions on every symbol for me.
With a few debug prints placed in RA, I've observed the following behaviour: after the first set of completion suggestions is received, next symbol input does not trigger a server request, if the completions contain this symbol.
When more symbols added, the existing completion suggestions are filtered out until none are left and only then, on the next symbol it queries for completions.
It seems like the only alternative to get an updated set of results is to manually retrigger it with Esc and Ctrl + Space.

Despite the eerie latter bullet, the completion seems to work pretty fine and fast nontheless, but if you have any ideas on how to make it more smooth, I'll gladly try it out.

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2020-11-17 17:50:08 +00:00
Lukas Wirth
c868f0255f Fill the diagnostic code field in publish_diagnostics 2020-11-17 16:23:53 +01:00
Kirill Bulatov
4109968934 Remove query aliases 2020-11-16 21:24:54 +02:00
Kirill Bulatov
4c8edd003a Use imports_locator 2020-11-16 21:19:06 +02:00
Kirill Bulatov
f62e8616c8 Add imports in auto completion 2020-11-16 21:19:05 +02:00
Aleksey Kladov
ba8d6d1e4e Remove more unreachable pubs 2020-11-02 16:58:33 +01:00
GrayJack
08e95a5dc1
Fix case where non FnOnce variables is marked callable 2020-10-26 15:20:33 -03:00
bors[bot]
2fa942ad30
Merge #6251 #6310
6251: Semantic Highlight: Add Callable modifier for variables r=matklad a=GrayJack

This PR added the `HighlightModifier::Callable` variant and assigned it to variables and parameters that are fn pointers, closures and implements FnOnce trait.

This allows to colorize these variables/parameters when used in call expression.



6310: Rewrite algo::diff to support insertion and deletion r=matklad a=Veykril

This in turn also makes `algo::diff` generate finer diffs(maybe even minimal diffs?) as insertions and deletions aren't always represented as as replacements of parent nodes now.

Required for #6287 to go on.

Co-authored-by: GrayJack <gr41.j4ck@gmail.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-23 22:12:15 +00:00
Jonas Schievink
93dc6f511b Diagnose #[cfg]s in bodies 2020-10-23 19:27:04 +02:00
Jonas Schievink
4cb3cf352f Rename UnconfiguredCode -> InactiveCode 2020-10-20 18:22:31 +02:00
Jonas Schievink
80d2741401 Add a (hint) diagnostic for unconfigured items 2020-10-20 17:53:04 +02:00
Aleksey Kladov
3b1a648539 More type safety around names 2020-10-20 17:09:03 +02:00
Aleksey Kladov
af4e75533f Rename declaration_name -> display_name
Declaration names sounds like a name of declaration -- something you
can use for analysis. It empathically isn't, and is just a label
displayed in various UI. It's important not to confuse the two, least
we accidentally mix semantics with UI (I believe, there's already a
case of this in the FamousDefs at least).
2020-10-20 15:38:11 +02:00
GrayJack
a483b5545d
Add Callable modifier for variables that implements Fnonce 2020-10-16 07:52:18 -03:00
bors[bot]
c518fe7f6c
Merge #6130 #6135
6130: Items case quick fix (snake_case / UPPER_SNAKE_CASE / CamelCase) r=matklad a=popzxc

Resolves #4598.

After a third try, it finally works. Boy, it appeared tougher than it seemed.

Initially I thought like "Ha, `rustc` already tells us where idents are named incorrectly. It shouldn't be that hard, should it?".

Well, the problems with the information provided by `rustc` appeared shortly:

- `rustc` warnings are `flycheck` warnings, which are slightly aside from our diagnostics with fixes.
  When we map flycheck diagnostic to LSP, we can convert it into a fix, but only if it's marked as `Applicability::MachineApplicable`.
  Name case fix is marked `Applicability::MaybeIncorrect`, and for a reason: it only suggest to rename symbol under cursor, without tracking any references.
- Warning spawned by `rustc` are identified by string labels rather than enum. It means that if one day the diagnostic will be renamed in `rustc`, `rust-analyzer` code will still compile, but won't find the required diagnostic by name anymore. If by chance this will happen when some unlucky guy will decide to create their first pull request, they'll be confused by suddenly failing tests  (likely) not related to their changes.
- Even if we'll try to build fixes atop of `rustc` warnings, we'll have to do it in the `rust_analyzer::diagnostics::to_proto` module, which is far less
  convenient for that matter than `ide` crate.

That's why I decided that it's worth a separate `rust-analyzer` diagnostic, which will implement `DiagnosticWithFix` trait.

After that, I discovered that currently `hir_ty::diagnostics` only check `DefWithBody` types, like function bodies. I had to add support for diagnostics
which look at any `ModuleDef`.

And of course, since I'd added a lot of new functionality, it required extensive testing.

That explains why the diff is so big for a (looking) relatively small feature.

I hope that this PR doesn't only add a small feature, but also creates a base for building another features.

## Example:

![case_quick_fix](https://user-images.githubusercontent.com/12111581/95008475-e07ee780-0622-11eb-9978-62a9ea0e7782.gif)

P.S. My eyes were bleeding when I had to write the code for the example...


6135: when generating new function, focus on return type instead of body r=matklad a=bnjjj

I made a little change when we use the assist to generate a new function, instead of focusing on the function body, it will focus on return type

Co-authored-by: Igor Aleksanov <popzxc@yandex.ru>
Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-10-12 16:00:13 +00:00
bors[bot]
fac59f4f28
Merge #6195
6195: Shorten iterators in associated params r=matklad a=SomeoneToIgnore

Applies the same iterator-shortening logic to the iterator associated types, recursively.

Before: 
![image](https://user-images.githubusercontent.com/2690773/95662735-e6ecf200-0b41-11eb-8e54-28493ad4e644.png)

After:
<img width="1192" alt="image" src="https://user-images.githubusercontent.com/2690773/95662894-e9038080-0b42-11eb-897d-527571ccac58.png">


Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2020-10-12 15:06:45 +00:00
Igor Aleksanov
50a147dcdf Apply case check diagnostic to impl items 2020-10-12 11:05:00 +03:00
Igor Aleksanov
e24e22f288 Add fix for incorrect case diagnostic 2020-10-12 11:04:59 +03:00
Igor Aleksanov
4039176ec6 Create basic support for names case checks and implement function name case check 2020-10-12 10:59:54 +03:00
bors[bot]
518f6d7724
Merge #5917
5917: Add a command to open docs for the symbol under the cursor r=matklad a=zacps

#### Todo

- [ ] Decide if there should be a default keybind or context menu entry
- [x] Figure out how to get the documentation path for methods and other non-top-level defs
- [x] Design the protocol extension. In future we'll probably want parameters for local/remote documentation URLs, so that should maybe be done in this PR?
- [x] Code organisation
- [x] Tests


Co-authored-by: Zac Pullar-Strecker <zacmps@gmail.com>
2020-10-12 07:38:24 +00:00
Kirill Bulatov
2bb80a4f03 Also replace the associated types with iter 2020-10-10 21:39:57 +03:00
Jonas Schievink
468b804856 Fix source_to_def for named enum variant fields 2020-10-09 02:57:35 +02:00
Zac Pullar-Strecker
3bd4fe96dc Remove methodowner & fix formatting 2020-10-08 15:50:48 +13:00
Zac Pullar-Strecker
8af1dd7337 Rebase fixes 2020-10-08 15:22:57 +13:00
Zac Pullar-Strecker
26086faab2 Change Option::Some bug to a fixme note
IMO this is too much work to be worth fixing at the moment.
2020-10-08 15:04:57 +13:00
Zac Pullar-Strecker
c648884397 Differentiate method/tymethod by determining 'defaultness'
Currently a method only has defaultness if it is a provided trait
method, but this will change when specialisation is available and may
need to become a concept known to hir.

I opted to go for a 'fewest changes' approach given specialisation is
still under development.
2020-10-08 15:04:21 +13:00
Zac Pullar-Strecker
974518fde7 Code reorganisation and field support 2020-10-08 15:04:20 +13:00
Lukas Wirth
aaa3905fdd Shorten type hints for std::iter Iterators 2020-10-06 19:20:42 +02:00
Aleksey Kladov
2090b534fc Move ModPath->ast::Path function to IDE layer
closes #6092
2020-10-06 16:19:18 +02:00
bors[bot]
87cb840a4e
Merge #6124
6124: Better normalized crate name usage r=jonas-schievink a=SomeoneToIgnore

Closes https://github.com/rust-analyzer/rust-analyzer/issues/5343 
Closes https://github.com/rust-analyzer/rust-analyzer/issues/5932

Uses normalized name for code snippets (to be able to test the fix), hover messages and documentation rewrite links (are there any tests for those?).
Also renamed the field to better resemble the semantics.

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
2020-10-06 11:51:15 +00:00
Lukas Wirth
8699331014 Make ImportPrefix a configuration option 2020-10-05 17:41:49 +02:00
Lukas Wirth
67e71619b9 Make find_path_prefixed configurable 2020-10-05 17:12:37 +02:00
Kirill Bulatov
9d19e5b962 Properly name the field 2020-10-02 21:38:22 +03:00
Kirill Bulatov
99952f3be2 Fix the hover dash issues 2020-10-02 21:16:22 +03:00
kjeremy
82d6cfd495 Minor clippy performance suggestions 2020-09-30 15:22:49 -04:00
Lukas Wirth
e1d6981f90 Don't unnecessarily unnest imports for import insertion 2020-09-25 15:19:22 +02:00
bors[bot]
9d3483a74d
Merge #5846
5846: Add references to fn args during completion r=matklad a=adamrk

When completing a function call, if there is an argument taken as a ref or mut ref which matches the name and type of a variable in scope, we will insert a `&` or `&mut` when filling in the function arguments. This addresses https://github.com/rust-analyzer/rust-analyzer/issues/5449.

E.g. 
```rust
fn foo(x: &i32) {}
fn main() {
  let x = 5;
  foo # completing foo here generates `foo(&x)` now instead of `foo(x)`
}
```

Co-authored-by: adamrk <ark.email@gmail.com>
2020-09-24 12:23:28 +00:00
Aleksey Kladov
fcc3c49013
Apply suggestions from code review
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2020-09-21 15:35:42 +03:00
Aleksey Kladov
2c916bbc18 Document SemanticScope 2020-09-21 12:30:55 +02:00
Jonas Schievink
9dc0afe854 Rename CustomDerive to ProcMacro
It handles fn-like macros too, and will handle attribute macros in the
future
2020-09-18 15:37:31 +02:00
bors[bot]
0d03fe6ef5
Merge #5971
5971: Implement async blocks r=flodiebold a=oxalica

Fix #4018

@flodiebold already gave a generic guide in the issue. Here's some concern about implementation detail:
- Chalk doesn't support generator type yet.
- Adding generator type as a brand new type (ctor) can be complex and need to *re-introduced* builtin impls. (Like how we implement closures before native closure support of chalk, which is already removed in #5401 )
- The output type of async block should be known after type inference of the whole body.
  - We cannot directly get the type from source like return-positon-impl-trait. But we still need to provide trait bounds when chalk asking for `opaque_ty_data`.
  - During the inference, the output type of async block can be temporary unknown and participate the later inference.
    `let a = async { None }; let _: i32 = a.await.unwrap();`

So in this PR, the type of async blocks is inferred as an opaque type parameterized by the `Future::Output` type it should be, like what we do with closure type.
And it really works now.

Well, I still have some questions:
- The bounds `AsyncBlockImplType<T>: Future<Output = T>` is currently generated in `opaque_ty_data`. I'm not sure if we should put this code here.
- Type of async block is now rendered as `impl Future<Output = OutputType>`. Do we need to special display to hint that it's a async block? Note that closure type has its special format, instead of `impl Fn(..) -> ..` or function type.



Co-authored-by: oxalica <oxalicc@pm.me>
2020-09-13 17:28:22 +00:00
oxalica
529c369c9b
Fix type walking about type of async block 2020-09-12 01:08:50 +08:00
Pavan Kumar Sunkara
4d97f5f037 Rename record_field_pat to record_pat_field 2020-09-10 18:56:04 +02:00
oxalica
251ef93ac3
Implement async blocks 2020-09-10 20:01:23 +08:00
adamrk
e11cd8fe35 Remove exposing unification 2020-09-02 22:33:54 +02:00
adamrk
04fc937700 Add back Param struct 2020-09-01 22:13:12 +02:00
adamrk
c6ddb90714 Add references to fn args during completion 2020-08-30 12:34:32 +02:00
Aleksey Kladov
f8a59adf5e Tease apart orthogonal concerns in markdown link rewriting
`hir` should know nothing about URLs, markdown and html. It should
only be able to:

* resolve stringy path from documentation
* generate canonical stringy path for a def

In contrast, link rewriting should not care about semantics of paths
and names resolution, and should be concern only with text mangling
bits.
2020-08-26 20:24:00 +02:00
Aleksey Kladov
cd9ecdf467 Remove monomorphisation from doclinks resolving code 2020-08-25 14:58:22 +02:00
Aleksey Kladov
66e5ced894 Remove AttrDef 2020-08-25 14:44:15 +02:00
Aleksey Kladov
7487885309 Simplify 2020-08-25 12:58:00 +02:00
Aleksey Kladov
575fb9ab6a Move attrs from code_module to a separate module 2020-08-25 12:56:01 +02:00
Aleksey Kladov
663749beab Minor 2020-08-25 12:48:00 +02:00
Aleksey Kladov
b45dd9ef54 Use the same abstraction for attrs and docs
Doc comments *are* attributes, so there's no reason to have two crates
here.
2020-08-25 12:13:31 +02:00
Zac Pullar-Strecker
b835f06cec Merge remote-tracking branch 'upstream/master' into 503-hover-doc-links 2020-08-25 16:44:36 +12:00
Zac Pullar-Strecker
452afaebe1 Changes from review 2020-08-25 16:40:43 +12:00
Pavan Kumar Sunkara
335add49db Add description for crates that will be published 2020-08-24 13:07:22 +02:00
Zac Pullar-Strecker
5452368fad Renames, comments, and dead code removal 2020-08-24 21:50:30 +12:00
Zac Pullar-Strecker
7bbca7a1b3 Merge remote-tracking branch 'upstream/master' into 503-hover-doc-links 2020-08-24 21:20:13 +12:00
Pavan Kumar Sunkara
a8fa5cd42e Add version to deps in cargo.toml 2020-08-24 11:10:41 +02:00
Aleksey Kladov
863b1fb731 ⬆️ ungrammar 2020-08-21 19:14:05 +02:00
Aleksey Kladov
61754678fb Better API factoring around self access modes 2020-08-19 17:02:50 +02:00
Aleksey Kladov
70fd542822 Introduce hir::Param
We generally shouldn't expose TypeRef out of hir. So, let's just use a
placehoder here.
2020-08-19 16:04:18 +02:00
Aleksey Kladov
b9b4693ce3 Add SelfParam to code_model 2020-08-19 15:16:24 +02:00
Aleksey Kladov
a3b0a3aeb8 Minor cleanups 2020-08-19 13:46:34 +02:00
bors[bot]
529ca7e5e0
Merge #5643
5643: Add new consuming modifier, apply consuming and mutable to methods r=matklad a=Nashenas88

This adds a new `consuming` semantic modifier for syntax highlighters.

This also emits `mutable` and `consuming` in two cases:

- When a method takes `&mut self`, then it now has `function.mutable` emitted.
- When a method takes `self`, and the type of `Self` is not `Copy`, then `function.consuming` is emitted.

CC @flodiebold 

Co-authored-by: Paul Daniel Faria <Nashenas88@users.noreply.github.com>
2020-08-19 11:27:02 +00:00
Dmitry
e18748ed15 Merge remote-tracking branch 'rust-analyzer/master' 2020-08-18 19:37:22 +07:00
Paul Daniel Faria
3456e2eec7 Add new method to Semantics, method_receiver_kind, which returns the kind of self
The options are Shared, Mutable, Consuming, and Copied. Use this to add proper
highlighting to methods based on usage.
2020-08-16 10:26:16 -04:00
Paul Daniel Faria
a044ff0138 Mark mutating functions with mutable modifier, and owning functions with consuming. 2020-08-16 10:22:51 -04:00
Aleksey Kladov
0ca1ba29e8 Don't expose hir::Path out of hir
Conjecture: it's impossible to use hir::Path *correctly* from an IDE.

I am not entirely sure about this, and we might need to add it back at
some point, but I have to arguments that convince me that we probably
won't:

* `hir::Path` has to know about hygiene, which an IDE can't set up
  properly.

* `hir::Path` lacks identity, but you actually have to know identity
  to resolve it correctly
2020-08-15 18:50:41 +02:00
Dmitry
73315c9168 synchronizing changes 2020-08-15 02:37:43 +07:00
Aleksey Kladov
125744c057 Rename hypothetical -> speculative 2020-08-14 15:23:27 +02:00
Aleksey Kladov
9664c57e60 Make hygiene private to hir 2020-08-13 23:54:37 +02:00
Aleksey Kladov
ae71a631fd Rename ra_hir -> hir 2020-08-13 16:36:55 +02:00