Commit Graph

256 Commits

Author SHA1 Message Date
Pascal Kuthe
2e465d18f2
generate correct completion edits for missing macro arguments
rust-analyzer used the token at the cursor after macro expansion
to decide whether to replace the token at the cursor before macro
expansion. In most cases these two are the same but in some cases these
can mismatch which can lead to incorrect replacements.

For example if an ident/expr macro argument is missing rust-analyzer
generates a "missing" identifier as a placeholder, there is only a
brace at the cursor. Therefore, rust-analyzer will incorrectly replace
the macro brace with the completion in that case leading to #14246.

Using the expanded token type was intentional. However, this doesn't
seem to ever be desirable (this is supported by the fact that there
were no tests that relied on this behavior) since the type of edit to
perform should always be determined by the token it's actually applied
to.
2023-03-04 02:05:09 +01:00
Lukas Wirth
78b2dd813a Diagnose unresolved field accesses 2023-03-03 20:43:10 +01:00
bors
6756294aa0 Auto merge of #14184 - lowr:feat/trait-alias-def, r=Veykril
Handle trait alias definitions

Part of #2773

This PR adds a bunch of structs and enum variants for trait aliases. Trait aliases should be handled as an independent item because they are semantically distinct from traits.

I basically started by adding `TraitAlias{Id, Loc}` to `hir_def::item_tree` and iterated adding necessary stuffs until compiler stopped complaining what's missing. Let me know if there's still anything I need to add.

I'm opening up this PR for early review and stuff. I'm planning to add tests for IDE functionalities in this PR, but not type-related support, for which I put FIXME notes.
2023-03-03 15:45:18 +00:00
Ryo Yoshida
29c957f973
Lower and handle trait aliases in HIR 2023-03-04 00:24:07 +09:00
Ryo Yoshida
bda2af71c6
feat: allow generate_function to generate in different local crate 2023-03-03 18:40:13 +09:00
Lukas Wirth
9e5fa74279 Simplify 2023-02-27 15:51:45 +01:00
Lukas Wirth
404a51f26a internal: Make CompletionItem more POD-like 2023-02-16 09:29:55 +01:00
Lukas Wirth
23fc596e40 Don't reconstruct ref match completion in to_proto manually 2023-02-15 14:15:22 +01:00
Lukas Wirth
026a8c976d Simplify 2023-02-15 13:38:42 +01:00
bors
523fea8f25 Auto merge of #14149 - Veykril:completion, r=Veykril
Trigger call info for more completions of signature having things
2023-02-14 16:42:30 +00:00
Lukas Wirth
cade9f7020 Trigger call info for more completions of signature having things 2023-02-14 17:05:07 +01:00
Lukas Wirth
3c0f20a7bd internal: Enable smallvec's union feature 2023-02-14 17:01:01 +01:00
bors
44568007d1 Auto merge of #14128 - Veykril:parser, r=Veykril
internal: Improve parser recovery for delimited lists

Closes https://github.com/rust-lang/rust-analyzer/issues/11188, https://github.com/rust-lang/rust-analyzer/issues/10410, https://github.com/rust-lang/rust-analyzer/issues/10173

Should probably be merged after the stable release as this might get the parser stuck if I missed something
2023-02-14 12:59:39 +00:00
Duong Quoc Khanh
0285acc5f7
Find next_non_trivia_token of name_ref. 2023-02-13 20:11:04 +09:00
Lukas Wirth
d2cf8c234a Make else autocompletion work in more places 2023-02-12 10:49:57 +01:00
Lukas Wirth
33cacde04b Fix active parameter analysis 2023-02-12 10:26:19 +01:00
Duong Quoc Khanh
e1396bde73
Don't trigger postfix completion if block which has an else block
Discard postfix completion if the next_non_trivia_sibling of dot_token
is an ELSE_KW.
2023-02-11 21:26:00 +09:00
Duong Quoc Khanh
74cd8ecc7e
Add completion without body.
Add completion for Fn, Const, TypeAlias without body.
2023-02-09 17:37:11 +09:00
Duong Quoc Khanh
58136b01ba
Add more tests for completion without body.
Add tests for Fn, Const, TypeAlias without body inside Trait.
2023-02-09 17:32:55 +09:00
bors
6effb26062 Auto merge of #14095 - dqkqd:master, r=Veykril
Add postfix completion for `unsafe`.

Fix #13779.

Hi, this is my first PR. Please tell me if there is anything I should do.
2023-02-08 09:44:22 +00:00
bors
a05ce5a3e7 Auto merge of #13986 - MariaSolOs:limit-completions, r=Veykril
Add setting for limiting number of completions

For #13911.
2023-02-08 09:31:35 +00:00
Duong Quoc Khanh
2666e6eda8
Add test for LetElse case.
Postfix completion is not triggered.
2023-02-08 04:04:10 +09:00
Duong Quoc Khanh
8535f2bb1b
Handle edge cases.
Handle case when BlockExpr is child of IfExpr, WhileExpr, LoopExpr,
ForExpr.
An additional { } will be added when:
- It is not a BlockExpr
- It is a BlockExpr and a child of IfExpr, WhileExpr, LoopExpr, ForExpr.
2023-02-08 03:37:20 +09:00
Duong Quoc Khanh
370ba94ca2
Add more tests.
Add tests for control flows and `let`.
2023-02-08 01:50:09 +09:00
Duong Quoc Khanh
a7df61f1d3
Add postfix completion for unsafe.
Wrap receiver_text with { } if it's not a BlockExpr.
2023-02-07 23:55:44 +09:00
Ryo Yoshida
a4d0b5c522
Add regression tests 2023-02-05 22:28:03 +09:00
Ryo Yoshida
0ec2911857
fix: consider relative offset to fake ident token in expansion for completion 2023-02-05 22:27:52 +09:00
Maybe Waffle
249ea9502d Set "current" edition to 2021 2023-01-31 10:51:43 +00:00
Lukas Wirth
f8ed4d7ae4 Use lang item resolution instead of known paths 2023-01-21 19:03:36 +01:00
Laurențiu Nicola
392a6ee422 Bump once_cell 2023-01-21 08:48:46 +02:00
Maria José Solano
d044bc3504 Format code 2023-01-19 18:33:47 -08:00
Maria José Solano
ec89fc85a8 Add limit setting 2023-01-19 18:21:43 -08:00
bors
fa874627f0 Auto merge of #13969 - Veykril:workspace.dependencies, r=Veykril
Use workspace.dependencies to declare local dependencies
2023-01-17 10:29:27 +00:00
Lukas Wirth
bed4db3c62 Use workspace.dependencies to declare local dependencies 2023-01-17 10:52:26 +01:00
Lukas Wirth
e4858fe480 Specify authors, edition and license via workspace.package 2023-01-16 16:44:00 +01:00
Lukas Wirth
679df2adf1 Specify rust-version via workspace.package 2023-01-16 16:33:01 +01:00
Maybe Waffle
bd04416aaa Iterate over arrays dirrectly, instead of going through a slice 2023-01-14 13:02:28 +00:00
unvalley
9eabc2cde8 fix: add_format_like_completions to handle no exprs 2023-01-09 12:23:59 +01:00
bors
f77b68a3cb Auto merge of #13860 - danieleades:clippy, r=lnicola
fix a bunch of clippy lints

fixes a bunch of clippy lints for fun and profit

i'm aware of this repo's position on clippy. The changes are split into separate commits so they can be reviewed separately
2023-01-08 17:29:57 +00:00
Brent Westbrook
150da92b5c return immediately from render_record_lit if snippet_cap is None
this is the record literal version of #13805, which handled the same issue for
tuple literals
2023-01-04 12:55:05 -05:00
Daniel Eades
efd2c20e96 remove useless conversions 2023-01-02 15:02:54 +00:00
Daniel Eades
cc80c5bd07 remove unnecessary lazy evaluations 2023-01-02 15:02:54 +00:00
Daniel Eades
ed128872eb remove needless borrows 2023-01-02 14:52:32 +00:00
Daniel Eades
77051679d7 use inline format args 2023-01-02 14:52:32 +00:00
Laurențiu Nicola
3aae785693 Avoid useless format 2022-12-30 16:10:07 +02:00
Yuri Astrakhan
e16c76e3c3 Inline all format arguments where possible
This makes code more readale and concise,
moving all format arguments like `format!("{}", foo)`
into the more compact `format!("{foo}")` form.

The change was automatically created with, so there are far less change
of an accidental typo.

```
cargo clippy --fix -- -A clippy::all -W clippy::uninlined_format_args
```
2022-12-24 14:36:10 -05:00
bors
fb0db2a420 Auto merge of #13831 - bvanjoi:fix_bound_type_in_trait_insert, r=Veykril
fix(completion): remove bound insert of type in trait

Fixed https://github.com/rust-lang/rust-analyzer/issues/13819
2022-12-23 12:27:44 +00:00
bvanjoi
67cbd8f7c1 fix(completion): remove bound insert of type in trait 2022-12-23 18:45:25 +08:00
Yuri Astrakhan
1d59c7b667 Remove non-needed clones
I am not certain if this will improve performance,
but it seems having a .clone() without any need should be removed.

This was done with clippy, and manually reviewed:

```
cargo clippy --fix -- -A clippy::all -D clippy::redundant_clone
```
2022-12-23 02:20:03 -05:00
Brent Westbrook
694ae77bf6 pass snippet_cap to format_literal_label, return early if None 2022-12-20 11:27:19 -05:00