Skip to content

Commit 8658618

Browse files
committed
Add token type to debug print.
1 parent ede6f86 commit 8658618

File tree

2 files changed

+48
-42
lines changed

2 files changed

+48
-42
lines changed

analysis/src/SemanticTokens.ml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ module Token = struct
1212
| Type -> "2"
1313
| Module -> "3"
1414

15+
let tokenTypeDebug = function
16+
| Keyword -> "Keyword"
17+
| Variable -> "Variable"
18+
| Type -> "Type"
19+
| Module -> "Module"
20+
1521
let tokenModifiersToString = function NoModifier -> "0"
1622

1723
type token = int * int * int * tokenType * tokenModifiers
@@ -91,18 +97,18 @@ let emitLongident ?(backwards = false) ?(jsx = false)
9197
let rec loop pos segments =
9298
match segments with
9399
| [id] when isUppercaseId id || isLowercaseId id ->
94-
if debug then Printf.printf "Lident: %s %s\n" id (posToString pos);
95-
emitter
96-
|> emitFromPos pos
97-
(fst pos, snd pos + String.length id)
98-
~type_:(if isUppercaseId id then moduleToken else Variable)
100+
let type_ = if isUppercaseId id then moduleToken else Variable in
101+
if debug then
102+
Printf.printf "Lident: %s %s %s\n" id (posToString pos)
103+
(Token.tokenTypeDebug type_);
104+
emitter |> emitFromPos pos (fst pos, snd pos + String.length id) ~type_
99105
| id :: segments when isUppercaseId id || isLowercaseId id ->
100-
if debug then Printf.printf "Ldot: %s %s\n" id (posToString pos);
106+
let type_ = if isUppercaseId id then moduleToken else Variable in
107+
if debug then
108+
Printf.printf "Ldot: %s %s %s\n" id (posToString pos)
109+
(Token.tokenTypeDebug type_);
101110
let length = String.length id in
102-
emitter
103-
|> emitFromPos pos
104-
(fst pos, snd pos + length)
105-
~type_:(if isUppercaseId id then moduleToken else Variable);
111+
emitter |> emitFromPos pos (fst pos, snd pos + length) ~type_;
106112
loop (fst pos, snd pos + length + 1) segments
107113
| _ -> ()
108114
in
Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
Parse tests/src/Parser.res
22
structure items:15 diagnostics:0
3-
Lident: M (0,7)
4-
Lident: C (1,9)
5-
Lident: Component (1,13)
6-
Lident: Component (4,10)
7-
Lident: _c (4,4)
8-
Ldot: M (6,11)
9-
Lident: C (6,13)
10-
Lident: _mc (6,4)
11-
Lident: div (8,10)
12-
Lident: _d (8,4)
13-
Lident: div (11,3)
14-
Lident: div (16,4)
15-
Ldot: React (12,5)
16-
Lident: string (12,11)
17-
Lident: div (13,5)
18-
Lident: div (13,34)
19-
Ldot: React (13,11)
20-
Lident: string (13,17)
21-
Ldot: React (14,5)
22-
Lident: string (14,11)
23-
Ldot: React (15,5)
24-
Lident: string (15,11)
25-
Lident: _d2 (10,4)
3+
Lident: M (0,7) Module
4+
Lident: C (1,9) Module
5+
Lident: Component (1,13) Module
6+
Lident: Component (4,10) Module
7+
Lident: _c (4,4) Variable
8+
Ldot: M (6,11) Module
9+
Lident: C (6,13) Module
10+
Lident: _mc (6,4) Variable
11+
Lident: div (8,10) Variable
12+
Lident: _d (8,4) Variable
13+
Lident: div (11,3) Variable
14+
Lident: div (16,4) Variable
15+
Ldot: React (12,5) Module
16+
Lident: string (12,11) Variable
17+
Lident: div (13,5) Variable
18+
Lident: div (13,34) Variable
19+
Ldot: React (13,11) Module
20+
Lident: string (13,17) Variable
21+
Ldot: React (14,5) Module
22+
Lident: string (14,11) Variable
23+
Ldot: React (15,5) Module
24+
Lident: string (15,11) Variable
25+
Lident: _d2 (10,4) Variable
2626
Type: pair (18,5)->(18,9)
2727
Type: looooooooooooooooooooooooooooooooooooooong_int (20,5)->(20,51)
2828
Type: int (20,54)->(20,57)
@@ -39,17 +39,17 @@ Type: looooooooooooooooooooooooooooooooooooooong_string (27,4)->(27,53)
3939
BinaryExp: (31,14)->(31,16)
4040
BinaryExp: (31,10)->(31,11)
4141
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)
42+
Lident: MT (33,12) Type
43+
Lident: DDF (34,9) Module
44+
Lident: DDF (39,7) Module
45+
Lident: MT (39,12) Type
46+
Lident: DDF (40,9) Module
47+
Lident: XX (45,7) Module
48+
Lident: YY (46,9) Module
4949
Type: t (47,9)->(47,10)
5050
Type: int (47,13)->(47,16)
51-
Ldot: XX (51,5)
52-
Lident: YY (51,8)
51+
Ldot: XX (51,5) Module
52+
Lident: YY (51,8) Module
5353
Type: tt (53,5)->(53,7)
5454
Type: t (53,10)->(53,11)
5555

0 commit comments

Comments
 (0)