Skip to content

Commit a7a3729

Browse files
committed
Add a new command to extract expression into a fresh let binding.
1 parent 24319eb commit a7a3729

File tree

15 files changed

+1311
-2
lines changed

15 files changed

+1311
-2
lines changed

CHANGES.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ unreleased
1010
- `inlay-hints` fix inlay hints on function parameters (#1923)
1111
- Fix issues with ident validation and Lid comparison for occurrences (#1924)
1212
- Handle class type in outline (#1932)
13-
- Handle object expression inside a let in outline (#1936)
1413
+ ocaml-index
1514
- Improve the granularity of index reading by segmenting the marshalization
1615
of the involved data-structures. (#1889)

doc/dev/PROTOCOL.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,25 @@ The result is returned as a list of:
485485
}
486486
```
487487

488+
### `refactor-extract-region -start <position> -stop <position> -extract-name <name>`
489+
490+
```
491+
-start <position> Where extracted region start
492+
-stop <position> Where extracted region end
493+
-extract-name <name> Name used for the generated let binding
494+
```
495+
496+
Returns the string `Nothing to do` (if extractor is not ables to select an expression to extract in the given position interval) or the following object:
497+
498+
```javascript
499+
{
500+
'start': position, // the start of the region to be substituted
501+
'end': position, // the end of the region to be substituted
502+
'content' string, // the content of the substitution
503+
'selection_range': location // the location where to position the cursor for easy renaming of the generated let binding
504+
}
505+
```
506+
488507
### `syntax-document -position <position>`
489508

490509
-position <position> The position of the keyword to be documented

src/analysis/parsetree_utils.ml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1+
open Std
2+
13
open Parsetree
24

35
type nonrec constant_desc = constant_desc
46

57
let constant_desc c = c.pconst_desc
8+
9+
let filter_attr =
10+
let default = Ast_mapper.default_mapper in
11+
let keep attr =
12+
let { Location.txt; _ }, _ = Ast_helper.Attr.as_tuple attr in
13+
not (Std.String.is_prefixed ~by:"merlin." txt)
14+
in
15+
let attributes mapper attrs =
16+
default.Ast_mapper.attributes mapper (List.filter ~f:keep attrs)
17+
in
18+
{ default with Ast_mapper.attributes }
19+
20+
let filter_expr_attr expr = filter_attr.Ast_mapper.expr filter_attr expr

src/analysis/parsetree_utils.mli

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ open Parsetree
66
type nonrec constant_desc = constant_desc
77

88
val constant_desc : constant -> constant_desc
9+
10+
val filter_expr_attr : expression -> expression

0 commit comments

Comments
 (0)