Commit Graph

19764 Commits

Author SHA1 Message Date
Laurențiu Nicola
4c94e69115 Add in-rust-tree feature to hir-expand 2024-04-20 18:44:27 +03:00
Lukas Wirth
0ce7179e6b Correctly populate detached files roots 2024-04-19 18:25:10 +02:00
Lukas Wirth
46f05543a2 Patch cargo script root files back to manifest 2024-04-19 18:25:10 +02:00
Lukas Wirth
0b24599cf9 Re-implement dependecny tracking for cargo script 2024-04-19 18:25:06 +02:00
hkalbasi
2f828073aa Add minimal support for cargo scripts 2024-04-19 18:23:06 +02:00
bors
50bdeaad07 Auto merge of #17108 - Veykril:rustc-ws-hacks, r=Veykril
internal: Cleanup cfg and env handling in project-model

Fixes https://github.com/rust-lang/rust-analyzer/issues/16122#issuecomment-2065794340

`miri` and `debug_assertions` are now enabled via the `cargo.cfgs` config by default, allowing them to be disabled by overwriting the config.
2024-04-19 16:00:54 +00:00
bors
05428c5640 Auto merge of #17024 - roife:fix-issue-16980, r=Veykril
fix: handle escaped chars in doc comments

fix #16980.

For `ast::LiteralKind::String`, store the original string value.
2024-04-19 13:19:22 +00:00
roife
3e232bb78a fix: replace unescape fn with the one in ra-ap-rustc_lexer 2024-04-19 20:32:53 +08:00
Lukas Wirth
cdb8c3a327 Fix tests being non-deterministic 2024-04-19 13:22:00 +02:00
bors
77ce295006 Auto merge of #17094 - Lindronics:convert-from-to-tryfrom, r=Veykril
feat: Add convert From to TryFrom assist

Adds a new code assist to convert a `From` impl into a `TryFrom` impl.

This is useful in situations where it turns out after or halfway through writing a `From` implementation that the conversion is actually fallible.

## Example

https://github.com/rust-lang/rust-analyzer/assets/26360861/872ec7c4-c9ff-451c-9453-4baaaad47326
2024-04-19 09:15:20 +00:00
Lukas Wirth
0485a85ee2 Set debug_assertions and miri cfgs as config defaults, allowing them to be overwritten 2024-04-19 11:06:55 +02:00
Lukas Wirth
8989dcffd6 Support cfg overrides in all workspace kind 2024-04-19 10:59:32 +02:00
Lukas Wirth
ee10f9f5cd Cleanup cfg and env handling in project-model 2024-04-19 10:41:08 +02:00
Niklas Lindorfer
1aba0002df
Add convert From to TryFrom assist 2024-04-19 08:29:20 +01:00
bors
eea61bd4d1 Auto merge of #16726 - Veykril:rustc-ws-hacks, r=Veykril
internal: Remove rustc core test cfg hacks

cc https://github.com/rust-lang/rust-analyzer/issues/16538
2024-04-19 07:28:50 +00:00
Lukas Wirth
2e54c0af40 Remove rustc core test cfg hacks 2024-04-19 09:27:05 +02:00
roife
a543516ea4 fix: handle escaped chars in doc comments 2024-04-19 14:57:37 +08:00
Kevin Reid
db292bd89e Make test harness arguments configurable and not --nocapture.
* Added config `runnables.extraTestBinaryArgs` to control the args.
* The default is `--show-output` rather than `--nocapture` to prevent
  unreadable output when 2 or more tests fail or print output at once.
* Renamed variables in `CargoTargetSpec::runnable_args()` for clarity.

Fixes <https://github.com/rust-lang/rust-analyzer/issues/12737>.
2024-04-18 18:37:09 -07:00
bors
af1fd88c4d Auto merge of #16257 - lnicola:rustc-check-cfg, r=Veykril
internal: Teach cargo about `cfg(rust_analyzer)`

r? `@Urgau` is this a good idea?, CC `@Veykril`
2024-04-18 12:13:06 +00:00
Lukas Wirth
4135696ea7 Cleanup 2024-04-18 11:00:22 +02:00
Lukas Wirth
6bfdd38c69 Render matched macro arm on hover of macro calls 2024-04-18 10:51:58 +02:00
Wilfred Hughes
bd133eecda fix: VFS should not walk circular symlinks
As of #6246, rust-analyzer follows symlinks. This can introduce an
infinite loop if symlinks point to parent directories.

Considering that #6246 was added in 2020 without many bug reports,
this is clearly a rare occurrence. However, I am observing
rust-analyzer hang on projects that have symlinks of the form:

```
test/a_symlink -> ../../
```

Ignore symlinks that only point to the parent directories, as this is
more robust but still allows typical symlink usage patterns.
2024-04-17 14:40:01 -07:00
bors
46702ffc1a Auto merge of #17087 - davidbarsky:david/fix-some-tracing-spans, r=Veykril
chore: fix a few spans without `.entered()`
2024-04-17 16:59:33 +00:00
Lukas Wirth
011c2127c8 Update per_query_memory_usage query listing 2024-04-17 18:44:50 +02:00
David Barsky
5ba37f3f8e chore: fix a few spans without .entered() 2024-04-17 12:44:49 -04:00
bors
91b8441b3a Auto merge of #17055 - wyatt-herkamp:fix_panic_at_unused_variable, r=Veykril
fix: Replace Just the variable name in Unused Variable Diagnostic Fix

Changes Unused Variable diagnostic to just look at the variable name, not the entire syntax range.

Also added a test for an unused variable in an array destructure.

Closes #17053
2024-04-17 10:11:03 +00:00
Lukas Wirth
0eb7b6c7b5 Don't show unused_variables fixes if the name comes from a macro definition 2024-04-17 12:05:35 +02:00
Alex Kladov
f852a6fc7d ide: add a new test 2024-04-16 17:17:46 +01:00
Alex Kladov
9bd8eee21e ide: improve ReferenceCategoryType
It is bitset semantically --- many categorical things can be true about
a reference at the same time.

In parciular, a reference can be a "test" and a "write" at the same
time.
2024-04-16 17:17:46 +01:00
bors
1179c3ee83 Auto merge of #16639 - alibektas:13529/config_restruct, r=Veykril
internal : redesign rust-analyzer::config

This PR aims to cover the infrastructural requirements for the `rust-analyzer.toml` ( #13529 ) issue. This means, that

1. We no longer have a single config base. The once single `ConfigData` has been divided into 4 : A tree of `.ratoml` files, a set of configs coming from the client ( this is what was called before the `CrateData` except that now values do not default to anything when they are not defined) , a set of configs that will reflect what the contents of a `ratoml` file defined in user's config directory ( e.g `~/.config/rust-analyzer/.rust-analyzer.toml` and finally a tree root that is populated by default values only.
2. Configs have also been divided into 3 different blocks : `global` , `local` , `client`. The current status of a config may change until #13529 got merged.

Once again many thanks to `@cormacrelf` for doing all the serde work.
2024-04-16 07:52:07 +00:00
bors
e64610dbbe Auto merge of #17037 - davidsemakula:token-set-collisions, r=Veykril
internal: improve `TokenSet` implementation and add reserved keywords

The current `TokenSet` type represents "A bit-set of `SyntaxKind`s" as a newtype `u128`.
Internally, the flag for each `SyntaxKind` variant in the bit-set is set as the n-th LSB (least significant bit) via a bit-wise left shift operation, where n is the discriminant.

Edit: This is problematic because there's currently ~121 token `SyntaxKind`s, so adding new token kinds for missing reserved keywords increases the number of token `SyntaxKind`s above 128, thus making this ["mask"](7a8374c162/crates/parser/src/token_set.rs (L31-L33)) operation overflow.
~~This is problematic because there's currently 266 SyntaxKinds, so this ["mask"](7a8374c162/crates/parser/src/token_set.rs (L31-L33)) operation silently overflows in release mode.~~
~~This leads to a single flag/bit in the bit-set being shared by multiple `SyntaxKind`s~~.

This PR:
- Changes the wrapped type for `TokenSet` from `u128` to `[u64; 3]` ~~`[u*; N]` (currently `[u16; 17]`) where `u*` can be any desirable unsigned integer type and `N` is the minimum array length needed to represent all token `SyntaxKind`s without any collisions~~.
- Edit: Add assertion that `TokenSet`s only include token `SyntaxKind`s
- Edit: Add ~7 missing [reserved keywords](https://doc.rust-lang.org/stable/reference/keywords.html#reserved-keywords)
- ~~Moves the definition of the `TokenSet` type to grammar codegen in xtask, so that `N` is adjusted automatically (depending on the chosen `u*` "base" type) when new `SyntaxKind`s are added~~.
- ~~Updates the `token_set_works_for_tokens` unit test to include the `__LAST` `SyntaxKind` as a way of catching overflows in tests.~~

~~Currently `u16` is arbitrarily chosen as the `u*` "base" type mostly because it strikes a good balance (IMO) between unused bits and readability of the generated `TokenSet` code (especially the [`union` method](7a8374c162/crates/parser/src/token_set.rs (L26-L28))), but I'm open to other suggestions or a better methodology for choosing `u*` type.~~

~~I considered using a third-party crate for the bit-set, but a direct implementation seems simple enough without adding any new dependencies. I'm not strongly opposed to using a third-party crate though, if that's preferred.~~

~~Finally, I haven't had the chance to review issues, to figure out if there are any parser issues caused by collisions due the current implementation that may be fixed by this PR - I just stumbled upon the issue while adding "new" keywords to solve #16858~~

Edit: fixes #16858
2024-04-16 07:00:12 +00:00
David Barsky
ab8c112573 Revert "Auto merge of #17073 - roife:better-inline-preview, r=Veykril"
af728741de
2024-04-15 18:24:15 -04:00
bors
90cfa8035f Auto merge of #17078 - Veykril:diags-perf, r=Veykril
internal: Improve diagnostics performance
2024-04-15 20:17:26 +00:00
Lukas Wirth
531a270d91 Generally optimize diagnostics performance 2024-04-15 22:15:41 +02:00
Wyatt Herkamp
701068daf2 Verify we are not in a macro attempt 2 2024-04-15 14:11:45 -04:00
Lukas Wirth
94e38261b3 Optimize exhaustiveness checking perf a bit 2024-04-15 19:35:48 +02:00
bors
b223860c0e Auto merge of #17074 - Veykril:hl, r=Veykril
Add Static and Const highlighting token types
2024-04-15 15:19:56 +00:00
Lukas Wirth
597c293a69 Adjust package.json semantic highlighting items 2024-04-15 17:00:03 +02:00
Lukas Wirth
6b98e55dbb Add Static and Const highlighting token types 2024-04-15 16:54:17 +02:00
Wyatt Herkamp
0faa2940c7 Use the text range for the name. Not the entire syntax in Unused Variable Diagnostic. 2024-04-15 10:46:21 -04:00
bors
af728741de Auto merge of #17073 - roife:better-inline-preview, r=Veykril
Better inline preview for postfix completion

Better inline preview for postfix completion, a proper implementation of c5686c8941.

Here editors may filter completion item with the text within `delete_range`, so we need to include the `receiver text` in the `lookup` (aka `FilterText` in LSP spec) for editors to find the completion item. (See https://github.com/rust-lang/rust-analyzer/issues/17036#issuecomment-2056614180, Thanks to [pascalkuthe](https://github.com/pascalkuthe))
2024-04-15 14:33:38 +00:00
davidsemakula
69fe457cb5 internal: simplify TokenSet implementation 2024-04-15 17:33:09 +03:00
roife
8db1c64268 tests: fix tests for postfix 2024-04-15 22:21:15 +08:00
roife
76a8a976f3 fix: better inline preview for postfix completion 2024-04-15 22:21:06 +08:00
bors
c0371309b4 Auto merge of #17072 - Veykril:hir-ty-display, r=Veykril
internal: Use `hir_fmt_args` everywhere in `hir_ty::display`
2024-04-15 14:19:04 +00:00
Lukas Wirth
91659da5a6 internal: Use hir_fmt_args everywhere in hir_ty::display 2024-04-15 16:17:29 +02:00
bors
2e7059ca58 Auto merge of #16877 - Veykril:stackoverflow, r=Veykril
fix: Fix `impl Trait<Self>` causing stackoverflows

Fixes https://github.com/rust-lang/rust-analyzer/issues/15646
2024-04-15 13:47:46 +00:00
Lukas Wirth
1915980031 fix: Fix impl Trait<Self> causing stackoverflows 2024-04-15 15:41:20 +02:00
bors
40bb8f3272 Auto merge of #16813 - wyatt-herkamp:to-from-cfg_attr-assist, r=Veykril
Wrap/Unwrap cfg_attr

https://github.com/rust-lang/rust-analyzer/assets/11785959/f5f1bb71-22e7-438b-9a22-65ebab1b362d

https://github.com/rust-lang/rust-analyzer/assets/11785959/36933a4e-0000-455a-abe3-af774cd854d0

## TODO
- [x] Add Tests
- [x] Wrap derive elements

Closes #13965
2024-04-15 12:56:55 +00:00
Lukas Wirth
60d3a7320e Differentiate between full configs and toml only config groupings 2024-04-15 14:16:43 +02:00