Skip to content

Commit 413672c

Browse files
committed
Handle local modules in expressions.
1 parent c8f9504 commit 413672c

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

analysis/src/DocumentSymbol.ml

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,6 @@ let command ~path =
3434
| Pexp_constant _ -> Constant
3535
| _ -> Variable
3636
in
37-
let value_binding (iterator : Ast_iterator.iterator)
38-
(vb : Parsetree.value_binding) =
39-
(match vb.pvb_pat.ppat_desc with
40-
| Ppat_var {txt} | Ppat_constraint ({ppat_desc = Ppat_var {txt}}, _) ->
41-
symbols := (txt, vb.pvb_loc, exprKind vb.pvb_expr) :: !symbols
42-
| _ -> ());
43-
Ast_iterator.default_iterator.value_binding iterator vb
44-
in
4537
let processTypeKind (tk : Parsetree.type_kind) =
4638
match tk with
4739
| Ptype_variant constrDecls ->
@@ -67,6 +59,23 @@ let command ~path =
6759
let processModuleDeclaration (md : Parsetree.module_declaration) =
6860
symbols := (md.pmd_name.txt, md.pmd_loc, Module) :: !symbols
6961
in
62+
let value_binding (iterator : Ast_iterator.iterator)
63+
(vb : Parsetree.value_binding) =
64+
(match vb.pvb_pat.ppat_desc with
65+
| Ppat_var {txt} | Ppat_constraint ({ppat_desc = Ppat_var {txt}}, _) ->
66+
symbols := (txt, vb.pvb_loc, exprKind vb.pvb_expr) :: !symbols
67+
| _ -> ());
68+
Ast_iterator.default_iterator.value_binding iterator vb
69+
in
70+
let expr (iterator : Ast_iterator.iterator) (e : Parsetree.expression) =
71+
(match e.pexp_desc with
72+
| Pexp_letmodule ({txt}, modExpr, _) ->
73+
symbols :=
74+
(txt, {e.pexp_loc with loc_end = modExpr.pmod_loc.loc_end}, Module)
75+
:: !symbols
76+
| _ -> ());
77+
Ast_iterator.default_iterator.expr iterator e
78+
in
7079
let structure_item (iterator : Ast_iterator.iterator)
7180
(item : Parsetree.structure_item) =
7281
(match item.pstr_desc with
@@ -99,9 +108,10 @@ let command ~path =
99108
let iterator =
100109
{
101110
Ast_iterator.default_iterator with
102-
structure_item;
103-
signature_item;
111+
expr;
104112
module_expr;
113+
signature_item;
114+
structure_item;
105115
value_binding;
106116
}
107117
in

analysis/tests/src/Completion.res

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,5 @@ let foo = {
117117
type z = int
118118
let v = 44
119119
}
120-
add(x, y)
120+
add((x: Inner.z), Inner.v + y)
121121
}

analysis/tests/src/expected/Completion.res.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -615,6 +615,11 @@ DocumentSymbol tests/src/Completion.res
615615
"kind": 13,
616616
"location": {"uri": "Completion.res", "range": {"start": {"line": 113, "character": 2}, "end": {"line": 113, "character": 22}}}
617617
},
618+
{
619+
"name": "Inner",
620+
"kind": 2,
621+
"location": {"uri": "Completion.res", "range": {"start": {"line": 115, "character": 2}, "end": {"line": 118, "character": 3}}}
622+
},
618623
{
619624
"name": "z",
620625
"kind": 26,

0 commit comments

Comments
 (0)