Skip to content

Commit 73879ae

Browse files
committed
Other cases of module declarations and expressions.
1 parent 40a1511 commit 73879ae

File tree

3 files changed

+105
-9
lines changed

3 files changed

+105
-9
lines changed

analysis/src/SemanticTokens.ml

Lines changed: 66 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ let emitFromLoc ~loc ~type_ emitter =
7878
let posStart, posEnd = locToPositions loc in
7979
emitter |> emitFromPos posStart posEnd ~type_
8080

81-
let emitLongident ~backwards ~pos ~jsx ~lid ~debug emitter =
81+
let emitLongident ?(backwards = false) ?(jsx = false) ~pos ~lid ~debug emitter =
8282
let rec flatten acc lid =
8383
match lid with
8484
| Longident.Lident txt -> txt :: acc
@@ -115,13 +115,13 @@ let emitLongident ~backwards ~pos ~jsx ~lid ~debug emitter =
115115

116116
let emitVariable ~id ~debug ~loc emitter =
117117
emitter
118-
|> emitLongident ~backwards:false
118+
|> emitLongident
119119
~pos:(Utils.tupleOfLexing loc.Location.loc_start)
120-
~jsx:false ~lid:(Longident.Lident id) ~debug
120+
~lid:(Longident.Lident id) ~debug
121121

122122
let emitJsxOpen ~lid ~debug ~loc emitter =
123123
emitter
124-
|> emitLongident ~backwards:false
124+
|> emitLongident
125125
~pos:(Utils.tupleOfLexing loc.Location.loc_start)
126126
~lid ~jsx:true ~debug
127127

@@ -163,9 +163,7 @@ let parser ~debug ~emitter ~path =
163163
match e.pexp_desc with
164164
| Pexp_ident {txt = lid; loc} ->
165165
emitter
166-
|> emitLongident ~backwards:false
167-
~pos:(Utils.tupleOfLexing loc.loc_start)
168-
~lid ~jsx:false ~debug;
166+
|> emitLongident ~pos:(Utils.tupleOfLexing loc.loc_start) ~lid ~debug;
169167
Ast_mapper.default_mapper.expr mapper e
170168
| Pexp_apply ({pexp_desc = Pexp_ident lident; pexp_loc}, args)
171169
when Res_parsetree_viewer.isJsxExpression e ->
@@ -206,9 +204,69 @@ let parser ~debug ~emitter ~path =
206204
Ast_mapper.default_mapper.expr mapper e
207205
| _ -> Ast_mapper.default_mapper.expr mapper e
208206
in
207+
let module_expr (mapper : Ast_mapper.mapper) (me : Parsetree.module_expr) =
208+
match me.pmod_desc with
209+
| Pmod_ident {txt = lid; loc} ->
210+
emitter
211+
|> emitLongident ~pos:(Utils.tupleOfLexing loc.loc_start) ~lid ~debug;
212+
Ast_mapper.default_mapper.module_expr mapper me
213+
| _ -> Ast_mapper.default_mapper.module_expr mapper me
214+
in
215+
let module_binding (mapper : Ast_mapper.mapper)
216+
(mb : Parsetree.module_binding) =
217+
emitter
218+
|> emitLongident
219+
~pos:(Utils.tupleOfLexing mb.pmb_name.loc.loc_start)
220+
~lid:(Longident.Lident mb.pmb_name.txt) ~debug;
221+
Ast_mapper.default_mapper.module_binding mapper mb
222+
in
223+
let module_declaration (mapper : Ast_mapper.mapper)
224+
(md : Parsetree.module_declaration) =
225+
emitter
226+
|> emitLongident
227+
~pos:(Utils.tupleOfLexing md.pmd_name.loc.loc_start)
228+
~lid:(Longident.Lident md.pmd_name.txt) ~debug;
229+
Ast_mapper.default_mapper.module_declaration mapper md
230+
in
231+
let module_type (mapper : Ast_mapper.mapper) (mt : Parsetree.module_type) =
232+
match mt.pmty_desc with
233+
| Pmty_ident {txt = lid; loc} ->
234+
emitter
235+
|> emitLongident ~pos:(Utils.tupleOfLexing loc.loc_start) ~lid ~debug;
236+
Ast_mapper.default_mapper.module_type mapper mt
237+
| _ -> Ast_mapper.default_mapper.module_type mapper mt
238+
in
239+
let module_type_declaration (mapper : Ast_mapper.mapper)
240+
(mtd : Parsetree.module_type_declaration) =
241+
emitter
242+
|> emitLongident
243+
~pos:(Utils.tupleOfLexing mtd.pmtd_name.loc.loc_start)
244+
~lid:(Longident.Lident mtd.pmtd_name.txt) ~debug;
245+
Ast_mapper.default_mapper.module_type_declaration mapper mtd
246+
in
247+
let open_description (mapper : Ast_mapper.mapper)
248+
(od : Parsetree.open_description) =
249+
emitter
250+
|> emitLongident
251+
~pos:(Utils.tupleOfLexing od.popen_lid.loc.loc_start)
252+
~lid:od.popen_lid.txt ~debug;
253+
Ast_mapper.default_mapper.open_description mapper od
254+
in
209255

210256
let mapper =
211-
{Ast_mapper.default_mapper with expr; pat; typ; type_declaration}
257+
{
258+
Ast_mapper.default_mapper with
259+
expr;
260+
module_declaration;
261+
module_binding;
262+
module_expr;
263+
module_type;
264+
module_type_declaration;
265+
open_description;
266+
pat;
267+
typ;
268+
type_declaration;
269+
}
212270
in
213271

214272
if Filename.check_suffix path ".res" then (

analysis/tests/src/Parser.res

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,26 @@ type pairIntString = list<
3131

3232
let _ = 3 < 4 || 3 > 4
3333

34+
module type MT = {
35+
module DDF: {
36+
37+
}
38+
}
39+
40+
module DDF: MT = {
41+
module DDF = {
42+
43+
}
44+
}
45+
46+
module XX = {
47+
module YY = {
48+
type t = int
49+
}
50+
}
51+
52+
open XX.YY
53+
54+
type tt = t
55+
3456
// ^par

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
Parse tests/src/Parser.res
2-
structure items:10 diagnostics:0
2+
structure items:15 diagnostics:0
3+
Lident: M (0,7)
4+
Lident: C (1,9)
5+
Lident: Component (1,13)
36
Lident: Component (4,10)
47
Lident: _c (4,4)
58
Ldot: M (6,11)
@@ -36,4 +39,17 @@ Type: looooooooooooooooooooooooooooooooooooooong_string (27,4)->(27,53)
3639
BinaryExp: (31,14)->(31,16)
3740
BinaryExp: (31,10)->(31,11)
3841
BinaryExp: (31,19)->(31,20)
42+
Lident: MT (33,12)
43+
Lident: DDF (34,9)
44+
Lident: DDF (39,7)
45+
Lident: MT (39,12)
46+
Lident: DDF (40,9)
47+
Lident: XX (45,7)
48+
Lident: YY (46,9)
49+
Type: t (47,9)->(47,10)
50+
Type: int (47,13)->(47,16)
51+
Ldot: XX (51,5)
52+
Lident: YY (51,8)
53+
Type: tt (53,5)->(53,7)
54+
Type: t (53,10)->(53,11)
3955

0 commit comments

Comments
 (0)