7541: Use block_def_map in body lowering (third time's the charm) r=jonas-schievink a=jonas-schievink
After https://github.com/rust-analyzer/rust-analyzer/pull/7380 and https://github.com/rust-analyzer/rust-analyzer/pull/7506 both had to be reverted, this should have finally resolved all remaining bugs.
Most importantly, the optimization to skip `block_def_map` computation when the block contains no inner items was fixed (which fortunately was simpler than expected).
I've ran `analysis-stats` on libstd locally, which works fine, and also ran this PR locally for a short while without issues.
Note that this *still* has no (or almost no) user-facing impact, because the rest of r-a still relies on some local item support hacks.
bors r+
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
there are a few currently limitations:
* no modifications of function body
* does not handle mutability and references
* no method support
* may produce incorrect results
I've noticed that there are various suggestions that rust-analyzer seems
to filter out, even if they make sense.
Here's an example of where it seems like there should be a suggestion,
but there isn't:
![https://i.imgur.com/wsjM6iz.png](https://i.imgur.com/wsjM6iz.png)
It turns out that this specific suggestion is not considered
`MachineApplicable`, which are the only suggestions that rust-analyzer
accepts. However if you read the documentation for `MachineApplicable`,
b3897e3d13/compiler/rustc_lint_defs/src/lib.rs (L27-L29)
then you realize that these are specifically only those suggestions that
rust-analyzer could even automatically apply (in some distant future,
behind some setting or so). Other suggestions that may have some
semantic impact do not use `MachineApplicable`. So all other suggestions
are still intended to be suggested to the user, just not automatically
applied without the user being consulted.
b3897e3d13/compiler/rustc_lint_defs/src/lib.rs (L22-L24)
So with that in mind, rust-analyzer should almost definitely not filter
out `MaybeIncorrect` (which honestly is named horribly, it just means
that it's a semantic change, not just a syntactical one).
Then there's `HasPlaceholders` which basically is just another semantic
one, but with placeholders. The user will have to make some adjustments,
but the suggestion still is perfectly valid. rust-analyzer could
probably detect those placeholders and put proper "tab through" markers
there for the IDE, but that's not necessary for now.
Then the last one is `Unspecified` which is so unknown that I don't even
know how to judge it, meaning that the suggestion should probably also
just be suggested to the user and then they can decide.
So with all that in mind, I'm proposing to get rid of the check for
Applicability entirely.
7465: Only hide parameter hints for path, field and methodcall expressions r=SomeoneToIgnore a=Veykril
Doing this check for other expressions makes little sense to me.
Fixes#7458
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
7457: Add no-buffering file logging and wait for a debugger option. r=vsrs a=vsrs
Adds two command line flags: `--no-buffering` and `--wait-dbg`.
Not sure if someone else needs this, but personally I found both flags extremely useful trying to figure out why RA does not work with Visual Studio. Or better to say why Visual Studio does not work with RA.
Co-authored-by: vsrs <vit@conrlab.com>
7433: Support Macro v2 in mbe r=jonas-schievink a=edwin0cheng
Added `mbe::MacroDef` for Macro v2.
cc @jonas-schievink
Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
7426: Create all `ModuleId`s through a `DefMap` method r=jonas-schievink a=jonas-schievink
`ModuleId` needs to be able to represent blocks, and only the
associated `DefMap` will know how to construct that `ModuleId`
bors r+
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
7399: Make `ModuleId`'s `krate` field private and audit uses r=jonas-schievink a=jonas-schievink
bors r+
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
Detail should be rendered as shtort one line, just dumping fn header
there is not useful, despite the fact that TS does this.
The fact that this is a function should be indicated by the icon, the
same goes for pub/const/async etc qualitfiers
name is already present in the lable (and arg list should be a part of
that, as in idea)
But the return type is the small genuinerlly useful bit of info we can show here
7310: Add assist: add lifetime to type r=matklad a=bnjjj
close#7200
7395: Obtain `ModuleId`'s `DefMap` through a method r=jonas-schievink a=jonas-schievink
Once `ModuleId` can represent modules inside block expressions, this will be required in order to obtain the correct `DefMap`. Otherwise existing code might use a `LocalModuleId` from the wrong `DefMap` and cause a panic.
bors r+
Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
7353: Add LifetimeParam and ConstParam to CompletionItemKind r=matklad a=Veykril
Adds `LifetimeParam` and `ConstParam` to `CompletionItemKind` and maps them both to `TypeParam` in the protocol conversion as there are no equivalents, so nothing really changes there.
`ConstParam` could be mapped to `Const` I guess but I'm split on whether that would be better?
Additions were solely inspired by (the single) test output for const params.
Also sorts the variants of `CompletionItemKind` and its to_proto match.
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
7386: Handle box with allocator r=flodiebold a=tweksteen
In 1.49.0, the definition of Box was modified to support an optional
Allocator[1]. Adapt the parsing of the `box` keyword to supply the
expected number of parameters to the constructor.
[1] f288cd2e17Fixes: #6956
Co-authored-by: Thiébaud Weksteen <tweek@google.com>
In 1.49.0, the definition of Box was modified to support an optional
Allocator[1]. Adapt the parsing of the `box` keyword to supply the
expected number of parameters to the constructor.
[1] f288cd2e17
7348: Fix broken link in intra-doc r=edwin0cheng a=sasurau4
Fix#5546
The intra-doc link doesn't work fine for trait associated method.
Co-authored-by: Daiki Ihara <sasurau4@gmail.com>
7387: Refactor build script specific data r=edwin0cheng a=edwin0cheng
It refactors for separating logic for build script specific data.
bors r+
Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
7375: Add support for running name resolution in block expressions r=jonas-schievink a=jonas-schievink
This adds a `block_def_map` query that runs the name resolution algorithm on a block expression, and returns a `DefMap` that stores links to the parent `DefMap` (either the containing block or the crate-level `DefMap`). Blocks with no inner items return the parent's `DefMap` as-is, to avoid creating unnecessarily long `DefMap` chains.
Path resolution is updated to recurse into the parent `DefMap` after looking up a path in the original `DefMap`.
I've added a few new tests for this, but outside of those this isn't used yet.
bors r+
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
7359: ItemTree: store a mapping from blocks to inner items r=jonas-schievink a=jonas-schievink
To do name resolution within block expressions, we need to know which inner items are located inside each block expression. This adds such a mapping to `ItemTree`, replacing the previous one, which was seemingly unused other than to access all the inner items.
This also assigns `AstId`s to block expressions, which is needed to store the mapping in salsa.
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
7341: Fix warnings when running `cargo doc --document-private-items` r=Veykril a=jyn514
These were the warnings previously:
<details>
```
warning: could not parse code block as Rust code
--> crates/stdx/src/lib.rs:137:9
|
137 | /// ∀ x in slice[..idx]: pred(x)
| _________^
138 | | /// && ∀ x in slice[idx..]: !pred(x)
| |____^
|
= note: error from rustc: unknown start of token: \u{2200}
warning: 1 warning emitted
warning: unresolved link to `package`
--> crates/base_db/src/input.rs:181:15
|
181 | /// it's [package].name, can be different for other project types or even
| ^^^^^^^ no item named `package` in scope
|
= note: `#[warn(broken_intra_doc_links)]` on by default
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: unresolved link to `package`
--> crates/base_db/src/input.rs:181:15
|
181 | /// it's [package].name, can be different for other project types or even
| ^^^^^^^ no item named `package` in scope
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: 2 warnings emitted
warning: unresolved link to `package`
--> crates/base_db/src/input.rs:181:15
|
181 | /// it's [package].name, can be different for other project types or even
| ^^^^^^^ no item named `package` in scope
|
= note: `#[warn(broken_intra_doc_links)]` on by default
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: unresolved link to `package`
--> crates/base_db/src/input.rs:181:15
|
181 | /// it's [package].name, can be different for other project types or even
| ^^^^^^^ no item named `package` in scope
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: 2 warnings emitted
```
</details>
This does *not* fix the following warning, because it is actually rust
code and rustdoc is being over eager:
```
warning: Rust code block is empty
--> crates/parser/src/grammar.rs:16:5
|
16 | //! ```
| _____^
17 | | //! // test function_with_zero_parameters
18 | | //! // fn foo() {}
19 | | //! ```
| |_______^
|
help: mark blocks that do not contain Rust code as text
|
16 | //! ```text
| ^^^^^^^
```
https://github.com/rust-lang/rust/pull/79816 should make this
configurable so the warning can be `allow`ed.
Co-authored-by: Joshua Nelson <jyn514@gmail.com>
These were the warnings previously:
```
warning: could not parse code block as Rust code
--> crates/stdx/src/lib.rs:137:9
|
137 | /// ∀ x in slice[..idx]: pred(x)
| _________^
138 | | /// && ∀ x in slice[idx..]: !pred(x)
| |____^
|
= note: error from rustc: unknown start of token: \u{2200}
warning: 1 warning emitted
warning: unresolved link to `package`
--> crates/base_db/src/input.rs:181:15
|
181 | /// it's [package].name, can be different for other project types or even
| ^^^^^^^ no item named `package` in scope
|
= note: `#[warn(broken_intra_doc_links)]` on by default
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: unresolved link to `package`
--> crates/base_db/src/input.rs:181:15
|
181 | /// it's [package].name, can be different for other project types or even
| ^^^^^^^ no item named `package` in scope
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: 2 warnings emitted
warning: unresolved link to `package`
--> crates/base_db/src/input.rs:181:15
|
181 | /// it's [package].name, can be different for other project types or even
| ^^^^^^^ no item named `package` in scope
|
= note: `#[warn(broken_intra_doc_links)]` on by default
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: unresolved link to `package`
--> crates/base_db/src/input.rs:181:15
|
181 | /// it's [package].name, can be different for other project types or even
| ^^^^^^^ no item named `package` in scope
|
= help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
warning: 2 warnings emitted
```
This does *not* fix the following warning, because it is actually rust
code and rustdoc is being over eager:
```
warning: Rust code block is empty
--> crates/parser/src/grammar.rs:16:5
|
16 | //! ```
| _____^
17 | | //! // test function_with_zero_parameters
18 | | //! // fn foo() {}
19 | | //! ```
| |_______^
|
help: mark blocks that do not contain Rust code as text
|
16 | //! ```text
| ^^^^^^^
```
https://github.com/rust-lang/rust/pull/79816 should make this
configurable so the warning can be `allow`ed.
7340: Remove obsolete RangeInfo usage in references r=Veykril a=Veykril
Didn't even realize these were only here for renaming as well!
bors r+
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
7336: Rename `CrateDefMap` to `DefMap` r=matklad a=jonas-schievink
I propose handling local items by computing a `DefMap` for every block expression, using the regular (early) name resolution algorithm. The result of that will be a `DefMap` that has a reference to the parent `DefMap`, which is either the one computed for the containing block expression, or the crate's root `DefMap`. Name resolution will fall back to a name in the parent `DefMap` if it cannot be resolved in the inner block.
The `DefMap`s computed for block expressions will go through a separate query that can be garbage-collected much more aggressively, since these `DefMap`s should be cheap to compute and are never part of a crate's public API.
The first step towards that is to make `CrateDefMap` not specific to crates anymore, hence this rename (if this plans sounds reasonable).
cc https://github.com/rust-analyzer/rust-analyzer/issues/7325 and https://github.com/rust-analyzer/rust-analyzer/issues/1165
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
7339: Delete optional arg for inline attr and add doc alias attr completion r=lnicola a=bnjjj
close#7167
Co-authored-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
7331: shrink_to_fit `TokenMap`'s backing storage r=jonas-schievink a=jonas-schievink
Reduces `HygieneFrameQuery`'s memory usage by like 10 MB or so
bors r+
Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
7291: Wrap remaining self/super/crate in Name{Ref} r=matklad a=Veykril
That should be the remaining special casing for `self` 🎉
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
I've noticed a bunch of "main loop too long" warnings in console when
typing in Cargo.toml. Profiling showed that the culprit is `rustc
--print cfg` call.
I moved it to the background project loading phase, where it belongs.
This highlighted a problem: we generally use single `cfg`, while it
really should be per crate.
7276: Remove map module from la-arena public API r=lnicola a=arzg
It’s unlikely that more items will be added to the module, so it’s simpler for users if `ArenaMap` is re-exported and the module made private.
This doesn’t compile for the same reason that #7275 doesn’t:
> This pull request doesn’t compile because dependencies on la-arena go through crates.io, so existing dependencies on the crate are referencing an old version. As such, this PR will only compile once a new la-arena version has been published.
Co-authored-by: Aramis Razzaghipour <aramisnoah@gmail.com>
7211: Fixed expr meta var after path colons in mbe r=matklad a=edwin0cheng
Fixes#7207
Added `L_DOLLAR` in `ITEM_RECOVERY_SET` , but I don't know whether it is a good idea.
r? @matklad
Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
7257: vfs documentation r=matklad a=arnaudgolfouse
This documents every item in the `vfs` crate, except for a few private, windows-specific items.
Co-authored-by: Arnaud <arnaud.golfouse@free.fr>
7110: Deduplicate macros when offering completion r=matklad a=AdnoC
Closes https://github.com/rust-analyzer/rust-analyzer/issues/7081
When iterating over the names within the `hir_def::resolver::Scope` for a module, track what macros are in the `hir_def::item_scope::ItemScope::legacy_macros` collection for the module. When iterating over names from the prelude, do not proccess the name if it had been in the `legacy_macros` collection.
This is implemented with a `FxHashSet` in the `Scope::process_names` function that is populated when iterating over `legacy_macros` and checked when iterating over the prelude.
Alternative implementation could instead query the `legacy_macros` `FxHashMap` directly when processing names in the prelude.
Also, I'd like to add a test for this, but I'm not sure where it could be added.
Co-authored-by: AdnoC <adam.r.cutler@gmail.com>
7260: Render Fn* trait objects and impl types as rust does r=matklad a=Veykril
Also fixes raw ptr impl types being rendered ambiguously with multiple predicates.
This moves out the `FamousDefs::Fixture` into its own file as well, cause I figured it is big enough to get its own file at this point + we also get highlighting this way when editing it.
Fixes#3012
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
7220: same level folder rename for will_rename_files r=kjeremy a=ShuiRuTian
use tricky way to support folder rename.
Another step after #7009 and for #4471
Co-authored-by: ShuiRuTian <158983297@qq.com>
Co-authored-by: Song Gao <158983297@qq.com>
7051: Check dbg! macro in tidy_test r=matklad a=edwin0cheng
Same as `check_todo` but for dbg! macro
r? @matklad
7219: Refactor rename name checking r=matklad a=Veykril
Improves the user facing error messages a bit and prevents renaming to `_` when the name is referenced as this would change source to not compile anymore since `_` is only a pattern, not a proper identifier.
7245: Encourage gifs r=matklad a=matklad
bors r+
🤖
7246: Unfreeze cargo_metadata r=matklad a=kjeremy
It now pulls in a newer version of semver-parser.
This does add a dependency on `cargo-platform` in the interest of correctness.
Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
Co-authored-by: kjeremy <kjeremy@gmail.com>
7235: Postfix completions like ifl now works with references r=Veykril a=Maan2003
Closes#7230
Co-authored-by: Manmeet <manmeetmann2003@gmail.com>
Co-authored-by: Manmeet Maan <manmeetmann2003@gmail.com>
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>
After we started reporting progress when running cargo check during
loading, it is possible to crash the client with two identical progress
tokens.
This points to a deeper issue: we might be running several cargo checks
concurrently, which doesn't make sense.
This commit linearizes all workspace fetches, making sure no updates are
lost.
As an additional touch, it also normalizes progress & result reporting,
to make sure they stand in sync.
6238: Split punctuation semantic highlighting up into more tags r=matklad a=Veykril
Open question would be the name of the delimiter modifiers. I chose them this was as I see them this way but from what I remember people tend to mix the names however they like. So maybe using `delimSquare`, `delimCurly`, `delimRound` would be better. That would also go well with `angle` becoming `delimAngle`?
Closes#6152
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
6980: Implement to support intra-doc link r=matklad a=sasurau4
Helps with #6168
This PR is very limited implementation to support intra-doc. It only support links indicate same file function.
I want someone to feedback me about this implementation. If the approach is good, I will continue this PR to support other symbols like enum and struct.
Co-authored-by: Daiki Ihara <sasurau4@gmail.com>
7224: Remove unnecessary allocation when checking whether to hide argument name hint r=jhpratt a=jhpratt
The case-insensitive prefix/suffix check can be performed
character-by-character. This allows the check to be done without having
to allocate a new string. As a side effect, it's also no longer
necessary to convert the entire string to lowercase, as it's done as
needed. As the only case equality we're handling is ASCII, this
operation can be further optimized by using byte equality, rather than
character equality.
cc @SomeoneToIgnore, as it's an update on my PR from yesterday.
Co-authored-by: Jacob Pratt <jacob@jhpratt.dev>
The case-insensitive prefix/suffix check can be performed
character-by-character. This allows the check to be done without having
to allocate a new string. As a side effect, it's also no longer
necessary to convert the entire string to lowercase, as it's done as
needed. As the only case equality we're handling is ASCII, this
operation can be further optimized by using byte equality, rather than
character equality.