fix: Improve hover text in unlinked file diagnostics
Use full sentences, and mention how to disable the diagnostic if users are intentionally working on unowned files.
![Screenshot 2024-06-12 at 5 55 48 PM](https://github.com/rust-lang/rust-analyzer/assets/70800/c91ee1ed-1c72-495a-9ee3-9e360a5c6977)
(Full disclosure: I've tested a rust-analyzer build in VS Code, but the pop-up logic is currently disabled due to #17062, so I haven't tested that.)
fix: pattern completions in let-stmt
fix#17480.
We can write `let S { a, b } = s;` or `let Some(x) = a else {}`, so it is reasonable to allow pattern completions in `LetStmt`.
Simplify some term search tactics
Working on the paper `@phijor` found that "Data constructor" tactic could be simplified quite a bit by running it only in the backwards direction. With n+1 rounds it has same coverage as previous implementation in n rounds, however the tactic it self is more simple and also potentially faster as there is less to do.
In a nutshell the idea is to only work with types in the wish-list rather than with any types.
Turns out it is quite a bit faster:
Before:
```
ripgrep:
Tail Expr syntactic hits: 238/1692 (14%)
Tail Exprs found: 1223/1692 (72%)
Term search avg time: 15ms
nalgebra:
Tail Expr syntactic hits: 125/3001 (4%)
Tail Exprs found: 2143/3001 (71%)
Term search avg time: 849ms
```
After
````
ripgrep:
Tail Expr syntactic hits: 246/1692 (14%)
Tail Exprs found: 1209/1692 (71%)
Term search avg time: 8ms
nalgebra:
Tail Expr syntactic hits: 125/3001 (4%)
Tail Exprs found: 2028/3001 (67%)
Term search avg time: 305ms
````
_Also removed niche optimization of removing scope defs from the search space as this wasn't helping much anyway and made code a bit more complex._
fix: use ItemInNs::Macros to convert ModuleItem to ItemInNs
fix#17425.
When converting `PathResolution` to `ItemInNs`, we should convert `ModuleDef::Macro` to `ItemInNs::Macros` to ensure that it can be found in `DefMap`.
Filter builtin macro expansion
This PR adds a filter on the types of built in macros that are allowed to be expanded.
Currently, This list of allowed macros contains, `stringify, cfg, core_panic, std_panic, concat, concat_bytes, include, include_str, include_bytes, env` and `option_env`.
Fixes#14177
Remove panicbit.cargo extension warning
A warning was introduced regarding the incompatabilities between `rust-analyzer` and `panicbit.cargo`'s diagnostics / `cargo check` functionality.
This functionality has been removed in the latest version of the cargo extension (`0.3.0`), which is why the warning can be removed now.
fix: ensure there are no cycles in the source_root_parent_map
See #17409
We can view the connections between roots as a graph. The problem is that this graph may contain cycles, so when adding edges, it is necessary to check whether it will lead to a cycle.
Since we ensure that each node has at most one outgoing edge (because each SourceRoot can have only one parent), we can use a disjoint-set to maintain the connectivity between nodes. If an edge’s two nodes belong to the same set, they are already connected.
Additionally, this PR includes the following three changes:
1. Removed the workaround from #17409.
2. Added an optimization: If `map.contains_key(&SourceRootId(*root_id as u32))`, we can skip the current loop iteration since we have already found its parent.
3. Modified the inner loop to iterate in reverse order with `roots[..idx].iter().rev()` at line 319. This ensures that if we are looking for the parent of `a/b/c`, and both `a` and `a/b` meet the criteria, we will choose the longer match (`a/b`).
fix(completion): complete async keyword
Fixes#17452
Not entirely confident of the fix here, but my logic is that `async` should in general be offered in similar semantic scenarios as other keywords like `static` or `pub`.
Term search: new tactic for associated item constants
New tactic to cover some more exotic cases that started bothering me.
Associated constants seem to be common in [axum](806bc26e62/examples/readme/src/main.rs (L53)).
feat: add `toggleLSPLogs` command
Implement client-side command to toggle LSP logs in VSCode.
The command replaces the need to add/remove the `"rust-analyzer.trace.server": "verbose"` setting each time one wants to display logs. I've also updated the docs/ instances that reference the now outdated manual method.
The command labeled `rust-analyzer: Toggle LSP Logs` enables the setting project-wide and opens the relevant trace output channel.
Closes#8233
feat: add space after specific keywords in completion
fix#17428.
When completing some specific keywords, it would be convenient if r-a could automatically add a space afterwards.
This PR implements this feature for the following keywords:
- Visibility: `pub`, `pub(crate)`, `pub(super)`, `pub(in xxx)`
- Pattern: `ref` / `mut`
- Others: `unsafe` / `for` / `where`