Commit Graph

1301 Commits

Author SHA1 Message Date
Tavo Annus
a946970e2d Add quantified trees to reduce autocomplete options 2024-02-11 13:33:29 +02:00
Tavo Annus
bdbdd83ec1 Initial version of term_search for autocomplete 2024-02-11 13:33:29 +02:00
Tavo Annus
627255dd5a Add static method tactic 2024-02-11 13:33:29 +02:00
Tavo Annus
35eb0dbbc0 Add more documentation for term search 2024-02-11 13:33:29 +02:00
Tavo Annus
bb3c7cff60 Introduce term search to rust-analyzer 2024-02-11 13:33:29 +02:00
Lukas Wirth
5136705fad internal: Remove SELF_REF hack for self referential SyntaxContexts 2024-02-10 16:20:02 +01:00
bors
1ef7a2329b Auto merge of #16525 - Veykril:item-loc, r=Veykril
Abstract more over ItemTreeLoc-like structs

Allows reducing some code duplication by using functions generic over said structs. The diff isn't negative due to me adding some additional impls for completeness.
2024-02-10 10:47:37 +00:00
Lukas Wirth
00303c3b67 Abstract over ItemTreeLoc 2024-02-10 11:37:59 +01:00
Lukas Wirth
2ebf0c87c2 Deduplicate some code 2024-02-10 01:51:22 +01:00
Tetsuharu Ohzeki
eba1b13295 hir: Fix warnings about clippy str_to_string rule 2024-02-10 01:00:40 +09:00
Tetsuharu Ohzeki
7669619f9a clippy: Enable self_named_constructors rule 2024-02-09 22:31:21 +09:00
davidsemakula
602acfcb70 fix conflicting "unnecessary else" and "trailing return" diagnostics tests 2024-02-08 19:32:53 +03:00
davidsemakula
a250c2dde0 refactor remove trailing return diagnostic 2024-02-08 19:32:53 +03:00
davidsemakula
98e6f43a2f remove trailing return in trailing match expression 2024-02-08 19:32:53 +03:00
davidsemakula
2987fac76f diagnostic to remove trailing return 2024-02-08 19:32:53 +03:00
bors
0e5766b0d8 Auto merge of #16477 - davidsemakula:trait-incorrect-case-diagnostic, r=Veykril
feat: Add incorrect case diagnostics for traits and their associated items

Updates incorrect case diagnostic to:
- Check traits and their associated items
- Ignore trait implementations except for patterns in associated function bodies

Also cleans up `hir-ty::diagnostics::decl_check` a bit (mostly to make it a bit more DRY and easier to maintain)

Also fixes: #8675 and fixes: #8225
2024-02-08 14:40:16 +00:00
bors
e9d3565cd1 Auto merge of #16502 - davidsemakula:unnecessary-else-diagnostic, r=Veykril
feat: Add "unnecessary else" diagnostic and fix

Fixes #9457
2024-02-08 14:25:00 +00:00
Lukas Wirth
81ea48a573 fix: Fix tuple structs not rendering visibility in their fields 2024-02-08 10:05:28 +01:00
davidsemakula
62cc4f9c46 add unnecessary else diagnostic 2024-02-06 19:00:10 +03:00
bors
66cec4d11a Auto merge of #16470 - Veykril:clippy-disallow, r=lnicola
internal: Lint debug prints and disallowed types with clippy
2024-02-05 17:20:43 +00:00
bors
3e47532dd4 Auto merge of #16474 - davidbarsky:david/import-on-the-fly-improvements, r=lnicola
internal: even more `tracing`

As part of profiling completions, I added some additional spans and moved `TyBuilder::subst_for_def` closer to its usage site (the latter had a small impact on completion performance. Thanks for the tip, Lukas!)
2024-02-05 09:01:58 +00:00
davidsemakula
080d223dd4 incorrect case diagnostics for type aliases 2024-02-02 17:07:08 +03:00
davidsemakula
6d2d6323ac incorrect case diagnostics for trait assoc functions and consts 2024-02-02 17:07:08 +03:00
David Barsky
f9bef39d48 internal: add some more tracing spans inside of hir-ty 2024-02-01 16:10:32 -05:00
Lukas Wirth
9e8a0fae0c Lint debug prints and disallowed types with clippy 2024-02-01 17:57:27 +01:00
Johann Hemmann
b73ee2f50d useless_conversion 2024-01-31 19:06:18 +01:00
Johann Hemmann
c4302eaa56 unnecessary_lazy_evaluations 2024-01-31 19:06:18 +01:00
Johann Hemmann
de6f9561f2 unnecessary_cast 2024-01-31 19:06:18 +01:00
Johann Hemmann
daa20725c5 toplevel_ref_arg 2024-01-31 19:06:18 +01:00
Lukas Wirth
d252247ab7 internal: Remove unnecessary usages of ExpansionInfo 2024-01-31 09:57:17 +01:00
David Barsky
e1ea7c8844 internal: switch to tracing from log
This commit also adds `tracing` to NotificationDispatcher/RequestDispatcher,
bumps `rust-analyzer-salsa` to 0.17.0-pre.6, `always-assert` to 0.2, and
removes the homegrown `hprof` implementation in favor of a vendored
tracing-span-tree.
2024-01-30 12:27:31 -05:00
Johann Hemmann
43b1ae0446 cargo clippy --fix 2024-01-30 14:50:21 +01:00
bors
11b401d0b4 Auto merge of #16447 - Veykril:mir-errors, r=Veykril
intenral: Cleanup error variants in MIR code a bit
2024-01-30 11:38:41 +00:00
bors
22b6f9679d Auto merge of #16439 - wasd96040501:feat/gotodef3, r=Veykril
feat: Support for GOTO def from *inside* files included with include! macro

close #14937
Try to implement goto def from *inside* files included with include! macro.
This implementation has two limitations:
1. Only **one** file which calls include! will be tracked. (I think multiple file be included is a rare case and we may let it go for now)
2. Mapping token from included file to macro call file (semantics.rs:646~658) works fine but I am not sure is this the correct way to implement.
2024-01-30 11:27:18 +00:00
Lukas Wirth
5860763f18 Cleanup error variants in MIR code slightly 2024-01-30 09:53:39 +01:00
YangzeLuo
b22e772cab feat: Support for GOTO def from *inside* files included with include! macro 2024-01-27 23:36:01 +08:00
Lukas Wirth
6cf7b5f8d7 Don't parse intra doc links as syntax trees 2024-01-26 20:00:47 +01:00
Lukas Wirth
5a343415e8 Add some size assertions 2024-01-26 19:28:39 +01:00
Johann Hemmann
71d4dba960 redundant_pattern_matching 2024-01-19 17:31:01 +01:00
Johann Hemmann
5a62a0db46 redundant_closure 2024-01-19 17:31:01 +01:00
Johann Hemmann
3cf1358eb8 question_mark 2024-01-19 17:31:01 +01:00
Johann Hemmann
692212bbdd partialeq_to_none 2024-01-19 17:31:01 +01:00
Johann Hemmann
e58b683201 needless_return 2024-01-19 17:31:01 +01:00
Johann Hemmann
3839f9a9a2 needless_borrow 2024-01-19 17:31:01 +01:00
Johann Hemmann
add40c8660 match_like_matches_macro 2024-01-19 17:31:01 +01:00
Johann Hemmann
8982ff3bba get_first 2024-01-19 17:31:01 +01:00
Johann Hemmann
eb7aec5a8e map_clone 2024-01-19 17:31:01 +01:00
Johann Hemmann
c629ec7611 clone_on_copy 2024-01-19 17:31:01 +01:00
Johann Hemmann
6a2a603a8c let_and_return 2024-01-19 17:31:00 +01:00
Johann Hemmann
d8ad4afce8 manual_map 2024-01-19 17:31:00 +01:00
Johann Hemmann
3409645c3f bind_instead_of_map 2024-01-19 17:31:00 +01:00
Lukas Wirth
83591268ab minor: Make use of some new SmolStr improvements 2024-01-17 13:47:15 +01:00
Lukas Wirth
82e8355492 feat: Show notable trait impls on hover 2024-01-16 19:17:33 +01:00
Lukas Wirth
384488c157 feat: Hover for literals showing additional value information 2024-01-16 14:28:47 +01:00
Lukas Wirth
8f4f5a6cce fix: Make value_ty query fallible 2024-01-16 12:09:40 +01:00
Lukas Wirth
54f2111f69 internal: Make data queries transparent over their diagnostics variant 2024-01-16 10:47:54 +01:00
bors
5df53c9612 Auto merge of #16351 - Veykril:eager-enum-variant, r=Veykril
internal: Eagerly lower enum variants in CrateDefMap construction
2024-01-16 08:39:13 +00:00
Moritz Hedtke
fe35447617 fix: rename generator to coroutine also in dependencies
Follow the rename in nightly (see https://blog.rust-lang.org/inside-rust/2023/10/23/coroutines.html)
2024-01-15 12:24:48 +01:00
Lukas Wirth
180e9b2bbf Cleanup 2024-01-15 12:22:51 +01:00
Lukas Wirth
1669344b2a Thinner DefDiagnostics 2024-01-15 11:07:26 +01:00
Lukas Wirth
2d72ec71ec Deduplicate 2024-01-15 10:58:05 +01:00
Lukas Wirth
d80d2fcae0 Eagerly lower enum variants in CrateDefMap construction 2024-01-15 10:24:14 +01:00
Lukas Wirth
b6e6d5d3af internal: Consider all kinds of explicit private imports in find_path 2024-01-11 12:22:04 +01:00
Lukas Wirth
4d3a0dc329 Replace SourceRootCrates hashset output with slice for deterministic order 2024-01-10 14:51:51 +01:00
Lukas Wirth
4e16e0f2c1 Don't allocate DefDatabase::crate_lang_items if its empty 2024-01-09 21:06:21 +01:00
Lukas Wirth
9673915045 Make DefDatabase::lang_attr transparent 2024-01-09 20:52:10 +01:00
Matthias Krüger
3fb2cd2002 autofix remaining perf findings 2024-01-07 01:20:20 +01:00
Matthias Krüger
b22bd36f6e remove more redundant clones manually 2024-01-07 00:26:49 +01:00
Matthias Krüger
476e10e961 remove redundant clones 2024-01-07 00:17:48 +01:00
Lukas Wirth
5ac0c14384 Remove some vec clones in const-eval 2024-01-06 21:33:47 +01:00
Lukas Wirth
963568b46f feat: IDE features for primitive tuple fields 2024-01-06 15:04:58 +01:00
bors
11b0126679 Auto merge of #16267 - Veykril:import-map-fix, r=Veykril
internal: Deduplicate some code
2024-01-05 10:43:52 +00:00
Lukas Wirth
d60638e5e6 Deduplicate some code 2024-01-05 11:34:18 +01:00
bors
c84352a346 Auto merge of #16261 - Veykril:import-map-fix, r=Veykril
internal: Move query limits to the caller

Prior we calculated up to `limit` entries from a query, then filtered from that leaving us with less entries than the limit in some cases (which might give odd completion behavior due to items disappearing). This changes it so we filter before checking the limit.
2024-01-04 18:27:38 +00:00
Lukas Wirth
0af780ea3e Fix symbol_index::Query::search_maps not adhering to case-sensitivity correctly 2024-01-04 19:12:56 +01:00
Lukas Wirth
751d9d11e0 Add proc-macro-test crate back to the main workspace 2024-01-04 11:09:45 +01:00
Grégoire Geis
fe6f931ac2 hir: resolve associated items in docs (excl. type aliases) 2024-01-03 23:04:24 +09:00
bors
426d2842c1 Auto merge of #16222 - rosefromthedead:unresolved-assoc-item, r=Veykril
add unresolved-assoc-item assist

I tried to copy from private-assoc-item for this
2024-01-02 15:06:13 +00:00
bors
86e559bf3f Auto merge of #16211 - tetsuharuohzeki:update-lint, r=Veykril
Use Cargo's [workspace.lints.*] to config clippy

This change begin to use [`[workspace.lints.*]`](https://doc.rust-lang.org/cargo/reference/workspaces.html#the-lints-table) that is stabilized since [Rust 1.74](https://blog.rust-lang.org/2023/11/16/Rust-1.74.0.html).

By this change, we make the configure more readable and simplify `xargo lint` more.
2024-01-02 14:53:22 +00:00
bors
df94a87ea8 Auto merge of #16139 - jimmyhmiller:master, r=Veykril
Make functions in impl have a container name

fixes #16015
2024-01-02 14:08:37 +00:00
bors
f7a29e4e88 Auto merge of #16100 - Young-Flash:assoc_func_quickfix, r=Veykril
feat: add assoc func quickfix for `unresolved_method` diagnostic

![demo](https://github.com/rust-lang/rust-analyzer/assets/71162630/1ea1d8b8-3436-4251-a512-e0f9de01a13c)

close https://github.com/rust-lang/rust-analyzer/issues/13247

EDIT: I think add a demo gif would be helpful to `@lnicola` when he make a release change log :)
2024-01-02 13:46:35 +00:00
Luiz Carvalho
ed216e285d
fix(completion): make the expected type a tad smarter with Fns
This commit changes how the expected type is calculated when working
with Fn pointers, making the parenthesis stop vanishing when completing
the function name.

I've been bugged by the behaviour on parenthesis completion for a long
while now. R-a assumes that the `LetStmt` type is the same as the
function type I've just written. Worse is that all parenthesis vanish,
even from functions that have completely different signatures. It will
now verify if the signature is the same.

While working on this, I noticed that record fields behave the same, so
I also made it prioritize the field type instead of the current
expression when possible, but I'm unsure if this is OK, so input is
appreciated.

ImplTraits as return types will still behave weirdly because lowering is
disallowed at the time it resolves the function types.
2024-01-02 10:28:49 -03:00
Young-Flash
69410bb488 feat: add assoc func quickfix for unresolved_method diagnostic 2024-01-02 20:53:41 +08:00
bors
34df29620a Auto merge of #16112 - roife:rewrite-generate-delete-trait, r=Veykril
fix: rewrite code_action `generate_delegate_trait`

I've made substantial enhancements to the "generate delegate trait" code action in rust-analyzer. Here's a summary of the changes:

#### Resolved the "Can’t find CONST_ARG@158..159 in AstIdMap" error

Fix #15804, fix #15968, fix #15108

The issue stemmed from an incorrect application of PathTransform in the original code. Previously, a new 'impl' was generated first and then transformed, causing PathTransform to fail in locating the correct AST node, resulting in an error. I rectified this by performing the transformation before generating the new 'impl' (using make::impl_trait), ensuring a step-by-step transformation of associated items.

#### Rectified generation of `Self` type

`generate_delegate_trait` is unable to properly handle trait with `Self` type.

Let's take the following code as an example:

```rust
trait Trait {
    fn f() -> Self;
}

struct B {}
impl Trait for B {
    fn f() -> B { B{} }
}

struct S {
    b: B,
}
```

Here, if we implement `Trait` for `S`, the type of `f` should be `() -> Self`, i.e. `() -> S`. However we cannot automatically generate a function that constructs `S`.

To ensure that the code action doesn't generate delegate traits for traits with Self types, I add a function named `has_self_type` to handle it.

#### Extended support for generics in structs and fields within this code action

The former version of `generate_delegate_trait` cannot handle structs with generics properly. Here's an example:

```rust
struct B<T> {
    a: T
}

trait Trait<T> {
    fn f(a: T);
}

impl<T1, T2> Trait<T1> for B<T2> {
    fn f(a: T1) -> T2 { self.a }
}

struct A {}
struct S {
    b$0 : B<A>,
}
```

The former version  will generates improper code:

```rust
impl<T1, T2> Trait<T1, T2> for S {
    fn f(&self, a: T1) -> T1 {
        <B as Trait<T1, T2>>::f( &self.b , a)
    }
}
```

The rewritten version can handle generics properly:

```rust
impl<T1> Trait<T1> for S {
    fn f(&self, a: T1) -> T1 {
        <B<A> as Trait<T1>>::f(&self.b, a)
    }
}
```

See more examples in added unit tests.

I enabled support for generic structs in `generate_delegate_trait` through the following steps (using the code example provided):

1. Initially, to prevent conflicts between the generic parameters in struct `S` and the ones in the impl of `B`, I renamed the generic parameters of `S`.
2. Then, since `B`'s parameters are instantiated within `S`, the original generic parameters of `B` needed removal within `S` (to avoid errors from redundant parameters). An important consideration here arises when Trait and B share parameters in `B`'s impl. In such cases, these shared generic parameters cannot be removed.
3. Next, I addressed the matching of types between `B`'s type in `S` and its type in the impl. Given that some generic parameters in the impl are instantiated in `B`, I replaced these parameters with their instantiated results using PathTransform. For instance, in the example provided, matching `B<A>` and `B<T2>`, where `T2` is instantiated as `A`, I replaced all occurrences of `T2` in the impl with `A` (i.e. apply the instantiated generic arguments to the params).
4. Finally, I performed transformations on each assoc item (also to prevent the initial issue) and handled redundant where clauses.

For a more detailed explanation, please refer to the code and comments. I welcome suggestions and any further questions!
2024-01-02 12:30:19 +00:00
Rose Hudson
5878651e7e add unresolved-assoc-item diagnostic 2023-12-31 17:36:40 +00:00
Tetsuharu Ohzeki
efc87092b3 Use Cargo's [workspace.lints.*] to config clippy 2023-12-29 23:51:32 +09:00
cui fliter
638df27f99 Fix some comments
Signed-off-by: cui fliter <imcusg@gmail.com>
2023-12-29 11:50:24 +08:00
Lukas Wirth
9d24764624 internal: Cleanup Expander a bit 2023-12-22 13:01:13 +01:00
Lukas Wirth
874df3bffa Add eager-expand comment 2023-12-21 17:23:36 +01:00
Lukas Wirth
6be83b8204 Fix IDE layer not resolving assoc type paths in path qualifiers 2023-12-21 17:23:03 +01:00
Lukas Wirth
51a9e7831a Rename some things and turn macro to macro def into a query 2023-12-21 09:18:25 +01:00
Lukas Wirth
071fe4e4e9 Move Intern and Lookup traits to hir-expand 2023-12-20 21:24:20 +01:00
Lukas Wirth
4ec81230db Remove usages of Span::DUMMY 2023-12-20 12:53:46 +01:00
Lukas Wirth
002e611d09 fix: Deduplicate annotations 2023-12-19 08:49:00 +01:00
Lukas Wirth
f49a2fed3f internal: Move out WithFixture into dev-dep only crate 2023-12-18 15:24:08 +01:00
Lukas Wirth
66e29be1bd internal: Split out a span crate 2023-12-18 14:08:33 +01:00
Lukas Wirth
35620306a6 internal: Move proc-macro knowledge out of base-db 2023-12-18 12:37:18 +01:00
Jimmy Miller
b67b352ac7 Make functions in impl have a container name
fixes #16015
2023-12-17 13:44:47 -05:00
Lukas Wirth
9083017c9d Remove ModuleId from TypeOwnerId 2023-12-14 14:11:57 +01:00
roife
59aa791fe6 fix: rewrite code_action generate_delegate_trait 2023-12-13 11:22:42 +08:00