rust/crates
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
..
base_db Fixed remaining references to AnalysisChange (now: Change) 2021-02-28 12:57:41 +01:00
cfg Upgrade expect-test to 1.1 2021-01-03 14:43:29 +01:00
flycheck Bump cargo_metadata 2021-03-02 14:27:29 +02:00
hir Use chalk_ir::Mutability 2021-03-01 19:57:36 +01:00
hir_def Fix find_path when inner items are present 2021-03-01 19:39:17 +01:00
hir_expand Fix assert split exprs on comma 2021-02-28 20:46:24 +08:00
hir_ty Merge #7829 #7833 2021-03-01 19:31:01 +00:00
ide Merge #7335 #7691 2021-03-02 13:32:06 +00:00
ide_assists strip useless methods, and unary ops in suggest_name 2021-03-02 16:25:24 +03:00
ide_completion Format generated features manually instead of relying on rustfmt 2021-02-27 16:25:06 +02:00
ide_db Fixed remaining references to AnalysisChange (now: Change) 2021-02-28 12:57:41 +01:00
ide_ssr 7526: Renamed create ssr to ide_ssr. 2021-02-23 00:59:16 +05:30
mbe Merge #7513 2021-03-02 13:20:47 +00:00
parser rustfmt 1.4.30-stable 2021-02-18 16:51:21 +01:00
paths Document paths items 2021-01-22 15:38:33 +01:00
proc_macro_api Remove redundant clones 2021-02-05 16:57:26 +01:00
proc_macro_srv Merge #7848 2021-03-02 12:31:15 +00:00
proc_macro_test Add description for crates that will be published 2020-08-24 13:07:22 +02:00
profile add more counts 2021-01-27 12:39:19 +03:00
project_model Bump cargo_metadata 2021-03-02 14:27:29 +02:00
rust-analyzer Merge #7335 #7691 2021-03-02 13:32:06 +00:00
stdx Cleanup decl_check 2021-02-05 16:09:45 +01:00
syntax Merge #7777 2021-03-02 08:04:38 +00:00
test_utils Add benchmark test for mbe 2021-02-25 05:47:13 +08:00
text_edit Avoid turning completion objects into builders 2020-11-16 23:16:41 +02:00
toolchain Add description for crates that will be published 2020-08-24 13:07:22 +02:00
tt Refactor TokenBuffer for reduc cloning 2021-01-05 02:00:46 +08:00
vfs Fix slow tests sometimes failing 2021-02-12 16:31:16 +01:00
vfs-notify Fix slow tests sometimes failing 2021-02-12 16:31:16 +01:00