Commit graph

21025 commits

Author SHA1 Message Date
Lukas Wirth
727555fc04 Add excluded extern-prelude IDE resolution test 2024-10-05 15:17:34 +02:00
Lukas Wirth
a898493b82 Turn ImportSource into a struct 2024-10-05 15:02:47 +02:00
Lukas Wirth
f7ca085690 Remove ImportSource::ExternCrate as the fixed point loop can't affect it 2024-10-05 15:02:47 +02:00
bors
5982d9c420 Auto merge of #18227 - davidbarsky:davidbarsky/push-lmntvwvznyyx, r=davidbarsky
internal: add json `tracing` Layer for profiling startup

On `buck2/integrations/rust-project`, this results in the following being printed:

```json
{"name":"discover_command","elapsed_ms":18703}
{"name":"parallel_prime_caches","elapsed_ms":0}
{"name":"vfs_load","elapsed_ms":5895}
{"name":"vfs_load","elapsed_ms":547}
{"name":"parallel_prime_caches","elapsed_ms":23}
{"name":"parallel_prime_caches","elapsed_ms":84}
{"name":"parallel_prime_caches","elapsed_ms":5819}
```
2024-10-04 17:59:02 +00:00
David Barsky
56c10ca981 internal: add JSON formatting for hprof 2024-10-04 11:26:15 -04:00
bors
510f72e12c Auto merge of #18234 - Veykril:veykril/push-vzynqtlxmrnl, r=Veykril
internal: Filter out opaque tokens in some IDE feature macro descensions
2024-10-04 10:26:04 +00:00
Lukas Wirth
24d65bb7cf internal: Filter out opaque tokens in some of IDE feature macro descensions 2024-10-04 11:53:12 +02:00
Kajetan Puchalski
6656460490
fix: Join rustfmt overrideCommand with project root
When providing a custom rustfmt command, join it with the project
root instead of the workspace root. This fixes rust-analyzer
getting the wrong invocation path in projects containing subprojects.

This makes the behaviour consistent with how a custom path provided
in rust-analyzer.procMacro.server behaves already.

Resolves issue #18222
2024-10-02 17:01:10 +01:00
SabrinaJewson
e735906839
fix: correctly parse use in generic parameters 2024-10-01 22:10:47 +01:00
Shoyu Vanilla
e09c2a08d7 Fix: Handle block exprs as modules when finding their parents 2024-10-01 14:05:15 +09:00
Chayim Refael Friedman
ff3c95f414 Comment out cast checks for unknown ptr kind
Just like we don't check for types containing unknown.
2024-09-30 19:26:16 +03:00
David Barsky
fc6eb66450 internal: remove Default from OpQueue 2024-09-30 10:12:52 -04:00
bors
ac8509a74b Auto merge of #18210 - ChayimFriedman2:label-macro, r=Veykril
fix: Fix resolution of label inside macro

When working on Something Else (TM) (I left a hint in the commits :P), I noticed to my surprise that labels inside macros are not resolved. This led to a discovery of *two* unrelated bugs, which are hereby fixed in two commits.
2024-09-30 13:09:54 +00:00
Chayim Refael Friedman
cd7cbddaf6 When resolving labels in break and continue for the IDE, do not resolve them textually, instead reuse the results of HIR lowering
This fixes a bug where labels inside macros were not resolved, but more importantly this prepares us to a future where we have hygiene, and textual equivalence isn't enough to resolve identifiers.
2024-09-30 15:13:45 +03:00
bors
dfe6d503b8 Auto merge of #18167 - SomeoneToIgnore:fat-completions, r=Veykril
internal: Send less data during `textDocument/completion` if possible

Similar to https://github.com/rust-lang/rust-analyzer/pull/15522, stops sending extra data during `textDocument/completion` if that data was set in the client completions resolve capabilities, and sends those only during `completionItem/resolve` requests.
Currently, rust-analyzer sends back all fields (including potentially huge docs) for every completion item which might get large.

Same as the other one, this PR aims to keep the changes minimal and does not remove extra computations for such fields — instead, it just filters them out before sending to the client.

The PR omits primitive, boolean and integer, types such as `deprecated`, `preselect`, `insertTextFormat`, `insertTextMode`, etc.  AND `additionalTextEdits` — this one looks very dangerous to compute for each completion item (as the spec says we ought to if there's no corresponding resolve capabilities provided) due to the diff computations and the fact that this code had been in the resolution for some time.
It would be good to resolve this lazily too, please let me know if it's ok to do.

When tested with Zed which only defines `documentation` and `additionalTextEdits` in its client completion resolve capabilities, rust-analyzer starts to send almost 3 times less characters:

Request:
```json
{"jsonrpc":"2.0","id":104,"method":"textDocument/completion","params":{"textDocument":{"uri":"file:///Users/someonetoignore/work/rust-analyzer/crates/ide/src/inlay_hints.rs"},"position":{"line":90,"character":14},"context":{"triggerKind":1}}}
```

<img width="1338" alt="image" src="https://github.com/user-attachments/assets/104f19b5-7095-4fc1-b008-5d829623b2e2">

Before: 381944 characters
[before.json](https://github.com/user-attachments/files/17092385/before.json)

After: 140503 characters
[after.json](https://github.com/user-attachments/files/17092386/after.json)

After Zed's [patch](https://github.com/zed-industries/zed/pull/18212) to enable all resolving possible: 84452 characters
[after-after.json](https://github.com/user-attachments/files/17092755/after-after.json)
2024-09-30 08:36:54 +00:00
bors
7b60339273 Auto merge of #18207 - mbwilding:master, r=Veykril
fix: Ambiguity with CamelCase diagnostic messages, align with rustc warnings

Fixed diagnostic messages so they say UpperCamelCase rather than CamelCase, as it is ambiguous.
Usually I'd call it PascalCase, but in the code base it is called UpperCamelCase so I left it with that naming choice.

`rustc` says `upper camel case` also when the case is wrong
```
warning: trait `testThing` should have an upper camel case name
 --> src/main.rs:5:7
  |
5 | trait testThing {
  |       ^^^^^^^^^ help: convert the identifier to upper camel case: `TestThing`
  |
  = note: `#[warn(non_camel_case_types)]` on by default
```

This is in line with the UPPER_SNAKE_CASE diagnostic messages.
546339a7be/crates/hir-ty/src/diagnostics/decl_check.rs (L60)
546339a7be/crates/ide-diagnostics/src/handlers/incorrect_case.rs (L535)
2024-09-30 08:22:29 +00:00
bors
ceee056af6 Auto merge of #18085 - ChayimFriedman2:gate-test, r=Veykril
feat: Provide an config option to not set `cfg(test)`

Fixes #17957.
2024-09-30 06:32:20 +00:00
Chayim Refael Friedman
4a06675e9c Gate #[test] expansion under cfg(test).
This will mean users opting to not activate `cfg(test)` will lose IDE experience on them, which is quite unfortunate, but this is unavoidable if we want to avoid false positives on e.g. diagnostics. The real fix is to provide IDE experience even for cfg'ed out code, but this is out of scope for this PR.
2024-09-30 00:12:45 +03:00
Chayim Refael Friedman
4ea09dd9f6 Provide an config option to not set cfg(test) 2024-09-30 00:12:45 +03:00
bors
822644d97d Auto merge of #18205 - noahmbright:object_safety, r=HKalbasi
Rename object_safety

First PR here (yay!), so I read some of the getting started docs. There are a couple references to `handlers.rs`, which as far as I can tell has been refactored into `handlers/*.rs`. I made some tweaks to that in one commit. There is one fixme about a function called `to_lsp_runnable`, which I can't find anywhere at all. I can update that if I get some more info there.

Otherwise I changed references to object safety, is object safe, etc., trying to match case/style as I went. There was one case I found where there's a trait from somewhere else called `is_object_safe`, which I found defined in my cargo registry. I didn't touch that for now, just marked it with a fixme
2024-09-29 20:20:26 +00:00
Chayim Refael Friedman
9798cf81de When glueing together tokens from macros, merge their spans 2024-09-29 22:58:15 +03:00
bors
792e79566d Auto merge of #18208 - davidbarsky:davidbarsky/push-qkwkmttnukqt, r=lnicola
internal: allow overriding proc macro server in analysis-stats

Needed this argument in order to profile the proc macro expansion server (c.f., [this Zulip conversation](https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/.60macro_rules!.60-based.20macros.20for.20derives.2Fattributes/near/473466794)). I also took the opportunity to change the phrasing for `--proc-macro-srv`.

Ran with `samply record ~/.cargo/bin/rust-analyzer analysis-stats --proc-macro-srv /Users/dbarsky/.cargo/bin/rust-analyzer-proc-macro-srv --parallel .` on rust-analyzer itself.
2024-09-29 17:54:20 +00:00
David Barsky
931b1c32c9 internal: allow overriding proc macro server in analysis-stats 2024-09-29 12:09:16 -04:00
Noah Bright
4255cae1bb Rename object_safety to dyn_compatibility
Up to a trait implemented by another package, linking to
$CARGO_HOME/registry/cache/index.crates.io-6f17d22bba15001f/
2024-09-29 07:26:45 -04:00
Matthew Wilding
60219d0b11
Fix ambiguity with CamelCase diagnostic messages 2024-09-29 16:35:37 +08:00
bors
546339a7be Auto merge of #18192 - darichey:read-buildfile-into-vfs, r=Veykril
Include buildfiles in VFS

We subscribe to `textDocument/didSave` for `filesToWatch`, but the VFS doesn't contain those files. Before https://github.com/rust-lang/rust-analyzer/pull/18105, this would bring down the server. Now, it's only a benign error logged:
```
ERROR notification handler failed handler=textDocument/didSave error=file not found: /foo/bar/TARGETS
```
It's benign, because we will also receive a `workspace/didChangeWatchedFiles` for the file which will invalidate and load it.

Explicitly include the buildfiles in the VFS to prevent the handler from erroring.
2024-09-27 19:39:35 +00:00
bors
233b1ac14e Auto merge of #18196 - DropDemBits:sed-syntax-factory, r=Veykril
internal: Add `SyntaxFactory` to ease generating nodes with syntax mappings

Part of [#​15710](https://github.com/rust-lang/rust-analyzer/issues/15710)

Instead of requiring passing a `&mut SyntaxEditor` to every make constructor to generate mappings, we instead wrap that logic in `SyntaxFactory`, and afterwards add all the mappings to the `SyntaxEditor`.

Includes an example of using `SyntaxEditor` & `SyntaxFactory` in the `extract_variable` assist.
2024-09-27 05:44:11 +00:00
bors
c482421316 Auto merge of #18197 - alibektas:buggy_flycheck_message, r=Veykril
minor: Stricter requirements for package wide flycheck

Require the existence of a target and `check_workspace` to be false to restart package-wide flycheck. Fixes #18194 , #18104
2024-09-27 05:14:35 +00:00
Ali Bektas
aeed8f89a3 minor: Require both the existence of a target and check_workspace to be false to restart package-wide flycheck 2024-09-27 02:40:53 +02:00
DropDemBits
f9ad9a0bb6
minor: Use SyntaxEditor in extract_variable 2024-09-26 16:29:16 -04:00
DropDemBits
05b48e4005
internal: Add SyntaxFactory to ease generating nodes with syntax mappings 2024-09-26 16:28:48 -04:00
Wilfred Hughes
f498184cbb fix: Don't report a startup error when a discover command is configured
Previously, r-a would show an error if both fetch_workspaces_queue and
discover_workspace_queue were empty. We're in this state at startup,
so users would see an error if they'd configured
discover_workspace_config.

Instead, allow the fetch_workspaces_queue to have zero items if
discover_workspace_config is set.

Whilst we're here, prefer "failed to fetch" over "failed to discover",
so the error message better reflects what this function is doing.
2024-09-26 14:33:30 -04:00
David Richey
85ca217765 Include buildfiles in vfs 2024-09-26 12:54:55 -04:00
bors
88fad4983e Auto merge of #18180 - kpreid:search, r=davidbarsky
feat: Index workspace symbols at startup rather than on the first symbol search.

This will eliminate potential many-second delays when performing the first search, at the price of making cache priming (“Indexing N/M” in the VS Code status bar) take a little longer in total. Hopefully this additional time is insignificant because a typical session will involve at least one symbol search.

Further improvement would be to do this as a separate parallel task (which will be beneficial if the workspace contains a small number of large crates), but that would require significant additional refactoring of the progress-reporting mechanism to understand multiple tasks per crate. Happy to tackle that in this PR if desired, but I thought I'd propose the minimal change first.
2024-09-25 17:14:39 +00:00
bors
df478ea93c Auto merge of #18181 - davidbarsky:davidbarsky/push-nzstpumovmmx, r=davidbarsky
internal: add tracing to project discovery and VFS loading

With `"env RA_PROFILE=vfs_load|parallel_prime_caches|discover_command>500`, this results in the following output:

```
21888ms discover_command
11627ms vfs_load @ total = 701
1503ms vfs_load @ total = 701
30211ms parallel_prime_caches
```

As a followup, I'd like to make hprof emit the information above as JSON.
2024-09-25 16:48:05 +00:00
Kevin Reid
a050c5de9b Prime caches for symbol search too. 2024-09-25 09:41:09 -07:00
David Barsky
338003f30e internal: add tracing to project discovery and VFS loading 2024-09-25 10:10:25 -04:00
Laurențiu Nicola
f84aa5de4a Add missing rustc_private 2024-09-25 10:56:37 +03:00
bors
7ab2c171bf Auto merge of #18183 - lnicola:sync-from-rust, r=lnicola
internal: Sync from downstream
2024-09-25 06:41:56 +00:00
Laurențiu Nicola
f4bcae32fe Run rustfmt 2024-09-25 09:26:15 +03:00
Lukas Wirth
10ada02019 Pass all-targets for build scripts in more cli commands
Without this, build scripts don't run for tests and as such any proc-macros in dev-deps fail to resolve
2024-09-25 08:23:09 +02:00
Laurențiu Nicola
6c24765cd4 Add more LayoutError variants 2024-09-25 09:15:11 +03:00
Laurențiu Nicola
37f7190b3e Merge from rust-lang/rust 2024-09-25 09:00:53 +03:00
bors
2f55a91552 Auto merge of #18164 - ShoyuVanilla:use-as-alias, r=Veykril
fix: Temporary fix for `remove_unused_imports` not handling import aliases correctly

Fixes #18129
2024-09-24 15:22:57 +00:00
Shoyu Vanilla
d4de84f58a fix: Temporary fix for remove_unused_imports not handling import aliases correctly 2024-09-24 23:48:04 +09:00
bors
e775dd6c70 Auto merge of #18166 - ChayimFriedman2:dollar-crate-root, r=Veykril
fix: Fix a bug in span map merge, and add explanations of how span maps are stored

Because it took me hours to figure out that contrary to common sense, the offset stored is the *end* of the node, and we search by the *start*. Which is why we need a convoluted `partition_point()` instead of a simple `binary_search()`. And this was not documented at all. Which made me make mistakes with my implementation of `SpanMap::merge()`.

The other bug fixed about span map merging is correctly keeping track of the current offset in presence of multiple sibling macro invocations. Unrelated, but because of the previous issue it took me hours to debug, so I figured out I'll put them together for posterity.

Fixes #18163.
2024-09-24 11:01:05 +00:00
bors
f30d4ea9c0 Auto merge of #18161 - ChayimFriedman2:postfix-mut, r=Veykril
fix: Better support references in consuming postfix completions

Fixes #18155.
2024-09-24 10:46:48 +00:00
bors
a159b370ba Auto merge of #18160 - ChayimFriedman2:fix-18138, r=Veykril
fix: Fix name resolution when an import is resolved to some namespace and then later in the algorithm another namespace is added

The import is flagged as "indeterminate", and previously it was re-resolved, but only at the end of name resolution, when it's already too late for anything that depends on it.

This issue was tried to fix in https://github.com/rust-lang/rust-analyzer/pull/2466, but it was not fixed fully.

That PR is also why IDE features did work: the import at the end was resolved correctly, so IDE features that re-resolved the macro path resolved it correctly.

I was concerned about the performance of this, but this doesn't seem to regress `analysis-stats .`, so I guess it's fine to land this. I have no idea about the incremental perf however and I don't know how to measure that, although when typing in `zbus` (including creating a new function, which should recompute the def map) completion was fast enough.

I didn't check what rustc does, so maybe it does something more performant, like keeping track of only possibly problematic imports.

Fixes #18138.
Probably fixes #17630.
2024-09-24 10:32:28 +00:00
bors
b6b56d2abe Auto merge of #18157 - davidbarsky:davidbarsky/respect-disabling-proc-macros-in-analysis-stats, r=Veykril
analysis-stats: respect `--disable-proc-macros` flag

I noticed that this flag wasn't being respected by `analysis-stats` when profiling proc macro expansion, so here's a small fix.
2024-09-24 10:17:56 +00:00
bors
b4eff8971d Auto merge of #18123 - jhgg:fix-ambigius-package-cargo-check, r=Veykril
fix: fix ambigious package name in flycheck

fixes #18121
2024-09-24 10:03:41 +00:00
bors
7eb10bda57 Auto merge of #18175 - Wilfred:completion_marker, r=Veykril
internal: Make COMPLETION_MARKER more explicitly r-a

If a user ever sees the completion marker, it's confusing to see text about IntelliJ. Use a string that's more explicitly about completion for rust-analyzer.
2024-09-24 09:49:25 +00:00
bors
dfee4c8690 Auto merge of #18162 - ChayimFriedman2:gat-object-safe, r=Veykril
fix: Consider lifetime GATs object unsafe

Fixes #18156.
2024-09-24 08:14:00 +00:00
Wilfred Hughes
d95ad12c9c internal: Make COMPLETION_MARKER more explicitly r-a
If a user ever sees the completion marker, it's confusing to see text
about IntelliJ. Use a string that's more explicitly about completion
for rust-analyzer.
2024-09-23 17:04:04 -04:00
Kirill Bulatov
c03f5b63e2 Small fixes 2024-09-23 22:11:41 +03:00
Laurențiu Nicola
a6572e9234 Support expect in attribute completion and hover 2024-09-23 14:55:50 +03:00
Kirill Bulatov
983f2abc2c Less clones 2024-09-23 05:48:57 +03:00
Kirill Bulatov
950bb83f81 Resolve completion items 2024-09-23 05:29:30 +03:00
Kirill Bulatov
ba1c9146fc Omit completion fields to be resolved later 2024-09-23 05:10:31 +03:00
Kirill Bulatov
2395a4e932 Prepare for omittiong parts of completion data that need to be resolved 2024-09-23 04:44:31 +03:00
Chayim Refael Friedman
b275f37db6 Fix a bug in span map merge, and add explanations of how span maps are stored
Because it took me hours to figure out that contrary to common sense, the offset stored is the *end* of the node, and we search by the *start*. Which is why we need a convoluted `partition_point()` instead of a simple `binary_search()`. And this was not documented at all. Which made me make mistakes with my implementation of `SpanMap::merge()`.

The other bug fixed about span map merging is correctly keeping track of the current offset in presence of multiple sibling macro invocations. Unrelated, but because of the previous issue it took me hours to debug, so I figured out I'll put them together for posterity.
2024-09-23 01:54:40 +03:00
Chayim Refael Friedman
141833850c Consider lifetime GATs object unsafe 2024-09-22 15:00:01 +03:00
Chayim Refael Friedman
7c015944b3 Include dereferences in consuming postfix completions (e.g. call) 2024-09-22 06:07:49 +03:00
Chayim Refael Friedman
9274703ac4 Properly account for mutable references when postfix-completing consuming completions (e.g. call) 2024-09-22 06:07:27 +03:00
Chayim Refael Friedman
432b2559cd Fix name resolution when an import is resolved to some namespace and then later in the algorithm another namespace is added
The import is flagged as "indeterminate", and previously it was re-resolved, but only at the end of name resolution, when it's already too late for anything that depends on it.

This issue was tried to fix in https://github.com/rust-lang/rust-analyzer/pull/2466, but it was not fixed fully.
2024-09-22 04:19:10 +03:00
Folkert de Vries
02f677372b add C-cmse-nonsecure-entry ABI 2024-09-21 13:04:14 +02:00
David Barsky
ad52c46478 analysis-stats: respect --disable-proc-macros flag 2024-09-20 13:40:12 -04:00
bors
00037c18ed Auto merge of #18132 - ChayimFriedman2:fix-closure-semi, r=Veykril
fix: Don't complete `;` when in closure return expression

Completing it will break syntax.

Fixes #18130.
2024-09-20 07:38:16 +00:00
bors
d4689f183a Auto merge of #18151 - ChayimFriedman2:metavar-concat, r=Veykril
feat: Support the `${concat(...)}` metavariable expression

I didn't follow rustc precisely, because I think it does some things wrongly (or they are FIXME), but I only allowed more code, not less. So we're all fine.

Closes #18145.
2024-09-20 07:23:43 +00:00
bors
c467115fd9 Auto merge of #18108 - ChayimFriedman2:lint-level-cfg, r=Veykril
fix: Handle lint attributes that are under `#[cfg_attr]`

I forgot `cfg_attr` while working on #18099. Although the original code also didn't handle that (although case lints specifically were correct, by virtue of using hir attrs).
2024-09-20 06:54:53 +00:00
Chayim Refael Friedman
5c06f047b9 When checking for forbidden expr kind matches, account for rawness
An expression starting with `r#const` etc. should be accepted even in edition <=2021.
2024-09-19 23:38:48 +03:00
Christopher Serr
e1961b1078 feat: Highlight exit points of async blocks
Async blocks act similar to async functions in that the await keywords
are related, but also act like functions where the exit points are
related.
2024-09-19 22:00:22 +02:00
Chayim Refael Friedman
82124f33b5 Handle lint attributes that are under #[cfg_attr] 2024-09-19 22:21:48 +03:00
Chayim Refael Friedman
8a50aecb07 Support the ${concat(...)} metavariable expression
I didn't follow rustc precisely, because I think it does some things wrongly (or they are FIXME), but I only allowed more code, not less. So we're all fine.
2024-09-19 22:19:12 +03:00
bors
6dad8c5528 Auto merge of #18146 - ChayimFriedman2:allow-comment, r=Veykril
fix: Remove check that text of `parse_expr_from_str()` matches the produced parsed tree

This check is incorrect when we have comments and whitespace in the text.

We can strip comments, but then we still have whitespace, which we cannot strip without changing meaning for the parser. So instead I opt to remove the check, and wrap the expression in parentheses (asserting what produced is a parenthesized expression) to strengthen verification.

Fixes #18144.
2024-09-19 13:27:21 +00:00
Chayim Refael Friedman
9ef460ba2d Remove check that text of parse_expr_from_str() matches the produced parsed tree
This check is incorrect when we have comments and whitespace in the text.

We can strip comments, but then we still have whitespace, which we cannot strip without changing meaning for the parser. So instead I opt to remove the check, and wrap the expression in parentheses (asserting what produced is a parenthesized expression) to strengthen verification.
2024-09-19 14:18:07 +03:00
bors
990c48cb0d Auto merge of #18131 - ChayimFriedman2:macro-expand-dollar-crate, r=Veykril
fix: Get rid of `$crate` in expansions shown to the user

Be it "Expand Macro Recursively", "Inline macro" or few other things.

We replace it with the crate name, as should've always been.

Probably fixes some issues, but I don't know what they are.
2024-09-18 20:17:21 +00:00
bors
bd59dc8e4c Auto merge of #18139 - ShoyuVanilla:issue-18109, r=Veykril
fix: Extend `type_variable_table` when modifying index is larger than the table size

Fixes #18109

Whenever we create an inference variable in r-a, we extend `type_variable_table` to matching size here;

f4aca78c92/crates/hir-ty/src/infer/unify.rs (L378-L381)

But sometimes, an inference variable is [created from chalk](ab710e0c9b/chalk-solve/src/infer/unify.rs (L743)) and passed to r-a as a type of an expression or a pattern.
If r-a set diverging flag to this before the table is extended to a sufficient size, it panics here;

f4aca78c92/crates/hir-ty/src/infer/unify.rs (L275-L277)

I think that extending table when setting diverging flag is reasonable becase we are already doing such extending to a size that covers the inference vars created from chalk and this change only covers the order-dependent random cases that this might fail
2024-09-18 20:01:38 +00:00
Chayim Refael Friedman
cfb701ac78 Get rid of $crate in expansions shown to the user
Be it "Expand Macro Recursively", "Inline macro" or few other things.

We replace it with the crate name, as should've always been.
2024-09-18 18:30:59 +03:00
Shoyu Vanilla
b368f9125b fix: Extend type_variable_table when modifying index is larger than table size 2024-09-19 00:02:08 +09:00
Chayim Refael Friedman
c9758da280 Extract logic to decide how to complete semicolon for unit-returning function into CompletionContext
So that we don't recompute it for every item.
2024-09-18 14:07:23 +03:00
Chayim Refael Friedman
7f023154f0 Don't complete ; when in closure return expression
Completing it will break syntax.
2024-09-18 13:53:11 +03:00
bors
f4aca78c92 Auto merge of #18117 - ChayimFriedman2:issue-18089, r=Veykril
fix: Always cache macro expansions' root node in Semantics

Previously some expansions were not cached, but were cached in the expansion cache, which caused panics when later queries tried to lookup the node from the expansion cache.

Fixes #18089.
2024-09-18 09:19:30 +00:00
bors
4a08e77842 Auto merge of #18128 - ChayimFriedman2:external-macros-lint, r=Veykril
fix: Handle errors and lints from external macros

Some lints should not be reported if they originate from an external macro, and quickfixes should be disabled (or they'll change library code).

Fixes #18122.
Closes #18124.
2024-09-18 09:04:53 +00:00
bors
5b7c812634 Auto merge of #18136 - valadaptive:no-mangle-lints, r=Veykril
Don't lint names of #[no_mangle] extern fns

[Rust doesn't run the `non_snake_case_name` lint on `extern fn`s with the `#[no_mangle]` attribute](https://github.com/rust-lang/rust/pull/44966).

The conditions are:
- The function must be `extern` and have a `#[no_mangle]` attribute.
- The function's ABI must not be explicitly set to "Rust".

This PR replicates that logic here.
2024-09-18 08:50:40 +00:00
bors
30e0953187 Auto merge of #18135 - ChayimFriedman2:unsafe-op-in-unsafe-fn, r=Veykril
feat: Add diagnostics for `unsafe_op_in_unsafe_fn`

Turns out it's pretty easy, but I did have to add support for allowed-by-default lints.
2024-09-18 08:35:42 +00:00
bors
2617bd4b92 Auto merge of #18137 - ShoyuVanilla:expr-2021, r=Veykril
feat: Implement `expr_2021`

Resolves #18062
2024-09-18 08:21:24 +00:00
Shoyu Vanilla
d34a663c70 feat: Implement expr_2021 2024-09-18 15:58:03 +09:00
valadaptive
893f79270f Don't lint names of #[no_mangle] extern fns 2024-09-18 01:54:03 -04:00
Chayim Refael Friedman
f6eb5be591 Add diagnostics for unsafe_op_in_unsafe_fn
Turns out it's pretty easy, but I did have to add support for allowed-by-default lints.
2024-09-18 03:02:12 +03:00
DropDemBits
5537e2739c
Use SyntaxEditor in extract_type_alias 2024-09-17 18:25:32 -04:00
DropDemBits
23c4ab7e4b
internal: Extend SourceChangeBuilder to make make working with SyntaxEditors easier 2024-09-17 18:24:27 -04:00
Chayim Refael Friedman
30f53583c8 Handle errors and lints from external macros
Some lints should not be reported if they originate from an external macro, and quickfixes should be disabled (or they'll change library code).
2024-09-17 20:03:56 +03:00
Jake
99af938dea
fix: fix ambigious package name in flycheck 2024-09-16 15:53:08 -07:00
Lukas Markeffsky
cd442a0577 assert that unexpectedly unsized fields are sized in the param env 2024-09-17 00:06:56 +02:00
Chayim Refael Friedman
35e171aa01 Always cache macro expansions' root node in Semantics
Previously some expansions were not cached, but were cached in the expansion cache, which caused panics when later queries tried to lookup the node from the expansion cache.
2024-09-17 00:19:39 +03:00
Lukas Markeffsky
08344c2ae8 layout computation: eagerly error for unexpected unsized fields 2024-09-16 15:53:21 +02:00
Chayim Refael Friedman
798c963875 Fix printing of constants greater than i128::MAX 2024-09-16 01:30:18 +03:00
bors
4221354a8f Auto merge of #18073 - alibektas:immutable_tree_panics, r=lnicola
fix: Immutable tree panic in `generate_delegate_trait`

fixes #17835
2024-09-13 09:44:28 +00:00
Ali Bektas
8f5a5e02aa fix: Immutable tree panic in generate_delegate_trait 2024-09-12 23:52:09 +02:00
bors
fd243cd0fb Auto merge of #18099 - ChayimFriedman2:diag-only-necessary, r=Veykril
Use more correct handling of lint attributes

The previous analysis was top-down, and worked on a single file (expanding macros). The new analysis is bottom-up, starting from the diagnostics and climbing up the syntax and module tree.

While this is more efficient (and in fact, efficiency was the motivating reason to work on this), unfortunately the code was already fast enough. But luckily, it also fixes a correctness problem: outline parent modules' attributes were not respected for the previous analysis. Case lints specifically did their own analysis to accommodate that, but it was limited to only them. The new analysis works on all kinds of lints, present and future.

It was basically impossible to fix the old analysis without rewriting it because navigating the module hierarchy must come bottom-up, and if we already have a bottom-up analysis (including syntax analysis because modules can be nested in other syntax elements, including macros), it makes sense to use only this kind of analysis.

Few other bugs (not fundamental to the previous analysis) are also fixed, e.g. overwriting of lint levels (i.e. `#[allow(lint)] mod foo { #[warn(lint)] mod bar; }`.

After this PR is merged I intend to work on an editor command that does workspace-wide diagnostics analysis (that is, `rust-analyzer diagnostics` but from your editor and without having to spawn a new process, which will have to analyze the workspace from scratch). This can be useful to users who do not want to enable check on save because of its overhead, but want to see workspace wide diagnostics from r-a (or to maintainers of rust-analyzer).

Closes #18086.
Closes #18081.
Fixes #18056.
2024-09-12 12:39:27 +00:00
Chayim Refael Friedman
4eb19df5e9 Use more correct handling of lint attributes
The previous analysis was top-down, and worked on a single file (expanding macros). The new analysis is bottom-up, starting from the diagnostics and climbing up the syntax and module tree.

While this is more efficient (and in fact, efficiency was the motivating reason to work on this), unfortunately the code was already fast enough. But luckily, it also fixes a correctness problem: outline parent modules' attributes were not respected for the previous analysis. Case lints specifically did their own analysis to accommodate that, but it was limited to only them. The new analysis works on all kinds of lints, present and future.

It was basically impossible to fix the old analysis without rewriting it because navigating the module hierarchy must come bottom-up, and if we already have a bottom-up analysis (including syntax analysis because modules can be nested in other syntax elements, including macros), it makes sense to use only this kind of analysis.

Few other bugs (not fundamental ti the previous analysis) are also fixed, e.g. overwriting of lint levels (i.e. `#[allow(lint)] mod foo { #[warn(lint)] mod bar; }`.
2024-09-12 15:24:38 +03:00
bors
a91ca0e2fc Auto merge of #18038 - roife:fix-issue-18034, r=Veykril
feat: generate names for tuple-struct in add-missing-match-arms

fix #18034.

This PR includes the following enhancement:

- Introduced a `NameGenerator` in `suggest_name`, which implements an automatic renaming algorithm to avoid name conflicts. Here are a few examples:

```rust
let mut generator = NameGenerator::new();
assert_eq!(generator.suggest_name("a"), "a");
assert_eq!(generator.suggest_name("a"), "a1");
assert_eq!(generator.suggest_name("a"), "a2");

assert_eq!(generator.suggest_name("b"), "b");
assert_eq!(generator.suggest_name("b"), "b1");
assert_eq!(generator.suggest_name("b2"), "b2");
assert_eq!(generator.suggest_name("b"), "b3");
assert_eq!(generator.suggest_name("b"), "b4");
assert_eq!(generator.suggest_name("b3"), "b5");
```

- Updated existing testcases in ide-assists for the new `NameGenerator` (only modified generated names).
- Generate names for tuple structs instead of using wildcard patterns in `add-missing-match-arms`.
2024-09-12 08:21:37 +00:00
bors
27fb6d69ea Auto merge of #18107 - Veykril:push-oopkquknxqxs, r=Veykril
fix: Don't emit empty inlay hint parts
2024-09-12 06:49:21 +00:00
Lukas Wirth
0bb7a8e28b fix: Don't emit empty inlay hint parts 2024-09-12 08:48:06 +02:00
bors
58418ab0ce Auto merge of #18106 - Veykril:push-yzsqoykyowts, r=Veykril
fix: Don't report typed hole error in asm! out ops

Fixes https://github.com/rust-lang/rust-analyzer/issues/18103
2024-09-12 06:21:01 +00:00
Lukas Wirth
6daa6d59f3 fix: Don't report typed hole error in asm! out ops 2024-09-12 08:16:49 +02:00
bors
772acefce9 Auto merge of #18105 - Veykril:push-rquxwznuuwpu, r=Veykril
fix: Faulty notifications should not bring down the server

Fixes https://github.com/rust-lang/rust-analyzer/issues/18055, if a client sends us an unregistered document path in a did save notification it would force us to exit the thread. That is obviously not great behavior, we should be more fallible here
2024-09-12 06:06:14 +00:00
Lukas Wirth
3b8fe6d500 fix: Faulty notifications should not bring down the server 2024-09-12 08:03:45 +02:00
Chayim Refael Friedman
5c42c08518 Fix inference of literals when the expectation is Castable
I followed the compiler: 5bce6d48ff/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs (L1560-L1579).
2024-09-12 00:57:34 +03:00
bors
c54a827f50 Auto merge of #18075 - roife:fix-issue-17858, r=Veykril
feat: render patterns in params for hovering

Fix #17858

This PR introduces an option to [hir-def/src/body/pretty.rs](08c7bbc2db/crates/hir-def/src/body/pretty.rs) to render the result as a single line, which is then reused for rendering patterns in parameters for hovering.
2024-09-11 12:05:57 +00:00
bors
cfe8e376c9 Auto merge of #18080 - Veykril:dedup, r=Veykril
Remove crate graph deduplication logic

Fixes https://github.com/rust-lang/rust-analyzer/issues/17748
2024-09-11 11:47:17 +00:00
bors
14a18b4849 Auto merge of #18078 - cuishuang:master, r=Veykril
Remove unnecessary symbols and add missing symbols
2024-09-11 11:32:46 +00:00
bors
0267296278 Auto merge of #18057 - alibektas:better_ratoml_testing, r=Veykril
internal: Better testing infra for ratoml

This PR makes some improvements on how we test configs that come from `rust-analyzer.toml` files.
It was primarily used to solve #18021 but along the way I could not really determine the cause of the said issue which makes me think that it may not be related to the changes that I made earlier to the ratoml infra. In either way `custom_snippets` are now made `global` because we still don't have a tree that maps a `SourceRootId` to a set of `Snippet`s.
2024-09-11 11:02:50 +00:00
bors
77e1969c15 Auto merge of #18052 - Coekjan:fix-inline-const, r=Veykril
fix: Fix `inline_const_as_literal` error when the number >= 10

## Description

### The Bug

This PR fixes a small bug in the IDE assistence (`inline_const_as_literal`). When the being-inlined constant is a number and it is greater than or equal to 10, the assistence inserts unexpected string `(0x...)` after the number itself. A simple example is followed:

Current `inline_const_as_literal` changes

```rs
const A: usize = 16;

fn f() -> usize {
    A  // inline the constant
}
```

into

```rs
const A: usize = 16;

fn f() -> usize {
    16 (0x10)
}
```

The bug originates from #14925 & #15306 . #14925 added some unittests, but it just tested the number-inlining behavior when the number is `0`.

50882fbfa2/crates/ide-assists/src/handlers/inline_const_as_literal.rs (L124-L138)

And #15306 modified the behavior of `Const::render_eval` and added the `(0x...)` part after the number (if the number >= `10`). Because of insufficient unittests in #14925, changes about `Const::render_eval` in #15306 introduced this bug with no CI failure.

### The Fix

I think `Const::render_eval` is intended for user-facing value displaying (e.g. hover) and not designed for `inline_const_as_literal`. To fix the bug, I defined a new function named `Const::eval`, which evaluates the value itself faithfully and simply and does nothing else.

## Thanks

Thanks `@roife` for your kind help. Your guidance helped me better understand the code.
2024-09-11 10:48:32 +00:00
bors
b98a2f892c Auto merge of #18018 - ChayimFriedman2:unit-ret-complete-semi, r=Veykril
feat: Automatically add semicolon when completing unit-returning functions

But provide a config to suppress that.

I didn't check whether we are in statement expression position, because this is hard in completion (due to the natural incompleteness of source code when completion is invoked), and anyway using function returning unit as an argument to something seems... dubious.

Fixes #17263.
2024-09-11 10:33:43 +00:00
Lukas Wirth
c2258d8880 Properly set the working directory for proc-macro execution 2024-09-11 12:23:12 +02:00
bors
6c56df8cb4 Auto merge of #17904 - darichey:unresolved-references, r=Veykril
Add command to report unresolved references

Adds `rust-analyzer unresolved-references` which reports unresolved references. This is useful for debugging and regression testing for both rust-analyzer and project generators like Buck's rust-project.

As discussed: https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Command.20to.20report.20unresolved.20references
2024-09-11 10:19:30 +00:00
Lukas Wirth
db04f514f2 Lift out workspace related data into a separate query to preserve crategraph deduplication 2024-09-11 12:16:41 +02:00
bors
a90d78f327 Auto merge of #18050 - rust-lang:davidbarsky/push-uyvtlsvoqrxw, r=Veykril
assist: ensure `replace_qualified_name_with_use` applies to the first path segment

This change helps a bit with the discoverability of `replace_qualified_name_with_use`. Specifically, it ensures that a cursor on the first path segment (e.g., `$0std::fmt::Debug`, where `$0` is the cursor) would result in an import along the lines of `use std::fmt;` and `fmt::Debug;` at the usage sites.
2024-09-11 10:04:56 +00:00
Lukas Wirth
8905f86d8a Remove crate graph deduplication logic 2024-09-11 11:38:42 +02:00
bors
dd026ce6a4 Auto merge of #18093 - ShoyuVanilla:skip-dyn-trait-cast-check, r=Veykril
Skip checks for cast to dyn traits

It seems that chalk fails to solve some obvious goals when there are some recursiveness in trait environments.
And it doesn't support trait upcasting yet. rust-lang/chalk#796

This PR just skips for casting into types containing `dyn Trait` to prevent false positive diagnostics like #18047 and #18083
2024-09-11 07:14:58 +00:00
Shoyu Vanilla
569ac44daf Skip checks for cast to dyn traits 2024-09-11 01:40:13 +09:00
Chayim Refael Friedman
7c44d453c8 Correctly escape strings in our quote macro
This is a small change, but it was the cause of 90% of the errors in `rust-analyzer diagnostics .` 🫢

With this change and #18085 together, all remaining errors are type errors.

This may mean we can enable more errors, but this is out of scope for this PR.
2024-09-10 19:00:32 +03:00
bors
f13c776361 Auto merge of #18032 - DropDemBits:sed-tree-edits, r=davidbarsky
internal: Add preliminary `SyntaxEditor` functionality

Related to #15710

Implements a `SyntaxEditor` interface to abstract over the details of modifying syntax trees, to both simplify creating new code fixes and code actions, as well as start on the path of getting rid of mutable syntax nodes.

`SyntaxEditor` relies on `SyntaxMappingBuilder`s to feed in the correct information to map AST nodes created by `make` constructors, as `make` constructors do not guarantee that node identity is preserved. This is to paper over the fact that `make` constructors simply re-parse text input instead of building AST nodes from the ground up and re-using the provided syntax nodes.

`SyntaxAnnotation`s are used to find where syntax elements have ended up after edits are applied. This is primarily useful for the `add_{placeholder,tabstop}` set of methods on `SourceChangeBuilder`, as that currently relies on the nodes provided being in the final syntax tree.

Eventually, the goal should be to move this into the `rowan` crate when we move away from mutable syntax nodes, but for now it'll stay in the `syntax` crate.

---

Closes #14921 as `SyntaxEditor` ensures that all replace changes are disjoint
Closes #9649 by implementing `SyntaxAnnotation`s
2024-09-10 14:13:08 +00:00
roife
8b0fea8317 feat: generate names for tuple-struct in add-missing-match-arms 2024-09-10 00:30:48 +08:00
roife
825dec8108 refactor: introduce NameGenerator in suggest_name 2024-09-10 00:30:46 +08:00
roife
5db510b258 feat: use shorthand when pretty-print record pat 2024-09-09 23:20:31 +08:00
bors
e35227d186 Auto merge of #18041 - roife:fix-issue-17631, r=Veykril
feat: better name suggestions for fn

fix #17631.

Better name suggestions for fn-calls / method-calls in the form of `from()`, `from_xxx()`, `into()`, etc.
2024-09-09 13:55:20 +00:00
roife
c3c575ebd0 feat: better name suggestions for fn 2024-09-09 21:53:11 +08:00
roife
5c97361622 fix: add parenthesis for or-pattern 2024-09-09 20:59:23 +08:00
roife
5caa56e18a fix: use pretty_print_pat for params in fn 2024-09-09 20:59:23 +08:00
roife
60c42c25c7 feat: add prettifier for Pat 2024-09-09 20:59:23 +08:00
roife
5004371a4a feat: Allow hir-def prettifier formatting into one-line 2024-09-09 20:59:23 +08:00
cuishuang
2f29feab2f Remove unnecessary symbols and add missing symbols
Signed-off-by: cuishuang <imcusg@gmail.com>
2024-09-09 16:36:37 +08:00
Ali Bektas
31ed8c9361 Better testing infra for ratoml 2024-09-08 23:40:38 +02:00
Chayim Refael Friedman
779a7cb0e3 Automatically add semicolon when completing unit-returning functions
But provide a config to suppress that.

I didn't check whether we are in statement expression position, because this is hard in completion (due to the natural incompleteness of source code when completion is invoked), and anyway using function returning unit as an argument to something seems... dubious.
2024-09-08 23:41:16 +03:00
Michael Goulet
8851e4fa39 Fix tools 2024-09-06 10:32:48 -04:00
Lukas Wirth
7c5275939a fix: Properly prevent mir building with unknown types present 2024-09-06 14:44:05 +02:00
Lukas Wirth
20f7ab5ab4 fix: Always explicitly set trait ref self types when lowering 2024-09-06 14:06:41 +02:00
Lukas Wirth
70ee4e5545 Bump lsp-server 2024-09-06 14:06:38 +02:00
bors
e09dabf1f3 Auto merge of #18065 - Veykril:catchy-diagnostics, r=Veykril
fix: Catch panics from diagnostics computation
2024-09-06 06:22:41 +00:00
Lukas Wirth
f19a9fe7ba fix: Catch panics from diagnostics computation 2024-09-06 08:21:08 +02:00
Wilfred Hughes
3cf28f1fc6 fix: Updating settings should not clobber discovered projects
`linkedProjects` is owned by the user's configuration, so when users
update this setting, `linkedProjects` is reset. This is problematic when
`linkedProjects` also contains projects discovered with `discoverCommand`.

The buggy behaviour occurred when:

(1) The user configures `discoverCommand` and loads a Rust project.

(2) The user changes any setting in VS Code, so rust-analyzer receives
`workspace/didChangeConfiguration`.

(3) `handle_did_change_configuration` ultimately calls
`Client::apply_change_with_sink()`, which updates `config.user_config`
and discards any items we added in `linkedProjects`.

Instead, separate out `discovered_projects_from_filesystem` and
`discovered_projects_from_command` from user configuration, so user
settings cannot affect any type of discovered project.

This fixes the subtle issue mentioned here:
https://github.com/rust-lang/rust-analyzer/pull/17246#issuecomment-2185259122
2024-09-05 15:46:03 -07:00
David Richey
e602e015e5 Add command to report unresolved references 2024-09-05 12:11:28 -05:00
Lukas Wirth
5b79d922b2 fix: Fix parser panicking on invalid asm options 2024-09-05 17:07:10 +02:00
Lukas Wirth
f74a0c8801 asm! parsing and lowering fixes 2024-09-05 15:08:16 +02:00
Lukas Wirth
c075a9980e Fix name fetching being incorrect for asm operands 2024-09-05 13:41:03 +02:00
Lukas Wirth
564926ac99 Add missing doc comments 2024-09-05 13:19:32 +02:00
Lukas Wirth
95d8d8e697 Support more IDE features for asm operands 2024-09-05 13:19:02 +02:00
Lukas Wirth
811905fce8 Give InlineAsmOperand a HIR representation 2024-09-05 12:40:48 +02:00
Lukas Wirth
a600e1df73 Add Definition kind for asm register operand 2024-09-05 10:53:07 +02:00
Lukas Wirth
164b15bc62 Add Definition kind for asm register classes 2024-09-05 10:23:00 +02:00
Lukas Wirth
3b11ff8c4d Lower asm expressions 2024-09-05 09:59:08 +02:00
coekjan
0b9d2725ae
fix: Fix inline_const_as_literal error when the number >= 10 2024-09-05 14:26:21 +08:00
David Barsky
9d74b5f264 assist: ensure replace_qualified_name_with_use applies to the first path segment 2024-09-04 12:15:28 -04:00
Lukas Wirth
86658c66b4 Parse builtin#asm expressions 2024-09-04 14:09:03 +02:00
bors
50882fbfa2 Auto merge of #18045 - Veykril:fix-loop-lower, r=Veykril
fix: Fix lowering of for loops dropping the loop block
2024-09-04 10:03:39 +00:00
Lukas Wirth
fbca403ebe fix: Fix lowering of for loops dropping the loop block 2024-09-04 12:00:16 +02:00
Lukas Wirth
230cd21bed Add edition dependent keyword highlighting tests 2024-09-04 11:32:59 +02:00
Nadrieril
c304e9b817 Add an internal lint that warns when accessing untracked data 2024-09-03 19:14:19 +02:00
DropDemBits
12c62662aa
bundle old root into SyntaxEdit result
useful for `SourceChangeBuilder` so it can still perform a tree diff without having to store the old root separately
2024-09-03 11:20:23 -04:00
bors
6e8445139b Auto merge of #17984 - ShoyuVanilla:cast, r=Veykril
feat: Implement cast typecheck and diagnostics

Fixes  #17897 and fixes #16564
Mainly adopted from 100fde5246/compiler/rustc_hir_typeck/src/cast.rs
2024-09-03 06:00:10 +00:00
bors
1fddb11f0f Auto merge of #18031 - roife:suggest-name-in-completion, r=Veykril
feat: Suggest name in completion for let_stmt and fn_param

fix #17780

1. Refactor: move `ide_assist::utils::suggest_name` to `ide-db::syntax_helpers::suggest_name` for reuse.
2. When completing `IdentPat`, detecte if the current node is a `let_stmt` or `fn_param`, and suggesting a new name based on the context.
2024-09-03 05:45:53 +00:00
DropDemBits
69e8393963
misc fixes 2024-09-02 22:53:54 -04:00
DropDemBits
d929121f7b
handle replace_with_many and replace_all 2024-09-02 22:27:14 -04:00
DropDemBits
41dbaa415a
support replacing root node 2024-09-02 21:42:08 -04:00
DropDemBits
b565d8db74
properly sort changes by depth to sort between nodes that have the same start range 2024-09-02 21:34:00 -04:00
DropDemBits
5fe518361e
fix insert ranges not being excluded from disjointness 2024-09-02 20:45:57 -04:00
DropDemBits
21bb04d3a6
support insert{_all} 2024-09-02 19:11:39 -04:00
DropDemBits
3440408087
propagate annotations to mapped elements 2024-09-02 18:24:47 -04:00
roife
35ed65a513 tests: suggesting names in completions for let_stmt and fn_param 2024-09-03 05:23:04 +08:00
roife
492e66ceab feat: suggest name in let_stmt and fn_param 2024-09-03 05:22:55 +08:00
roife
b207e5781e refactor: move ide_assist::utils::suggest_name to ide-db 2024-09-03 05:21:05 +08:00
Shoyu Vanilla
d186bdc617 feat: Implement cast typechecks 2024-09-03 04:11:36 +09:00
Laurențiu Nicola
98cc4b6115 Merge some strings 2024-09-02 20:05:35 +03:00
Laurențiu Nicola
d398b8f3f9 Avoid Option::is_none_or for a while 2024-09-02 20:04:35 +03:00
bors
5461f494e6 Auto merge of #18028 - Veykril:lifetime-hints-panic, r=Veykril
fix: lifetime hint panic in non generic defs
2024-09-02 16:05:36 +00:00
Lukas Wirth
134e0a4e87 fix: lifetime hint panic in non generic defs 2024-09-02 18:04:21 +02:00
bors
d534cc63d3 Auto merge of #18016 - IvarWithoutBones:wrap-return-ty-local-result, r=Veykril
fix: use Result type aliases in "Wrap return type in Result" assist

This commit makes the "Wrap return type in Result" assist prefer type aliases of standard library type when the are in scope, use at least one generic parameter, and have the name `Result`.

The last restriction was made in an attempt to avoid false assumptions about which type the user is referring to, but that might be overly strict. We could also do something like this, in order of priority:
* Use the alias named "Result".
* Use any alias if only a single one is in scope, otherwise:
* Use the standard library type.

This is easy to add if others feel differently that is appropriate, just let me know.

Fixes #17796
2024-09-02 11:33:44 +00:00
Lukas Wirth
8c59bbe916 Adjust completions scoring 2024-09-02 13:17:52 +02:00
Lukas Wirth
26cd745104 Simplify CompletionRelevance 2024-09-02 13:17:49 +02:00
cuishuang
680de15ec3 chore: fix some comments
Signed-off-by: cuishuang <imcusg@gmail.com>
2024-09-02 18:33:23 +08:00
DropDemBits
db649195e9
handle merging two syntax editors together 2024-09-02 00:09:30 -04:00
DropDemBits
883e429179
elaborate SyntaxEdit comments 2024-09-02 00:02:32 -04:00
DropDemBits
ad9595d729
wip: new syntax tree editor 2024-09-02 00:02:32 -04:00
Ivar Scholten
4e9d17b96d fix: use Result type aliases in "Wrap return type in Result" assist
This commit makes the "Wrap return type in Result" assist prefer type aliases of standard library
type when the are in scope, use at least one generic parameter, and have the name "Result".

The last restriction was made in an attempt to avoid false assumptions about which type the
user is referring to, but that might be overly strict. We could also do something like this, in
order of priority:

* Use the alias named "Result".
* Use any alias if only a single one is in scope, otherwise:
* Use the standard library type.

This is easy to add if others feel differently that is appropriate, just let me know.
2024-09-02 02:00:19 +02:00
bors
779d9eee2e Auto merge of #17967 - Veykril:mbe-tests, r=Veykril
internal: Lay basic ground work for standalone mbe tests

Most of our mbe hir-def tests don't actually do anything name res relevant, we can (and should) move those down the stack into `mbe/hir-expand`.
2024-09-01 11:44:58 +00:00
Lukas Wirth
4502a602a7 internal: Lay basic ground work for standalone mbe tests 2024-09-01 12:42:44 +02:00
bors
bae49517f2 Auto merge of #17985 - riverbl:explicit-enum-discriminant, r=Veykril
Add explicit enum discriminant assist

Add assist for adding explicit discriminants to all variants of an enum.

Closes #17798.
2024-09-01 09:38:28 +00:00
Lukas Wirth
1e30cc0f35 minor: Reduce friction for updating minicore 2024-09-01 11:32:55 +02:00
bors
72fe274605 Auto merge of #17737 - hyf0:hyf_32089420384, r=Veykril
feat(ide-completion): extra sugar auto-completion `async fn ...` in `impl trait` for `async fn in trait` that's defined in desugar form

Solves #17719.

---

Preview

<img width="670" alt="image" src="https://github.com/user-attachments/assets/64ccef84-4062-4702-8760-89220585f422">

<img width="540" alt="image" src="https://github.com/user-attachments/assets/d22637f9-d531-43b2-a9f1-cd40a002903a">

<img width="631" alt="image" src="https://github.com/user-attachments/assets/21cd2142-bb8e-4493-9ac7-e6a9e7076904">
2024-09-01 09:24:04 +00:00
Lukas Wirth
eb64cc8c35 Complete desugared and resugared async fn in trait impls 2024-09-01 11:22:50 +02:00
Yunfei
18feb726be feat(ide-completion): extra sugar auto-completion async fn ... in impl trait for async fn in trait that's defined in desugar form 2024-09-01 10:08:25 +02:00
Lukas Wirth
2e2f798a74 minor: Downgrade cyclic deps error to warning 2024-09-01 10:02:41 +02:00
bors
8d1d5cdfc1 Auto merge of #18015 - ChayimFriedman2:flip-comma-attribute, r=Veykril
Handle attributes correctly in "Flip comma"

Attributes often contain path followed by a token tree (e.g. `align(2)`), and the previous code handled them as two separate items, which led to results such as `#[repr(alignC, (2))]`.

An alternative is to just make the assist unavailable in attributes, like we do in macros. But contrary to macros, attributes often have a fixed form, so this seems useful.

Fixes #18013.
2024-09-01 06:25:29 +00:00
Matthias Krüger
7136bce009
Rollup merge of #129207 - GrigorenkoPV:elided-is-named, r=cjgillot
Lint that warns when an elided lifetime ends up being a named lifetime

As suggested in https://github.com/rust-lang/rust/issues/48686#issuecomment-1817334575

Fixes #48686
2024-09-01 03:58:03 +02:00
Chayim Refael Friedman
5c14f13ce0 Handle attributes correctly in "Flip comma"
Attributes often contain path followed by a token tree (e.g. `align(2)`, and the previous code handled them as two separate items, which led to results such as `#[repr(alignC, (2))]`.

An alternative is to just make the assist unavailable in attributes, like we do in macros. But contrary to macros, attributes often have a fixed form, so this seems useful.
2024-09-01 02:07:05 +03:00
Chayim Refael Friedman
01cc847158 Provide an option to hide deprecated items from completion 2024-09-01 01:04:21 +03:00
Pavel Grigorenko
55207f61b4 Fix elided_named_lifetimes in code 2024-08-31 15:35:41 +03:00
riverbl
db1ccb8bec Rename function and remove flag argument
Use less confusing name for function, duplicate logic rather than taking flag as argument.
2024-08-31 10:17:37 +01:00
riverbl
fbc9d8a675 Update generated doctests
Update generated doctests, change unit test to be different to doctest.
2024-08-31 10:17:37 +01:00
riverbl
6d3ef599f7 Add explicit enum discriminant assist
Add assist for adding explicit discriminants to all variants of an enum.
2024-08-31 10:17:37 +01:00
bors
914a1caab5 Auto merge of #18012 - Veykril:inlay-hints-lt, r=Veykril
fix: Fix lifetime elision inlay hints breaking for ranged requests
2024-08-31 08:52:59 +00:00
Lukas Wirth
82f96b5e6a fix: Fix lifetime elision inlay hints breaking for ranged requests 2024-08-31 10:51:13 +02:00
bors
1a84cd68a8 Auto merge of #18011 - Wilfred:op_queue_doc_comments, r=Veykril
internal: Add doc comments to OpQueue

I spent a while debugging some OpQueue behaviours and found the API slightly confusing, so I've added doc comments to clarify what each OpQueue method does.
2024-08-31 04:54:50 +00:00
bors
30c14ca30d Auto merge of #17945 - alibektas:ratoml_categorization, r=alibektas
Recategorize config classes
2024-08-31 01:17:08 +00:00
Ali Bektas
b17f1eee7d Apply changes, fix path information in a comment in config.rs 2024-08-31 03:01:54 +02:00
bors
9fd7051950 Auto merge of #18010 - Veykril:inlay-hints-lt, r=Veykril
feat: Support fn-ptr and fn-path types for lifetime elision hints

All still syntax based unfortunately but that won't change for quite a while
2024-08-30 17:37:33 +00:00
Lukas Wirth
16077975fa Support fn-ptr and fn-path types for lifetime elision hints 2024-08-30 19:36:18 +02:00
bors
1cb426654a Auto merge of #18008 - Veykril:inlay-hints-resolve, r=Veykril
internal: Improve inlay hint resolution reliability

The payload now ships the range the inlay hint ought to be triggered for instead of trying to estimate it from its position which is somewhat brittle
2024-08-30 13:59:05 +00:00
Lukas Wirth
5ca5d52697 Improve inlay hint resolution reliability 2024-08-30 15:57:52 +02:00
rami3l
0b28126599
fix(ide-completion): fix handling of for in impl T for A in function body 2024-08-30 21:39:53 +08:00
bors
13ac53e73d Auto merge of #18003 - ChayimFriedman2:addr_of-static-mut, r=Veykril
Do not report missing unsafe on `addr_of[_mut]!(EXTERN_OR_MUT_STATIC)`

The compiler no longer does as well; see https://github.com/rust-lang/rust/pull/125834.

Also require unsafe when accessing `extern` `static` (other than by `addr_of!()`).

Fixes #17978.
2024-08-30 07:55:50 +00:00
bors
aefe34d876 Auto merge of #17999 - ShoyuVanilla:issue-17998, r=Veykril
fix: `std::error::Error` is object unsafe

Fixes #17998

I tried to get generic predicates of assoc function itself, not inherited from the parent here;

0ae42bd425/crates/hir-ty/src/object_safety.rs (L420-L442)

But this naive equality check approach doesn't work when the assoc function has one or more generic paramters like;

```rust
trait Foo {}
trait Bar: Foo {
    fn bar(&self);
}
```

because the generic predicates of the parent, `Bar` is `[^1.0 implements Foo]` and the generic predicates of `fn bar` is `[^1.1 implements Foo]`, which are different.

This PR implements a correct logic for filtering out parent generic predicates for this.
2024-08-30 05:53:23 +00:00
Ivar Scholten
f4070afb02 fix: consider indentation in the "Generate impl" and "Generate trait impl" assists
This makes the generated impl's indentation match the ADT it targets, improving formatting when
using nested modules inside of the same file or when defining types inside of a function.
2024-08-29 22:12:25 +02:00
Chayim Refael Friedman
91f2016ee1 Do not report missing unsafe on addr_of[_mut]!(EXTERN_OR_MUT_STATIC)
The compiler no longer does as well; see https://github.com/rust-lang/rust/pull/125834.
2024-08-29 22:58:26 +03:00
Chayim Refael Friedman
3d21d5e614 Add diagnostic for accessing an extern static 2024-08-29 22:12:12 +03:00
Shoyu Vanilla
231083958a fix: std::error::Error is object unsafe 2024-08-30 02:00:38 +09:00
bors
0ae42bd425 Auto merge of #17814 - ShoyuVanilla:object-safety, r=Veykril
feat: Implement object safety and its hovering hint

Resolves #17779

- [x] Fill missing implementations
- [x] Hover rendering
- [x] Implement object safety's own test suite, like layout
- [x] Add test cases (from rustc maybe)
- [x] Clean up ugly codes
- [x] Add doc string
2024-08-29 13:24:54 +00:00
Shoyu Vanilla
6520a43ca3 feat: Implement object safety 2024-08-29 22:22:21 +09:00
bors
d5a424f338 Auto merge of #17993 - ChayimFriedman2:convert-to-tuple-attrs, r=Veykril
Consider field attributes when converting from tuple to named struct and the opposite

Fixes #17983.

I tried to use the `SourceChangeBuilder::make_mut()` API, but it duplicated the attribute...
2024-08-29 08:28:46 +00:00
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