Commit graph

30342 commits

Author SHA1 Message Date
roife
ab7c7d4501 fix: skip container header if no generics params 2024-06-11 21:02:13 +08:00
roife
9f70f87d35 internal: simplify and rename display_xxx to write_xxx for consistency 2024-06-11 21:02:13 +08:00
roife
78118f98f6 feat: add hover config for showing container bounds 2024-06-11 21:02:13 +08:00
roife
184ddc6f5b feat: show type bounds from containers for functions 2024-06-11 21:02:13 +08:00
roife
af1291bbf3 internal: simplify and refactor write_where_clause 2024-06-11 21:02:13 +08:00
bors
ff83ec6835 Auto merge of #17389 - rust-lang:dependabot/npm_and_yarn/editors/code/braces-3.0.3, r=lnicola
Chore(deps-dev): Bump braces from 3.0.2 to 3.0.3 in /editors/code

Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to 3.0.3.
<details>
<summary>Commits</summary>
<ul>
<li><a href="74b2db2938"><code>74b2db2</code></a> 3.0.3</li>
<li><a href="88f1429a0f"><code>88f1429</code></a> update eslint. lint, fix unit tests.</li>
<li><a href="415d660c30"><code>415d660</code></a> Snyk js braces 6838727 (<a href="https://redirect.github.com/micromatch/braces/issues/40">#40</a>)</li>
<li><a href="190510f79d"><code>190510f</code></a> fix tests, skip 1 test in test/braces.expand</li>
<li><a href="716eb9f12d"><code>716eb9f</code></a> readme bump</li>
<li><a href="a5851e57f4"><code>a5851e5</code></a> Merge pull request <a href="https://redirect.github.com/micromatch/braces/issues/37">#37</a> from coderaiser/fix/vulnerability</li>
<li><a href="2092bd1fb1"><code>2092bd1</code></a> feature: braces: add maxSymbols (<a href="https://github.com/micromatch/braces/issues/">https://github.com/micromatch/braces/issues/</a>...</li>
<li><a href="9f5b4cf473"><code>9f5b4cf</code></a> fix: vulnerability (<a href="https://security.snyk.io/vuln/SNYK-JS-BRACES-6838727">https://security.snyk.io/vuln/SNYK-JS-BRACES-6838727</a>)</li>
<li><a href="98414f9f1f"><code>98414f9</code></a> remove funding file</li>
<li><a href="665ab5d561"><code>665ab5d</code></a> update keepEscaping doc (<a href="https://redirect.github.com/micromatch/braces/issues/27">#27</a>)</li>
<li>Additional commits viewable in <a href="https://github.com/micromatch/braces/compare/3.0.2...3.0.3">compare view</a></li>
</ul>
</details>
<br />

[![Dependabot compatibility score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=braces&package-manager=npm_and_yarn&previous-version=3.0.2&new-version=3.0.3)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting ``@dependabot` rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- ``@dependabot` rebase` will rebase this PR
- ``@dependabot` recreate` will recreate this PR, overwriting any edits that have been made to it
- ``@dependabot` merge` will merge this PR after your CI passes on it
- ``@dependabot` squash and merge` will squash and merge this PR after your CI passes on it
- ``@dependabot` cancel merge` will cancel a previously requested merge and block automerging
- ``@dependabot` reopen` will reopen this PR if it is closed
- ``@dependabot` close` will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
- ``@dependabot` show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency
- ``@dependabot` ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
- ``@dependabot` ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
- ``@dependabot` ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
You can disable automated security fix PRs for this repo from the [Security Alerts page](https://github.com/rust-lang/rust-analyzer/network/alerts).

</details>
2024-06-11 09:05:34 +00:00
dependabot[bot]
2a4886a8b6
Chore(deps-dev): Bump braces from 3.0.2 to 3.0.3 in /editors/code
Bumps [braces](https://github.com/micromatch/braces) from 3.0.2 to 3.0.3.
- [Changelog](https://github.com/micromatch/braces/blob/master/CHANGELOG.md)
- [Commits](https://github.com/micromatch/braces/compare/3.0.2...3.0.3)

---
updated-dependencies:
- dependency-name: braces
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2024-06-11 09:01:41 +00:00
bors
ba1c56c83a Auto merge of #17374 - Veykril:configs, r=Veykril
Allow choosing logical cores for num threads config
2024-06-11 08:49:19 +00:00
Lukas Wirth
1dcb11be5d Simplify some config serialization stuff 2024-06-11 10:45:17 +02:00
bors
575becbf27 Auto merge of #17377 - Young-Flash:hir_print, r=Veykril
internal: better print style for hir

before:
![before](https://github.com/rust-lang/rust-analyzer/assets/71162630/cd5e27b3-b4b1-450f-ba50-3c4f4e345d70)

after:
![after](https://github.com/rust-lang/rust-analyzer/assets/71162630/04e11345-cadd-49cb-b10c-6888ef51758e)
2024-06-11 08:05:40 +00:00
bors
c86d6230fe Auto merge of #17381 - roife:fix-issue-17378, r=Veykril
fix: ensure that the parent of a SourceRoot cannot be itself

fix #17378.

In `FileSetConfig.map`, different roots might be mapped to the same `root_id` due to deduplication in `ProjectFolders::new`:

```rust
// Example from rustup
/Users/roife/code/rustup/target/debug/build/rustup-863a063426b56c51/out
/Users/roife/code/rustup
```

In `source_root_parent_map`, r-a might encounter paths where their SourceRootId (i.e. `root_id`) is identical, yet one the them is the parent of the another. This situation can cause the `root_id` to be its own parent, potentially leading to an infinite loop.

This PR resolves such cases by adding a check.
2024-06-10 17:43:06 +00:00
roife
733995c0d7 fix: ensure that the parent of a SourceRoot cannot be itself 2024-06-10 23:15:26 +08:00
bors
14a1f4530c Auto merge of #17380 - Veykril:sema-source, r=Veykril
fix: Remove extra parse cache from Semantics again

Should fix https://github.com/rust-lang/rust-analyzer/issues/17376, specifically 30c04d5aa9

The recent changes here were heavily triggering what I realized in https://github.com/rust-lang/rust-analyzer/issues/17367#issuecomment-2156374726
2024-06-10 10:06:44 +00:00
Lukas Wirth
30c04d5aa9 Remove extra parse cache from Semantics again 2024-06-10 12:04:35 +02:00
Lukas Wirth
8520a0c585 Thread more HasSource::source calls through Semantics for caching 2024-06-10 10:33:07 +02:00
bors
72dfbe95de Auto merge of #17372 - Veykril:parallel-diagnostics, r=Veykril
feat: Compute native diagnostics in parallel
2024-06-10 07:34:36 +00:00
bors
b427d460eb Auto merge of #17375 - Veykril:attr-input-no-intern, r=Veykril
Don't intern attribute inputs as their spans make them unique
2024-06-09 19:35:14 +00:00
Lukas Wirth
2328085a79 Don't intern attribute inputs as their spans make them unique 2024-06-09 21:21:33 +02:00
Young-Flash
6403bdb930 minor: use push_str instead 2024-06-09 22:31:55 +08:00
Young-Flash
e8941dae46 internal: tweak test case 2024-06-09 20:55:40 +08:00
Lukas Wirth
2ced362e57 Fix divide by zero 2024-06-09 13:03:01 +02:00
Lukas Wirth
d4dc3ca83b Register virtual workspace Cargo.toml files in the VFS 2024-06-09 12:54:50 +02:00
Lukas Wirth
e972dd2385 Allow choosing logical cores for num threads config 2024-06-09 12:04:28 +02:00
Lukas Wirth
7f1f85ac16 feat: Compute native diagnostics in parallel 2024-06-09 11:44:44 +02:00
Young-Flash
dcbc76b967 internal: better print style for hir 2024-06-09 12:00:43 +08:00
bors
913371fb0b 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
6a171952f7 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
0c795a7226 fix: Fix generated markers not being patchable in package.json 2024-06-08 12:54:43 +02:00
DropDemBits
4e6d908382
internal: Expose snippet capability to diagnostic quickfixes 2024-06-07 21:29:48 -04:00
bors
a8ad08b9b2 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
0ee8a4f472 Add version info to status bar item 2024-06-07 14:39:50 +02:00
bors
47355766ca Auto merge of #17360 - Veykril:rename-alias-foreign, r=Veykril
fix: Fix renaming imports of foreign items touching foreign sources

Fixes https://github.com/rust-lang/rust-analyzer/issues/17318
2024-06-07 12:38:20 +00:00
Lukas Wirth
379f885373 fix: Fix renaming imports of foreign items touching foreign sources 2024-06-07 14:36:37 +02:00
bors
7c5d496ef8 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
26c1638bfb 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
5a7bf1d147 Fix processing of ratoml files 2024-06-07 12:31:50 +02:00
bors
d1f74a2630 Auto merge of #17356 - Wilfred:span_shorthand, r=lnicola
chore: Prefer tracing span shorthand macros

Use `info_span!()` and `debug_span!()` rather than the more verbose `tracing::span!(tracing::Level::INFO)`.
2024-06-07 06:25:24 +00:00
Wilfred Hughes
27182bb96b chore: Prefer tracing span shorthand macros 2024-06-06 16:52:25 -07:00
bors
5f3de7863a Auto merge of #17353 - roife:fix-issue-12728, r=Veykril
fix: incorrect formatting of hover actions

fix #12728.

### Changes

- Use ` | ` as the separator for actions. (I'm not sure why we use `___` previously)
- Reorder actions to match codelens
2024-06-06 13:49:08 +00:00
roife
4a4b13cbda fix: incorrect formatting of hover actions 2024-06-06 21:07:59 +08:00
bors
af488c971f 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
22e82c72ac test: add regression test for prelude shadowing in block modules 2024-06-06 17:03:40 +08:00
roife
c330c62aa2 fix: do not resolve prelude within block modules 2024-06-06 16:55:09 +08:00
Lukas Wirth
3178e5fb5a Fix file loading of r-a toml files 2024-06-06 10:40:41 +02:00
bors
577b0becd0 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
202359d258 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
bors
287c9f719a Auto merge of #17349 - Wilfred:update_libc, r=lnicola
chore: Update Cargo.lock to avoid yanked version

Building rust-analyzer currently generates a warning because libc 0.2.154 has been yanked. Update to 0.2.155 in Cargo.lock.
2024-06-06 04:11:34 +00:00
Wilfred Hughes
fcecbc5467 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
200ab1332a chore: Update Cargo.lock to avoid yanked version 2024-06-05 17:36:36 -07:00
Lukas Wirth
047b8d9f29 Keep config diagnostics across changes 2024-06-05 14:56:07 +02:00