Commit graph

9205 commits

Author SHA1 Message Date
Jonas Schievink
81ccf37d3b Remove Attrs::merge
Only the `RawAttrs` version of this is in use
2020-12-19 02:43:00 +01:00
Jonas Schievink
0ac75f8982 Remove resolved FIXME 2020-12-19 02:32:31 +01:00
Jonas Schievink
aa00d1acd6 fixture -> ra_fixture 2020-12-19 01:12:41 +01:00
Jonas Schievink
d5edd0e928 Test paths to derive macros 2020-12-19 01:11:33 +01:00
Jonas Schievink
ea5cc8d07a More accurate #[derive] parsing
This now allows full paths to the derive macro
2020-12-19 01:10:56 +01:00
bors[bot]
c7b7c37ea5
Merge #6937
6937: Deduplicate highlight tags and symbol kinds r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-12-18 20:05:20 +00:00
Aleksey Kladov
c45221907a Deduplicate highlight tags and symbol kinds
Curiously, LSP uses different enums for those, and unsurprising and
annoyingly, there are things which exist in one but not in the other.

Let's not repeat the mistake and unify the two things
2020-12-18 23:04:26 +03:00
bors[bot]
38b108c20e
Merge #6935
6935: Don't look at attributes when lowering to ItemTree r=jonas-schievink a=jonas-schievink

Resolves 2 `cfg_attr` FIXMEs

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-12-18 19:38:07 +00:00
Jonas Schievink
77972e2001 Don't look at attributes when lowering to ItemTree
Resolves 2 `cfg_attr` FIXMEs
2020-12-18 20:37:26 +01:00
bors[bot]
c073e4f6ba
Merge #6934
6934: Implement `cfg_attr` handling r=jonas-schievink a=jonas-schievink

Part of https://github.com/rust-analyzer/rust-analyzer/issues/5548

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-12-18 19:27:18 +00:00
Jonas Schievink
aab9cc9cfb Hit a mark 2020-12-18 20:25:41 +01:00
Jonas Schievink
382ee2fa03 Add test 2020-12-18 20:01:02 +01:00
Jonas Schievink
d42d1d33f0 Fix parsing of active cfg_attr 2020-12-18 20:00:59 +01:00
Aleksey Kladov
ade2f5cd12 Reduce test verbosity 2020-12-18 21:26:47 +03:00
Aleksey Kladov
0e3581e823 NavTarget doesn't assume that it points to a symbol 2020-12-18 21:15:48 +03:00
Jonas Schievink
08de1b4fa5 Implement RawAttr::filter 2020-12-18 18:58:42 +01:00
Aleksey Kladov
cd4a7bf36e Minor, cleanup API 2020-12-18 19:50:00 +03:00
Aleksey Kladov
55ba353b39 Don't expose SyntaxKind from IDE API
SyntaxKind is somewhat of an internal type, but IDE is using it to
basically specify an icon. Let's have a dedicated entity for this
instead.
2020-12-18 19:28:48 +03:00
Aleksey Kladov
2465fa02b7 Cleaup imports
ide should re-export everything it needs.
2020-12-18 18:02:11 +03:00
Jesse Bakker
700034bd5a Do not merge imports with different attributes 2020-12-18 15:29:37 +01: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
Jonas Schievink
4f07d8dd58 Refactor attributes API to allow handling cfg_attr 2020-12-18 02:24:14 +01:00
Kirill Bulatov
9d2cbf05e3 Show first fuzzy completions fully containing the input 2020-12-17 23:10:18 +02:00
Lukas Wirth
fa65d6ba85 Higher-ranked trait bounds for where clauses 2020-12-17 22:01:42 +01:00
bors[bot]
b55cb897e5
Merge #6912
6912: Default to host platform for cargo metadata r=jonhoo a=jonhoo

This modifies the logic for calling cargo metadata so that it will use
the host platform if no explicit target platform is given. This is
needed since cargo metadata defaults to outputting information for _all_
targets.

Fixes #6908.

Co-authored-by: Jon Gjengset <jongje@amazon.com>
Co-authored-by: Jon Gjengset <jon@thesquareplanet.com>
2020-12-17 18:32:13 +00:00
Jon Gjengset
faed47b3d3 Fun times with rustfmt 2020-12-17 10:24:58 -08:00
Jon Gjengset
71478e067b
Update crates/project_model/src/cargo_workspace.rs
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-12-17 13:18:23 -05:00
bors[bot]
b0e5d1efdb
Merge #6920
6920: Minor API cleanup r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-12-17 17:18:50 +00:00
Aleksey Kladov
30216880c4 Minor API cleanup 2020-12-17 20:14:13 +03:00
Aleksey Kladov
c888f1de6f Rewrite doctest runnables
Handle more cases in a generic way without copy-pasting code.
2020-12-17 20:11:40 +03:00
Aleksey Kladov
0da1532ef2 Minor code style 2020-12-17 20:10:39 +03:00
kjeremy
d828bd794b LSP 3.16 - Released 2020-12-17 11:33:35 -05:00
Jonas Schievink
9231821c03 Make Attrs::from_attrs_owner private 2020-12-17 15:45:26 +01:00
Jonas Schievink
eaeabbb815 Add AttrDefId::krate
Access to the containing crate will be needed to handle `cfg_attr`
2020-12-17 14:29:29 +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
bors[bot]
d641bccb0f
Merge #6907
6907: Lifetime reference search  r=matklad a=Veykril

PR #6787 but rewritten to make use of the HIR now. This only applies to Lifetimes, not labels. Also Higher-Ranked Trait Bounds aren't supported yet, but I feel like this PR is big enough as is which is why I left them out after noticing I forgot about them.

Supporting renaming required slight changes in the renaming module as lifetime names aren't allowed for anything but lifetimes(and labels) and vice versa for normal names.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-17 11:00:39 +00:00
Jon Gjengset
9802c0ccd0 Default to host platform for cargo metadata
This modifies the logic for calling cargo metadata so that it will use
the host platform if no explicit target platform is given. This is
needed since cargo metadata defaults to outputting information for _all_
targets.

Fixes #6908.
2020-12-16 17:38:37 -08: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
Jonas Schievink
28b5334580 Avoid querying attributes in item tree lowering
ItemTree is per-file, so there is no unique crate associated with it.
This means that it cannot know the active CfgOptions and thus couldn't
handle `cfg_attr`.

Prepare it for `cfg_attr`s by avoiding accessing attributes.
2020-12-16 23:42:03 +01:00
Lukas Wirth
55faa2daa3 Lifetime reference search 2020-12-16 22:21: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
bors[bot]
c1c36acb02
Merge #6861
6861: generate default implementation for an enum from an enum variant #6860 r=matklad a=bnjjj

close #6860

Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-12-16 08:36:05 +00:00
bors[bot]
ece626fe81
Merge #6894
6894: Parenthesize composite if condition before inverting in invert-if assist r=matklad a=Jesse-Bakker

Fixes #6867

Co-authored-by: Jesse Bakker <github@jessebakker.com>
2020-12-16 08:20:11 +00:00
Benjamin Coenen
2c82a1aec7 generate default implementation for an enum from an enum variant #6860
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-12-15 21:35:41 +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
Jesse Bakker
0f42a71806 Parenthesize composite if condition before inverting in invert-if assist 2020-12-15 16:25:57 +01:00
Jonas Schievink
479babf874 Reject visibilities on macro_rules! 2020-12-15 15:37:49 +01:00
Jonas Schievink
c1cb595382 Move to upstream macro_rules! model 2020-12-15 15:37:37 +01:00
bors[bot]
39aae835fd
Merge #6886
6886: Expand statements for macros in lowering r=matklad a=edwin0cheng

Fixes #6811

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-12-15 12:41:07 +00:00
bors[bot]
435d46b183
Merge #6888
6888: Use standard test style r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2020-12-15 12:34:37 +00:00
Edwin Cheng
1f4da7098c Remove obsolete comment 2020-12-15 17:25:59 +08:00
bors[bot]
a9d19200f2
Merge #6889
6889: Resolve `macro-error` diagnostics on asm & llvm_asm r=matklad a=lf-

We currently stub these out as returning unit.

This fixes spurious RA `macro-error` diagnostics introduced somewhere around 0.2.400 in the following:
```rust
unsafe { asm!(""); llvm_asm!(""); }
```

I'd ideally like to write a unit test for this, but I'm not familiar with where the tests for `hir_expand` are.

Thanks to @edwin0cheng for help on resolving this issue.

Co-authored-by: lf- <lf-@users.noreply.github.com>
2020-12-15 09:15:41 +00:00
lf-
090a59970d Resolve macro-error diagnostics on asm & llvm_asm
We currently stub these out as returning unit.

This fixes spurious RA diagnostics in the following:
```rust
unsafe { asm!(""); llvm_asm!(""); }
```
2020-12-15 01:06:53 -08:00
Aleksey Kladov
c582e52a1b Use standard test style 2020-12-15 11:53:16 +03:00
Benjamin Coenen
490475ee19 generate default implementation for an enum from an enum variant #6860
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-12-15 09:46:02 +01:00
bors[bot]
65e31a1b5b
Merge #6875
6875: Add find usages for enum constructors r=matklad a=sasurau4

Fix #2549 for enum

Co-authored-by: Daiki Ihara <sasurau4@gmail.com>
2020-12-15 08:38:08 +00:00
Edwin Cheng
9da1eee436 Add regression test 2020-12-15 15:24:35 +08:00
Edwin Cheng
a68ff269a9 Expand statements for mbe in lowering 2020-12-15 14:39:15 +08:00
Daiki Ihara
36a9daac70 Add find usages for enum constructors 2020-12-15 00:39:42 +09:00
bors[bot]
34f7b5383a
Merge #6874
6874: Implement `module_path!()` r=jonas-schievink a=jonas-schievink

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

bors r+

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-12-14 15:39:31 +00:00
Jonas Schievink
81820fe52c Implement module_path!() 2020-12-14 16:38:53 +01:00
bors[bot]
817fbebbb5
Merge #6862
6862: Add LifetimeParam resolving to Semantics r=matklad a=Veykril

This is stuff required for the lifetime references/definitions PR. I pulled this out to make it easier to review as well as because there is one thing that still has to be addressed which can be found in the review comments.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-14 15:15:52 +00:00
bors[bot]
134c7563be
Merge #6817
6817: Replace goblin crate with object r=matklad a=lnicola

Continuation of #4385.

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-12-14 15:04:47 +00:00
Lukas Wirth
c6172f3f6d Add LifetimeParam resolving to Semantics 2020-12-14 16:04:28 +01:00
Benjamin Coenen
08090d81b1 generate default implementation for an enum from an enum variant #6860
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-12-14 09:44:24 +01:00
Florian Diebold
4788aaa5f0 Add test for #6852 2020-12-13 14:53:04 +01:00
Laurențiu Nicola
dc519b88af Replace goblin crate with object 2020-12-13 14:08:59 +02:00
Florian Diebold
7d7949b315 Change recommendation when source can't be loaded from sysroot
Since we just tried running `rustup component add`, it doesn't make sense to me
to recommend trying that again. If we're reaching this case, it's probably more
likely that rustc was installed via package manager, in which case the source
should be installed the same way (e.g. if you install the rust-src package on
Ubuntu it will install a symlink in the right place to make our sysroot
detection work).
2020-12-13 13:04:50 +01:00
bors[bot]
ca3a54f0a4
Merge #6852
6852: Ignore lifetime params in substitutions r=matklad a=Veykril

[`hir_ty::utils::Generics`](https://github.com/rust-analyzer/rust-analyzer/blob/master/crates/hir_ty/src/utils.rs#L153) currently only assumes type parameters but not lifetime parameters and therefor creates incorrect index and length calculations, this PR just makes the use sites ignore LifetimeGenerics for now.

This fixes the panic at least locally for me for `analysis-stats`. Funnily enough this panic prevented me from using reference search for the `args` field to fix this problem.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-13 11:34:43 +00:00
Lukas Wirth
ae8a802085 Ignore lifetime params in substitutions 2020-12-13 11:34:44 +01:00
bors[bot]
a15d19619e
Merge #6845
6845: Don't HirDisplay unknown types when displaying for source r=Veykril a=Veykril

Was wondering why the add missing impl assist didn't do anything here:
![Code_JCA1Qo0V9P](https://user-images.githubusercontent.com/3757771/101990300-7af44a80-3ca6-11eb-8431-e5eb4de4e78c.png)
Turns out me forgetting to set the Index::Idx type in the trait causes RA to panic due to it trying to to create an unparsable type in the `make` module.
Now we get this instead which imo is definitely better to have.
![Code_MUFPJUCULY](https://user-images.githubusercontent.com/3757771/101990347-c9094e00-3ca6-11eb-9c6a-146bddf64b7c.png)



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-12 18:06:36 +00:00
Lukas Wirth
69b78edb5e Don't HirDisplay unknown types when displaying for source 2020-12-12 19:05:00 +01:00
Jeremy Kolb
26a1675764 Remove some redundant allocations 2020-12-12 12:27:09 -05: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
ivan770
f7f4f366ac
Added remove this semicolon test 2020-12-12 13:50:11 +02:00
bors[bot]
70db57cc59
Merge #6839
6839: Infer labeled blocks r=flodiebold a=Veykril

The test should cover all the interesting cases I believe(main part of it is copied from the loop label break test above it).

The test is indented to stay consistent with the rest of the tests in the file, I can dedent all the tests in the file in a follow up PR if desired.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-12 10:18:16 +00:00
Lukas Wirth
11f8664182 Add Lifetimes to the HIR 2020-12-12 00:56:52 +01:00
Lukas Wirth
378ec2841b Infer labeled blocks 2020-12-12 00:06:48 +01:00
bors[bot]
4998807039
Merge #6813
6813: negative sign matching in mbe matching for literal r=edwin0cheng a=edwin0cheng

Fix #6292

r @jonas-schievink 

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2020-12-11 22:17:40 +00:00
Edwin Cheng
ae29fb0211 Add missing arg for eat_char 2020-12-12 06:14:11 +08:00
Lukas Wirth
8ed8e4f25a Use Attrs::docs in NavigationTarget instead of DocCommentsOwner 2020-12-11 21:19:58 +01:00
bors[bot]
91bf15a2f5
Merge #6834
6834: Use Attrs::docs in runnables instead of DocCommentsOwner r=kjeremy a=Veykril

I figured that we should probably move as much of the doc usage to the HIR as possible hence this PR. If we should keep this AST-based feel free to close.

This change does have the nice(but not really useful as I doubt anyones gonna write doc tests like these) side effect that these two doc string snippets allow being run now.
![image](https://user-images.githubusercontent.com/3757771/101945607-bf241400-3bee-11eb-96ce-ccae80028b1f.png)
![image](https://user-images.githubusercontent.com/3757771/101946375-2e9a0380-3bef-11eb-9950-e35168fdd048.png)


Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-12-11 19:57:08 +00:00
Lukas Wirth
ac19a71459 Use Attrs::docs in runnables instead of DocCommentsOwner 2020-12-11 20:11:03 +01:00
Jonas Schievink
00c34b048e Add upstream commit to builtin_attr.rs 2020-12-11 19:12:06 +01:00
bors[bot]
3674e494ca
Merge #6819
6819: Add builtin attributes for use in nameres r=jonas-schievink a=jonas-schievink

These are not yet used, but have to go through nameres later in order to support procedural macro attributes

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2020-12-11 18:03:09 +00:00
Jonas Schievink
2fdde98b5c Move print_memory_usage to cli.rs 2020-12-11 18:24:27 +01:00
Jonas Schievink
c007ac3830 Avoid panic when collecting memory metrics 2020-12-11 18:18:27 +01:00
Lukas Wirth
37c5b82938 Don't highlight parent nodes of comments on hover 2020-12-11 16:00: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
Jonas Schievink
253678ead2 Add builtin attributes for use in nameres 2020-12-11 14:04:33 +01:00
Aleksey Kladov
e179ed6f53 Use natural trait ordering in derive completion
derive(Clone, Copy) reads better than derive(Copy, Clone).

However, we preserve the reverse ordering in the lookup text for
sorting purposes. That way, it's convenient to type just `Ord` to
derive everything.
2020-12-11 15:45:53 +03:00
Edwin Cheng
175229ab3d negative sign matching in mbe matching for literal 2020-12-11 17:59:04 +08:00