Commit graph

20704 commits

Author SHA1 Message Date
bors
5350c65443 Auto merge of #17991 - ChayimFriedman2:extract-variable-ref, r=Veykril
fix: Don't add reference when it isn't needed for the "Extract variable" assist

I.e. don't generate `let var_name = &foo()`. Because it always irritates me when I need to fix that.

Anything that creates a new value don't need a reference. That excludes mostly field accesses and indexing.

I had a thought that we can also not generate a reference for fields and indexing as long as the type is `Copy`, but sometimes people impl `Copy` even when they don't want to copy the values (e.g. a large type), so I didn't do that.
2024-08-29 08:14:04 +00:00
bors
d9be51bbc9 Auto merge of #17987 - ChayimFriedman2:column-macro, r=Veykril
fix: Fix name resolution of shadowed builtin macro

Fixes #17969.
2024-08-29 07:59:12 +00:00
bors
fc08e04570 Auto merge of #17988 - darichey:fix-scip-def, r=Veykril
Fix incorrect symbol definitions in SCIP output

The SCIP output incorrectly marks some symbols as definitions because it doesn't account for the file ID when comparing the token's range to its definition's range.

This means that if a symbol is referenced in a file at the same position at which it is defined in another file, that reference will be marked as a definition. I was quite surprised by how common this is. For example, `PartialEq` is defined [here](https://github.com/rust-lang/rust/blob/1.80.1/library/core/src/cmp.rs#L273) and `uuid` references it [here](https://github.com/uuid-rs/uuid/blob/1.8.0/src/lib.rs#L329). And what do you know, they're both at offset 10083! In our large monorepo, this happens for basically every common stdlib type!
2024-08-29 07:44:29 +00:00
bors
07a66c475c Auto merge of #17940 - ChayimFriedman2:closure-to-fn, r=Veykril
feat: Create an assist to convert closure to freestanding fn

The assist converts all captures to parameters.

Closes #17920.

This was more work than I though, since it has to handle a bunch of edge cases...

Based on #17941. Needs to merge it first.
2024-08-29 07:21:46 +00:00
Laurențiu Nicola
2c6dc024d3 Merge from rust-lang/rust 2024-08-29 10:02:18 +03:00
Lukas Wirth
abed6e24a8 fix: Fix TokenStream::to_string implementation dropping quotation marks 2024-08-29 08:45:35 +02:00
Lukas Wirth
d6666b16c4 fix: Fix proc-macro server crashing when parsing a non-lexable string into a TokenStream 2024-08-29 08:45:19 +02:00
bors
6f3356d0dd Auto merge of #17992 - Wilfred:newlines_in_logs, r=Veykril
internal: Avoid newlines in fetch errors

Most logs lines don't have newlines, ensure fetch errors follow this pattern. This makes it easier to see which log line is associated with the error.

Before:

    2024-08-28T21:11:58.431856Z ERROR FetchWorkspaceError:
    rust-analyzer failed to discover workspace

After:

    2024-08-28T21:11:58.431856Z ERROR FetchWorkspaceError: rust-analyzer failed to discover workspace
2024-08-29 04:52:11 +00:00
David Richey
2b3183500a Fix incorrect symbol definitions in SCIP output 2024-08-28 19:57:26 -05:00
Wilfred Hughes
730e7fb9b3 internal: Add doc comments to OpQueue 2024-08-28 16:29:18 -07:00
Chayim Refael Friedman
1fc6cbc6f1 Consider field attributes when converting from tuple to named struct and the opposite 2024-08-29 01:14:25 +03:00
Chayim Refael Friedman
f297860715 Also handle deref expressions in "Extract variable"
And BTW, remove the parentheses of the extracted expression if there are.
2024-08-29 00:35:45 +03:00
Wilfred Hughes
efdfb7998f internal: Avoid newlines in fetch workspace errors
Most logs lines don't have newlines, ensure fetch workspace errors follow this
 pattern.

Before:

2024-08-28T21:11:58.431856Z ERROR FetchWorkspaceError:
rust-analyzer failed to discover workspace

After:

2024-08-28T21:11:58.431856Z ERROR FetchWorkspaceError: rust-analyzer failed to discover workspace
2024-08-28 14:18:45 -07:00
Chayim Refael Friedman
1663891d3d Don't add reference when it isn't needed for the "Extract variable" assist
I.e. don't generate `let var_name = &foo()`.

Anything that creates a new value don't need a reference. That excludes mostly field accesses and indexing.

I had a thought that we can also not generate a reference for fields and indexing as long as the type is `Copy`, but sometimes people impl `Copy` even when they don't want to copy the values (e.g. a large type), so I didn't do that.
2024-08-29 00:10:26 +03:00
Chayim Refael Friedman
70c53a6903 Consider all expressions that autoderef in "Extract variable", not just method and field accesses. 2024-08-28 23:55:31 +03:00
Chayim Refael Friedman
1cd707e693 Fix name resolution of shadowed builtin macro 2024-08-28 23:20:46 +03:00
Ali Bektas
5e6f5b1f38 Minor errors 2024-08-28 19:40:58 +02:00
Ali Bektas
987a9342ad Remove invalid tests 2024-08-28 19:33:21 +02:00
Ali Bektas
23eb20794e Make almost every client config global 2024-08-28 19:33:21 +02:00
Ali Bektas
a7207f4b64 Make completion_* local 2024-08-28 19:33:21 +02:00
Ali Bektas
eef79b4e47 Make diagnostics_* local 2024-08-28 19:33:21 +02:00
Ali Bektas
3a4efb4141 Make workspace_symbol_search_* workspace 2024-08-28 19:33:21 +02:00
Ali Bektas
e4edbf4601 Make procMacro_* workspace 2024-08-28 19:33:21 +02:00
Ali Bektas
c304ceeb4c Make rustc_* workspace 2024-08-28 19:33:21 +02:00
Ali Bektas
65d39f32d6 Make runnables workspace 2024-08-28 19:33:21 +02:00
Ali Bektas
c3acdc2fa1 Make check workspace 2024-08-28 19:33:20 +02:00
Ali Bektas
f09997993b Make checkOnSave workspace 2024-08-28 19:30:58 +02:00
Ali Bektas
100d3f9c06 Make cargo_ workspace again 2024-08-28 19:30:55 +02:00
bors
f454ea8771 Auto merge of #17981 - lnicola:proc-macro-cwd, r=Veykril
minor: Fix cwd used for proc macro expansion

Fixes #17980.
2024-08-28 10:36:11 +00:00
Laurențiu Nicola
5f7bda743f Fix cwd used for proc macro expansion 2024-08-28 13:20:21 +03:00
Chayim Refael Friedman
0e4f4d3f9c Create an assist to convert closure to freestanding fn
The assist converts all captures to parameters.
2024-08-27 17:07:55 +03:00
bors
8db40df2a3 Auto merge of #17757 - alibektas:toggle_macro_delimiters, r=Veykril
assist: Add new assist toggle_macro_delimiter

Closes #17716
2024-08-27 12:25:43 +00:00
Lukas Wirth
a7c519c98f Fix tests 2024-08-27 14:23:23 +02:00
bors
b675c93fc5 Auto merge of #17974 - lnicola:rm-apache-appendix, r=lnicola
internal: Drop Apache license appendices

Closes #14586

Similar to https://github.com/rust-lang/rust/pull/67734
2024-08-27 12:08:25 +00:00
bors
06a40a61b0 Auto merge of #17973 - Veykril:proc-macro-curr-dir, r=Veykril
Expand proc-macros in workspace root, not package root

Should fix https://github.com/rust-lang/rust-analyzer/issues/17748. The approach is generally not perfect though as rust-project.json projects don't benefit from this (still, nothing changes in that regard)
2024-08-27 11:53:04 +00:00
Laurențiu Nicola
90f903b521 Drop Apache license appendices 2024-08-27 14:52:34 +03:00
Lukas Wirth
9a47e6f2c8 Expand proc-macros in workspace root, not package root 2024-08-27 13:40:24 +02:00
bors
66b9b56853 Auto merge of #17970 - ChayimFriedman2:unwrap-unsafe-block, r=Veykril
fix: Fix "Unwrap block" assist with block modifiers

The assist just assumes the `{` will be the first character, which led to strange outputs such as `nsafe {`.

Fixes #17964.
2024-08-27 09:17:10 +00:00
Lukas Wirth
fa48bc216c
Revert "feat: Implement module_path macro" 2024-08-27 08:19:09 +02:00
Chayim Refael Friedman
104c29764b Fix "Unwrap block" assist with block modifiers
The assist just assumes the `{` will be the first character, which led to strange outputs such as `nsafe {`.
2024-08-26 19:02:36 +03:00
bors
095926ea6f Auto merge of #17963 - avrong:avrong/error-lifetimes, r=Veykril
Always show error lifetime arguments as `'_`

Fixes #17947

Changed error lifetime argument presentation in non-test environment to `'_` and now showing them even if all of args are error lifetimes.

This also influenced some of the other tests like `extract_function.rs`, `predicate.rs` and `type_pos.rs`. Not sure whether I need to refrain from adding lifetimes args there. Happy to fix if needed
2024-08-26 10:06:21 +00:00
Aleksei Trifonov
f1b4a9cfb0 Show lifetime args if there are only error ones 2024-08-26 12:19:50 +03:00
Aleksei Trifonov
7ea4241afa Show and render error lifetime args as '_ 2024-08-26 12:19:42 +03:00
bors
0ad26e6025 Auto merge of #17941 - ChayimFriedman2:pre-closure-to-fn, r=Veykril
Preliminary work for #17940

I split the PR as requested, and made small commits.
2024-08-26 08:09:15 +00:00
Chayim Refael Friedman
21e6058ab7 Fix Return Type Syntax to include .. (i.e. method(..) and not method()) as specified in the RFC 2024-08-26 01:45:52 +03:00
bors
7106cd3be5 Auto merge of #17960 - duncanawoods:master, r=HKalbasi
fix: add extra_test_bin_args to test explorer test runner

`@HKalbasi` I thought I included this in #17470 but it appears not so I have created a new issue #17959 for this fix.
2024-08-25 11:48:32 +00:00
bors
316590f5b1 Auto merge of #17961 - Veykril:autoderef-alloc, r=Veykril
internal: Don't allocate autoderef steps when not needed
2024-08-25 11:13:53 +00:00
Lukas Wirth
b6ed2f5a41 internal: Don't allocate autoderef steps when not needed 2024-08-25 13:12:07 +02:00
duncan
18081eabd0 fix: add extra_test_bin_args to test explorer test runner
trim whitespace
2024-08-25 12:11:36 +01:00
bors
071997d475 Auto merge of #17958 - Veykril:deref-chain-method-completions, r=Veykril
fix: Fix trait method completions not acknowledging Deref impls
2024-08-25 08:56:23 +00:00
Lukas Wirth
737d5088e5 fix: Fix trait method completions not acknowledging Deref impls 2024-08-25 10:47:30 +02:00
bors
f4dbbac7ca Auto merge of #17956 - Veykril:metadata-err, r=Veykril
fix: Fix metadata retrying eating original errors
2024-08-25 07:30:09 +00:00
Lukas Wirth
191949eabe fix: Fix metadata retrying eating original errors 2024-08-25 09:28:47 +02:00
Chayim Refael Friedman
b98278307e Don't enable the search fast path for short associated functions when a search scope is set
In most places where we set a search scope it is a single file, and so the fast path will actually harm performance, since it has to search for aliases in the whole project.
The only exception that qualifies for the fast path is SSR (there is an exception that don't qualify for the fast path as it search for `use` items). It sets the search scope to avoid dependencies. We could make it use the fast path, but I didn't bother.
2024-08-25 04:35:58 +03:00
Chayim Refael Friedman
52462ada22 Impl PartialEq and Eq for IndentLevel
We can impl PartialOrd and Ord too, but I didn't need that.
2024-08-24 23:46:32 +03:00
Chayim Refael Friedman
5c59a718c5 Provide impl From<ast::TypeOrConstParam> for ast::GenericParam 2024-08-24 23:46:32 +03:00
Chayim Refael Friedman
ddbb28daa0 Modify hacks::parse_expr_from_str() to take an edition too
This will be needed as we parse unknown identifiers and want to insert them into source code.
2024-08-24 23:46:32 +03:00
Chayim Refael Friedman
e6d59e65ec Add helper methods to retrieve Future::Output and Iterator::Item 2024-08-24 23:46:32 +03:00
Chayim Refael Friedman
34920dde8d Provide Future::Output and Iterator lang items 2024-08-24 23:46:32 +03:00
Chayim Refael Friedman
3712bb7f6a Handle associated types that are lang items
Previously we were ignoring them.
2024-08-24 23:46:32 +03:00
Chayim Refael Friedman
cc07652be5 Add gen modifier to functions
We don't yet lower or maybe even parse them, but blocks already have `gen`, so why not.
2024-08-24 23:46:32 +03:00
Chayim Refael Friedman
506b9663bf Preserve all spans for closure captures, not just one
This is important for the "convert closure to fn" assist, as it needs to find and modify the places the captures are used.
2024-08-24 23:46:32 +03:00
Chayim Refael Friedman
da931e7398 Fix few bugs in closure capture computation, and add tests
Also create a test infrastructure for capture computation.
2024-08-24 22:35:49 +03:00
Wilfred Hughes
fa83d3c414 Include buildfile path in watcher list 2024-08-23 17:49:03 -07:00
Shoyu Vanilla
ad05705a4c fix: Wrong Self: Sized predicate for trait assoc items 2024-08-24 01:28:48 +09:00
bors
ae420e353e Auto merge of #17857 - ChayimFriedman2:rust-project-cfg-group, r=Veykril
feat: Allow declaring cfg groups in rust-project.json, to help sharing common cfgs

Closes #17815.
2024-08-23 10:01:35 +00:00
bors
4be461788a Auto merge of #17946 - Veykril:flycheck-crates-for, r=Veykril
internal: Don't requery crates_for for flycheck when crates are known
2024-08-23 09:47:05 +00:00
Lukas Wirth
806d54c18a internal: Don't requery crates_for for flycheck when crates are known 2024-08-23 11:45:47 +02:00
bors
33c1f57a1a Auto merge of #17936 - Veykril:module_path, r=Veykril
feat: Implement `module_path` macro

Turns out this is a pain to implement because of our hir-def hir-expand split :)
2024-08-23 09:32:27 +00:00
bors
2025b43653 Auto merge of #17927 - ChayimFriedman2:speedup-new-usages, r=Veykril
perf: Speed up search for short associated functions, especially very common identifiers such as `new`

`@Veykril` said in https://github.com/rust-lang/rust-analyzer/pull/17908#issuecomment-2292958068 that people complain searches for `new()` are slow (they are right), so here I am to help!

The search is used by IDE features such as rename and find all references.

The search is slow because we need to verify each candidate, and that requires analyzing it; the key to speeding it up is to avoid the analysis where possible.

I did that with a bunch of tricks that exploits knowledge about the language and its possibilities. The first key insight is that associated methods may only be referenced in the form `ContainerName::func_name` (parentheses are not necessary!) (Rust doesn't include a way to `use Container::func_name`, and even if it will in the future most usages are likely to stay in that form.

Searching for `::` will help only a bit, but searching for `Container` can help considerably, since it is very rare that there will be two identical instances of both a container and a method of it.

However, things are not as simple as they sound. In Rust a container can be aliased in multiple ways, and even aliased from different files/modules. If we will try to resolve the alias, we will lose any gain from the textual search (although very common method names such as `new` will still benefit, most will suffer because there are more instances of a container name than its associated item).

This is where the key trick enters the picture. The key insight is that there is still a textual property: a container namer cannot be aliased, unless its name is mentioned in the alias declaration, or a name of alias of it is mentioned in the alias declaration.

This becomes a fixpoint algorithm: we expand our list of aliases as we collect more and more (possible) aliases, until we eventually reach a fixpoint. A fixpoint is not guaranteed (and we do have guards for the rare cases where it does not happen), but it is almost so: most types have very few aliases, if at all.

We do use some semantic information while analyzing aliases. It's a balance: too much semantic analysis, and the search will become slow. But too few of it, and we will bring many incorrect aliases to our list, and risk it expands and expands and never reach a fixpoint. At the end, based on benchmarks, it seems worth to do a lot to avoid adding an alias (but not too much), while it is worth to do a lot to avoid the need to semantically analyze func_name matches (but again, not too much).

After we collected our list of aliases, we filter matches based on this list. Only if a match can be real, we do semantic analysis for it.

The results are promising: searching for all references on `new()` in `base-db` in the rust-analyzer repository, which previously took around 60 seconds, now takes as least as two seconds and a half (roughly), while searching for `Vec::new()`, almost an upper bound to how much a symbol can be used, that used to take 7-9 minutes(!) now completes in 100-120 seconds, and with less than half of non-verified results (aka. false positives).

This is the less strictly correct (but faster) branch of this patch; it can miss some (rare) cases (there is a test for that - `goto_ref_on_short_associated_function_complicated_type_magic_can_confuse_our_logic()`). There is another branch that have no false negatives but is slower to search (`Vec::new()` never reaches a fixpoint in aliases collection there). I believe it is possible to create a strategy that will have the best of both worlds, but it will involve significant complexity and I didn't bother, especially considering that in the vast majority of the searches the other branch will be more than enough. But all in all, I decided to bring this branch (of course if the maintainers will agree), since our search is already not 100% accurate (it misses macros), and I believe there is value in the additional perf.

You can find the strict branch at https://github.com/ChayimFriedman2/rust-analyzer/tree/speedup-new-usages-strict.

Should fix #7404, I guess (will check now).
2024-08-23 09:17:47 +00:00
Lukas Wirth
afcf3f2b28
Remove incorrect FIXME comment 2024-08-23 11:05:25 +02:00
bors
44fd708415 Auto merge of #17912 - alibektas:cargo_check_on_binary, r=Veykril
fix: run flycheck without rev_deps when target is specified

Since querying for a crate's target is a call to salsa and therefore blocking, flycheck task is now deferred out of main thread by using `GlobalState`s `deferred_task_queue`. Fixes #17829  and https://github.com/rust-lang/rustlings/issues/2071
2024-08-23 09:03:11 +00:00
Ali Bektas
03456c545f Apply changes 2024-08-22 23:59:01 +02:00
Chayim Refael Friedman
6a910f637e Add cov_marks to test #17927 2024-08-22 20:52:51 +03:00
Chayim Refael Friedman
d89bdd9b83 Speed up search for short associated functions, especially very common identifiers such as new
The search is used by IDE features such as rename and find all references.

The search is slow because we need to verify each candidate, and that requires analyzing it; the key to speeding it up is to avoid the analysis where possible.

I did that with a bunch of tricks that exploits knowledge about the language and its possibilities. The first key insight is that associated methods may only be referenced in the form `ContainerName::func_name` (parentheses are not necessary!) (Rust doesn't include a way to `use Container::func_name`, and even if it will in the future most usages are likely to stay in that form.

Searching for `::` will help only a bit, but searching for `Container` can help considerably, since it is very rare that there will be two identical instances of both a container and a method of it.

However, things are not as simple as they sound. In Rust a container can be aliased in multiple ways, and even aliased from different files/modules. If we will try to resolve the alias, we will lose any gain from the textual search (although very common method names such as `new` will still benefit, most will suffer because there are more instances of a container name than its associated item).

This is where the key trick enters the picture. The key insight is that there is still a textual property: a container namer cannot be aliased, unless its name is mentioned in the alias declaration, or a name of alias of it is mentioned in the alias declaration.

This becomes a fixpoint algorithm: we expand our list of aliases as we collect more and more (possible) aliases, until we eventually reach a fixpoint. A fixpoint is not guaranteed (and we do have guards for the rare cases where it does not happen), but it is almost so: most types have very few aliases, if at all.

We do use some semantic information while analyzing aliases. It's a balance: too much semantic analysis, and the search will become slow. But too few of it, and we will bring many incorrect aliases to our list, and risk it expands and expands and never reach a fixpoint. At the end, based on benchmarks, it seems worth to do a lot to avoid adding an alias (but not too much), while it is worth to do a lot to avoid the need to semantically analyze func_name matches (but again, not too much).

After we collected our list of aliases, we filter matches based on this list. Only if a match can be real, we do semantic analysis for it.

The results are promising: searching for all references on `new()` in `base-db` in the rust-analyzer repository, which previously took around 60 seconds, now takes as least as two seconds and a half (roughly), while searching for `Vec::new()`, almost an upper bound to how much a symbol can be used, that used to take 7-9 minutes(!) now completes in 100-120 seconds, and with less than half of non-verified results (aka. false positives).

This is the less strictly correct (but faster) of this patch; it can miss some (rare) cases (there is a test for that - `goto_ref_on_short_associated_function_complicated_type_magic_can_confuse_our_logic()`). There is another branch that have no false negatives but is slower to search (`Vec::new()` never reaches a fixpoint in aliases collection there). I believe it is possible to create a strategy that will have the best of both worlds, but it will involve significant complexity and I didn't bother, especially considering that in the vast majority of the searches the other branch will be more than enough. But all in all, I decided to bring this branch (of course if the maintainers will agree), since our search is already not 100% accurate (it misses macros), and I believe there is value in the additional perf.
2024-08-22 20:52:51 +03:00
Chayim Refael Friedman
2fa0d4e2a8 When descending into macros in search, first check if there is a need to - i.e. if we are inside a macro call
This avoids the need to analyze the file when we are not inside a macro call.

This is especially important for the optimization in the next commit(s), as there the common case will be to descent into macros but then not analyze.
2024-08-22 20:52:51 +03:00
bors
9b724459b5 Auto merge of #17943 - Veykril:diags, r=Veykril
fix: Improve proc-macro panic message and workspace loading failure diagnostic
2024-08-22 16:47:56 +00:00
Lukas Wirth
ada65feaa1 Improve proc-macro panic message and workspace loading failure diagnostic 2024-08-22 18:46:23 +02:00
bors
a84c3d4d08 Auto merge of #17898 - Veykril:descend-2.0, r=Veykril
internal: Improve macro token mapping heuristics

Fixes https://github.com/rust-lang/rust-analyzer/issues/16235
2024-08-22 16:17:22 +00:00
Lukas Wirth
f854e19ef0 Fix sorting order for tokens in hover 2024-08-22 18:08:36 +02:00
Lukas Wirth
46feeb3f05 Consider interleaving hover kinds 2024-08-22 17:29:32 +02:00
Lukas Wirth
01fc1e57d2 Sort hover results by relevance 2024-08-22 17:01:51 +02:00
Lukas Wirth
c2a07e21f5 Thread file id through descension API for semantic highlighting 2024-08-22 16:45:37 +02:00
Lukas Wirth
354ab7a9e8 Rename macro descension functions 2024-08-22 16:24:01 +02:00
Lukas Wirth
64064907ce Fully remove old macro descension API 2024-08-22 16:18:01 +02:00
Lukas Wirth
495118015e Remove DescendPreference::SameKind 2024-08-22 16:00:57 +02:00
hkalbasi
850a83c7ce Implement floating point casts in const eval 2024-08-22 09:16:00 -04:00
Lukas Wirth
ce8f32022b Drop MacroInputKind 2024-08-22 12:39:53 +02:00
Lukas Wirth
f979667fb5 Remove DescendPreference::SameText 2024-08-22 12:34:20 +02:00
Shoyu Vanilla
71080cfb6b fix: Wrong Sized predicate for generic_predicates_for_param 2024-08-22 00:32:44 +09:00
Lukas Wirth
d44a3ab30c internal: Implement module_path macro 2024-08-21 13:50:05 +02:00
Ali Bektas
ffc3bfe435 Run flycheck only on crate if target is binary. 2024-08-21 01:39:16 +02:00
bors
3723e5910c Auto merge of #17913 - alibektas:ratoml_improvements, r=alibektas
fix: Add workspace level config to ratoml
2024-08-20 11:25:19 +00:00
bors
0e8df6f873 Auto merge of #17930 - Veykril:config-user-config, r=alibektas
Remove the ability to configure the user config path

Being able to do this makes little sense as this is effectively a cyclic dependency (and we do not want to fixpoint this really).
2024-08-20 11:10:55 +00:00
Ali Bektas
2559ddf631 Old configs are back 2024-08-20 12:35:56 +02:00
Ali Bektas
94ed6217dd Next up : generating configs for workspace level configs 2024-08-20 12:35:56 +02:00
Ali Bektas
d51fd9f196 Define workspace level configs. 2024-08-20 12:35:54 +02:00
Lukas Wirth
9b7b93e031 fix: Fix panics for semantic highlighting at startup 2024-08-20 09:53:37 +02:00
Wilfred Hughes
0edb0e1e62 ServerStatusParams should consider 'prime caches' in quiescent status
Priming caches is a performance win, but it takes a lock on the salsa
database and prevents rust-analyzer from responding to e.g. go-to-def
requests.

This causes confusion for users, who see the spinner next to
rust-analyzer in the VS Code footer stop, so they start attempting to
navigate their code.

Instead, set the `quiescent` status in LSP to false during cache
priming, so the VS Code spinner persists until we can respond to any
LSP request.
2024-08-19 10:27:53 -07:00
Shoyu Vanilla
722f0d3b46 fix: Panic when a TAIT exists in a RPIT 2024-08-19 23:07:13 +09:00
Lukas Wirth
90e08d3c93 Allow user config to not exist 2024-08-19 16:00:06 +02:00
Lukas Wirth
fd3fce2600 Remove the ability to configure the user config path 2024-08-19 15:12:33 +02:00
Lukas Wirth
3c4cdbbd1a Improve documentation for InvocationStrategy 2024-08-19 14:23:05 +02:00
bors
0c395dc5a4 Auto merge of #17928 - roife:fix-issue-17869, r=Veykril
fix: keep comments in convert_while_to_loop

Fix #17869.
2024-08-19 10:20:50 +00:00
roife
6a85595bb8 fix: keep comments in convert_while_to_loop 2024-08-19 17:27:54 +08:00
bors
c1879398af Auto merge of #17888 - Tyrubias:remove-invocation-location, r=Veykril
chore(config): remove `invocationLocation` in favor of `invocationStrategy`

These flags were added to help rust-analyzer integrate with repos requiring non-Cargo invocations. The consensus is that having two independent settings are no longer needed. This change removes `invocationLocation` in favor of `invocationStrategy` and changes the internal representation of `InvocationStrategy::Once` to hold the workspace root.

Closes #17848.
2024-08-19 08:19:38 +00:00
Victor Song
b0f20c7deb chore(config): remove invocationLocation in favor of invocationStrategy
These flags were added to help rust-analyzer integrate with repos
requiring non-Cargo invocations. The consensus is that having two
independent settings are no longer needed. This change removes
`invocationLocation` in favor of `invocationStrategy` and changes
the internal representation of `InvocationStrategy::Once` to hold
the workspace root.
2024-08-19 02:25:40 -05:00
David Richey
e350bc2cf5 Include generics when lowering extern type 2024-08-18 15:12:01 -05:00
bors
fa00326247 Auto merge of #17915 - Veykril:offline-no-deps, r=Veykril
feat: Make rust-analyzer work partially when offline

Helps out with https://github.com/rust-lang/rust-analyzer/issues/12499 a bit
2024-08-17 17:20:39 +00:00
Lukas Wirth
1013bf36dc Adress new clippy::large_enum_variant diagnostics 2024-08-17 19:18:56 +02:00
Lukas Wirth
07c1b83e98 feat: Make rust-analyzer work partially when missing an internet connection 2024-08-17 19:14:46 +02:00
bors
469b06214a Auto merge of #17916 - ShoyuVanilla:issue-17711, r=Veykril
fix: Wrong BoundVar index when lowering impl trait parameter of parent generics

Fixes #17711

From the following test code;

```rust
//- minicore: deref
use core::ops::Deref;

struct Struct<'a, T>(&'a T);

trait Trait {}

impl<'a, T: Deref<Target = impl Trait>> Struct<'a, T> {
    fn foo(&self) -> &Self { self }

    fn bar(&self) {
        let _ = self.foo();
    }

}
```

when we call `register_obligations_for_call` for `let _ = self.foo();`,

07659783fd/crates/hir-ty/src/infer/expr.rs (L1939-L1952)

we are querying `generic_predicates` and it has `T: Deref<Target = impl Trait>` predicate from the parent `impl Struct`;

07659783fd/crates/hir-ty/src/lower.rs (L375-L399)

but as we can see above, lowering `TypeRef = impl Trait` doesn't take into account the parent generic parameters, so the `BoundVar` index here is `0`, as `fn foo` has no generic args other than parent's,

But this `BoundVar` is pointing at `'a` in `<'a, T: Deref<Target = impl Trait>>`.
So, in the first code reference `register_obligations_for_call`'s L:1948 - `.substitute(Interner, parameters)`, we are substituting `'a` with `Ty`, not `Lifetime` and this makes panic inside the chalk.

This PR fixes this wrong `BoundVar` index in such cases
2024-08-17 17:00:52 +00:00
Shoyu Vanilla
d7431ecdfa fix: Wrong BoundVar index when lowering impl trait parameter of parent generics 2024-08-17 22:33:27 +09:00
Shoyu Vanilla
95470c250a Pin rowan to 0.15.15 2024-08-17 21:35:07 +09:00
Matthias Krüger
a9a91233de
Rollup merge of #129086 - slanterns:is_none_or, r=dtolnay
Stabilize `is_none_or`

Closes: https://github.com/rust-lang/rust/issues/126383.

`@rustbot` label: +T-libs-api

r? libs-api
2024-08-16 19:58:58 +02:00
bors
7f77e09fbe Auto merge of #17900 - darichey:exclude-vendored-libraries, r=davidbarsky
Add scip/lsif flag to exclude vendored libaries

#17809 changed StaticIndex to include vendored libraries. This PR adds a flag to disable that behavior.

At work, our monorepo has too many rust targets to index all at once, so we split them up into several shards. Since all of our libraries are vendored, if rust-analyzer includes them, sharding no longer has much benefit, because every shard will have to index the entire transitive dependency graphs of all of its targets. We get around the issue presented in #17809 because some other shard will index the libraries directly.
2024-08-16 14:25:36 +00:00
bors
c9ee892263 Auto merge of #17905 - ChayimFriedman2:edition-dependent-raw-keyword, r=Veykril
fix: Properly account for editions in names

This PR touches a lot of parts. But the main changes are changing `hir_expand::Name` to be raw edition-dependently and only when necessary (unrelated to how the user originally wrote the identifier), and changing `is_keyword()` and `is_raw_identifier()` to be edition-aware (this was done in #17896, but the FIXMEs were fixed here).

It is possible that I missed some cases, but most IDE parts should properly escape (or not escape) identifiers now.

The rules of thumb are:

 - If we show the identifier to the user, its rawness should be determined by the edition of the edited crate. This is nice for IDE features, but really important for changes we insert to the source code.
 - For tests, I chose `Edition::CURRENT` (so we only have to (maybe) update tests when an edition becomes stable, to avoid churn).
 - For debugging tools (helper methods and logs), I used `Edition::LATEST`.

Reviewing notes:

This is a really big PR but most of it is mechanical translation. I changed `Name` displayers to require an edition, and followed the compiler errors. Most methods just propagate the edition requirement. The interesting cases are mostly in `ide-assists`, as sometimes the correct crate to fetch the edition from requires awareness (there may be two). `ide-completions` and `ide-diagnostics` were solved pretty easily by introducing an edition field to their context. `ide` contains many features, for most of them it was propagated to the top level function and there the edition was fetched based on the file.

I also fixed all FIXMEs from #17896. Some required introducing an edition parameter (usually not for many methods after the changes to `Name`), some were changed to a new method `is_any_identifier()` because they really want any possible keyword.

Fixes #17895.
Fixes #17774.
2024-08-16 13:49:32 +00:00
Chayim Refael Friedman
9d3368f2c2 Properly account for editions in names
This PR touches a lot of parts. But the main changes are changing
`hir_expand::Name` to be raw edition-dependently and only when necessary
(unrelated to how the user originally wrote the identifier),
and changing `is_keyword()` and `is_raw_identifier()` to be edition-aware
(this was done in #17896, but the FIXMEs were fixed here).

It is possible that I missed some cases, but most IDE parts should properly
escape (or not escape) identifiers now.

The rules of thumb are:

 - If we show the identifier to the user, its rawness should be determined
   by the edition of the edited crate. This is nice for IDE features,
   but really important for changes we insert to the source code.
 - For tests, I chose `Edition::CURRENT` (so we only have to (maybe) update
   tests when an edition becomes stable, to avoid churn).
 - For debugging tools (helper methods and logs), I used `Edition::LATEST`.
2024-08-16 16:46:24 +03:00
dfireBird
8a4261aca8
implement basic inferring of lifetimes 2024-08-16 16:40:32 +05:30
bors
4cd8dcf287 Auto merge of #17903 - tmandry:graceful-exit, r=Veykril
Allow flycheck process to exit gracefully

Assuming it isn't cancelled. Closes #17902.

The only place CommandHandle::join() is used is when the flycheck command
finishes, so this commit changes the behavior of the method itself.

The only reason I can see for the existing behavior is if the command is somehow holding onto a build lock longer than it should, this would force it to be released. But it would be a pretty heavy-handed way to solve that issue. I'm not aware of this occurring in practice.
2024-08-16 07:35:16 +00:00
bors
28b6838a0e Auto merge of #17908 - ChayimFriedman2:usages-word-boundaries, r=Veykril
Test for word boundary in `FindUsages`

This speeds up short identifiers search significantly, while unlikely to have an effect on long identifiers (the analysis takes much longer than some character comparison).

Tested by finding all references to `eq()` (from `PartialEq`) in the rust-analyzer repo. Total time went down from 100s to 10s (a 10x reduction!).

Feel free to close this if you consider this a non-issue, as most short identifiers are local.
2024-08-16 07:20:23 +00:00
bors
fc36e0ca16 Auto merge of #17907 - ChayimFriedman2:no-once_cell, r=Veykril
internal: Replace once_cell with std's recently stabilized OnceCell/Lock and LazyCell/Lock

This doesn't get rid of the once_cell dependency, unfortunately, since we have dependencies that use it, but it's a nice to do cleanup. And when our deps will eventually get rid of once_cell we will get rid of it for free.
2024-08-16 07:05:59 +00:00
Chayim Refael Friedman
1a31fe299b Test for word boundary in FindUsages
This speeds up short identifiers search significantly, while unlikely to have an effect on long identifiers (the analysis takes much longer than some character comparison).

Tested by finding all references to `eq()` (from `PartialEq`) in the rust-analyzer repo. Total time went down from 100s to 10s (a 10x reduction!).
2024-08-16 10:02:36 +03:00
Chayim Refael Friedman
955e609867 Replace once_cell with std's recently stabilized OnceCell/Lock and LazyCell/Lock
This doesn't get rid of the once_cell dependency, unfortunately, since we have dependencies that use it, but it's a nice to do cleanup. And when our deps will eventually get rid of once_cell we will get rid of it for free.
2024-08-16 09:53:37 +03:00
Tyler Mandry
da34676104 Allow flycheck process to exit gracefully
Assuming it isn't cancelled. Closes #17902.

The only place CommandHandle::join is used is when the flycheck command
finishes, so this commit changes the behavior of the method itself.
2024-08-15 15:18:15 -07:00
David Richey
e257b9880f Add scip/lsif flag to exclude vendored libaries 2024-08-15 17:00:31 -05:00
Lukas Wirth
f90bdfc13d internal: Properly check the edition for edition dependent syntax kinds 2024-08-15 15:57:47 +02:00
bors
2b86639018 Auto merge of #17893 - ShoyuVanilla:issue-17871, r=flodiebold
fix: Panic while hovering associated function with type annotation on generic param that not inherited from its container type

Fixes #17871

We call `generic_args_sans_defaults` here;

64a140527b/crates/hir-ty/src/display.rs (L1021-L1034)

but the following substitution inside that function panic in #17871;

64a140527b/crates/hir-ty/src/display.rs (L1468)

it's because the `Binders.binder` inside `default_parameters` has a same length with the generics of the function we are hovering on, but the generics of it is split into two, `fn_params` and `parent_params`.
Because of this, it may panic if the function has one or more default parameters and both `fn_params` and `parent_params` are non-empty, like the case in the title of this PR.

So, we must call `generic_args_sans_default` first and then split it into `fn_params` and `parent_params`
2024-08-15 07:05:47 +00:00
Shoyu Vanilla
f4b7e8100c fix: Panic while displaying associated function with a type annotation 2024-08-15 09:37:49 +09:00
Nadrieril
40731f4bd6 rust-analyzer: use in-tree pattern_analysis crate 2024-08-14 20:52:19 +02:00
Slanterns
de28f30d81
fix r-a 2024-08-15 01:22:42 +08:00
bors
64a140527b Auto merge of #17882 - ShoyuVanilla:issue-17866, r=lnicola
fix: Panic while canonicalizing erroneous projection type

Fixes #17866

The root cause of #17866 is quite horrifyng 😨

```rust
trait T {
    type A;
}

type Foo = <S as T>::A; // note that S isn't defined

fn main() {
    Foo {}
}
```

While inferencing alias type `Foo = <S as T>::A`;

78c2bdce86/crates/hir-ty/src/infer.rs (L1388-L1398)

the error type `S` in it is substituted by inference var in L1396 above as below;

78c2bdce86/crates/hir-ty/src/infer/unify.rs (L866-L869)

This new inference var's index is `1`, as the type inferecing procedure here previously inserted another inference var into same `InferenceTable`.

But after that, the projection type made from the above then passed to the following function;

78c2bdce86/crates/hir-ty/src/traits.rs (L88-L96)

here, a whole new `InferenceTable` is made, without any inference var and in the L94, this table calls;

78c2bdce86/crates/hir-ty/src/infer/unify.rs (L364-L370)

And while registering `AliasEq` `obligation`, this obligation contains inference var `?1` made from the previous table, but this table has only one inference var `?0` made at L365.
So, the chalk panics when we try to canonicalize that obligation to register it, because the obligation contains an inference var `?1` that the canonicalizing table doesn't have.

Currently, we are calling `InferenceTable::new()` to do some normalizing, unifying or coercing things to some targets that might contain inference var that the new table doesn't have.
I think that this is quite dangerous footgun because the inference var is just an index that does not contain the information which table does it made from, so sometimes this "foreign" index might cause panic like this case, or point at the wrong variable.

This PR mitigates such behaviour simply by inserting sufficient number of inference vars to new table to avoid such problem.
This strategy doesn't harm current r-a's intention because the inference vars that passed into new tables are just "unresolved" variables in current r-a, so this is just making sure that such "unresolved" variables exist in the new table
2024-08-14 15:12:03 +00:00
Shoyu Vanilla
e6d8970e07 fix: Panic while canonicalizing erroneous projection type 2024-08-14 23:17:48 +09:00
bors
36a071c04d Auto merge of #17891 - lnicola:binop-bad-lang-items, r=flodiebold
internal: Be more resilient to bad language item definitions in binop inference

Fixes #16287
Fixes #16286

There's one more in `write_fn_trait_method_resolution`, but I'm not sure if it won't cause further problems in `infer_closures`.
2024-08-14 12:06:50 +00:00
Laurențiu Nicola
e37df4cd24 Be more resilient to bad language item definitions in binop inference 2024-08-14 14:38:39 +03:00
bors
b6913c577a Auto merge of #17885 - Wilfred:op_queue_docs, r=lnicola
minor: Add a doc comment for OpQueue

Add an explanatory sentence and some sample code to help readers understand why this struct exists.
2024-08-14 05:13:44 +00:00
Wilfred Hughes
da907c2ec3 docs: Add a doc comment for OpQueue
Add an explanatory sentence and some sample code to help
readers understand why this struct exists.
2024-08-13 16:51:54 -07:00
Laurențiu Nicola
bd6fb363f0 Merge from rust-lang/rust 2024-08-13 17:58:52 +03:00
Shoyu Vanilla
588fa2c6ef Bump rustc_pattern_analysis 2024-08-13 23:15:37 +09:00
Shoyu Vanilla
a7bc556a5e Temporarily remove non-working test case 2024-08-13 23:10:55 +09:00
Shoyu Vanilla
5316ba9158 feat: `min-exhaustive-patterns 2024-08-13 23:10:55 +09:00
bors
f3d9c9df90 Auto merge of #17876 - Veykril:semantics-include-simplify, r=Veykril
internal: Remove unreachable logic for include token mapping

Turns out https://github.com/rust-lang/rust-analyzer/pull/17863 made this obsolete 🎉
2024-08-13 07:48:55 +00:00
Lukas Wirth
bd4785a6f0 Remove unreachable logic for include token mapping 2024-08-13 09:44:13 +02:00
bors
1093803e38 Auto merge of #17867 - ShoyuVanilla:issue-17854, r=Veykril
fix: Trailing excess comma in "Convert to named struct" assist

Fixes #17854
2024-08-13 06:24:19 +00:00
Chayim Refael Friedman
2607c09fdd Allow declaring cfg groups in rust-project.json, to help sharing common cfgs 2024-08-12 22:03:16 +03:00
Shoyu Vanilla
2191a4686b fix: Trailing excess comma in "Convert to named struct" assist 2024-08-12 23:36:28 +09:00
Shoyu Vanilla
db24cf5a48 fix: Missing non-exhaustive let diagnostics inside async or unsafe block 2024-08-12 23:19:03 +09:00
bors
18414cdf64 Auto merge of #17864 - Veykril:lsif, r=Veykril
fix: Build and run build scripts in lsif command
2024-08-12 12:34:31 +00:00
Lukas Wirth
154a9a15db Build and run build scripts in lsif command 2024-08-12 14:33:11 +02:00
bors
518532426d Auto merge of #17863 - Veykril:include-diags, r=Veykril
fix: Resolve included files to their calling modules in IDE layer

Fixes https://github.com/rust-lang/rust-analyzer/issues/17390 at the expense of reporting duplicate diagnostics for modules that have includes in them when both the calling and called file are included.
2024-08-12 11:48:32 +00:00