Commit graph

20692 commits

Author SHA1 Message Date
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
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
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
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
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
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
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