Commit graph

148317 commits

Author SHA1 Message Date
Lukas Wirth
36caa43ec1 fix: Fix HirDisplay stackoverflow for parameter Self defaults 2024-06-11 17:04:07 +02:00
bors
0ef2213ed8 Auto merge of #17372 - Veykril:parallel-diagnostics, r=Veykril
feat: Compute native diagnostics in parallel
2024-06-10 07:34:36 +00:00
Lukas Wirth
a65c912663 Don't intern attribute inputs as their spans make them unique 2024-06-09 21:21:33 +02:00
Lukas Wirth
a800a1d86a Fix divide by zero 2024-06-09 13:03:01 +02:00
Lukas Wirth
7053aed3dc Register virtual workspace Cargo.toml files in the VFS 2024-06-09 12:54:50 +02:00
Lukas Wirth
3243ea0c2b feat: Compute native diagnostics in parallel 2024-06-09 11:44:44 +02:00
bors
994a9b86ff Auto merge of #17365 - DropDemBits:diagnostic-snippet-cap, r=Veykril
internal: Expose snippet capability to diagnostic quickfixes

Fixes #16767
2024-06-08 12:41:17 +00:00
bors
4f180b6fed Auto merge of #17368 - Veykril:dist-fix, r=Veykril
fix: Fix generated markers not being patchable in package.json

I think the newlines are tripping up CI, so I hope clearing the property to leave an empty object won't make VSCode made here.
2024-06-08 10:56:55 +00:00
Lukas Wirth
b4891c3f56 fix: Fix generated markers not being patchable in package.json 2024-06-08 12:54:43 +02:00
DropDemBits
4f67f71db5
internal: Expose snippet capability to diagnostic quickfixes 2024-06-07 21:29:48 -04:00
bors
c501753236 Auto merge of #17359 - Veykril:status-bar, r=Veykril
Add version info to status bar item
2024-06-07 12:51:28 +00:00
Lukas Wirth
fc92e5c87a Add version info to status bar item 2024-06-07 14:39:50 +02:00
Lukas Wirth
ab0917ed58 fix: Fix renaming imports of foreign items touching foreign sources 2024-06-07 14:36:37 +02:00
bors
a9f0e206d9 Auto merge of #17058 - alibektas:13529/ratoml, r=Veykril
feat: TOML based config for rust-analyzer

> Important
>
> We don't promise _**any**_ stability with this feature yet, any configs exposed may be removed again, the grouping may change etc.

# TOML Based Config for RA

This PR ( addresses #13529 and this is a follow-up PR on #16639 ) makes rust-analyzer configurable by configuration files called `rust-analyzer.toml`. Files **must** be named `rust-analyzer.toml`. There is not a strict rule regarding where the files should be placed, but it is recommended to put them near a file that triggers server to start (i.e., `Cargo.{toml,lock}`, `rust-project.json`).

## Configuration Types

Previous configuration keys are now split into three different classes.

1. Client keys: These keys only make sense when set by the client (e.g., by setting them in `settings.json` in VSCode). They are but a small portion of this list. One such example is `rust_analyzer.files_watcher`, based on which either the client or the server will be responsible for watching for changes made to project files.
2. Global keys: These keys apply to the entire workspace and can only be set on the very top layers of the hierarchy. The next section gives instructions on which layers these are.
3. Local keys: Keys that can be changed for each crate if desired.

### How Am I Supposed To Know If A Config Is Gl/Loc/Cl ?

#17101

## Configuration Hierarchy

There are 5 levels in the configuration hierarchy. When a key is searched for, it is searched in a bottom-up depth-first fashion.

### Default Configuration

**Scope**: Global, Local, and Client

This is a hard-coded set of configurations. When a configuration key could not be found, then its default value applies.

### User configuration

**Scope**: Global, Local

If you want your configurations to apply to **every** project you have, you can do so by setting them in your `$CONFIG_DIR/rust-analyzer/rust-analyzer.toml` file, where `$CONFIG_DIR` is :

| Platform | Value                                 | Example                                  |
| ------- | ------------------------------------- | ---------------------------------------- |
| Linux   | `$XDG_CONFIG_HOME` or `$HOME`/.config | /home/alice/.config                      |
| macOS   | `$HOME`/Library/Application Support   | /Users/Alice/Library/Application Support |
| Windows | `{FOLDERID_RoamingAppData}`           | C:\Users\Alice\AppData\Roaming           |

### Client configuration

**Scope**: Global, Local, and Client

Previously, the only way to configure rust-analyzer was to configure it from the settings of the Client you are using. This level corresponds to that.

> With this PR, you don't need to port anything to benefit from new features. You can continue to use your old settings as they are.

### Workspace Root Configuration

**Scope**: Global, Local

Rust-analyzer already used the path of the workspace you opened in your Client. We used this information to create a configuration file that won't affect your other projects and define global level configurations at the same time.

### Local Configuration

**Scope**: Local

You can also configure rust-analyzer on a crate level. Although it is not an error to define global ( or client ) level keys in such files, they won't be taken into consideration by the server. Defined local keys will affect the crate in which they are defined and crate's descendants. Internally, a Rust project is split into what we call `SourceRoot`s. This, although with exceptions, is equal to splitting a project into crates.

> You may choose to have more than one `rust-analyzer.toml` files within a `SourceRoot`, but among them, the one closer to the project root will be
2024-06-07 10:49:02 +00:00
bors
1eda1ae586 Auto merge of #17308 - mathew-horner:prefer-workspace, r=Veykril
Add preference modifier for workspace-local crates when using auto import.

`@joshka` pointed out some odd behavior of auto import ordering. It doesn't seem that the current heuristics were applying any sort of precedence to imports from the workspace. I've went ahead and added that.

I hope to get some feedback on the modifier numbers here. I just went with something that felt like it balanced giving more power to workspace crates without completely ignoring relative path distance.

closes https://github.com/rust-lang/rust-analyzer/issues/17303
2024-06-07 10:35:49 +00:00
Lukas Wirth
59002b3828 Fix processing of ratoml files 2024-06-07 12:31:50 +02:00
Wilfred Hughes
22ee477606 chore: Prefer tracing span shorthand macros 2024-06-06 16:52:25 -07:00
roife
8573eb2060 fix: incorrect formatting of hover actions 2024-06-06 21:07:59 +08:00
bors
49dd2d3d29 Auto merge of #17352 - roife:fix-issue-17338, r=Veykril
fix: do not resolve prelude within block modules

fix #17338 (continuing from #17251).

In #17251, we injected preludes into non-top-level modules, which leading to r-a to directly resolve names in preludes in block modules. This PR fix it by checking whether the module is a pseudo-module introduced by blocks. (similar to what we do for extern preludes)
2024-06-06 09:40:39 +00:00
roife
07fde0779e test: add regression test for prelude shadowing in block modules 2024-06-06 17:03:40 +08:00
roife
6561b71eed fix: do not resolve prelude within block modules 2024-06-06 16:55:09 +08:00
Lukas Wirth
d726854555 Fix file loading of r-a toml files 2024-06-06 10:40:41 +02:00
bors
56a298bf3d Auto merge of #17346 - ChosenName:master, r=Veykril
Changed package.json so vscode extension settings have submenus

There are a lot of options that are a part of rust-analyzer, sometimes it can be hard to find an option that you are looking for. To fix this I have put all configurations into categories based on their names. I have also changed the schema in `crates/rust-analyzer/src/config.rs` to reflect this.

Currently for each generated entry the title is redeclared, this does function but I am prepared to change this if it is a problem.
2024-06-06 08:03:17 +00:00
bors
b8e94ddb7d Auto merge of #17350 - Wilfred:mark_missing_file_unused, r=Veykril
fix: Highlight unlinked files consistently with inactive files

Currently, rust-analyzer highlights the entire region when a `cfg` is inactive (e.g. `#[cfg(windows)]` on a Linux machine). However, unlinked files only highlight the first three characters of the file.

This was introduced in #8444, but users have repeatedly found themselves with no rust-analyzer support for a file and unsure why (see e.g. #13226 and the intentionally prominent pop-up added in PR #14366).

(Anecdotally, we see this issue bite our users regularly, particularly people new to Rust.)

Instead, highlight the entire inactive file, but mark it as all as unused. This allows users to hover and run the quickfix from any line.

Whilst this is marginally more prominent, it's less invasive than a pop-up, and users do want to know why they're getting no rust-analyzer support in certain files.

Before (note the subtle grey underline is only at the beginning of the first line):

![Screenshot 2024-06-05 at 5 41 17 PM](https://github.com/rust-lang/rust-analyzer/assets/70800/96f5d778-612e-4838-876d-35d9647fe2aa)

After (user can hover and fix from any line):

![Screenshot 2024-06-05 at 5 42 13 PM](https://github.com/rust-lang/rust-analyzer/assets/70800/6af90b79-018c-42b9-b3c5-f497de2ccbff)
2024-06-06 07:49:58 +00:00
Wilfred Hughes
901c01c279 fix: Highlight unlinked files consistently with inactive files
Currently, rust-analyzer highlights the entire region when a `cfg` is
inactive (e.g. `#[cfg(windows)]` on a Linux machine). However,
unlinked files only highlight the first three characters of the file.

This was introduced in #8444, but users have repeatedly found
themselves with no rust-analyzer support for a file and unsure
why (see e.g. #13226 and the intentionally prominent pop-up added in
PR #14366).

(Anecdotally, we see this issue bite our users regularly, particularly
people new to Rust.)

Instead, highlight the entire inactive file, but mark it as all as
unused. This allows users to hover and run the quickfix from any line.

Whilst this is marginally more prominent, it's less invasive than a
pop-up, and users do want to know why they're getting no rust-analyzer
support in certain files.
2024-06-05 17:44:07 -07:00
Wilfred Hughes
9e31bce003 chore: Update Cargo.lock to avoid yanked version 2024-06-05 17:36:36 -07:00
Lukas Wirth
003106cf6b Keep config diagnostics across changes 2024-06-05 14:56:07 +02:00
Lukas Wirth
dfae2a5437 Diagnose most incorrect ra-toml config errors 2024-06-05 13:09:49 +02:00
bors
6e7eecc423 Auto merge of #17348 - regexident:fix-type-or-const-param-source, r=Veykril
Use `.get(…)` instead of `[…]` in `TypeOrConstParam::source(…)` and `LifetimeParam::source(…)`

Resolves #17344.
2024-06-05 10:34:31 +00:00
Vincent Esche
bd5f27605a Resolve #17344 by using .get(…) instead of […] in TypeOrConstParam::source(…)
(… and `LifetimeParam::source(…)`)
2024-06-05 11:03:56 +02:00
Lukas Wirth
cf89e9ce95 Fix local configs allowing to contain global changes 2024-06-05 10:47:53 +02:00
Lukas Wirth
0e207fef97 Shuffle around some of the configs between the levels 2024-06-05 10:47:33 +02:00
Ali Bektas
292bb94c6b Apply requested changes round 3 2024-06-05 10:45:22 +02:00
Ali Bektas
ff6e912efb Apply requested changes round 2 2024-06-05 10:45:22 +02:00
Ali Bektas
53b5038b54 Apply suggested changes 2024-06-05 10:45:19 +02:00
Lukas Wirth
9559894312 Add debug info to invalid offset error 2024-06-05 10:20:05 +02:00
ChosenName
ca07bf2f8d fmt 2024-06-04 22:16:08 -06:00
ChosenName
728001eb33 fmt 2024-06-04 22:12:54 -06:00
ChosenName
d47848ec99
Update dist.rs 2024-06-04 21:44:07 -06:00
ChosenName
adb7de2c69
Update config.rs 2024-06-04 21:39:37 -06:00
ChosenName
e592d8866f
fmt 2024-06-04 21:35:41 -06:00
ChosenName
48f1b49721
Fix typos 2024-06-04 21:30:36 -06:00
ChosenName
dc1074862b
Update config.rs 2024-06-04 21:09:21 -06:00
ChosenName
b885cea989
Update package.json 2024-06-04 21:08:30 -06:00
Lukas Wirth
6eab89fd37 Use dyn cache for Semantics macro resolution 2024-06-04 16:25:38 +02:00
Lukas Wirth
8d5e14d408 Cache parse trees in Semantics 2024-06-04 15:29:24 +02:00
Lukas Wirth
c5a5c93ed9 Cache file_to_def in SourceToDefCtx 2024-06-04 15:23:02 +02:00
Lukas Wirth
98769133c6 Try caching macro calls more aggressively 2024-06-04 15:23:00 +02:00
bors
59c3a3a86b Auto merge of #17341 - Veykril:inert-attr, r=Veykril
internal: Cleanup some inert attribute stuff
2024-06-04 10:42:15 +00:00
Lukas Wirth
211af03439 Cleanup some inert attribute stuff 2024-06-04 12:38:20 +02:00