summary refs log tree commit diff
path: root/src/tools/rust-analyzer/crates/ide
AgeCommit message (Collapse)AuthorLines
2024-08-28Fix name resolution of shadowed builtin macroChayim Refael Friedman-0/+19
2024-08-27Revert "feat: Implement `module_path` macro"Lukas Wirth-71/+3
2024-08-26Auto merge of #17963 - avrong:avrong/error-lifetimes, r=Veykrilbors-1/+1
Always show error lifetime arguments as `'_` Fixes #17947 Changed error lifetime argument presentation in non-test environment to `'_` and now showing them even if all of args are error lifetimes. This also influenced some of the other tests like `extract_function.rs`, `predicate.rs` and `type_pos.rs`. Not sure whether I need to refrain from adding lifetimes args there. Happy to fix if needed
2024-08-26Show and render error lifetime args as `'_`Aleksei Trifonov-1/+1
2024-08-26Auto merge of #17941 - ChayimFriedman2:pre-closure-to-fn, r=Veykrilbors-3/+3
Preliminary work for #17940 I split the PR as requested, and made small commits.
2024-08-24Provide `Future::Output` and `Iterator` lang itemsChayim Refael Friedman-3/+3
2024-08-23Auto merge of #17936 - Veykril:module_path, r=Veykrilbors-3/+71
feat: Implement `module_path` macro Turns out this is a pain to implement because of our hir-def hir-expand split :)
2024-08-22Add cov_marks to test #17927Chayim Refael Friedman-0/+10
2024-08-22Speed up search for short associated functions, especially very common ↵Chayim Refael Friedman-0/+230
identifiers such as `new` The search is used by IDE features such as rename and find all references. The search is slow because we need to verify each candidate, and that requires analyzing it; the key to speeding it up is to avoid the analysis where possible. I did that with a bunch of tricks that exploits knowledge about the language and its possibilities. The first key insight is that associated methods may only be referenced in the form `ContainerName::func_name` (parentheses are not necessary!) (Rust doesn't include a way to `use Container::func_name`, and even if it will in the future most usages are likely to stay in that form. Searching for `::` will help only a bit, but searching for `Container` can help considerably, since it is very rare that there will be two identical instances of both a container and a method of it. However, things are not as simple as they sound. In Rust a container can be aliased in multiple ways, and even aliased from different files/modules. If we will try to resolve the alias, we will lose any gain from the textual search (although very common method names such as `new` will still benefit, most will suffer because there are more instances of a container name than its associated item). This is where the key trick enters the picture. The key insight is that there is still a textual property: a container namer cannot be aliased, unless its name is mentioned in the alias declaration, or a name of alias of it is mentioned in the alias declaration. This becomes a fixpoint algorithm: we expand our list of aliases as we collect more and more (possible) aliases, until we eventually reach a fixpoint. A fixpoint is not guaranteed (and we do have guards for the rare cases where it does not happen), but it is almost so: most types have very few aliases, if at all. We do use some semantic information while analyzing aliases. It's a balance: too much semantic analysis, and the search will become slow. But too few of it, and we will bring many incorrect aliases to our list, and risk it expands and expands and never reach a fixpoint. At the end, based on benchmarks, it seems worth to do a lot to avoid adding an alias (but not too much), while it is worth to do a lot to avoid the need to semantically analyze func_name matches (but again, not too much). After we collected our list of aliases, we filter matches based on this list. Only if a match can be real, we do semantic analysis for it. The results are promising: searching for all references on `new()` in `base-db` in the rust-analyzer repository, which previously took around 60 seconds, now takes as least as two seconds and a half (roughly), while searching for `Vec::new()`, almost an upper bound to how much a symbol can be used, that used to take 7-9 minutes(!) now completes in 100-120 seconds, and with less than half of non-verified results (aka. false positives). This is the less strictly correct (but faster) of this patch; it can miss some (rare) cases (there is a test for that - `goto_ref_on_short_associated_function_complicated_type_magic_can_confuse_our_logic()`). There is another branch that have no false negatives but is slower to search (`Vec::new()` never reaches a fixpoint in aliases collection there). I believe it is possible to create a strategy that will have the best of both worlds, but it will involve significant complexity and I didn't bother, especially considering that in the vast majority of the searches the other branch will be more than enough. But all in all, I decided to bring this branch (of course if the maintainers will agree), since our search is already not 100% accurate (it misses macros), and I believe there is value in the additional perf.
2024-08-22Fix sorting order for tokens in hoverLukas Wirth-13/+15
2024-08-22Consider interleaving hover kindsLukas Wirth-84/+95
2024-08-22Sort hover results by relevanceLukas Wirth-6/+18
2024-08-22Thread file id through descension API for semantic highlightingLukas Wirth-36/+40
2024-08-22Rename macro descension functionsLukas Wirth-11/+8
2024-08-22Fully remove old macro descension APILukas Wirth-53/+40
2024-08-22Remove DescendPreference::SameKindLukas Wirth-17/+52
2024-08-22Drop MacroInputKindLukas Wirth-1/+1
2024-08-22Remove DescendPreference::SameTextLukas Wirth-79/+77
2024-08-21internal: Implement `module_path` macroLukas Wirth-3/+71
2024-08-16Auto merge of #17900 - darichey:exclude-vendored-libraries, r=davidbarskybors-11/+58
Add scip/lsif flag to exclude vendored libaries #17809 changed StaticIndex to include vendored libraries. This PR adds a flag to disable that behavior. At work, our monorepo has too many rust targets to index all at once, so we split them up into several shards. Since all of our libraries are vendored, if rust-analyzer includes them, sharding no longer has much benefit, because every shard will have to index the entire transitive dependency graphs of all of its targets. We get around the issue presented in #17809 because some other shard will index the libraries directly.
2024-08-16Properly account for editions in namesChayim Refael Friedman-286/+738
This PR touches a lot of parts. But the main changes are changing `hir_expand::Name` to be raw edition-dependently and only when necessary (unrelated to how the user originally wrote the identifier), and changing `is_keyword()` and `is_raw_identifier()` to be edition-aware (this was done in #17896, but the FIXMEs were fixed here). It is possible that I missed some cases, but most IDE parts should properly escape (or not escape) identifiers now. The rules of thumb are: - If we show the identifier to the user, its rawness should be determined by the edition of the edited crate. This is nice for IDE features, but really important for changes we insert to the source code. - For tests, I chose `Edition::CURRENT` (so we only have to (maybe) update tests when an edition becomes stable, to avoid churn). - For debugging tools (helper methods and logs), I used `Edition::LATEST`.
2024-08-15Add scip/lsif flag to exclude vendored libariesDavid Richey-11/+58
2024-08-15internal: Properly check the edition for edition dependent syntax kindsLukas Wirth-14/+22
2024-08-15fix: Panic while displaying associated function with a type annotationShoyu Vanilla-0/+28
2024-08-13Remove unreachable logic for include token mappingLukas Wirth-0/+15
2024-08-08fix: Panic while rendering function with impl trait argShoyu Vanilla-0/+23
2024-08-07Auto merge of #17809 - nicolas-guichard:index-vendored, r=Veykrilbors-10/+36
Include vendored crates in StaticIndex `StaticIndex::compute` filters out modules from libraries. This makes an exceptions for vendored libraries, ie libraries actually defined inside the workspace being indexed. This aims to solve https://bugzilla.mozilla.org/show_bug.cgi?id=1846041 In general StaticIndex is meant for code browsers, which likely want to index all visible source files.
2024-08-07Auto merge of #17813 - roife:fix-issue-17803, r=Veykrilbors-1/+24
fix: tyck for non-ADT types when searching refs for `Self` kw See https://github.com/rust-lang/rust-analyzer/pull/15864/files/e0276dc5ddc38c65240edb408522bb869f15afb4#r1389848845 For ADTs, to handle `{error}` in generic args, we should to convert them to ADT for comparisons; for others, we can directly compare the types.
2024-08-06fix: tyck for non-ADT types when searching refs for `Self` kwroife-1/+24
2024-08-06Include vendored crates in StaticIndexNicolas Guichard-10/+36
StaticIndex::compute filters out modules from libraries. This makes an exceptions for vendored libraries, ie libraries actually defined inside the workspace being indexed. This aims to solve https://bugzilla.mozilla.org/show_bug.cgi?id=1846041 In general StaticIndex is meant for code browsers, which likely want to index all visible source files.
2024-08-06Replace `[package.repository] = "…"` of published crates with ↵Vincent Esche-1/+1
`[package.repository.workspace] = true`
2024-08-06Add repository URL for published crates' missing `[package.repository]` fieldsVincent Esche-0/+1
2024-08-06Replace `"TBD"` with more helpful desciptions in published crates' ↵Vincent Esche-1/+1
`[package.description]` fields
2024-08-05Auto merge of #17775 - ShoyuVanilla:segregate-diags, r=Veykrilbors-4/+23
perf: Segregate syntax and semantic diagnostics Closes #17731
2024-08-05perf: Segregate syntax and semantic diagnosticsShoyu Vanilla-4/+23
2024-08-05Auto merge of #17784 - Young-Flash:block_with_label, r=Veykrilbors-3/+31
feat: support inlay hint for more expr with label follow up https://github.com/rust-lang/rust-analyzer/pull/17635
2024-08-05SimplifyLukas Wirth-7/+1
2024-08-05Simplify FileDelegateLukas Wirth-7/+7
2024-08-04test: add test case for inlay hint support for expr with labelYoung-Flash-0/+13
2024-08-01feat: support inlay hint for more expr with labelYoung-Flash-3/+24
2024-07-29Auto merge of #17707 - Veykril:proc-macro-err-cleanup, r=Veykrilbors-63/+0
feat: Use spans for builtin and declarative macro expansion errors This should generally improve some error reporting for macro expansion errors. Especially for `compile_error!` within proc-macros
2024-07-28Fix for #17497 - Invalid RA diagnostic error: expected 2 arguments, found 1Francis McKenzie-1/+1
The issue occurs because in some configurations of traits where one of them has Deref as a supertrait, RA's type inference algorithm fails to resolve the Deref::Target type, and instead uses a TyKind::BoundVar (i.e. an unknown type). This "autoderefed" type then incorrectly acts as if it implements all traits in scope. The fix is to re-apply the same sanity-check that is done in iterate_method_candidates_with_autoref(), that is: don't try to resolve methods on unknown types. This same sanity-check is now done on each autoderefed type for which trait methods are about to be checked. If the autoderefed type is unknown, then the iterating of the trait methods for that type is skipped. Includes a unit test that only passes after applying the fixes in this commit. Includes a change to the assertion count in test syntax_highlighting::tests::benchmark_syntax_highlighting_parser as suggested by Lukas Wirth during review. Includes a change to the sanity-check code as suggested by Florian Diebold during review.
2024-07-26Internal: Cleanup proc-macro error handlingLukas Wirth-63/+0
2024-07-22internal: Shrink size of `Binding`Lukas Wirth-11/+21
2024-07-22Auto merge of #17542 - roife:fix-issue-17517, r=Veykrilbors-179/+1182
feat: go-to-def and find-references on control-flow keywords fix #17517. This PR implements **go-to-definition** and **find-references** functionalities for control flow keywords, which is similar to the behaviors in the `highlight-related` module. Besides, this PR also fixes some incorrect behaviors in `highlight-related`. ## Changes 1. **Support for go-to-definition on control flow keywords**: This PR introduces functionality allowing users to navigate on the definition of control flow keywords (`return`, `break`, `continue`). Commit: 2a3244ee147f898dd828c06352645ae1713c260f..7391e7a608634709db002a4cb09229de4d12c056. 2. **Bug fixes and refactoring in highlight-related**: - **Handling return/break/continue within try_blocks**: This PR adjusted the behavior of these keywords when they occur within `try_blocks`. When encounter these keywords, the program should exit the outer function or loop which containing the `try_blocks`, rather than the `try_blocks` itself; while the `?` will cause the program to exit `try_blocks`. Commit: 59d697e807f0197f59814b37dca1563959da4aa1. - **Support highlighting keywords in macro expansion for highlight-related**: Commit: 88df24f01727c23a667a763ee3ee0cec22d5ad52. - Detailed description for the bug fixes + The previous implementation of `preorder_expr` incorrectly treated `try_blocks` as new contexts, thereby r-a will not continue to traverse inner `return` and `break/continue` statements. To resolve this, a new function `preorder_expr_with_ctx_checker` has been added, allowing users to specify which expressions to skip. * For example, when searching for the `?` in the context, r-a should skip `try_blocks` where the `?` insides just works for `try_blocks`. But when search for the `return` keyword, r-a should collect both the `return` keywords inside and outside the `try_blocks` + Thus, this PR added `WalkExpandedExprCtx` (builder pattern). It offers the following improvements: customizable context skipping, maintenance of loop depth (for `break`/`continue`), and handling macro expansion during traversal. 3. **Support for find-references on control flow keywords**: This PR enables users to find all references to control flow keywords. Commit: 9202a33f81218fb9c2edb5d42e6b4de85b0323a8.
2024-07-21fix: Allow flyimport to import primitive shadowing modulesLukas Wirth-1/+3
2024-07-20Fix some typosLaurențiu Nicola-1/+2
2024-07-20minor: tweak commentYoung-Flash-1/+2
2024-07-20internal: add test case for inlay hint support for block expr with lifetime ↵Young-Flash-0/+23
label
2024-07-20feat: add inlay hint support for block expr with lifetime labelYoung-Flash-1/+8