rust/crates/rust-analyzer/src
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
..
bin Switch from pico-args to xflags 2021-03-02 15:08:20 +03:00
cli Switch from pico-args to xflags 2021-03-02 15:08:20 +03:00
diagnostics Bump cargo_metadata 2021-03-02 14:27:29 +02:00
caps.rs Start LSP 3.17 support 2021-02-14 14:51:29 -05:00
cargo_target_spec.rs More maintainable config 2021-01-06 15:39:28 +03:00
cli.rs Split pub fn cargo_load into pub fn load_workspace_at and pub fn load_workspace 2021-02-16 16:37:52 +01:00
config.rs Merge #7657 2021-02-16 16:34:22 +00:00
diagnostics.rs Avoid transmitting unchanged diagnostics 2021-02-17 12:45:17 +01:00
diff.rs Split textDocument/formatting TextEdit with diff 2020-12-31 15:33:20 +01:00
dispatch.rs
document.rs
from_proto.rs Fix bitrotted module name 2021-02-16 19:17:32 +03:00
global_state.rs Fix bitrotted module name 2021-02-16 19:17:32 +03:00
handlers.rs Fix bitrotted module name 2021-02-16 19:17:32 +03:00
lib.rs Fix bitrotted module name 2021-02-16 19:17:32 +03:00
line_index.rs Fix bitrotted module name 2021-02-16 19:17:32 +03:00
lsp_ext.rs Enable offset-encoding capability 2021-02-16 19:17:32 +03:00
lsp_utils.rs Fix bitrotted module name 2021-02-16 19:17:32 +03:00
main_loop.rs Fix slow tests sometimes failing 2021-02-12 16:31:16 +01:00
markdown.rs Fixed typos in tests 2021-01-09 15:41:29 +01:00
op_queue.rs Async Loading outdir and proc-macro 2021-01-29 01:04:14 +08:00
reload.rs Fix slow tests sometimes failing 2021-02-12 16:31:16 +01:00
request_metrics.rs
semantic_tokens.rs Add a semantic token type for char literals 2021-02-05 23:46:39 +00:00
thread_pool.rs
to_proto.rs Merge #7335 #7691 2021-03-02 13:32:06 +00:00