File tree Expand file tree Collapse file tree 2 files changed +64
-3
lines changed
Expand file tree Collapse file tree 2 files changed +64
-3
lines changed Original file line number Diff line number Diff line change @@ -55,6 +55,12 @@ let fold_over_parsetree (parsetree : Mreader.parsetree) =
5555 Ast_iterator. default_iterator.class_field self class_field
5656 in
5757
58+ let class_type_declaration (self : Ast_iterator.iterator )
59+ (class_type_decl : Parsetree.class_type_declaration ) =
60+ Range. of_loc class_type_decl.pci_loc |> push;
61+ Ast_iterator. default_iterator.class_type_declaration self class_type_decl
62+ in
63+
5864 let value_binding (self : Ast_iterator.iterator )
5965 (value_binding : Parsetree.value_binding ) =
6066 let range = Range. of_loc value_binding.pvb_loc in
@@ -185,21 +191,22 @@ let fold_over_parsetree (parsetree : Mreader.parsetree) =
185191 | Pstr_module _
186192 | Pstr_eval _
187193 | Pstr_recmodule _
194+ | Pstr_extension _
195+ | Pstr_class_type _
188196 | Pstr_open _ ->
189197 Ast_iterator. default_iterator.structure_item self structure_item
190198 | Pstr_primitive _
191199 | Pstr_typext _
192200 | Pstr_exception _
193- | Pstr_class_type _
194201 | Pstr_include _
195- | Pstr_attribute _
196- | Pstr_extension _ -> ()
202+ | Pstr_attribute _ -> ()
197203 in
198204
199205 { Ast_iterator. default_iterator with
200206 case
201207 ; class_declaration
202208 ; class_field
209+ ; class_type_declaration
203210 ; expr
204211 ; extension
205212 ; module_binding
Original file line number Diff line number Diff line change @@ -670,4 +670,58 @@ describe("textDocument/foldingRange", () => {
670670 ]
671671 ` ) ;
672672 } ) ;
673+
674+ it ( "traverses Pstr_extension structure item" , async ( ) => {
675+ await openDocument ( outdent `
676+ let%expect_test "test from jsonrpc_test.ml" =
677+ let a =
678+ let b = 5 in
679+ 6 + 5
680+ in
681+ Stdlib.print_endline (string_of_int 5)
682+ ` ) ;
683+
684+ let result = await foldingRange ( ) ;
685+ expect ( result ) . toMatchInlineSnapshot ( `
686+ Array [
687+ Object {
688+ "endCharacter": 40,
689+ "endLine": 5,
690+ "kind": "region",
691+ "startCharacter": 0,
692+ "startLine": 0,
693+ },
694+ Object {
695+ "endCharacter": 9,
696+ "endLine": 3,
697+ "kind": "region",
698+ "startCharacter": 2,
699+ "startLine": 1,
700+ },
701+ ]
702+ ` ) ;
703+ } ) ;
704+
705+ it ( "returns folding ranges for class_type" , async ( ) => {
706+ await openDocument ( outdent `
707+ class type foo_t =
708+ object
709+ inherit castable
710+ method foo: string
711+ end;;
712+ ` ) ;
713+
714+ let result = await foldingRange ( ) ;
715+ expect ( result ) . toMatchInlineSnapshot ( `
716+ Array [
717+ Object {
718+ "endCharacter": 3,
719+ "endLine": 4,
720+ "kind": "region",
721+ "startCharacter": 0,
722+ "startLine": 0,
723+ },
724+ ]
725+ ` ) ;
726+ } ) ;
673727} ) ;
You can’t perform that action at this time.
0 commit comments