Commit Graph

15408 Commits

Author SHA1 Message Date
bors
f8c416e1b9 Auto merge of #12650 - lowr:fix/12591, r=lnicola
fix: improve whitespace insertion in pretty printer

Fixes #12591

The `=>` token in the macro_rules! should be parsed as one fat arrow, but it ["requires a lot of changes in r-a"](143cc528b1), so I left it for the larger refactoring in the future and put a FIXME note.
2022-07-01 08:32:04 +00:00
Lukas Wirth
ddddca8717 fix: Fix flycheck sending cancel progress with no running process 2022-06-30 22:58:57 +02:00
bors
642084093a Auto merge of #12634 - iDawer:match-check.witnesses, r=flodiebold
feat: Show witnesses of non-exhaustiveness in `missing-match-arm` diagnostic

Shamelessly copied from rustc. Thus reporting format is same.

This extends public api  `hir::diagnostics::MissingMatchArms` with `uncovered_patterns: String` field. It does not expose data for implementing a quick fix yet.

-----
Worth to note: current implementation does not give a comprehensive list of missing patterns. Also mentioned in [paper](http://moscova.inria.fr/~maranget/papers/warn/warn.pdf):

> One may think that algorithm I should make an additional effort to provide more
> non-matching values, by systematically computing recursive calls on specialized
> matrices when possible, and by returning a list of all pattern vectors returned by
> recursive calls. We can first observe that it is not possible in general to supply the
> users with all non-matching values, since the signature of integers is (potentially)
> infinite.
2022-06-30 14:51:58 +00:00
iDawer
e417992674 Add static assertions for some unreachble paths 2022-06-30 18:36:05 +05:00
iDawer
461c0cc07a Correct wording 2022-06-30 17:19:03 +05:00
bors
7f9c054686 Auto merge of #12626 - CuriousCorrelation:fix/empty-reasons, r=flodiebold
fix: trailing ':' on empty inactive reasons

## Description
Fixes trailing ':' even when there is no explanation. e.g.
``` sh
code is inactive due to #[cfg] directives:
```
## Issue
Fixes: #12615
2022-06-30 10:19:21 +00:00
bors
2ff505ab48 Auto merge of #12428 - lowr:experimental/destructuring-assignment, r=flodiebold
feat: implement destructuring assignment

This is an attempt to implement destructuring assignments, or more specifically, type inference for [assignee expressions](https://doc.rust-lang.org/reference/expressions.html#place-expressions-and-value-expressions).

I'm not sure if this is the right approach, so I don't even expect this to be merged (hence the branch name 😉) but rather want to propose one direction we could choose. I don't mind getting merged if this is good enough though!

Some notes on the implementation choices:

- Assignee expressions are **not** desugared on HIR level unlike rustc, but are inferred directly along with other expressions. This matches the processing of other syntaxes that are desugared in rustc but not in r-a. I find this reasonable because r-a only needs to infer types and it's easier to relate AST nodes and HIR nodes, so I followed it.
- Assignee expressions obviously resemble patterns, so type inference for each kind of pattern and its corresponding assignee expressions share a significant amount of logic. I tried to reuse the type inference functions for patterns by introducing `PatLike` trait which generalizes assignee expressions and patterns.
  - This is not the most elegant solution I suspect (and I really don't like the name of the trait!), but it's cleaner and the change is smaller than other ways I experimented, like making the functions generic without such trait, or making them take `Either<ExprId, PatId>` in place of `PatId`.

in case this is merged:
Closes #11532
Closes #11839
Closes #12322
2022-06-30 09:14:12 +00:00
Ryo Yoshida
36d2b43dfd
fix: improve whitespace insertion in pretty printer 2022-06-28 20:44:55 +09:00
Florian Diebold
8b3ec12aac fix: Report proc macro errors in expressions correctly as well
They didn't have a krate before, resulting in the generic "proc macro
not found" error.

Also improve error messages a bit more.
2022-06-28 10:43:22 +02:00
bors
9eaf96c9ea Auto merge of #12643 - Veykril:macro-compl, r=Veykril
fix: Fix completions for locals not working properly inside macro calls
2022-06-27 12:40:46 +00:00
Lukas Wirth
bdbffdd463 fix: Fix completions for locals not working properly inside macro calls 2022-06-27 14:39:44 +02:00
bors
4c3954682d Auto merge of #12635 - antogilbert:tgt_feat, r=Veykril
Correct target_feature completion

I changed the `target_feature` to match the description given in #12616.
2022-06-27 12:28:36 +00:00
Manas
7f1fac7c26 fix: deduplicate cfg completions
cfg completions are duplicated if they are set with multiple values.
This patch deduplicates them.
2022-06-27 16:17:06 +05:30
Antonello Palazzi
bef89e95e7 Udate unit tests 2022-06-27 09:04:42 +01:00
buffet
45b896002a Fix typo in build.rs 2022-06-26 10:09:45 +00:00
Hongxu Xu
f536766efb complete raw identifier with "r#" prefix 2022-06-26 14:45:30 +08:00
Antonello Palazzi
e4e2a46773 Correct target_feature completion 2022-06-26 00:50:41 +01:00
iDawer
fb6278e750 Reduce intermediate allocations while printing witnesses 2022-06-25 20:08:00 +05:00
bors
5bb123d970 Auto merge of #12520 - Veykril:flycheck-cancel, r=Veykril
internal: Bring back JodChild into flychecking for cancellation

cc https://github.com/rust-lang/rust-analyzer/pull/10517/files#r895241975
2022-06-24 17:42:00 +00:00
bors
401a71d1d7 Auto merge of #12629 - flodiebold:proc-macro-error-improvement, r=Veykril
fix: Improve proc macro errors a bit

Distinguish between
 - there is no build data (for some reason?)
 - there is build data, but the cargo package didn't build a proc macro dylib
 - there is a proc macro dylib, but it didn't contain the proc macro we expected
 - the name did not resolve to any macro (this is now an
 unresolved_macro_call even for attributes)

I changed the handling of disabled attribute macro expansion to
immediately ignore the macro and report an unresolved_proc_macro,
because otherwise they would now result in loud unresolved_macro_call
errors. I hope this doesn't break anything.

Also try to improve error ranges for unresolved_macro_call / macro_error
by reusing the code for unresolved_proc_macro. It's not perfect but
probably better than before.
2022-06-24 12:27:59 +00:00
Florian Diebold
45fd5e697f Improve comments 2022-06-24 14:19:18 +02:00
Florian Diebold
c80c34867f Improve proc macro errors a bit
Distinguish between
 - there is no build data (for some reason?)
 - there is build data, but the cargo package didn't build a proc macro dylib
 - there is a proc macro dylib, but it didn't contain the proc macro we expected
 - the name did not resolve to any macro (this is now an
 unresolved_macro_call even for attributes)

I changed the handling of disabled attribute macro expansion to
immediately ignore the macro and report an unresolved_proc_macro,
because otherwise they would now result in loud unresolved_macro_call
errors. I hope this doesn't break anything.

Also try to improve error ranges for unresolved_macro_call / macro_error
by reusing the code for unresolved_proc_macro. It's not perfect but
probably better than before.
2022-06-24 13:45:19 +02:00
bors
434e718b67 Auto merge of #12605 - erhuve:fix/determine-doc-link-type-at-start, r=erhuve
fix: doc_links link type - Determine link type at start (fixes #12601)

fixes #12601
Looked like autolink/inline mismatch happened because end_link_type was parsed from the Text/Code events.
I changed it to be determined from the Start event, which should hopefully remain accurate while staying true to the cases where link type may need to be changed, according to the comment
```
// normally link's type is determined by the type of link tag in the end event,
// however in some cases we want to change the link type, for example,
// `Shortcut` type doesn't make sense for url links
```
Hopefully this is the desired behavior?
![Untitled](https://user-images.githubusercontent.com/59463268/174696581-3b1140a5-cdf0-4eda-9a11-ec648e4e7d21.gif)
2022-06-23 23:15:33 +00:00
Raymond Luo
5107123f9a clarify comment and add autolink test case 2022-06-23 19:02:30 -04:00
bors
32b40ded0f Auto merge of #12628 - Veykril:simplify, r=Veykril
internal: Simplify
2022-06-23 18:13:08 +00:00
Lukas Wirth
2642f64570 internal: Simplify 2022-06-23 20:08:29 +02:00
CuriousCorrelation
e0c17e8777 fix: trailing ':' on empty inactive reasons
Fixes: #12615
2022-06-23 22:10:27 +05:30
yue4u
472ae16bfb fix: completes non exhaustive variant within the defining crate 2022-06-24 00:00:51 +09:00
Raymond Luo
96ff235770 condense matches on autolink 2022-06-22 22:07:26 -04:00
Raymond Luo
b7e3f525bd handle autolink as edge case 2022-06-20 23:15:27 -04:00
Raymond Luo
c6f776c5f9 determine doc link type from start instead of text or code 2022-06-20 21:10:45 -04:00
bors
6fc5c3cd21 Auto merge of #12604 - Veykril:completions, r=Veykril
internal: Simplify some completions
2022-06-20 19:56:05 +00:00
Lukas Wirth
7a0774defa internal: Simplify some completions 2022-06-20 21:55:33 +02:00
bors
312ac83caf Auto merge of #12599 - flodiebold:no-test-deps, r=flodiebold
fix: Only apply `cfg(test)` for local crates

Don't analyze dependencies with `test`; this should fix various cases where crates use `cfg(not(test))` and so we didn't find things.

"Local" here currently means anything that's not from the registry, so anything inside the workspace, but also path dependencies. So this isn't perfect, and users might still need to use `rust-analyzer.cargo.unsetTest` for these in some cases.
2022-06-20 18:42:48 +00:00
Florian Diebold
07d78b67cb Fix test 2022-06-20 20:34:08 +02:00
Lukas Wirth
8b078986dc Reimplement auto-ref completions for fields 2022-06-20 20:22:51 +02:00
Florian Diebold
05ca0a2377 Refactor a bit 2022-06-20 20:21:30 +02:00
Lukas Wirth
46d22719fc Remove pattern rendering hack 2022-06-20 20:16:40 +02:00
Florian Diebold
98a58114a4 Only apply cfg(test) for local crates
Don't analyze dependencies with `test`; this should fix various cases
where crates use `cfg(not(test))` and so we didn't find things.

"Local" here currently means anything that's not from the registry, so
anything inside the workspace, but also path dependencies. So this isn't
perfect, and users might still need to use
`rust-analyzer.cargo.unsetTest` for these in some cases.
2022-06-20 20:10:25 +02:00
Lukas Wirth
06ee4d6222 fix: Fix auto-ref completions inserting into wrong locations 2022-06-20 18:59:57 +02:00
Lukas Wirth
1f028403cd fix: Don't trigger pattern completions when typing a wildcard pattern 2022-06-20 18:03:09 +02:00
Lukas Wirth
6e9c963348 internal: Lift out IdentContext from CompletionContext 2022-06-20 17:41:04 +02:00
Lukas Wirth
bcf10cde13 internal: Remove previous_token field from CompletionContext 2022-06-20 15:07:48 +02:00
Lukas Wirth
90483321ee Remove some usages of Completions::add_resolution 2022-06-20 14:47:30 +02:00
Lukas Wirth
7685245282 Even more completion context filtering 2022-06-20 14:23:46 +02:00
Lukas Wirth
ce5859e387 Lift out PathKind variant fields into structs 2022-06-20 13:29:13 +02:00
Lukas Wirth
5c69df93df Split remaining completion calls on the context kinds 2022-06-20 13:17:30 +02:00
iDawer
4ff9bedbed Display witnesses of non-exhaustive match
Reporting format follows rustc and shows at most three witnesses.
2022-06-20 15:48:09 +05:00
Lukas Wirth
013c6a3f75 fix: attribute macros not being properly diagnosed 2022-06-19 00:37:37 +02:00
bors
817f46bc6c Auto merge of #12580 - Veykril:completion, r=Veykril
internal: Move more things out of `CompletionContext::function_def` into more specific parts
2022-06-18 09:21:13 +00:00
Lukas Wirth
f271b18129 Consider walking up macro expansions when searching for surrounding entities in completion analysis 2022-06-18 11:19:36 +02:00
Lukas Wirth
c1446a2743 Move CompletionContext::impl_def into corresponding entities 2022-06-18 10:45:53 +02:00
Lukas Wirth
83e8f3ac30 Move CompletionContext::incomplete_let into PathKind::Expr 2022-06-18 10:19:04 +02:00
bors
7a87f810ca Auto merge of #12576 - harpsword:fold_range_non_block_match_arm, r=Veykril
feat: add fold range for multi line match arm list

fix: #11893
2022-06-18 08:10:31 +00:00
harpsword
3a78cc5e67 feat: add fold range for multi line match arm list 2022-06-18 16:05:56 +08:00
Lukas Wirth
7369e5120d Move CompletionContext::function_def into PathKind::Expr 2022-06-18 09:54:03 +02:00
Lukas Wirth
309ecdd71c internal: NameRefKind classification is not optional 2022-06-18 08:58:47 +02:00
Lukas Wirth
0665428b4e minor: Simplify 2022-06-18 01:15:08 +02:00
Lukas Wirth
173bb10a76 internal: Split flyimport into its 3 applicable contexts 2022-06-18 00:47:28 +02:00
Lukas Wirth
00fdb4a3d8 Only run completion functions if their corresponding context is active 2022-06-17 23:36:39 +02:00
Lukas Wirth
d97a8ee865 Remove superfluous early returns 2022-06-17 17:49:25 +02:00
Lukas Wirth
85b68b1f7d Inline PathQualifierCtx 2022-06-17 17:27:12 +02:00
Lukas Wirth
d6f161ffa9 internal: Collapse lift is_infer_qualifier into Qualified variant 2022-06-17 17:15:29 +02:00
Lukas Wirth
2f2ea77d88 Move existing_derives into PathKind::Derive 2022-06-17 16:56:21 +02:00
Lukas Wirth
531060f103 internal: Collapse completion ctx path qualifier and is_absolute_path into enum 2022-06-17 16:36:22 +02:00
Lukas Wirth
85363d18e8 Simplify 2022-06-17 16:22:51 +02:00
Lukas Wirth
f35a9a1dcc Split out tests 2022-06-17 15:19:09 +02:00
Lukas Wirth
a2537e591a Split completion context module into definitions and analysis parts 2022-06-17 15:16:20 +02:00
Lukas Wirth
f201a40492 Remove ImmediateLocation in favor of PathKind::Type 2022-06-17 15:09:48 +02:00
Lukas Wirth
6b246292ca Move more ImmediateLocation::TypeAnnotation into PathKind::Type 2022-06-17 11:31:36 +02:00
Lukas Wirth
6e07b17f69 Introduce NameRefKind for completions 2022-06-17 10:45:19 +02:00
Lukas Wirth
59799312e2 Send a DidCancel event when restarting flychecks 2022-06-16 15:25:50 +02:00
bors
7322a982f9 Auto merge of #12554 - XFFXFF:fix_11959, r=Veykril
fix: local items should not be completed in parent signature

fixes #11959

> We get a Bar completion for the following snippet which is wrong as the item is not visible in that position.
> ``` rust
> fn foo() -> $0 {
>    struct Bar;
> }
> ```

I investigated the problem and found that the scope of the cursor offset, also `CompletionContext.scope` is the body of the function
2022-06-16 12:48:33 +00:00
XFFXFF
6df969f5f4 the offset used for the completion cursor should always be relative to the original file and not to the marco file 2022-06-16 20:34:37 +08:00
bors
7ade4d49fc Auto merge of #12517 - xuhongxu96:master, r=Veykril
fix methods in pub trait generated by macro cannot be completed

Fix #12483

Check if the container is trait and inherit the visibility to associate items during collection.
2022-06-16 09:14:09 +00:00
XFFXFF
fbf8e12234 the scope of the return type is not the body of the function 2022-06-16 16:24:18 +08:00
Hongxu Xu
534d71a852 disable private editable in TEST_CONFIG by default
adjust test_visibility_filter test case
2022-06-16 08:52:57 +08:00
Jeremy Banks
c32f133236 fix: inserted imports must come after a shebang if present 2022-06-15 19:42:43 +00:00
Jeremy Banks
f32ad8362f add failing test: inserts_after_shebang 2022-06-15 19:42:43 +00:00
Lukas Wirth
bc1aa93e7e Polish 2022-06-15 18:35:48 +02:00
Lukas Wirth
1dd2c50298 Update test outputs 2022-06-15 18:07:37 +02:00
Lukas Wirth
0e41d15b82 Use the correct crates proc-macro loading error message 2022-06-15 18:06:33 +02:00
Lukas Wirth
1d34cdcac0 Diagnose unresolved attribute proc-macros 2022-06-15 17:34:13 +02:00
Lukas Wirth
7d51fc4640 Show proc-macro loading errors in unresolved-proc-macro diagnostics 2022-06-15 17:34:01 +02:00
bors
15c63c4119 Auto merge of #12541 - Veykril:vs-reload, r=Veykril
fix: Clear proc-macro changed flag when reloading workspace
2022-06-15 12:29:34 +00:00
Lukas Wirth
664a751f2b fix: Clear proc-macro changed flag when reloading workspace 2022-06-15 14:29:13 +02:00
Hongxu Xu
549c810436 revert hir-def lib.rs 2022-06-15 07:48:34 +08:00
Hongxu Xu
8805a768d4 check if the container is trait and inherit the visibility 2022-06-15 07:47:06 +08:00
Hongxu Xu
070456838d remove inherit_visibility test case in item_tree 2022-06-14 23:24:48 +08:00
Hongxu Xu
ded412d56b implement inherited_visibility in collector 2022-06-14 23:23:15 +08:00
Hongxu Xu
3f60e71a12 remove inherited_visibility in lower.rs 2022-06-14 21:44:07 +08:00
Hongxu Xu
d7eebd9706 add test cases to complete fn generated by macro in pub trait 2022-06-14 21:41:09 +08:00
Lukas Wirth
325ceaef19 fix: Check for the correct proc-macro settings in missing proc-macro diagnostics 2022-06-14 11:00:06 +02:00
Lukas Wirth
6438ef9aa3 internal: Bring back JodChild into flychecking for cancellation 2022-06-13 13:51:10 +02:00
bors
7db73875ac Auto merge of #12519 - Veykril:hover-assoc, r=Veykril
feat: On assoc item name hover, render trait decl docs
2022-06-13 09:58:04 +00:00
Lukas Wirth
9b9c13fc40 feat: On assoc item name hover, render trait decl docs 2022-06-13 11:57:33 +02:00
bors
366bd7242e Auto merge of #12515 - Veykril:rustc-proc-macros, r=Veykril
fix: Pass the build data to rustc_private crates

With this all proc-macros should resolve in rustc now when setting up the build script running command properly.
2022-06-12 17:35:55 +00:00
Lukas Wirth
10e9f47dce fix: Pass the build data to rustc_private crates 2022-06-12 19:29:45 +02:00
Lukas Wirth
0e4eb647f6 More precise proc-macro errors 2022-06-12 18:44:46 +02:00
bors
4f2a67b26f Auto merge of #12513 - Veykril:ty-utils, r=Veykril
internal: Simplify `hir_ty::utils`
2022-06-12 14:08:08 +00:00