Commit graph

20349 commits

Author SHA1 Message Date
bors
36f58f5fff Auto merge of #17670 - Veykril:mem, r=Veykril
LRU `body_with_source_map` query

This query is being invalidated all the time anyways (we have an extra query on top of it for the body incrementality that is not source dependent), so there is little reason to keep these around all the time when only some IDE features are interested in them.
2024-07-22 14:48:05 +00:00
Lukas Wirth
bd359b32b0 LRU body_with_source_map query 2024-07-22 16:34:59 +02:00
bors
9d86412498 Auto merge of #17668 - Veykril:incorrect-nevers, r=Veykril
Remove incorrect never! invocations

These can crop up when the `Future` related lang items are missing
2024-07-22 09:36:15 +00:00
bors
d092f7d78f Auto merge of #17542 - roife:fix-issue-17517, r=Veykril
feat: go-to-def and find-references on control-flow keywords

fix #17517.

This PR implements **go-to-definition** and **find-references** functionalities for control flow keywords, which is similar to the behaviors in the `highlight-related` module. Besides, this PR also fixes some incorrect behaviors in `highlight-related`.

## Changes

1. **Support for go-to-definition on control flow keywords**:
   This PR introduces functionality allowing users to navigate on the definition of control flow keywords (`return`, `break`, `continue`).
   Commit: 2a3244ee147f898dd828c06352645ae1713c260f..7391e7a608634709db002a4cb09229de4d12c056.

2. **Bug fixes and refactoring in highlight-related**:
   - **Handling return/break/continue within try_blocks**:
     This PR adjusted the behavior of these keywords when they occur within `try_blocks`. When encounter these keywords, the program should exit the outer function or loop which containing the `try_blocks`, rather than the `try_blocks` itself; while the `?` will cause the program to exit `try_blocks`.
     Commit: 59d697e807f0197f59814b37dca1563959da4aa1.
   - **Support highlighting keywords in macro expansion for highlight-related**:
     Commit: 88df24f01727c23a667a763ee3ee0cec22d5ad52.
   - Detailed description for the bug fixes
     + The previous implementation of `preorder_expr` incorrectly treated `try_blocks` as new contexts, thereby r-a will not continue to traverse inner `return` and `break/continue` statements. To resolve this, a new function `preorder_expr_with_ctx_checker` has been added, allowing users to specify which expressions to skip.
       * For example, when searching for the `?` in the context, r-a should skip `try_blocks` where the `?` insides just works for `try_blocks`. But when search for the `return` keyword, r-a should collect both the `return` keywords inside and outside the `try_blocks`
     + Thus, this PR added `WalkExpandedExprCtx` (builder pattern). It offers the following improvements: customizable context skipping, maintenance of loop depth (for `break`/`continue`), and handling macro expansion during traversal.

3. **Support for find-references on control flow keywords**:
   This PR enables users to find all references to control flow keywords.
   Commit: 9202a33f81218fb9c2edb5d42e6b4de85b0323a8.
2024-07-22 09:22:13 +00:00
bors
6f3030f316 Auto merge of #17586 - ShoyuVanilla:tuple-arg-macro-rest, r=Veykril
Allow macro expansions into `RestPat` in tuple args work as ellipsis like plain `RestPat`

Fixes #17292

Currently, Rust Analyzer lowers `ast::Pat::RestPat` into `Pat::Missing` in general cases on the following lines;

ffbc5ad993/crates/hir-def/src/body/lower.rs (L1359-L1367)

And in some proper positions such as `TupleStruct(..)`, it is specially handed on the following lines;

ffbc5ad993/crates/hir-def/src/body/lower.rs (L1429-L1437)

This behavior is reasonable because rustc does similar things in
62c068feea/compiler/rustc_ast_lowering/src/pat.rs (L108-L111)
and
62c068feea/compiler/rustc_ast_lowering/src/pat.rs (L123-L142)

But this sometimes works differently because Rust Analyzer expands macros while ast lowering;

ffbc5ad993/crates/hir-def/src/body/lower.rs (L1386-L1398)
ffbc5ad993/crates/hir-def/src/body/lower.rs (L941-L963)
but rustc uses expanded ast in the corresponding tuple-handling process, so it does not have macro patterns there.
62c068feea/compiler/rustc_ast_lowering/src/pat.rs (L114)

So, if a macro expansion in a tuple arg results in `..`, rustc permits it like plain `..` pattern, but Rust Analyzer rejects it.
This is the root cause of #17292 and this PR allows macros expanded into `..` in a tuple arg position work as ellipsis like that.
2024-07-22 09:08:12 +00:00
Lukas Wirth
5806950712 Remove incorrect never! invocations 2024-07-22 10:53:18 +02:00
bors
c29bac1cdf Auto merge of #17647 - joshka:jm/rename-commands, r=Veykril
Rename rust-analyzer commands

The commands `editor.action.triggerParameterHints` and
`editor.action.rename` are now renamed to
`rust-analyzer.triggerParameterHints` and `rust-analyzer.rename`

This change helps make it clear that these commands are specific to
rust-analyzer and not part of the default set of commands provided by
VSCode.

Fixes: https://github.com/rust-lang/rust-analyzer/issues/17644

Note: This seems like it will be a breaking change for any RA client that previously reacted to `editor.action.triggerParameterHints` - naive search: https://github.com/search?q=editor.action.triggerParameterHints+AND+%28NOT+is%3Afork%29+rust-analyzer&type=code
2024-07-22 08:10:03 +00:00
bors
274c214b16 Auto merge of #17666 - Veykril:simplify, r=Veykril
Simplify
2024-07-22 07:56:04 +00:00
Lukas Wirth
e3f16223c8 Simplify 2024-07-22 09:54:31 +02:00
bors
232e55515f Auto merge of #17660 - ObsidianMinor:fix/17645, r=Veykril
Fix more path resolution for included submodules

Now with more comprehensive testing! This adds tests for includes within modules. Previous testing was not comprehensive enough since submodules that use `include!` didn't actually work either! The `ModDir` used for resolving mods relative to included files has to be `ModDir::root()`. The original test just so happened to put the submodules in the root which made this work, but if you put the `include!` inside a `mod` block it didn't work.

With this change, when collecting a macro expansion, if the macro call is an `include!`, we use the `ModDir::root()` instead of the current module we're in.
2024-07-22 07:00:54 +00:00
bors
6512e29a80 Auto merge of #17658 - alibektas:rename_get_field, r=Veykril
minor: Rename `config::get_field` to `config::get_field_json`
2024-07-22 06:24:53 +00:00
Ali Bektas
e0db833082 Read rust-analyzer.toml files on startup 2024-07-22 02:42:39 +02:00
Sydney Acksman
cdd7b18149 Fix more path resolution for included submodules
Now with much more comprehensive testing! This
adds tests for includes within modules.
2024-07-21 19:04:19 -05:00
Ali Bektas
db2ba64540 Add FIXME to root ratoml tests. 2024-07-22 01:42:50 +02:00
Ali Bektas
4f8735fd56 Apply changes to ratoml/fixes 2024-07-22 01:33:15 +02:00
Ali Bektas
97bad3582a Minor fixes for ratoml module
- Parse errors are reflected as such by defining a new variant called `ConfigError::ParseError`
- New error collection has been added to store config level agnostic errors.
2024-07-22 01:31:38 +02:00
Ali Bektas
d4214ec502 Rename config::get_field to config::get_field_json 2024-07-21 22:52:37 +02:00
bors
4afe0d5393 Auto merge of #17657 - Veykril:cfg-slim, r=lnicola
internal: Make `CfgExpr` slimmer
2024-07-21 15:50:31 +00:00
Lukas Wirth
1141c35a4b Make CfgExpr slimmer 2024-07-21 14:50:44 +02:00
bors
db1343e1d6 Auto merge of #17656 - Veykril:flyimport-builtin-mod, r=Veykril
fix: Allow flyimport to import primitive shadowing modules

Fixes https://github.com/rust-lang/rust-analyzer/issues/16371
2024-07-21 11:35:12 +00:00
Lukas Wirth
0851d21d1e fix: Allow flyimport to import primitive shadowing modules 2024-07-21 13:26:19 +02:00
bors
e88946ace8 Auto merge of #17655 - Veykril:std-find-path, r=Veykril
More `find_path` improvements
2024-07-21 11:21:25 +00:00
Lukas Wirth
733cb1e645 Optimize find_path for sysroot library search some more 2024-07-21 13:20:12 +02:00
Lukas Wirth
4b2a123280 Fix visited module tracking not clearing itself on backtracking 2024-07-21 12:17:50 +02:00
Lukas Wirth
2a32976e90 Use out parameter instead of return value for find_path choice 2024-07-21 11:32:48 +02:00
Lukas Wirth
9fd6d26e97 Fix using wrong length for max_len arg 2024-07-21 11:16:23 +02:00
Lukas Wirth
2564b69e1d Specialize find_path local search 2024-07-21 11:10:15 +02:00
Lukas Wirth
a6e4ac705c Optimize find_path choice selection 2024-07-21 10:53:33 +02:00
bors
88258b7fd2 Auto merge of #17653 - Veykril:std-find-path, r=Veykril
Prefer standard library paths over shorter extern deps re-exports

This should generally speed up path finding for std items as we no longer bother looking through all external dependencies. It also makes more sense to prefer importing std items from the std dependencies directly.

Fixes https://github.com/rust-lang/rust-analyzer/issues/17540
2024-07-21 07:24:38 +00:00
Lukas Wirth
40bbc684ad Prefer standard library paths over shorter extern deps re-exports 2024-07-21 09:14:17 +02:00
bors
5f26438b5d Auto merge of #17650 - ObsidianMinor:fix/17645, r=Veykril
Fix path resolution for child mods of those expanded by `include!`

Child modules wouldn't use the correct candidate paths due to a branch that doesn't seem to be doing what it's intended to do. Removing the branch fixes the problem and all existing test cases pass.

Having no knowledge of how any of this works, I believe this fixes #17645. Using another test that writes the included mod directly into `lib.rs` instead, I found the difference can be traced to the candidate files we use to look up mods. A separate branch for if the file comes from an `include!` macro doesn't take into account the original mod we're contained within:

```rust
None if file_id.macro_file().map_or(false, |it| it.is_include_macro(db.upcast())) => {
    candidate_files.push(format!("{}.rs", name.display(db.upcast())));
    candidate_files.push(format!("{}/mod.rs", name.display(db.upcast())));
}
```

I'm not sure why this branch exists. Tracing the branch back takes us to 3bb9efb but it doesn't say *why* the branch was added. The test case that was added in this commit passes with the branch removed, so I think it's just superfluous at this point.
2024-07-21 06:17:14 +00:00
Mark Rousskov
f410a2d02f Allow deprecated temporarily to unblock version bump 2024-07-20 15:51:58 -04:00
Sydney Acksman
b9469f52a3 Fix path resolution for child mods of those expanded by include!
Child modules wouldn't use the correct candidate paths due to a branch that doesn't seem to be doing what it's intended to do. Removing the branch fixes the problem and all existing test cases pass.
2024-07-20 14:32:28 -05:00
bors
8d489e21eb Auto merge of #17649 - ShoyuVanilla:issue-17585, r=Veykril
fix: Panic in debug profile for tuple deconstruct with arity mismatch

Fixes #17585, which doesn't affect daily use cases but quite annoying in development of r-a itself like writing tests.

This PR applies similar approach as in #17534, skipping match usefulness check for patterns containing errors
2024-07-20 18:04:01 +00:00
Shoyu Vanilla
6e728df43a fix: Panic in debug profile for tuple deconstruct with arity mismatch 2024-07-21 02:37:37 +09:00
Josh McKinney
5b1a5a250b
Rename rust-analyzer commands
The commands `editor.action.triggerParameterHints` and
`editor.action.rename` are now renamed to
`rust-analyzer.triggerParameterHints` and `rust-analyzer.rename`

This change helps make it clear that these commands are specific to
rust-analyzer and not part of the default set of commands provided by
VSCode.

Fixes: https://github.com/rust-lang/rust-analyzer/issues/17644
2024-07-20 01:11:14 -07:00
Lukas Wirth
41603ab14e Add missing dyn parse special cases in 2015 edition 2024-07-20 09:18:40 +02:00
bors
062822ce91 Auto merge of #17641 - nyurik:optimize-refs, r=Veykril
Avoid ref when using format! in compiler

Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing). Inlining format args prevents accidental `&` misuse.

See https://github.com/rust-lang/rust-clippy/issues/10851
2024-07-20 06:40:27 +00:00
Lukas Wirth
3092e1c0b1
Keep references in format! when the target is unsized 2024-07-20 08:39:04 +02:00
Laurențiu Nicola
1075978bed Fix some typos 2024-07-20 08:30:22 +03:00
Young-Flash
18e7299997 minor: tweak comment 2024-07-20 09:33:23 +08:00
Young-Flash
a2d142b9f2 internal: add test case for inlay hint support for block expr with lifetime label 2024-07-20 09:33:23 +08:00
Young-Flash
0416dec50a feat: add inlay hint support for block expr with lifetime label 2024-07-20 09:33:23 +08:00
bors
b333f85a9d Auto merge of #17639 - Veykril:salsa-perf, r=Veykril
Some more small salsa memory improvements

This does limit our lru limits to 2^16 but if you want to set them higher than that you might as well not set them at all. Also makes `LRU` opt-in per query now, allowing us to drop all the unnecessary LRU stuff for most queries
2024-07-19 18:45:16 +00:00
Yuri Astrakhan
cc1aded86c Avoid ref when using format! in compiler
Clean up a few minor refs in `format!` macro, as it has a performance cost. Apparently the compiler is unable to inline `format!("{}", &variable)`, and does a run-time double-reference instead (format macro already does one level referencing). Inlining format args prevents accidental `&` misuse.
2024-07-19 14:41:59 -04:00
Lukas Wirth
09ef75c717 Add back equality check that went missing 2024-07-19 20:39:09 +02:00
Lukas Wirth
92f5e806f1 Fix edition used for include macro parsing 2024-07-19 20:29:53 +02:00
Lukas Wirth
f4199f786e Parse contextual dyn keyword properly in edition 2015 2024-07-19 20:20:30 +02:00
roife
f027a46d94 internal: move NavigationTarget::from_expr to goto_definition 2024-07-20 01:58:51 +08:00
roife
1b59cf2d52 fix: sort references in tests 2024-07-20 01:55:55 +08:00
roife
55cd8ab904 fix: handle highlightings inside macro calls & only highlight kws in current file 2024-07-20 01:45:51 +08:00
roife
d94dcfa841 fix: ensure that highlight_related works for macro_expr 2024-07-20 01:42:52 +08:00
roife
ae6e8d56d4 use token_ancestors_with_macros to simplify goto-def on kw 2024-07-20 01:42:52 +08:00
roife
22c5924080 fix: navigate to label directly when perform 'goto-def' on control-flow kw
See https://github.com/rust-lang/rust-analyzer/pull/17542#discussion_r1667656190
2024-07-20 01:42:52 +08:00
roife
07570bac66 feat: find references on control-flow kws 2024-07-20 01:42:52 +08:00
roife
3650b40714 fix: keyword highlighting in macro expansion 2024-07-20 01:42:52 +08:00
roife
1bca00d1bc fix: incorrect highlighting of try blocks with control flow kws 2024-07-20 01:42:51 +08:00
roife
a93a7c2403 fix: ensure that goto-def works on fn/try/async kw 2024-07-20 01:41:01 +08:00
roife
37085d9dcd feat: goto-def on keywords 2024-07-20 01:41:00 +08:00
Lukas Wirth
a324e46b0b Drop an unnecessary Arc::clone 2024-07-19 18:53:52 +02:00
Lukas Wirth
89bcc79b5d Regenerate files 2024-07-19 18:39:42 +02:00
Lukas Wirth
6d4989b3c7 Make LRU opt-in 2024-07-19 18:38:08 +02:00
Lukas Wirth
7fcac48023 Remove duplicate information from interned::Slot 2024-07-19 17:52:49 +02:00
bors
9fd6c695da Auto merge of #17638 - Veykril:salsa-perf, r=Veykril
perf: Reduce memory usage of salsa slots by 8 bytes
2024-07-19 15:48:57 +00:00
Lukas Wirth
8e3133f118 Reduce maximum LRU size to 2^16 entries, reducing memory footprint of LRU entries 2024-07-19 17:48:12 +02:00
Lukas Wirth
4691ca97f1 perf: Reduce memory usage of salsa slots by 8 bytes 2024-07-19 17:34:48 +02:00
bors
aa4768f7be Auto merge of #17622 - roife:fix-issue-17602, r=Veykril
fix: handle synonymous imports with different renaming in 'merge imports'

fix #17602
2024-07-19 15:16:02 +00:00
bors
fa3dd33c27 Auto merge of #17620 - Veykril:edition-aware-parser, r=Veykril
Edition aware parser

Fixes https://github.com/rust-lang/rust-analyzer/issues/16324 by allowing us to properly thread through the edition to the parser
2024-07-19 14:56:56 +00:00
Lukas Wirth
546eb6b530 Test macros doing edition dependent parsing 2024-07-19 16:43:58 +02:00
Lukas Wirth
2c32ee7cfa Prevent generated runner module from being format checked 2024-07-19 16:01:47 +02:00
Lukas Wirth
d235d09bf9 Parse try as a keyword only in edition 2018 and up 2024-07-19 15:43:20 +02:00
Lukas Wirth
713c47f25b Add basic edition inline parser test support 2024-07-19 15:19:43 +02:00
bors
52143a5ac0 Auto merge of #17246 - davidbarsky:david/move-rust-project-generation-to-server, r=Veykril
feature: teach rust-analyzer to discover `linked_projects`

This PR's been a long-time coming, but like the title says, it introduces server-side project discovery and removes the extension hooks I previously introduced. I don't think this PR is ready to land, but here are the things I'm feeling squishy about:
- I don't think I like the idea of introducing the `cargo-metadata` command-but-for-everything-else in the `flycheck` module, but the progress reporting infrastructure was too convenient to pass up. Happy to move it elsewhere.

Here are the things I _know_ I need to change:
- For progress reporting, I'm extracting from a `serde_json::Value` that corresponds to `tracing_subsciber::fmt::Layer`'s JSON output. I'd like to make this a bit more structured/documented than the current nonsense I wrote.
- The progress reporting currently hardcodes "Buck"; it should be deriving that from the previously mentioned more-structured-output.
- This doesn't handle *reloading* when a corresponding buildfile is changed. It should be doing that.

<details>
<summary>Anyway, here's a video of rust-analyzer discovering a Buck target.</summary>

https://github.com/rust-lang/rust-analyzer/assets/2067774/be6cd9b9-2c9a-402d-847f-05f860a91df1
</details>
2024-07-18 16:15:31 +00:00
David Barsky
db43a5a6e9 feature: move linked_projects discovery to the rust-analyzer server 2024-07-18 12:01:27 -04:00
Lukas Wirth
7a5bf92b89 Rewrite inline parser test infra to generated proper rust test cases 2024-07-18 10:03:19 +02:00
Lukas Wirth
ef462ca88e Update test fixtures 2024-07-18 09:09:31 +02:00
Lukas Wirth
5264f86242 Encode edition within FileId in the hir layer 2024-07-18 08:49:10 +02:00
roife
87a3ab4658 fix: handle synonymous imports in 'merge imports' 2024-07-18 05:01:58 +08:00
bors
a62ea0a59e Auto merge of #17618 - Veykril:rustc_skip_during_method_dispatch, r=Veykril
Support rustc_skip_during_method_dispatch

Fixes https://github.com/rust-lang/rust-analyzer/issues/17256
2024-07-17 09:48:18 +00:00
Lukas Wirth
92268627a8 Support rustc_skip_during_method_dispatch 2024-07-17 11:46:36 +02:00
bors
b78cc87b1b Auto merge of #17617 - Veykril:grammar-kind-gen, r=Veykril
Derive kinds information from ungrammar file

This reduces the need to touch more files when adding a new grammar rule
2024-07-17 09:27:03 +00:00
Lukas Wirth
b8cac1bb6b string is not a keyword 2024-07-17 11:11:57 +02:00
Lukas Wirth
7011094685 Add always disabled gen parse support 2024-07-17 10:49:12 +02:00
Lukas Wirth
983c9c122e Derive kinds information from ungrammar file 2024-07-17 10:04:45 +02:00
bors
3fa78e113b Auto merge of #17616 - Veykril:config-param-hints, r=Veykril
Fix incorrect generic parameter hint defaults

Missed this in the review but we should show const param hints, not lifetime param hints by default
2024-07-17 06:54:06 +00:00
Lukas Wirth
8f044d9681 Fix incorrect generic parameter hint defaults 2024-07-17 08:52:23 +02:00
Laurențiu Nicola
f0c3cb3738 Add --keep-going to rust-analyzer.cargo.buildScripts.overrideCommand docs 2024-07-17 08:42:39 +03:00
bors
26747bd1e5 Auto merge of #17611 - Veykril:macro-arg-no-call, r=Veykril
fix: Don't call macro_arg directly in `ExpandDatabase::syntax_context`
2024-07-16 20:12:14 +00:00
Lukas Wirth
e75dbe52a1 Don't call macro_arg directly in ExpandDatabase::syntax_context 2024-07-16 22:10:42 +02:00
bors
cf156a7a43 Auto merge of #17609 - lnicola:sync-from-rust, r=lnicola
minor: Sync from downstream
2024-07-16 13:38:39 +00:00
Laurențiu Nicola
6a121d177d Merge from rust-lang/rust 2024-07-16 16:23:47 +03:00
Lukas Wirth
33ce9a4211 Set RUSTC_SYSROOT for runnables 2024-07-16 13:48:14 +02:00
bors
f5efae854c Auto merge of #127617 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer`

r? `@ghost`
2024-07-16 10:54:30 +00:00
Lukas Wirth
2346a80ab4 Remove Name::to_smol_str 2024-07-16 12:43:58 +02:00
Lukas Wirth
df5f1777b8 More symbol usage 2024-07-16 12:05:16 +02:00
Lukas Wirth
c30bdfcc84 Use symbol in cfg 2024-07-16 10:41:42 +02:00
Lukas Wirth
93024ad411 Switch token trees to use Symbols 2024-07-16 10:11:59 +02:00
Laurențiu Nicola
5f9ce1dcd4 Use re-exported Idx and IndexVec in pat_analysis 2024-07-16 10:41:13 +03:00
Lukas Wirth
05ce57efd5 Fix incorrect encoding of literals in the proc-macro-api on version 4 2024-07-15 14:51:01 +02:00
bors
f913901399 Auto merge of #17559 - Veykril:tokentree, r=Veykril
Encode ident rawness and literal kind separately in tt::Leaf
2024-07-15 11:25:51 +00:00