Commit Graph

607 Commits

Author SHA1 Message Date
Lukas Wirth
814d617d34 Show whether a binding is mutable or not on hover 2021-03-09 17:18:50 +01:00
Lukas Wirth
983726a45c Don't show const items initializer expressions on hover 2021-03-09 16:33:23 +01:00
Kirill Bulatov
33c83e72b9 Work towards better import labels 2021-03-08 23:59:20 +02:00
Laurențiu Nicola
fc9eed4836 Use upstream cov-mark 2021-03-08 22:19:44 +02:00
Laurențiu Nicola
42057896bc Fix some warnings 2021-03-05 15:59:50 +02:00
Lukas Wirth
e194f2edc4 Prevent renaming SelfType and BuiltinType 2021-03-03 19:48:53 +01:00
Lukas Wirth
183ba483a9 Reorder functions in rename.rs 2021-03-03 19:48:35 +01:00
bors[bot]
f8152171bb
Merge #7850
7850: Don't add space when joining line to opening quote r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-03-02 14:19:45 +00:00
Aleksey Kladov
e2fc9411f1 Don't add space when joining line to opening quote 2021-03-02 17:18:45 +03:00
bors[bot]
6a585c6ee2
Merge #7795
7795: Show docs on hover for keywords and primitives r=matklad a=Veykril

![lAWFadkziX](https://user-images.githubusercontent.com/3757771/109369534-eeb4f500-789c-11eb-8f2b-2f9c4e129de3.gif)

It's a bit annoying that this requires the `SyntaxNode` and `Semantics` to be pulled through `hover_for_definition` just so we can get the `std` crate but I couldn't think of a better way.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-02 13:46:50 +00:00
Lukas Wirth
8d305680e6 Show docs on hover for keywords and primitives 2021-03-02 14:41:01 +01:00
bors[bot]
657ec3616f
Merge #7335 #7691
7335: added region folding r=matklad a=LucianoBestia

Regions of code that you'd like to be folded can be wrapped with  `// #region` and `// #endregion` line comments.
This is called "Region Folding". It is originally available for many languages in VSCode. But Rust-analyzer has its own folding function and this is missing.
With this Pull Request I am suggesting a simple solution. 
The regions are a special kind of comments, so I added a bit of code in the comment folding function.
The regex to match are: `^\s*//\s*#?region\b` and `^\s*//\s*#?endregion\b`.
The number of space characters is not important. There is an optional # character. The line can end with a name of the region.
Example:
```rust
// 1. some normal comment
// region: test
// 2. some normal comment
calling_function(x,y);
// endregion: test
```
I added a test for this new functionality in `folding_ranges.rs`.
Please, take a look and comment. 
I found that these exact regexes are already present in the file `language-configuration.json`, but I don't find a way to read this configuration. So my regex is hardcoded in the code.

7691: Suggest name in extract variable r=matklad a=cpud36

Generate better default name in extract variable assist as was mentioned in issue #1587

# Currently supported
(in order of declining precedence)
1. Expr is argument to a function; use corresponding parameter name
2. Expr is result of a function or method call; use this function/method's name
3. Use expr type name (if possible)
4. Fallback to `var_name` otherwise

# Showcase

![generate_derive_variable_name_from_method](https://user-images.githubusercontent.com/4218373/108013304-72105400-701c-11eb-9f13-eec52e74d0cc.gif)
![generate_derive_variable_name_from_param](https://user-images.githubusercontent.com/4218373/108013305-72a8ea80-701c-11eb-957e-2214f7f005de.gif)

# Questions

* Should we more aggressively strip known types? E.g. we already strip `&T -> T`; should we strip `Option<T> -> T`, `Result<T, E> -> T`, and others?
* Integers and floats use `var_name` by default. Should we introduce a name, like `i`, `f` etc?
* Can we return a list and suggest a name when renaming(like IntelliJ does)?
* Should we add counters to remove duplicate variables? E.g. `type`, `type1`, type2`, etc.


Co-authored-by: Luciano Bestia <LucianoBestia@gmail.com>
Co-authored-by: Luciano <31509965+LucianoBestia@users.noreply.github.com>
Co-authored-by: Vladyslav Katasonov <cpud47@gmail.com>
2021-03-02 13:32:06 +00:00
bors[bot]
f3139d46b0
Merge #7778
7778: Fix lowering trailing self paths in UseTrees r=Veykril a=Veykril

Noticed that hovering over `self` in a use tree like `use foo::bar::{self}` showing documentation and such for the current module instead of `bar`.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-03-01 14:50:58 +00:00
Lukas Wirth
91ff47ef6a Update vscode README with a small features list 2021-03-01 11:08:26 +01:00
Lukas Wirth
ca7cd41a48 Fix lowering trailing self paths in UseTrees 2021-02-28 23:44:49 +01:00
Aleksey Kladov
05729fd3c4 For unresolved macros, hightlight only the last segment 2021-02-28 14:29:10 +03:00
vsrs
f234b80520 Remove erroneous comment 2021-02-27 21:59:53 +03:00
vsrs
5d23d8bc29 Add runnables::related_tests 2021-02-27 18:00:17 +03:00
Lukas Wirth
9e8f4d31a4 Pickup ConstReference patterns in FindUsages 2021-02-23 23:31:53 +01:00
Chetan Khilosiya
eb6cfa7f15 7526: Renamed create ssr to ide_ssr. 2021-02-23 00:59:16 +05:30
Chetan Khilosiya
e4756cb4f6 7526: Rename crate assists to ide_assists. 2021-02-23 00:59:16 +05:30
bors[bot]
62bc753f8b
Merge #7732
7732: Don't lower TypeBound::Lifetime as GenericPredicate::Error r=flodiebold a=Veykril

Basically we just discard the typebound for now instead when lowering to `GenericPredicate`. I think this shouldn't have any other side effects?

Fixes #7683(hopefully for real this time)

I also played around with introducing `GenericPredicate::LifetimeOutlives` and `GenericPredicate::TypeOutlives`(see b9d6904845) but that won't fix this issue(at least not for now) due to lifetime predicate mismatches when resolving methods so I figure this is a good way to fix it for now.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-20 20:17:14 +00:00
Lukas Wirth
9e5192d917 Don't lower TypeBound::Lifetime as GenericPredicate::Error 2021-02-20 19:08:20 +01:00
Laurențiu Nicola
4c589aded0 Remove documentation of obsolete extend selection command 2021-02-20 17:18:53 +02:00
Aleksey Kladov
3db64a400c rename completion -> ide_completion
We don't have completion-related PRs in flight, so lets do it
2021-02-17 17:53:31 +03:00
bors[bot]
4054525c41
Merge #7699
7699: Implement ast::AstNode for NameLike and move it to node_ext r=matklad a=Veykril

With this `search`(and 2 other modules) don't necessarily go through 3 calls of `find_node_at_offset_with_descend` to find the correct node. Also makes the code that searches for NameLikes a bit easier on the eyes imo, though that can be fixed with just a helper function as well so its not that relevant.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-17 13:45:27 +00:00
bors[bot]
056601b41f
Merge #7705
7705: Show hover info of the definition of ConstReference patterns instead of its type r=Veykril a=Veykril

Closes #7671
bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-17 13:17:15 +00:00
Lukas Wirth
51dda8ea8e Show hover info of the definition of ConstReference patterns instead of its type 2021-02-17 14:14:58 +01:00
Paco Soberón
e0eb80eaee Allow comments between newlines in chaining hints 2021-02-17 00:09:56 +01:00
Lukas Wirth
e52bdc55ef Implement ast::AstNode for NameLike and move it to node_ext 2021-02-16 19:27:08 +01:00
bors[bot]
c9672a0539
Merge #7657
7657: utf8 r=matklad a=matklad

- Prepare for utf-8 offsets
- reduce code duplication in tests
- Make utf8 default, implement utf16 in terms of it
- Make it easy to add additional context for offset conversion
- Implement utf8 offsets

closes #7453

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
2021-02-16 16:34:22 +00:00
Aleksey Kladov
95209aa3f8 Make utf8 default, implement utf16 in terms of it 2021-02-16 19:17:32 +03:00
Aleksey Kladov
2cb4ac9eb4 Prepare for utf-8 offsets 2021-02-16 19:17:32 +03:00
kjeremy
f9bb398cc5 Fix a few clippy::perf warnings 2021-02-16 10:55:34 -05:00
ivan770
66de90b85a
Actually fix runnable order 2021-02-15 16:09:50 +02:00
bors[bot]
a0322defc3
Merge #7656
7656: Implement constructor usage search for almost all items r=matklad a=Veykril

This PR moves the filering for enum constructors to the HIR, with this unprefixed variants as well as when the enum has been renamed via use will then still show up properly.
We now walk the ast of the `NameRef` up until we find a `PathExpr`(which also handles `CallExpr` for tuple-type structs and variants already) or a `RecordExpr`. For enum search we then take the `path` out of that expression and do a resolution on it to compare it with the definition enum.
With this PR we now support searching for all constructor literals, Unit-, Tuple- and Record-Structs, Unit-, Tuple- and Record-Variants as well as Unions.

There is one shortcoming due to how the search is triggered. Unit Variants constructors can't be searched as we have no position for it to kick off the search(since a comma doesn't have to exist for the last variant).

Closes #2549 though it doesn't implement it as outlined in the issue since the reference kind was removed recently, though I believe the approach taken here is better personally.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-14 16:17:03 +00:00
bors[bot]
63c5c92856
Merge #7668
7668: Finalize rename infra rewrite r=matklad a=Veykril

This should be the final PR in regards to rewriting rename stuff, #4290.

It addresses 3 things:
	- Currently renaming import aliases causes some undesired behavior(see #5198) which is why this PR causes us to just return an error if an attempt at renaming an alias is made for the time being. Though this only prevents it from happening when the alias import is renamed, so its not too helpful.
	- Fixes #6898
	- If we are inside a macro file simply rename the input name node as there isn't really a way to do any of the fancy shorthand renames and similar things as for that we would have to exactly know what the macro generates and what not.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-14 15:29:00 +00:00
Lukas Wirth
7b64622780 Don't rename field record patterns directly 2021-02-13 23:47:21 +01:00
Lukas Wirth
403a63d2b4 Don't classify attribute macros as their path unless it's a function with the proc_macro_attribute attribute 2021-02-13 22:11:31 +01:00
Lukas Wirth
9b04506924 Fallback to renaming input NameRef node for macros when inside macro 2021-02-13 21:41:04 +01:00
Lukas Wirth
1901172841 Prevent aliases from being renamed for now 2021-02-13 20:49:04 +01:00
ivan770
4c2b201b7d
Make annotations tests similar to those in runnables 2021-02-13 19:18:13 +02:00
Lukas Wirth
8ac6041bcf Only use HIR when searching for enum constructors, otherwise fall back to AST 2021-02-13 17:57:14 +01:00
Luciano Bestia
790bda1f85 corrected no newline at end of file 2021-02-13 17:57:05 +01:00
Luciano Bestia
a28f9545e1 removed logging stuff 2021-02-13 17:50:52 +01:00
Luciano
75015b6eaa
Update crates/ide/src/folding_ranges.rs
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-02-13 17:46:26 +01:00
ivan770
ee049b256a
Improve runnable annotations order, fix incorrect ignore detection 2021-02-13 15:47:53 +02:00
ivan770
c46b32c449
Added annotation tests 2021-02-13 15:27:04 +02:00
ivan770
02ad828c6d
Fix incorrect references annotation 2021-02-13 13:22:12 +02:00
ivan770
185da286d2
Moved CodeLens to ide crate 2021-02-13 13:07:47 +02:00
Lukas Wirth
c395dd1032 Implement constructor usage search for almost all items
For all struct kinds, unions and enums, as well as for record- and
tuple-variants but not for unit-variants, as these have no trailing
character we can anchor the search to. Functionality wise it is
implemented though.
2021-02-12 21:30:55 +01:00
Lukas Wirth
fd6cf4d566 Update references test output 2021-02-12 19:00:37 +01:00
Lukas Wirth
c5be0b2589 Use NameLike in FileReference directly as its not exported from ide anymore 2021-02-12 18:58:29 +01:00
Lukas Wirth
d644728d82 Refactor reference searching to work with the ast 2021-02-12 18:58:28 +01:00
Lukas Wirth
43ccbf4360 Remove unused ReferenceSearchResult functions 2021-02-12 18:58:28 +01:00
bors[bot]
dee5aba43a
Merge #7644
7644: Primitive completion r=jonas-schievink a=jonas-schievink

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

Co-authored-by: Jonas Schievink <jonasschievink@gmail.com>
2021-02-12 13:18:30 +00:00
Jonas Schievink
70f388cedb Pin Rust to 1.49.0 on CI 2021-02-12 13:05:56 +01:00
Jonas Schievink
216dc856c5 Wrap BuiltinType in code model 2021-02-11 19:52:33 +01:00
Jonas Schievink
244d8e37f1 Update fixed tests 2021-02-10 14:48:52 +01:00
Lukas Wirth
a195711df0 Resolve TupleStructPat in SourceAnalyzer::resolve_path 2021-02-10 09:37:22 +01:00
Aleksey Kladov
61f15b72ac Add parsing benchmark 2021-02-09 21:52:34 +03:00
Aleksey Kladov
4b1279d0b1 Infra for "unit" benchmarking 2021-02-09 20:25:39 +03:00
Aleksey Kladov
9ea2c96ddd restore accidentally deleted test 2021-02-09 18:29:15 +03:00
Aleksey Kladov
ef8f38efc6 More precise navigation to parent 2021-02-09 18:21:09 +03:00
Aleksey Kladov
2ac20b05f1 Cleanup tests 2021-02-09 18:13:11 +03:00
Aleksey Kladov
2dc67c85b9 Cleanup test 2021-02-09 17:48:25 +03:00
Aleksey Kladov
5ddfde3038 Modernize tests 2021-02-09 17:23:35 +03:00
Aleksey Kladov
7022ea52b5 AdtDef -> Adt 2021-02-07 14:15:02 +03:00
Luciano Bestia
084b21bc36 simple comparison instead of regex 2021-02-05 14:32:03 +01:00
Lukas Wirth
34d5d77cfa Increase Highlights highlight range to covering element 2021-02-04 11:37:14 +01:00
lumenian
cafaab8b96 Show alias underlying type 2021-02-02 17:47:56 +03:00
Lukas Wirth
999e020da2 Return inner attributes of outline mod declarations in attrs_query 2021-01-31 19:53:01 +01:00
Lukas Wirth
426ad8e165 Classify function calls as functions when shadowed by types 2021-01-28 19:08:55 +01:00
bors[bot]
c76cab6247
Merge #7465
7465: Only hide parameter hints for path, field and methodcall expressions r=SomeoneToIgnore a=Veykril

Doing this check for other expressions makes little sense to me.

Fixes #7458

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-01-27 14:40:57 +00:00
Lukas Wirth
0aaa61cd56 Only hide parameter hints for path, field and methodcall expressions 2021-01-27 15:03:43 +01:00
Aleksey Kladov
d35bda6429 Make always-assert crate reusable 2021-01-26 22:13:42 +03:00
Lukas Wirth
d912444cac Shorten hir::TypeParam full_range in NavigationTarget 2021-01-26 01:01:00 +01:00
Lukas Wirth
a872ebf81f Support unions in symbol search 2021-01-24 01:32:52 +01:00
Phil Ellison
db6dda94a3 Remove use of SourceFileEdit 2021-01-23 07:54:45 +00:00
Phil Ellison
920e57bd15 cargo fmt 2021-01-23 07:40:25 +00:00
Phil Ellison
e62e4ed148 Address review comments 2021-01-23 07:40:25 +00:00
Phil Ellison
449ced4d21 cargo fmt 2021-01-23 07:40:25 +00:00
Phil Ellison
1ff860b93c Implement fix, add tests 2021-01-23 07:40:25 +00:00
Phil Ellison
1316422a7c Add diagnostic for filter_map followed by next 2021-01-23 07:40:24 +00:00
bors[bot]
0c37b3a0fc
Merge #7353
7353: Add LifetimeParam and ConstParam to CompletionItemKind r=matklad a=Veykril

Adds `LifetimeParam` and `ConstParam` to `CompletionItemKind` and maps them both to `TypeParam` in the protocol conversion as there are no equivalents, so nothing really changes there.
`ConstParam` could be mapped to `Const` I guess but I'm split on whether that would be better?

Additions were solely inspired by (the single) test output for const params.

Also sorts the variants of `CompletionItemKind` and its to_proto match.



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-01-22 15:31:47 +00:00
bors[bot]
1b96c79ab5
Merge #7348
7348: Fix broken link in intra-doc r=edwin0cheng a=sasurau4

Fix #5546 
The intra-doc link doesn't work fine for trait associated method.

Co-authored-by: Daiki Ihara <sasurau4@gmail.com>
2021-01-22 12:29:42 +00:00
Aleksey Kladov
f67a2eedf5 Cleanup tests 2021-01-22 15:13:18 +03:00
Aleksey Kladov
2c786f1b98 Remove index based fallback for goto def
We are so precise that the fallback creates more confusion, when you can
goto def on an unresolved reference.
2021-01-22 15:11:29 +03:00
Daiki Ihara
f5b97e52c9 Fix broken link in intra-doc 2021-01-22 20:06:45 +09:00
Aleksey Kladov
e5c5c0a040 Include countme crate to count important data structures. 2021-01-21 19:30:52 +03:00
Jonas Schievink
82146737ac Treat BlockExpr as a potential module origin 2021-01-20 20:05:48 +01:00
Lukas Wirth
563a175fdb Move SymbolKind to ide_db 2021-01-20 15:25:34 +01:00
Aleksey Kladov
74f8201586 Avoid intermediate collections 2021-01-20 14:49:29 +03:00
Aleksey Kladov
724059569b Don't show runnable suggestions for other files
It't be actually great to have these once we have run anything dialog,
but for run the thing at point it makes sense to show a limited set.
2021-01-20 14:30:50 +03:00
Aleksey Kladov
46b4f89c92 . 2021-01-20 01:56:11 +03:00
bors[bot]
8935106b39
Merge #7321
7321: Support runnables in macros r=matklad a=edwin0cheng

fixes  #4771

Co-authored-by: Edwin Cheng <edwin0cheng@gmail.com>
2021-01-19 09:27:45 +00:00
Edwin Cheng
8b03b58ad7 Support runnables in macros 2021-01-19 16:58:11 +08:00
Lukas Wirth
e31420fbe2 Remove obsolete RangeInfo usage in references 2021-01-18 21:10:01 +01:00
bors[bot]
342bf41022
Merge #7297 #7338
7297: Propose trait associated items and autoimport traits on completion r=matklad a=SomeoneToIgnore

![trait_imports](https://user-images.githubusercontent.com/2690773/104819998-6faeb480-583a-11eb-8b45-b7351b51b90e.gif)

Closes #7248

7338: Parse `impl const Trait` r=Veykril a=Veykril

Closes #7313

bors r+

Co-authored-by: Kirill Bulatov <mail4score@gmail.com>
Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
2021-01-18 19:40:11 +00:00
Lukas Wirth
21a6384ce6 Remove obsolete RangeInfo usage in rename 2021-01-18 20:28:20 +01:00