Commit Graph

14805 Commits

Author SHA1 Message Date
Lukas Wirth
15e7112da3 fix: Check whether a parameter can be converted to a local 2022-04-09 00:55:45 +02:00
bors[bot]
399559e597
Merge #11940
11940: minor: bump lsp-server version r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-04-08 22:14:48 +00:00
Lukas Wirth
2d445de170 minor: bump lsp-server version 2022-04-09 00:13:47 +02:00
Jonas Schievink
22b13c8bff Make trait item completions work in a bare impl and score them 2022-04-08 19:56:41 +02:00
Jonas Schievink
cdeb6140bf Account for macros in get_missing_assoc_items 2022-04-08 18:05:34 +02:00
Florian Diebold
340f0fc333 Ignore Drop and Destruct bounds for now
- `T: ~const Drop` has a special meaning in Rust 1.61 that we don't implement.
  (So ideally, we'd only ignore `~const Drop`, but this should be fine
  for now.)
- `Destruct` impls are built-in in 1.62 (current nightlies as of 08-04-2022), so until
  the builtin impls are supported by Chalk, we ignore them as well.
  Since `Destruct` is implemented for everything in non-const contexts
  IIUC, this should also work fine.

Fixes #11932.
2022-04-08 14:29:43 +02:00
Jonas Schievink
99d91bc550 flyimport: omit types when completing where-clause 2022-04-07 20:02:33 +02:00
bors[bot]
b8ed4a388c
Merge #11920
11920: Consider types of const generics r=flodiebold a=HKalbasi

fix #11913 

We should emit type_mismatch in const generics, probably after #7434. Currently they will lead to a misleading, time of use type error (like the added test).


Co-authored-by: hkalbasi <hamidrezakalbasi@protonmail.com>
2022-04-07 17:08:02 +00:00
Jonas Schievink
5d8b4c40eb Determine function unsafety semantically 2022-04-07 18:33:03 +02:00
bors[bot]
12f803d1e3
Merge #11925
11925: internal: Add and use `HirFormatter::write_{str,char}` r=Veykril a=lnicola

Saves slightly over 3 KB of `text`, but comparing the total with that from two weeks ago in #11776, this is a losing battle (we're 951 KB larger).

```
   text	   data	    bss	    dec	    hex	filename
24693512	1542704	   4424	26240640	1906680	rust-analyzer-baseline
24690216	1542112	   4424	26236752	1905750	rust-analyzer-pr
```


Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2022-04-07 14:38:46 +00:00
Jonas Schievink
c71c30419c Use bitflags for FnFlags 2022-04-07 16:22:34 +02:00
Jonas Schievink
16d0f724b6 use stdx::never 2022-04-07 15:55:44 +02:00
Jonas Schievink
67495b618b Fix panics with #[cfg]'d-out self parameter 2022-04-07 15:47:03 +02:00
Laurențiu Nicola
bd570903b0 Add and use HirFormatter::write_{str,char} 2022-04-07 16:41:07 +03:00
Jonas Schievink
6501e45131 Remove FnFlags::IS_IN_EXTERN_BLOCK 2022-04-07 15:22:11 +02:00
hkalbasi
204a1561b2 consider types of const generics 2022-04-07 05:30:33 +04:30
Lukas Wirth
3632d5946f minor: Remove pointless rebindings 2022-04-07 01:29:31 +02:00
Lukas Wirth
96b641e95e internal: Add more doc-link tests 2022-04-06 20:58:46 +02:00
Lukas Wirth
4a1423337f fix: Attempt to resolve paths in const arguments heuristically
While we don't support const args in type inference yet, we can at least
make use of the fallback path resolution to resolve paths in const args
in the IDE layer to enable some features for them.
2022-04-06 20:24:24 +02:00
Lukas Wirth
7959c24876 fix: Fix path qualifiers not resolving generic type params when shadowed by trait 2022-04-06 19:38:45 +02:00
Lukas Wirth
4e6390bb12 Fix SearchScope::reverse_dependencies trying to search more files than necessary 2022-04-06 14:24:06 +02:00
Lukas Wirth
d9f6cee100 fix: Fix SearchScope using incorrect text ranges for macro-emitted inline modules 2022-04-06 13:58:40 +02:00
bors[bot]
2366d8e05f
Merge #11905
11905: internal: Remove hir_expand macro recursion check r=jonas-schievink a=jonas-schievink

This check is insufficient to ensure finite macro nesting, and so all callers already have their own recursion limit, which makes this check redundant.

...at least I hope it's redundant. Would be great if someone could double-check this.

Originally, this check was added in https://github.com/rust-analyzer/rust-analyzer/pull/3671

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2022-04-05 17:00:56 +00:00
bors[bot]
ee6becc5dd
Merge #11891
11891: Better error message on Flycheck Error message (from: unactionable error message if we are using `clippy` as the checker) r=Veykril a=flipbit03

I have commented on this [S-unactionable issue](https://github.com/rust-analyzer/rust-analyzer/issues/6589) that the Flycheck error message should maybe provide a hint about what tool it actually runs. Searching on some places on the Internet I've found multiple people, including myself, losing copious amounts of time on the same issue. So I've decided to make this very small PR :-)

From an user experience standpoint, the current error message is unhelpful to the end user, because the end user does not know exactly what it needs to check/fix (outdated, broken, or missing `cargo clippy`). In my own case, `cargo clippy` was actually missing altogether (developing off `rust:1.59.0-bullseye` official Docker image).

Thanks in advance!




Co-authored-by: Cadu <cadu.coelho@gmail.com>
2022-04-05 16:31:18 +00:00
Jonas Schievink
9de54570d6 Remove hir_expand macro recursion check 2022-04-05 17:59:48 +02:00
Jonas Schievink
872b7b9660 Wrap macros in expr position in MacroExpr node 2022-04-05 17:43:34 +02:00
Cadu
84cf6ad091 Using error instead of output.stderr in failure mode. 2022-04-05 11:17:39 -03:00
Cadu
ca9718aa42 Made error output the contents of Cargo's stderr as well. 2022-04-04 19:15:20 -03:00
Cadu
8e5c57f050 wordsmithing. 2022-04-04 19:15:20 -03:00
Cadu
635270d4ad Better error message hinting about cargo clippy 2022-04-04 19:15:20 -03:00
iDawer
86665e50c2 fix: Skip match check on a pattern of unexpected TyKind::FnDef 2022-04-05 00:05:20 +05:00
bors[bot]
bf6303df37
Merge #11896
11896: fix: Show the path to be created in the unresolved-module fix label r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-04-04 14:14:26 +00:00
Lukas Wirth
3a847eacc8 fix: Show the path to be created in the unresolved-module fix label 2022-04-04 16:04:09 +02:00
bors[bot]
f5c069c9d9
Merge #11894
11894: complete pattern args based on type name r=Veykril a=cameron1024

Addresses #11892 

Changes function argument completion to cover a case like this:
```rust
struct Foo { bar: i32 }

fn qux(Foo { bar }: Foo) {
  println!("{bar}");
}
```
When completing the function call for `qux`, instead of expanding to `qux(_)`, it will now expand to `qux(foo)` (based on the snake-cased version of the name of the ADT)

Non ADTs are unaffected


Co-authored-by: cameron <cameron.studdstreet@gmail.com>
Co-authored-by: cameron1024 <cameron.studdstreet@gmail.com>
2022-04-04 13:06:51 +00:00
cameron1024
37d2a8243f
Update crates/ide_completion/src/render/function.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-04-04 13:33:14 +01:00
cameron
bb1c3a20b5 fix type error 2022-04-04 14:30:49 +01:00
cameron
2137bdfca3 remove unwarp on adt name 2022-04-04 14:28:15 +01:00
cameron
c735b979ed complete pattern args based on type name 2022-04-04 13:51:51 +01:00
bors[bot]
46d7ee68f2
Merge #11865
11865: Fix: Select correct insert position for disabled group import r=jonasbb a=jonasbb

The logic for importing with and without `group_imports` differed
significantly when no previous group existed. This lead to the problem
of using the wrong position when importing inside a module (#11585) or
when inner attributes are involved.
The existing code for grouped imports is better and takes these things
into account.

This PR changes the flow to use the pre-existing code for adding a new
import group even for the non-grouped import settings.
Some coverage markers are updated and the `group` is removed, since they
are now invoked in both cases (grouping and no grouping).

Tests are updated and two tests (empty module and inner attribute) are
added.

Fixes #11585

Co-authored-by: Jonas Bushart <jonas@bushart.org>
2022-04-03 18:46:45 +00:00
Jonas Bushart
156f9074e1 Use check_count! instead of multiple check! in separate scopes
Changes are based on the review feedback by Veykril.
2022-04-03 18:34:06 +00:00
bors[bot]
65eaabc200
Merge #11887
11887: fix: Add missing fields diagnostic fix for patterns r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2022-04-03 13:42:15 +00:00
Lukas Wirth
dd3f7664fd fix: Add missing fields diagnostic fix for patterns 2022-04-03 15:18:05 +02:00
bors[bot]
63d2df1e36
Merge #11699
11699: feat: assist to remove unneeded `async`s r=Ethiraric a=Ethiraric

This should fix #11392 

This PR adds a quickfix on functions marked with `async` that suggests, if and only if no `await` expression in find in the body of the function (it relies on `SyntaxNode::descendants()` to recursively traverse blocks), to remove the `async` keyword.

The lint is made so that it triggers only if the cursor is not in the body of the function, so that it does not pollute the quickfix list.

It does not trigger a diagnostic. I don't know if this repository is the place to implement those (`clippy`?). If it is, I would very much like pointers on where to start looking.

If there are test cases I haven't thought about, please do suggest.

Co-authored-by: Ethiraric <ethiraric@gmail.com>
2022-04-03 12:42:52 +00:00
Ethiraric
520557d45c feat: assist to remove unneeded asyncs 2022-04-03 14:34:08 +02:00
bors[bot]
bc0825d135
Merge #10802
10802: Allow clients to configure the global workspace search limit r=Veykril a=knutwalker

Playing around with [helix](https://helix-editor.com) I realized that the global worksapce symbol search works different compared to vs-code.
Helix requires all possible symbols in one query and does no subsequent refinement searched.
This PR adds a configuration option to override the default search limit with the default being the currently hardocded value.
Helix users can increment this limit for their instance with a config like

```toml
[[language]]
name = "rust"
language-server = { command = "rust-analyzer" }
[language.config]
workspace = { symbol = { search = { limit = 65536 }}}
```

Other editors are not affected by this change.


Co-authored-by: Paul Horn <dev@knutwalker.engineer>
2022-04-03 12:03:46 +00:00
Jonas Bushart
0cc079f3e9 Merge test functions using the same coverage marks to avoid parallelism 2022-04-03 12:01:11 +00:00
bors[bot]
5b5ca0bd17
Merge #11866
11866: fix: Prevent underflow in range conversion  r=Veykril a=skyfmmf

Previously, when line numbers of Rust spans were converted to LSP ranges, they could underflow resulting in very large line numbers. As an underflow is always wrong, prevent it and use 0 instead.

This was noticed when opening an empty file in `src/bin/` of a library crate. In this case rustc produces a span with `"line_start": 0, "line_end": 0` resulting in the underflow.

Co-authored-by: Felix Maurer <felix@felix-maurer.de>
2022-04-03 11:49:23 +00:00
Aleksey Kladov
a8f460209d add test for postfix completion relevance
Follow up to #11857, add a test and cov-marks
2022-04-03 12:13:26 +01:00
bors[bot]
4204e35563
Merge #11879
11879: Suggest infered type in auto complete r=HKalbasi a=HKalbasi

fix #11855

It doesn't work for return types and consts (so their tests are failing) because I can't find their body node in the original file. (Are these original and fake file documented somewhere?)

Also it currently needs to type first character of the type (or manual ctrl+space) to open the auto complete panel, is it possible to open it automatically on typing `:` and `->`?


Co-authored-by: hkalbasi <hamidrezakalbasi@protonmail.com>
2022-04-03 07:05:41 +00:00
hkalbasi
003a6b74e4 suggest infered type in auto complete 2022-04-03 11:17:33 +04:30