Commit graph

8412 commits

Author SHA1 Message Date
bors[bot]
d8e5265309
Merge #5954
5954: Add flexible configuration for runnables r=popzxc a=popzxc

This PR introduces two new configuration options for runnables: `overrideCargo` and `cargoExtraArgs`.
These options are applied to all the "run" tasks of rust analyzer, such as binaries and tests.

Overall motivation is that rust-analyzer provides similar options, for example, for `rustfmt`, but not for runnables.

## `overrideCargo`

This option allows user to replace `cargo` command with something else (well, something that is compatible with the cargo arguments).

Motivation is that some projects may have wrappers around cargo (or even whole alternatives to cargo), which do something related to the project, and only then run `cargo`. With this feature, such users will be able to use lens and run tests directly from the IDE rather than from terminal.

![cargo_override](https://user-images.githubusercontent.com/12111581/92306622-2f404f80-ef99-11ea-9bb7-6c6192a2c54a.gif)

## `cargoExtraArgs`

This option allows user to add any additional arguments for `cargo`, such as `--release`.

It may be useful, for example, if project has big integration tests which take too long in debug mode, or if any other `cargo` flag has to be passed.

![cargo_extra_args](https://user-images.githubusercontent.com/12111581/92306658-821a0700-ef99-11ea-8be9-bf0aff78e154.gif)

Co-authored-by: Igor Aleksanov <popzxc@yandex.ru>
2020-10-02 09:42:03 +00:00
Igor Aleksanov
4ebacf9024 Fix failing test 2020-10-02 12:35:25 +03:00
Igor Aleksanov
4a1b4b23bb Replace 'cargo_prefix' option with 'override_cargo' 2020-10-02 12:34:27 +03:00
Igor Aleksanov
2c125f3c63 Add support of runnables arguments in Rust Analyzer 2020-10-02 12:34:27 +03:00
bors[bot]
40a028c9a8
Merge #6105
6105: Fix path comparison not comparing paths correctly with unequal lengths r=matklad a=Veykril

~~This PR includes the commit from #6102 there as I found a bug while writing that(so either merging this or both in order works) so I included a test there already which was just ignored.~~ This PR fixes that, basically inserting imports didn't consider path length for equality, so depending on the order it might insert the path before or after another import if they only differ in segment length.

~~Diff without the commit of #6102 2d90d3937d~~



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-10-02 09:30:25 +00:00
bors[bot]
e535489f03
Merge #6104
6104: Minor clippy performance suggestions r=matklad a=kjeremy



Co-authored-by: kjeremy <kjeremy@gmail.com>
2020-10-02 08:07:42 +00:00
kjeremy
ff678e1349 Up rustc-ap-rustc_lexer to 681
cargo update as well
2020-10-01 15:21:13 -04:00
Lukas Wirth
95ea23cdef Fix path comparison not comparing paths correctly with unequal lengths 2020-10-01 17:18:34 +02:00
kjeremy
82d6cfd495 Minor clippy performance suggestions 2020-09-30 15:22:49 -04:00
Lukas Wirth
0671bf2d73 Fix MergingBehaviour::Last not working properly 2020-09-30 19:09:17 +02:00
vlakreeh
b2bfadb52c Add tests for convert integer literal assist 2020-09-29 19:05:17 -04:00
vlakreeh
91b4746c01 Add ability to specify ResolvedAssist by label 2020-09-29 18:22:09 -04:00
Aleksey Kladov
af8063fe37 Extend **Status** command to also show dep info for the file
This should help with troubleshooting wrong project configuration
2020-09-29 22:13:23 +02:00
Aleksey Kladov
e7df0ad2fb Remove periodic gc stub 2020-09-29 21:22:48 +02:00
Aleksey Kladov
8e34c0fb73 More panic_context 2020-09-29 20:49:48 +02:00
vlakreeh
c84fdb8b3e Add convert integer literal assist 2020-09-29 14:48:43 -04:00
Aleksey Kladov
d3a2b21a8c Add panic_context module for better panic messages 2020-09-29 20:20:47 +02:00
vsrs
91da41b3b1 Replace "No references" with "0 references". 2020-09-29 15:29:20 +03:00
vsrs
cd5eeb904e Add tests 2020-09-29 15:29:20 +03:00
vsrs
1895716c88 Do not show references CodeLens for tests. 2020-09-29 15:29:20 +03:00
vsrs
06fbd69050 Make method references CodeLens lazy. 2020-09-29 15:29:20 +03:00
vsrs
b7fda5f936 Make method references CodeLens off by default. 2020-09-29 15:29:20 +03:00
vsrs
eeb40dbece Add method references CodeLens 2020-09-29 15:29:20 +03:00
flw
e73ee9dfa2
Add hover config linksInHover to suppress links 2020-09-29 19:47:18 +08:00
bors[bot]
18c62c8a39
Merge #6019
6019: Remove make::path_from_text r=matklad a=Veykril

This removes the `make::path_from_text` function, which according to a note should've been private. I removed it since it didn't really serve a purpose as it was simply wrapping `make::ast_from_text`.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-09-29 10:29:33 +00:00
bors[bot]
7b674f9ab4
Merge #6088
6088: Update chalk to 0.30.0 r=flodiebold a=nathanwhit

Fixes #6078 and CI failures.



Co-authored-by: Nathan Whitaker <nathan.whitaker01@gmail.com>
2020-09-28 18:30:50 +00:00
Nathan Whitaker
f50458deaf Update chalk to 0.30.0 2020-09-28 14:24:11 -04:00
Aleksey Kladov
6ff78962b3 Microoptimize 2020-09-28 19:06:51 +02:00
Jeremy Kolb
76dfac7894 chalk 0.29.0 2020-09-28 07:44:27 -04:00
bors[bot]
0fb5d9d87a
Merge #6033
6033: Make name resolution resolve proc macros instead of relying purely on the build system r=matklad a=jonas-schievink

This makes name resolution look at proc-macro declaration attributes like `#[proc_macro_derive]` and defines the right proc macro in the macro namespace, fixing unresolved custom derives like `thiserror::Error` (which can cause false positives, now that we emit diagnostics for unresolved imports).

This works even when proc-macro support is turned off, in which case we fall back to a dummy expander that always returns an error. IMO this is the right way to handle at least the name resolution part of proc. macros, while the *expansion* itself should rely on the build system to build and provide the macro DLL. It does mean that they may go out of sync, but we can provide diagnostics if that happens (something like "could not find macro X in crate Y – ensure that all files of crate Y are saved").

I think it is valuable to be able to reason about proc macros even when we can't expand them, since proc macro expansion can break between Rust releases or users might not want to turn it on for performance reasons. It allows us to provide better diagnostics on any proc macro invocation we're not expanding (like a weak warning that informs the user that proc macro support is turned off, or that it has been disabled because the server crashed).

Fixes https://github.com/rust-analyzer/rust-analyzer/issues/5763

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2020-09-28 11:03:47 +00:00
Jonas Schievink
e88e4fbb7b Add more comments about proc macro resolution 2020-09-28 13:02:28 +02:00
Jonas Schievink
e799dbe5d7 Simplify iterator chain 2020-09-28 12:51:40 +02:00
bors[bot]
000046cfa0
Merge #6085
6085: Mark unresolved imports diagnostic as experimental r=jonas-schievink a=jonas-schievink

It causes a lot of false positives for people. We collected all of the known ones during the last week.

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2020-09-28 10:47:33 +00:00
Jonas Schievink
f0b5832cb8 Mark unresolved imports diagnostic as experimental 2020-09-28 12:45:20 +02:00
Jonas Schievink
1a28f30ba4 Spawn a flycheck instance per workspace 2020-09-27 19:41:54 +02:00
bors[bot]
662ed41ebc
Merge #6073
6073: Dont unnecessarily unnest imports r=matklad a=Veykril

Fixes #6071

This has the side effect that paths that refer to items inside of the current module get prefixed with `self`. Changing this behavior is unfortunately not straightforward should it be unwanted, though I don't see a problem with this as prefixing imports like this with `self` is what I do personally anyways 😅. You can see what I mean with this in one of the tests which had to be changed in `crates/ssr/src/tests.rs`.

There is one test that i still have to look at though, ~~which I by accident pushed with `#[ignore]` on it~~, which is `different_crate_renamed`, for some reason this now doesn't use the crate alias. This also makes me believe that aliases in general will break with this. So maybe this is not as straight forwards as I'd hoped for, but I don't really know how aliases work here.

Edit: The failing test should work now

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-09-25 14:57:15 +00:00
bors[bot]
dc09f1597f
Merge #6076
6076: Update chalk to 0.28.0 r=matklad a=vandenheuvel



Co-authored-by: Bram van den Heuvel <bram@vandenheuvel.online>
2020-09-25 14:47:56 +00:00
Bram van den Heuvel
dff6895ce8 Update chalk to 0.28.0 2020-09-25 15:29:31 +02:00
Lukas Wirth
747f6f64d7 Remove partial import test in insert_use 2020-09-25 15:21:50 +02:00
Lukas Wirth
e1d6981f90 Don't unnecessarily unnest imports for import insertion 2020-09-25 15:19:22 +02:00
bors[bot]
cfe987bcdf
Merge #6055
6055: Add ok postfix completion r=matklad a=mullr

Wrapping values in `Ok(...)` is so pervasive that it seems reasonable for it to
have its own postfix completion.


Co-authored-by: Russell Mull <russell.mull@gmail.com>
2020-09-25 11:55:35 +00:00
bors[bot]
163ffb8803
Merge #6072
6072: Cleanup unintended unresolved reference in syntax higlighting test r=matklad a=Nashenas88

Fixes the issue brought up here https://github.com/rust-analyzer/rust-analyzer/pull/5957#discussion_r486625707

cc @jonas-schievink 

Co-authored-by: Paul Daniel Faria <Nashenas88@users.noreply.github.com>
2020-09-25 11:49:12 +00:00
Jean SIMARD
875ad9b5c4
Bump smol_str from 0.1.16 to 0.1.17 2020-09-24 16:39:08 +02:00
Paul Daniel Faria
ed8968af49 Cleanup unintended unresolved reference in syntax higlighting test 2020-09-24 10:14:25 -04:00
bors[bot]
5d137f21f2
Merge #6056
6056: Add dbgr postfix completion r=matklad a=lnicola

Expanding to `dbg!(&e)`.

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-09-24 14:14:01 +00:00
bors[bot]
9d3483a74d
Merge #5846
5846: Add references to fn args during completion r=matklad a=adamrk

When completing a function call, if there is an argument taken as a ref or mut ref which matches the name and type of a variable in scope, we will insert a `&` or `&mut` when filling in the function arguments. This addresses https://github.com/rust-analyzer/rust-analyzer/issues/5449.

E.g. 
```rust
fn foo(x: &i32) {}
fn main() {
  let x = 5;
  foo # completing foo here generates `foo(&x)` now instead of `foo(x)`
}
```

Co-authored-by: adamrk <ark.email@gmail.com>
2020-09-24 12:23:28 +00:00
kjeremy
95d7e3ce49 lsp-types 0.82 2020-09-23 15:41:55 -04:00
Laurențiu Nicola
eb0e710779 Add dbgr postfix completion 2020-09-22 08:54:57 +03:00
Russell Mull
197d1e1b05 Cargo fmt 2020-09-21 17:47:20 -07:00
Russell Mull
e3b19da8c1 Add ok postfix completion 2020-09-21 17:15:20 -07:00
Aleksey Kladov
fcc3c49013
Apply suggestions from code review
Co-authored-by: Laurențiu Nicola <lnicola@users.noreply.github.com>
2020-09-21 15:35:42 +03:00
Aleksey Kladov
8e3082ff6e Document AstTransformation 2020-09-21 12:36:51 +02:00
Aleksey Kladov
2c916bbc18 Document SemanticScope 2020-09-21 12:30:55 +02:00
bors[bot]
3b52d3181a
Merge #6043
6043: Allow missing trait members assist without needing braces r=matklad a=M-J-Hooper

Assist to complete missing items when implementing a trait does not appear without impl def braces (see #5144 ).

The reason behind this was that this assist is based on `ast::AssocItemList` which only appears in the AST after the braces are added to the impl def.

Instead of relying on and replacing the item list, we now instead replace the entire `ast::Impl` and add the item list if its missing.

Co-authored-by: Matt Hooper <matthewjhooper94@gmail.com>
2020-09-21 09:06:24 +00:00
Matt Hooper
7d90bb1f47 Rename impl edit method to be more explicit 2020-09-21 10:01:50 +01:00
Matt Hooper
532be0e780 Added test for impl member assist when impl def is missing braces 2020-09-21 09:48:51 +01:00
Matt Hooper
9724af038b Replace entire impl def instead of only associated items for missing impl member assist (if braces are missing from an impl def then there is no associated item list in the AST) 2020-09-21 00:42:27 +01:00
Matt Hooper
ae7c982421 Add make utility for empty associated item lists 2020-09-21 00:39:17 +01:00
Matt Hooper
4362297a0b Add edit utility for adding an associated item list to a impl def 2020-09-21 00:38:18 +01:00
bors[bot]
e70cf706bb
Merge #6018
6018: Correct project_root path for ProjectJson. r=jonas-schievink a=woody77

It was already the folder containing the rust-project.json file, not the file itself.  This also removes the Option-ness of it, since it's now an infallible operation to set the member value.

Co-authored-by: Aaron Wood <aaronwood@google.com>
2020-09-20 19:25:09 +00:00
Aaron Wood
38f1ce633d Add rustdoc for ProjectJson methods 2020-09-20 12:06:12 -07:00
bors[bot]
fb1b0a4bff
Merge #6036
6036: Don't re-read open files from disk when reloading a workspace r=kjeremy a=lnicola

Fixes #5742
Fixes #4263

or so I hope.

Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
2020-09-18 21:29:47 +00:00
Laurențiu Nicola
5a0bad7754 Don't re-read open files from disk when reloading a workspace 2020-09-18 22:15:44 +03:00
Jonas Schievink
46c5b557fe Log failure to load crate root file 2020-09-18 19:27:19 +02:00
Jonas Schievink
7474a42b00 Remove incorrect docs 2020-09-18 18:09:47 +02:00
Jonas Schievink
baab72e611 Reduce visibility of non-proc-macros
proc-macro crates only export proc-macros, but currently other items
are also considered public (and show up in completion)
2020-09-18 17:50:04 +02:00
kjeremy
c7243e4a59 Support active parameters at the per-signature level
Update crates
2020-09-18 11:39:25 -04:00
Jonas Schievink
069045015c Remove obsolete proc macro collection code
The new attribute-based resolution takes care of this
2020-09-18 16:52:24 +02:00
Jonas Schievink
5486b70bc0 Use hir_def to resolve proc macros 2020-09-18 16:43:50 +02:00
Jonas Schievink
dfa3a3f017 Add test 2020-09-18 16:37:12 +02:00
Jonas Schievink
9dc0afe854 Rename CustomDerive to ProcMacro
It handles fn-like macros too, and will handle attribute macros in the
future
2020-09-18 15:37:31 +02:00
Jonas Schievink
700a3d5d75 Invert condition to unindent code 2020-09-18 12:32:07 +02:00
Jonas Schievink
d328ee647f Use log::error! in a few more places 2020-09-17 17:37:52 +02:00
Jonas Schievink
6eea06415d Give ExternCrate a Name, not a ModPath 2020-09-17 15:28:23 +02:00
bors[bot]
d84c18d989
Merge #6017
6017: Don't return any TextEdit if formatting is unchanged r=jonas-schievink a=cuviper

I found that `textDocument/formatting` was always returning a full
`TextEdit` replacement, even when there are no changes, which caused Vim
(w/ vim-lsp) to always indicate a modified buffer after formatting. We
can easily compare whether there were changes and return `null` if not,
so the client knows there's nothing to do.

Co-authored-by: Josh Stone <cuviper@gmail.com>
2020-09-17 13:08:09 +00:00
bors[bot]
933fc1eb18
Merge #6016
6016: Emit diagnostics for unresolved imports and extern crates r=jonas-schievink a=jonas-schievink

AFAIK, we don't have any major bugs in name resolution that would cause a lot of false positives here (except procedural attribute macro support and some rare issues around `#[path]` on module files), so these are *not* marked as experimental diagnostics right now.

I noticed that diagnostics in a file sometimes don't get displayed after opening, but require some edit to be performed. This seems like a preexisting issue though.

Co-authored-by: Jonas Schievink <jonas.schievink@ferrous-systems.com>
2020-09-17 13:00:25 +00:00
Jonas Schievink
0dca7acf0f Don't diagnose imports whose base crate is missing 2020-09-17 14:48:17 +02:00
bors[bot]
3877421373
Merge #5989
5989: Rewrite import merging r=jonas-schievink a=Veykril

Rewrites how import merging is being handled. It is now a recursive function to properly handle merging of intermediate levels in the import trees. With this ordering the imports is also now possible tho it doesn't quite order it the same way as `rustfmt` does yet, namely it orders lowercase identifiers after uppercase identifiers as that is the standard character order that rust uses. This also fixes a few weird behaviors that were visible in some of the `replace_qualified_name_with_use.rs` tests.

This really took longer than I was hoping for, fighting with import trees is quite the exhausting task 😅 

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-09-16 20:03:41 +00:00
Lukas Wirth
f2ae412ccf Remove make::path_from_text 2020-09-16 21:36:10 +02:00
Aaron Wood
2fbb09a73f Correct project_root path for ProjectJson.
It was already the folder containing the rust-project.json file, not the file itself.
2020-09-16 12:09:44 -07:00
Lukas Wirth
45298b5d2a Add make::glob_use_tree function to create star-only UseTree 2020-09-16 20:33:08 +02:00
bors[bot]
4bc8015370
Merge #6013
6013: Add support for custom flycheck commands with JSON project workspaces r=jonas-schievink a=woody77

Enable flychecks with JSON project workspaces if an override command was provided as part
of the client configuration:

```
    "rust-analyzer.checkOnSave.enable": true,
    "rust-analyzer.checkOnSave.overrideCommand": ["custom_tool", "arg1", "arg2"],
```


Co-authored-by: Aaron Wood <aaronwood@google.com>
2020-09-16 18:04:29 +00:00
bors[bot]
5df69d9034
Merge #5993
5993: Update chalk to 0.27 and add support for extern opaque types. r=crlf0710 a=crlf0710



Co-authored-by: Charles Lew <crlf0710@gmail.com>
2020-09-16 17:07:05 +00:00
Josh Stone
29c3421391 Don't return any TextEdit if formatting is unchanged
I found that `textDocument/formatting` was always returning a full
`TextEdit` replacement, even when there are no changes, which caused Vim
(w/ vim-lsp) to always indicate a modified buffer after formatting. We
can easily compare whether there were changes and return `null` if not,
so the client knows there's nothing to do.
2020-09-16 10:05:41 -07:00
Charles Lew
3fff5aa4d7 Use Ty::apply instead of simple and fix method resolution. 2020-09-17 00:58:41 +08:00
Charles Lew
eb96964756 Add a test. 2020-09-17 00:21:34 +08:00
Jonas Schievink
f792bc7ddd Add annotation-based nameres diagnostic tests 2020-09-16 17:26:51 +02:00
Jonas Schievink
603613a302 Update tests 2020-09-16 17:26:51 +02:00
Jonas Schievink
4785162b08 Track import sources and emit diagnostics 2020-09-16 17:26:51 +02:00
Jonas Schievink
4ac9a2e5d3 Leave extern crate items unresolved if they are 2020-09-16 17:26:51 +02:00
Jonas Schievink
2a9a66d254 Add diagnostic types for unresolved crates/imports 2020-09-16 17:26:51 +02:00
Charles Lew
389d9a6c2d Lower extern type alias as foreign opaque type. 2020-09-16 20:57:14 +08:00
Jonas Schievink
44f4510caa Store Import indices for later reconstruction 2020-09-16 12:35:09 +02:00
Aaron Wood
74c26a785a Add support for custom flycheck commands with JSON project workspaces
Enable flychecks with JSON project workspaces if an override command was provided as part
of the client configuration.
2020-09-15 18:51:57 -07:00
oxalica
d2fced1c26
Avoid checking all ancestors and fix mis-completion 2020-09-16 01:16:06 +08:00
Benjamin Coenen
e0f0d93eda inline parameters for a function description #6002
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-09-15 18:04:34 +02:00
Benjamin Coenen
2e91159ced inline parameters for a function description #6002
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
2020-09-15 17:15:33 +02:00
Charles Lew
b302f69b7c Update chalk to 0.27 and adapt to chalk changes. 2020-09-15 22:37:05 +08:00
bors[bot]
d134a81037
Merge #5976
5976: Complete trait impl immediately after type/const/fn r=jonas-schievink a=oxalica

Currently, we can complete type/const/fn but only if we typed an identifier.
That is, `impl .. { fn f<|> }` has completions with all trait fn including `f`, but `impl .. { fn <|> }` doesn't provide any suggestion (even if explicit trigger it).

This PR tweak the logic of completion match to make it possible.

However, we still need to explicit trigger suggestions (`Control + Space` by default) in vscode to show. Not sure if we can make it automatically triggered after typing the space after `fn`.

Another question is that I cannot figure out why `BLOCK_EXPR` need to be checked. A block expr directly inside a impl block should be invalid, and nested items will failed to locate impl block in specific offset and skip the suggestion. Now I simply removed it and no tests are broken.
4f91478e50/crates/ide/src/completion/complete_trait_impl.rs (L109)


Co-authored-by: oxalica <oxalicc@pm.me>
2020-09-14 10:22:20 +00:00
bors[bot]
a61178d218
Merge #5985
5985: Make MergeBehaviour configurable r=jonas-schievink a=Veykril

This should make the newly implemented `MergeBehaviour` for import insertion configurable as roughly outlined in https://github.com/rust-analyzer/rust-analyzer/pull/5935#issuecomment-685834257. For the config name and the like I just picked what came to mind so that might be up for bikeshedding.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2020-09-14 10:12:08 +00:00