Commit Graph

264871 Commits

Author SHA1 Message Date
Chayim Refael Friedman
16f3eb969f 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
2053d7d23e 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
b304701b67 feat: generate names for tuple-struct in add-missing-match-arms 2024-09-10 00:30:48 +08:00
roife
32d9597200 refactor: introduce NameGenerator in suggest_name 2024-09-10 00:30:46 +08:00
roife
129acd2e08 feat: use shorthand when pretty-print record pat 2024-09-09 23:20:31 +08:00
bors
600f7cfb05 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
e1653b6d5e feat: better name suggestions for fn 2024-09-09 21:53:11 +08:00
roife
cbfa357813 fix: add parenthesis for or-pattern 2024-09-09 20:59:23 +08:00
roife
81fae18c9e fix: use pretty_print_pat for params in fn 2024-09-09 20:59:23 +08:00
roife
352bd9f8e1 feat: add prettifier for Pat 2024-09-09 20:59:23 +08:00
roife
544ccedd55 feat: Allow hir-def prettifier formatting into one-line 2024-09-09 20:59:23 +08:00
cuishuang
06d1aa257e Remove unnecessary symbols and add missing symbols
Signed-off-by: cuishuang <imcusg@gmail.com>
2024-09-09 16:36:37 +08:00
Ali Bektas
81227a309c Better testing infra for ratoml 2024-09-08 23:40:38 +02:00
Chayim Refael Friedman
ca262a34ac 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
David Barsky
3bcc2b7888 assist: ensure replace_qualified_name_with_use applies to the first path segment 2024-09-08 10:57:23 -04:00
bors
f16a03f3a9 Auto merge of #18067 - Veykril:prevent-mir-building, r=Veykril
fix: Properly prevent mir building with unknown types present
2024-09-06 13:47:03 +00:00
Lukas Wirth
bdc9da9361 fix: Properly prevent mir building with unknown types present 2024-09-06 14:44:05 +02:00
bors
835972b30b Auto merge of #18068 - Veykril:ty-fixes, r=Veykril
fix: Always explicitly set `TraitRef` self types when lowering
2024-09-06 12:18:04 +00:00
Lukas Wirth
2c8e24e9e8 fix: Always explicitly set trait ref self types when lowering 2024-09-06 14:06:41 +02:00
Lukas Wirth
5f8823bf8f Bump lsp-server 2024-09-06 14:06:38 +02:00
bors
07544c57dd Auto merge of #18066 - Veykril:lsp-server-no-panic, r=Veykril
fix: Don't panic lsp writer thread on dropped receiver

Should reduce the noise a bit (https://github.com/rust-lang/rust-analyzer/issues/18055). This removes the panic (and a follow up panic) when the server incorrectly shuts down, turning it into a proper late exit error.
2024-09-06 07:15:13 +00:00
Lukas Wirth
775c5c84a5 fix: Don't panic lsp writer thread on dropped receiver 2024-09-06 09:13:00 +02:00
bors
56fde6ef41 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
7e5a0e5777 fix: Catch panics from diagnostics computation 2024-09-06 08:21:08 +02:00
bors
ecd835de15 Auto merge of #18059 - Wilfred:config_cleanups, r=Veykril
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-06 06:04:03 +00:00
Wilfred Hughes
06c86a1069 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
f44bdb5c78 Add command to report unresolved references 2024-09-05 12:11:28 -05:00
bors
a3be866668 Auto merge of #18053 - Veykril:asm-parse, r=Veykril
fix: Couple asm! parsing and lowering fixes
2024-09-05 15:09:02 +00:00
Lukas Wirth
4e2e1bf6ed fix: Fix parser panicking on invalid asm options 2024-09-05 17:07:10 +02:00
Lukas Wirth
20e9c8d110 asm! parsing and lowering fixes 2024-09-05 15:08:16 +02:00
bors
bdfb2f6745 Auto merge of #18022 - Veykril:asm-parse, r=Veykril
feat: IDE support for `asm!` expressions

Fixes https://github.com/rust-lang/rust-analyzer/issues/10461, Fixes https://github.com/rust-lang/rust-analyzer/issues/6031 Progresses https://github.com/rust-lang/rust-analyzer/issues/11621

Notably this only works for asm expressions not items yet. Most IDE features work, mainly completions need extra logic still.
2024-09-05 11:50:34 +00:00
Lukas Wirth
72980c417c Fix name fetching being incorrect for asm operands 2024-09-05 13:41:03 +02:00
Lukas Wirth
2120b38adf Add missing doc comments 2024-09-05 13:19:32 +02:00
Lukas Wirth
bdb734b63a Support more IDE features for asm operands 2024-09-05 13:19:02 +02:00
Lukas Wirth
f3b6965f90 Give InlineAsmOperand a HIR representation 2024-09-05 12:40:48 +02:00
Lukas Wirth
304f54e023 Add Definition kind for asm register operand 2024-09-05 10:53:07 +02:00
Lukas Wirth
44e3b7d205 Add Definition kind for asm register classes 2024-09-05 10:23:00 +02:00
Lukas Wirth
1328b52e91 Lower asm expressions 2024-09-05 09:59:08 +02:00
coekjan
b41f6ab525
fix: Fix inline_const_as_literal error when the number >= 10 2024-09-05 14:26:21 +08:00
David Barsky
38514bade2 assist: ensure replace_qualified_name_with_use applies to the first path segment 2024-09-04 12:15:28 -04:00
Lukas Wirth
7222f2de38 Parse builtin#asm expressions 2024-09-04 14:09:03 +02:00
bors
1c26c99fcd 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
1e7d99ff43 fix: Fix lowering of for loops dropping the loop block 2024-09-04 12:00:16 +02:00
bors
0b432fc32c Auto merge of #18044 - Veykril:highlight-kw-test, r=Veykril
internal: Add edition dependent keyword highlighting tests
2024-09-04 09:49:17 +00:00
Lukas Wirth
01b1bfd18a Add edition dependent keyword highlighting tests 2024-09-04 11:32:59 +02:00
DropDemBits
a07e54c6ea
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
b7138a816d Auto merge of #18036 - Veykril:smol_str, r=Veykril
Bump `smol_str`
2024-09-03 09:59:33 +00:00
Lukas Wirth
17e5f01d2b Bump smol_str 2024-09-03 11:54:33 +02:00
bors
c01d5e03f2 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
6faf40992e 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