Commit Graph

1931 Commits

Author SHA1 Message Date
Isobel Redelmeier
b116fe9be0
Fix: Handle empty checkOnSave/target values
This fixes a regression introduced by #13290, in which failing to set
`checkOnSave/target` (or `checkOnSave/targets`) would lead to an invalid
config.
2022-11-21 16:40:32 -05:00
bors
38fa47fd79 Auto merge of #13290 - poliorcetics:multiple-targets, r=Veykril
Support multiple targets for checkOnSave (in conjunction with cargo 1.64.0+)

This PR adds support for the ability to pass multiple `--target` flags when using
`cargo` 1.64.0+.

## Questions

I needed to change the type of two configurations options, but I did not plurialize the names to
avoid too much churn, should I ?

## Zulip thread

https://rust-lang.zulipchat.com/#narrow/stream/185405-t-compiler.2Frust-analyzer/topic/Issue.2013282.20.28supporting.20multiple.20targets.20with.201.2E64.2B.29

## Example

To see it working, on a macOS machine:

```sh
$ cd /tmp
$ cargo new cargo-multiple-targets-support-ra-test
$ cd !$
$ mkdir .cargo
$ echo '
[build]
target = [
    "aarch64-apple-darwin",
    "x86_64-apple-darwin",
]
' > .cargo/config.toml
$ echo '
fn main() {
    #[cfg(all(target_arch = "aarch64", target_os = "macos"))]
    {
        let a = std::fs::read_to_string("/tmp/test-read");
    }

    #[cfg(all(target_arch = "x86_64", target_os = "macos"))]
    {
        let a = std::fs::read_to_string("/tmp/test-read");
    }

    #[cfg(all(target_arch = "x86_64", target_os = "windows"))]
    {
        let a = std::fs::read_to_string("/tmp/test-read");
    }
}
' > src/main.rs
# launch your favorite editor with the version of RA from this PR
#
# You should see warnings under the first two `let a = ...` but not the third
```

## Screen

![Two panes of a terminal emulator, on the left pane is the main.rs file described above, with warnings for the first two let a = declaration, on the right pane is a display of the .cargo/config.toml, an ls of the current files in the directory and a call to cargo build to show the same warnings as in the editor on the left pane](https://user-images.githubusercontent.com/7951708/192122707-7a00606a-e581-4534-b9d5-b81c92694e8e.png)

Helps with #13282
2022-11-19 13:09:37 +00:00
bors
ac60077ee5 Auto merge of #13639 - Veykril:macro-diags, r=Veykril
fix: Fix proc-macro-srv search paths for Arch Linux

Fixes https://github.com/rust-lang/rust-analyzer/issues/13616
2022-11-19 09:33:10 +00:00
Lukas Wirth
52bc15fc1f fix: Fix proc-macro-srv search paths for Arch Linux 2022-11-18 23:32:26 +01:00
bors
791cb87cdf Auto merge of #13633 - Veykril:vscode-full-diagnostics, r=Veykril
feat: Allow viewing the full compiler diagnostic in a readonly textview

![Code_y1qrash9gg](https://user-images.githubusercontent.com/3757771/202780459-f751f65d-2b1b-4dc3-9685-100d65ebf6a0.gif)

Also adds a VSCode only config that replaces the split diagnostic message with the first relevant part of the diagnostic output

![Code_7k4qsMkx5e](https://user-images.githubusercontent.com/3757771/202780346-cf9137d9-eb77-46b7-aed6-c73a2e41e1c7.png)

This only affects diagnostics generated by primary spans and has no effect on other clients than VSCode.

Fixes https://github.com/rust-lang/rust-analyzer/issues/13574
2022-11-18 19:33:38 +00:00
Lukas Wirth
8452844c26 Fix tests checking the data value 2022-11-18 20:15:49 +01:00
Lukas Wirth
073a63b93e feat: Allow viewing the full compiler diagnostic in a readonly textview 2022-11-18 19:56:08 +01:00
Lukas Wirth
656d886ca8 Make it more obvious which SCIP features we do not yet emit in code 2022-11-18 11:31:12 +01:00
yue4u
f26d5484d8 fix: filter unnecessary completions after colon 2022-11-12 22:33:40 +09:00
Lukas Wirth
a143ff0248 fix: Fix r-a eagerly showing no discovered workspace errors 2022-11-11 14:36:27 +01:00
Alexis (Poliorcetics) Bourget
0d4737adb6 feat: Support passing multiple targets to cargo (for Rust 1.64.0+) 2022-11-11 14:36:07 +01:00
Alexis (Poliorcetics) Bourget
c6c932d3f3 chore: Align config property 2022-11-11 14:36:07 +01:00
Lukas Wirth
e35836eb81 Send status notification if there are no found workspaces 2022-11-11 13:00:22 +01:00
Laurențiu Nicola
79923c382a ⬆️ rust-analyzer 2022-11-09 21:49:10 +02:00
bors
b8b1951ee8 Auto merge of #13573 - Veykril:invalid-file-range, r=Veykril
internal: error instead of panic on invalid file range

Fixes the panic in https://github.com/rust-lang/rust-analyzer/issues/13170
2022-11-07 16:45:26 +00:00
Lukas Wirth
1cb6ab89ee internal: error instead of panic on invalid file range 2022-11-07 17:45:12 +01:00
bors
0aa0da9dda Auto merge of #13572 - Veykril:cancellable, r=Veykril
internal: Use Cancellable in favor of Result for clarity
2022-11-07 16:22:33 +00:00
Lukas Wirth
fa70b0a86e internal: Use Cancellable in favor of Result for clarity 2022-11-07 17:21:37 +01:00
bors
b0e56ef5e8 Auto merge of #13545 - Veykril:adjustment-hints, r=Veykril
Generalize reborrow hints as adjustment hints

Like reborrow hints, these are still mainly useful for teaching/learning

![image](https://user-images.githubusercontent.com/3757771/200073606-b5cd3b95-a9ad-454d-a3c4-d4d89bf45928.png)
2022-11-07 14:38:59 +00:00
Lukas Wirth
ffd7bf8bf9 Bump Cargo rust-version fields to latest stable 2022-11-07 12:59:51 +01:00
Laurențiu Nicola
cff7ab1308 Fix typos 2022-11-07 12:54:12 +02:00
Lukas Wirth
28afe57068 Add tests for LineEndings::normalize 2022-11-05 11:00:17 +01:00
Lukas Wirth
e468a1af35 internal: Optimize apply_document_changes a bit 2022-11-05 10:59:46 +01:00
Lukas Wirth
d841ad116a Fix up adjustment hints configurations 2022-11-04 22:59:07 +01:00
Lukas Wirth
c98fc537e6 Generalize reborrow hints as adjustment hints 2022-11-04 21:53:23 +01:00
bors
bbcb77ea6f Auto merge of #13456 - emilio:scip-local-symbol, r=Veykril
scip: Generate symbols for local crates.

Consider something like:

```
// a.rs
pub struct Foo { .. } // Foo is "local 1"

fn something() {
    crate:🅱️:Bar::new() // Bar is "local 1", but of "b.rs"
}

// b.rs
pub struct Bar { .. } // "local 1"
```

Without this there's no way to disambiguate whether "local 1" references "Bar" or "Foo".
2022-11-03 13:58:36 +00:00
bors
af1f48deab Auto merge of #13359 - feniljain:feat-must-use-option, r=Veykril
feat: add config for inserting must_use in `generate_enum_as_method`

Should fix #13312

Didn't add a test because I was not sure on how to add test for a specific configuration option, tried to look for the usages for other `AssistConfig` variants but couldn't find any in `tests`. If there is a way to test this, do point me towards it.

I tried to extract the formatting string as a common `template_string` and only have if-else for that, but it didn't compile :(

Also it seems these tests are failing:

```
test config::tests::generate_config_documentation ... FAILED
test config::tests::generate_package_json_config ... FAILED
```

Can you also point me to how to correct these 😅  ( I guess there is some command to automatically generate these? )
2022-11-02 10:50:08 +00:00
Laurențiu Nicola
c60b1f6414 ⬆️ rust-analyzer 2022-11-01 11:31:31 +02:00
Laurențiu Nicola
8807fc4cc3 ⬆️ rust-analyzer 2022-10-26 17:40:41 +03:00
Laurențiu Nicola
e93a2bff67 Pin lsp-types 2022-10-25 15:03:35 +03:00
Laurențiu Nicola
956b96a19d Switch to upstream positionEncoding 2022-10-25 14:43:26 +03:00
feniljain
4bf9b9b003 refactor: remove repetitive string interpolation and doc changes 2022-10-24 21:12:31 +05:30
Lukas Wirth
6a00e14c7a fix: Don't respond with an error when requesting a shutdown while starting 2022-10-24 14:56:58 +02:00
feniljain
c4bdb8e516 feat: add config for inserting must_use in generate_enum_as_method 2022-10-24 13:18:24 +05:30
Lukas Wirth
859f5594ac Handle multiple projects sharing dependency correctly in once strategy 2022-10-23 18:01:35 +02:00
Lukas Wirth
0f8904ec9c Implement invocation location config 2022-10-22 23:33:03 +02:00
Emilio Cobos Álvarez
8039a07a5e
ide: Generate monikers for local crates. 2022-10-22 19:33:47 +02:00
Emilio Cobos Álvarez
ec6d72baa1
scip: Rewrite tests to be closer to what we actually do.
It's also less code.
2022-10-22 15:21:31 +02:00
Emilio Cobos Álvarez
7ee72256eb
scip: minor clean-ups
Avoids a couple redundant hash map lookups and so.
2022-10-22 14:14:43 +02:00
Lukas Wirth
de195ff97c fix: Fix DidSaveDocument requests blocking the server on startup 2022-10-20 19:55:04 +02:00
bors
a77ac93b2a Auto merge of #13128 - Veykril:invocation-strategy, r=Veykril
Implement invocation strategy config

Fixes https://github.com/rust-lang/rust-analyzer/issues/10793

This allows to change how we run build scripts (and `checkOnSave`), exposing two configs:
- `once`: run the specified command once in the project root (the working dir of the server)
- `per_workspace`: run the specified command per workspace in the corresponding workspace

This also applies to `checkOnSave` likewise, though `once_in_root` is useless there currently, due to https://github.com/rust-lang/cargo/issues/11007
2022-10-19 21:53:19 +00:00
Lukas Wirth
46732369f4 Remove simplistic interpolation for manifest-path 2022-10-19 23:53:00 +02:00
Lukas Wirth
7db50294a3 {manifest-path} interpolation 2022-10-19 23:21:34 +02:00
Lukas Wirth
5174b65ed8 Use correct invocation strategy config for checkOnSave 2022-10-19 23:21:34 +02:00
Lukas Wirth
4a287d2525 Implement invocation strategy config for checkOnSave
Note that due to how cargo works, none of the modes currently work for r-a
2022-10-19 23:21:34 +02:00
Lukas Wirth
7e2c41dbd6 Implement invocation strategy config for build scripts 2022-10-19 23:21:29 +02:00
Laurențiu Nicola
a99a48e786 ⬆️ rust-analyzer 2022-10-18 09:12:49 +03:00
bors
4d4c05d32b Auto merge of #13428 - Veykril:fmt-stuck, r=Veykril
fix: Fix formatting requests hanging when r-a is still starting

The reason for that was that we were calculating the crate defmaps of the file we are saving by accident causing us to get stuck waiting on their expensive computation, while we only need the relevant crate id.

Closes https://github.com/rust-lang/rust-analyzer/issues/4054
Closes https://github.com/rust-lang/rust-analyzer/issues/11654
2022-10-17 16:21:32 +00:00
Lukas Wirth
a762baca02 fix: Fix formatting requests hanging when r-a is still starting
The reason for that was that we were calculating the crate defmaps
of the file we are saving by accident causing us to get stuck waiting
on their expensive computation, while we only need the relevant crate
id.
2022-10-17 18:21:18 +02:00
Lukas Wirth
e41023ce46 Make flycheck workdone progress reports cancellable 2022-10-17 16:32:47 +02:00
Laurențiu Nicola
342764d31a Add new license 2022-10-15 14:26:30 +03:00
Laurențiu Nicola
275848803b Bump mimalloc 2022-10-15 12:59:56 +03:00
Laurențiu Nicola
bb6990c4c9 Bump tracing 2022-10-15 12:52:34 +03:00
Laurențiu Nicola
cbce0cda08 Bump anyhow, arbitrary, itertools, semver, serde 2022-10-15 12:52:34 +03:00
Laurențiu Nicola
4f55ebbd4f ⬆️ rust-analyzer 2022-10-11 10:37:35 +03:00
Aleksey Kladov
39fa8b5c39 internal: ⬆️ xflags
The main change here should be that flags are not inhereted, so

   $ rust-analyzer analysis-stats . -v -v

would do what it should do

We also no longer Don\'t
2022-10-08 15:35:07 +01:00
Petr Portnov
ed532e5a34 Fix duplicate usage of a article.
This fixes a typo first appearing in #94624
in which test-macro diagnostic uses "a" article twice.

Since I searched sources for " a a " sequences,
I also fixed the same issue in a few source files where I found it.

Signed-off-by: Petr Portnov <gh@progrm-jarvis.ru>
2022-10-02 21:40:39 +03:00
Lukas Wirth
5424c51158 Add config for supplying sysroot path 2022-10-01 21:17:06 +02:00
bors
bf5cad8e77 Auto merge of #13326 - Veykril:proc-macro-srv-config, r=Veykril
Do not use the sysroot proc-macro server when a server path is given explicitly
2022-10-01 17:51:47 +00:00
Lukas Wirth
26cf250ccc Do not use the sysroot proc-macro server when a server path is given explicitly 2022-10-01 19:50:34 +02:00
bors
2293949bbf Auto merge of #13318 - Veykril:annotations, r=Veykril
Fix annotations not resolving when lens location is set to whole item

Fixes https://github.com/rust-lang/rust-analyzer/issues/13310
2022-09-30 22:31:05 +00:00
Lukas Wirth
3cd57c425a Fix annotations not resolving when lens location is set to whole item 2022-10-01 00:18:23 +02:00
Lukas Wirth
8c433c7296 Fix requests not being retried anymore 2022-10-01 00:07:33 +02:00
Lukas Wirth
1a6c1595fe Don't retry requests that have already been cancelled 2022-09-27 17:39:15 +02:00
bors
093de32f80 Auto merge of #13237 - Veykril:process-changes, r=Veykril
Amalgamate file changes for the same file ids in process_changes

When receiving multiple change events for a single file id where the last change is a delete the server panics, as it tries to access the file contents of a deleted file. This occurs due to the VFS changes and the in memory file contents being updated immediately, while `process_changes` processes the events afterwards in sequence which no longer works as it will only observe the final file contents. By folding these events together, we will no longer try to process these intermediate changes, as they aren't relevant anyways.

Potentially fixes https://github.com/rust-lang/rust-analyzer/issues/13236
2022-09-27 14:41:40 +00:00
Lukas Wirth
c3a6c963e5 Amalgamate file changes for the same file ids in process_changes
When receiving multiple change events for a single file id where the
last change is a delete the server panics, as it tries to access the
file contents of a deleted file. This occurs due to the VFS changes and
the in memory file contents being updated immediately, while
`process_changes` processes the events afterwards in sequence which no
longer works as it will only observe the final file contents. By
folding these events together, we will no longer try to process these
intermediate changes, as they aren't relevant anyways.

Potentially fixes https://github.com/rust-lang/rust-analyzer/issues/13236
2022-09-27 16:41:04 +02:00
bors
bd8c5b6b42 Auto merge of #13300 - Veykril:cfg-false, r=Veykril
Use cfg(any()) instead of cfg(FALSE) for disabling proc-macro test

cc https://github.com/rust-lang/rust-analyzer/pull/13286
2022-09-27 14:11:04 +00:00
Lukas Wirth
fb736449fd Use cfg(any()) instead of cfg(FALSE) for disabling proc-macro test 2022-09-27 13:52:04 +02:00
Lukas Wirth
7929e9c56b Remove obsolete in-rust-tree feature from sourcegen 2022-09-26 11:34:30 +02:00
Lukas Wirth
73f6af54c1 Use the sysroot proc-macro server for analysis-stats 2022-09-24 22:04:17 +02:00
Lukas Wirth
f57cd838d8 Don't run proc-macro-srv tests on the rust-analyzer repo
proc-macro ABI breakage still affects the tests when a new stable version
releases. Ideally we'd still be able to run the tests on the rust-analyzer
repo without having to update the proc-macro ABI, but for now just to
unblock CI we will ignore them here, as they are still run in upstream.
2022-09-24 00:08:28 +02:00
Laurențiu Nicola
f5fde4df43 ⬆️ rust-analyzer 2022-09-20 17:39:17 +03:00
Lukas Wirth
a6c067c06d Simplify 2022-09-19 17:31:08 +02:00
Lukas Wirth
d9f5709609 Simplify feature representation in CargoConfig 2022-09-19 16:52:44 +02:00
bors
11bf2e7ffb Auto merge of #13058 - dpaoliello:extraenv, r=Veykril
Add a new configuration settings to set env vars when running cargo, rustc, etc. commands: cargo.extraEnv and checkOnSave.extraEnv

It can be extremely useful to be able to set environment variables when rust-analyzer is running various cargo or rustc commands (such as `cargo check`, `cargo --print cfg` or `cargo metadata`): users may want to set custom `RUSTFLAGS`, change `PATH` to use a custom toolchain or set a different `CARGO_HOME`.

There is the existing `server.extraEnv` setting that allows env vars to be set when the rust-analyzer server is launched, but using this as the recommended mechanism to also configure cargo/rust has some drawbacks:
- It convolutes configuring the rust-analyzer server with configuring cargo/rustc (one may want to change the `PATH` for cargo/rustc without affecting the rust-analyzer server).
- The name `server.extraEnv` doesn't indicate that cargo/rustc will be affected but renaming it to `cargo.extraEnv` doesn't indicate that the rust-analyzer server would be affected.
- To make the setting useful, it needs to be dynamically reloaded without requiring that the entire extension is reloaded. It might be possible to do this, but it would require the client communicating to the server what the overwritten env vars were at first launch, which isn't easy to do.

This change adds two new configuration settings: `cargo.extraEnv` and `checkOnSave.extraEnv` that can be used to change the environment for the rust-analyzer server after launch (thus affecting any process that rust-analyzer invokes) and the `cargo check` command respectively. `cargo.extraEnv` supports dynamic changes by keeping track of the pre-change values of environment variables, thus it can undo changes made previously before applying the new configuration (and then requesting a workspace reload).
2022-09-18 17:43:46 +00:00
Daniel Paoliello
c407cc554e Add cargo.extraEnv setting 2022-09-13 11:29:14 -07:00
bors
dbb8fedf8b Auto merge of #13221 - mdx97:mdx97/annotations-above-whole-item, r=Veykril
Allow configuration of annotation location.

I've added the ability to configure where lens annotations render relevant to the item they describe. Previously, these would render directly above the line the item is declared on. Now, there is the ability to render these annotations above the entire item (including doc comments, and attributes).

The names of the config options are up for debate, I did what seemed best to me but if anyone has better ideas let me know.

This is my first contribution so if I've missed anything please let me know.

Here's a preview of what the new option looks like:

<img width="577" alt="Screen Shot 2022-09-11 at 10 39 51 PM" src="https://user-images.githubusercontent.com/33100798/189570298-b4fcbf9c-ee49-4b79-aae6-1037ae4f26af.png">

closes https://github.com/rust-lang/rust-analyzer/issues/13218
2022-09-13 15:09:53 +00:00
bors
125d43cb2c Auto merge of #13227 - Veykril:core-pref, r=Veykril
Restructure `find_path` into a separate functions for modules and non-module items

Follow up to https://github.com/rust-lang/rust-analyzer/pull/13212
Also renames `prefer_core` imports config to `prefer_no_std` and changes the behavior of no_std path searching by preferring `core` paths `over` alloc

This PR turned into a slight rewrite, so it unfortunately does a few more things that I initially planned to (including a bug fix for enum variant paths)
2022-09-13 13:16:57 +00:00
Lukas Wirth
a8ecaa1979 Restructure find_path into a separate functions for modules and non-module items
Also renames `prefer_core` imports config to `prefer_no_std` and changes the behavior of no_std path searching by preferring `core` paths `over` alloc
2022-09-13 15:15:27 +02:00
Lukas Wirth
cadb01c315 Move reference imports filtering into to_proto layer 2022-09-13 14:58:50 +02:00
Laurențiu Nicola
459bbb4222 ⬆️ rust-analyzer 2022-09-13 15:38:11 +03:00
Mathew Horner
f57c15f3e9 Address comments and fix build. 2022-09-12 16:34:13 -05:00
bors
e38dfe5536 Auto merge of #13186 - enomado:master, r=Veykril
Filter imports on find-all-references

Attempt to #13184
2022-09-12 12:09:57 +00:00
bors
352a5b8625 Auto merge of #13212 - Veykril:no-std-config, r=Veykril
Add config to unconditionally prefer core imports over std

Fixes https://github.com/rust-lang/rust-analyzer/issues/12979
2022-09-12 11:51:31 +00:00
Mathew Horner
8a2803d9ae Allow configuration of annotation location.
Previously, annotations would only appear above the name of an item (function signature, struct declaration, etc).

Now, rust-analyzer can be configured to show annotations either above the name or above the whole item (including doc comments and attributes).
2022-09-11 22:40:33 -05:00
Lukas Wirth
7d19971666 Add config to unconditionally prefer core imports over std
Fixes https://github.com/rust-lang/rust-analyzer/issues/12979
2022-09-09 20:04:56 +02:00
Stanislav
f7f4792f4f fixes 2022-09-09 20:58:06 +03:00
Stanislav
0240294759 fix comment round 2 2022-09-08 22:47:39 +03:00
Stanislav
1764c42518 fix comment 2022-09-08 22:36:36 +03:00
bors
4e1a3da8f2 Auto merge of #13158 - jonas-schievink:inlayhint-links, r=jonas-schievink
feat: make clicking a closing brace inlay hint go to the opening brace
2022-09-08 16:38:40 +00:00
Jonas Schievink
c4eadab016
Update crates/rust-analyzer/src/to_proto.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-09-08 18:33:53 +02:00
Stanislav
9f6553e1d6 add config for import filtering 2022-09-08 01:53:20 +03:00
Joseph Ryan
5d126a18b4 Use proc-macro-srv from sysroot in rust-project.json 2022-09-06 18:27:17 -07:00
Laurențiu Nicola
65e1dc4d9c ⬆️ rust-analyzer 2022-09-06 21:20:49 +03:00
Jonas Schievink
241807dbf9 Allow multi-part inlay hint labels with location links 2022-08-31 18:34:10 +02:00
Laurențiu Nicola
3e358a6827 ⬆️ rust-analyzer 2022-08-30 14:51:24 +03:00
Lukas Wirth
66ec636fec Highlight namerefs by syntax until proc-macros have been loaded 2022-08-29 18:44:55 +02:00
Lukas Wirth
9ad0a8c467 Move empty diagnostics workaround back into the server 2022-08-28 11:54:46 +02:00
bors
ca8093e282 Auto merge of #13116 - Veykril:nohash, r=Veykril
Make use of NoHash hashing for FileId and CrateId

Both of these are mere integers so there is nothing to hash here.

Ideally we would use this for `la_arena::Idx` too, but that doesn't work due to the orphan rule, and `la_arena` is unfortunately a public library so we can't really do much here... Unless we remove the trait restriction but I'd like not to
2022-08-25 19:08:57 +00:00
Lukas Wirth
d025c5d8d6 Make use of NoHash hashing for FileId and CrateId 2022-08-25 20:41:49 +02:00