Commit graph

20019 commits

Author SHA1 Message Date
Wilfred Hughes
d68e549205 internal: Fix rustdoc warnings
`cargo doc` generates a bunch of warnings on rust-analyzer. Fix all the
bare URL and empty code block warnings.
2024-06-13 17:29:10 -07:00
David Hewitt
0cbf9009e6 fix: add a breaker to avoid infinite loops from source root cycles 2024-06-13 06:32:05 +01:00
bors
fa486e694e Auto merge of #17406 - Veykril:modpath-clone, r=Veykril
internal: Don't unnecessarily clone ModPaths out of interning wrappers
2024-06-12 09:49:41 +00:00
Lukas Wirth
ba543f7d76 internal: Don't unnecessarily clone ModPaths out of interning wrappers 2024-06-12 11:43:36 +02:00
bors
22648b2655 Auto merge of #17405 - Veykril:modpath-clone, r=Veykril
internal: Don't unnecessarily clone ModPaths in early name res
2024-06-12 09:27:49 +00:00
Lukas Wirth
855282fa53 internal: Don't unnecessarily clone ModPaths in early name res 2024-06-12 11:25:19 +02:00
bors
b5e0d7c349 Auto merge of #17398 - Veykril:bogus-file, r=Veykril
internal: Remove FileId::BOGUS
2024-06-12 07:19:31 +00:00
Lukas Wirth
8ebabce475 internal: Remove FileId::BOGUS 2024-06-12 08:16:07 +02:00
bors
4af21ffb02 Auto merge of #16840 - Wilfred:shell_runnable, r=Veykril
Allow rust-project.json to include arbitrary shell commands for runnables

This is a follow-up on #16135, resolving the feedback raised :)

Allow rust-project.json to include shell runnables, of the form:

```
{
  "build_info": {
    "label": "//project/foo:my-crate",
    "target_kind": "bin",
    "shell_runnables": [
      {
        "kind": "run",
        "program": "buck2",
        "args": ["run", "//project/foo:my-crate"]
      },
      {
        "kind": "test_one",
        "program": "test_runner",
        "args": ["--name=$$TEST_NAME$$"]
      }
    ]
  }
}

```

If these runnable configs are present for the current crate in rust-project.json, offer them as runnables in VS Code.

This PR required some boring changes to APIs that previously only handled cargo situations. I've split out these changes as commits labelled 'refactor', so it's easy to see the interesting changes.
2024-06-11 16:13:10 +00:00
Wilfred Hughes
71a78a9cdc feature: add build system info; runnables to rust-project.json 2024-06-11 11:55:17 -04:00
bors
c07076b35c Auto merge of #17394 - Veykril:recurse-fix, r=Veykril
fix: Fix `HirDisplay` stackoverflow for parameter Self defaults

Fixes https://github.com/rust-lang/rust-analyzer/issues/10932
2024-06-11 15:05:26 +00:00
Lukas Wirth
1ecf230792 fix: Fix HirDisplay stackoverflow for parameter Self defaults 2024-06-11 17:04:07 +02:00
bors
43d59851f6 Auto merge of #17364 - roife:fix-issue-12917, r=Veykril
feat: show type bounds from containers when hovering on functions

fix #12917.

### Changes

1. Added Support for displaying the container and type bounds from it when hovering on functions with generic types.
2. Added a user config to determine whether to display container bounds (enabled by default).
3. Added regression tests.
4. Simplified and refactored `hir/display.rs` to improve readability.
2024-06-11 13:28:11 +00:00
bors
0a16ae340b Auto merge of #17392 - randomicon00:17242, r=Veykril
Change 'Length' to 'Len'

This is a fix for #17242
2024-06-11 13:14:56 +00:00
randomicon00
bcf4221ab3 edit: Length to Len in benchmark 2024-06-11 09:09:56 -04:00
roife
224d0dd36e refactor: move the logic that displays container type bounds to function fmt 2024-06-11 21:02:13 +08:00
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
randomicon00
df63300092 edit: change 'Length' to 'Len' 2024-06-11 08:49:30 -04: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
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
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
DropDemBits
4e6d908382
internal: Expose snippet capability to diagnostic quickfixes 2024-06-07 21:29:48 -04: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
Wilfred Hughes
27182bb96b chore: Prefer tracing span shorthand macros 2024-06-06 16:52:25 -07: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