Skip to content

Commit 4faa239

Browse files
committed
Use JsxTag for lower-case jsx, and Namespace for modules.
1 parent 8658618 commit 4faa239

File tree

4 files changed

+33
-30
lines changed

4 files changed

+33
-30
lines changed

analysis/src/SemanticTokens.ml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@ module Token = struct
33

44
(* This needs to stay synced with the same legend in `server.ts` *)
55
(* See https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_semanticTokens *)
6-
type tokenType = Keyword | Variable | Type | Module
6+
type tokenType = Keyword | Variable | Type | JsxTag | Namespace
77
type tokenModifiers = NoModifier
88

99
let tokenTypeToString = function
1010
| Keyword -> "0"
1111
| Variable -> "1"
1212
| Type -> "2"
13-
| Module -> "3"
13+
| JsxTag -> "3"
14+
| Namespace -> "4"
1415

1516
let tokenTypeDebug = function
1617
| Keyword -> "Keyword"
1718
| Variable -> "Variable"
1819
| Type -> "Type"
19-
| Module -> "Module"
20+
| JsxTag -> "JsxTag"
21+
| Namespace -> "Namespace"
2022

2123
let tokenModifiersToString = function NoModifier -> "0"
2224

@@ -85,7 +87,8 @@ let emitFromLoc ~loc ~type_ emitter =
8587
emitter |> emitFromPos posStart posEnd ~type_
8688

8789
let emitLongident ?(backwards = false) ?(jsx = false)
88-
?(moduleToken = Token.Module) ~pos ~lid ~debug emitter =
90+
?(moduleToken = Token.Namespace) ~pos ~lid ~debug emitter =
91+
let variableToken = if jsx then Token.JsxTag else Variable in
8992
let rec flatten acc lid =
9093
match lid with
9194
| Longident.Lident txt -> txt :: acc
@@ -97,13 +100,13 @@ let emitLongident ?(backwards = false) ?(jsx = false)
97100
let rec loop pos segments =
98101
match segments with
99102
| [id] when isUppercaseId id || isLowercaseId id ->
100-
let type_ = if isUppercaseId id then moduleToken else Variable in
103+
let type_ = if isUppercaseId id then moduleToken else variableToken in
101104
if debug then
102105
Printf.printf "Lident: %s %s %s\n" id (posToString pos)
103106
(Token.tokenTypeDebug type_);
104107
emitter |> emitFromPos pos (fst pos, snd pos + String.length id) ~type_
105108
| id :: segments when isUppercaseId id || isLowercaseId id ->
106-
let type_ = if isUppercaseId id then moduleToken else Variable in
109+
let type_ = if isUppercaseId id then moduleToken else variableToken in
107110
if debug then
108111
Printf.printf "Ldot: %s %s %s\n" id (posToString pos)
109112
(Token.tokenTypeDebug type_);
Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
Parse tests/src/Parser.res
22
structure items:15 diagnostics:0
3-
Lident: M (0,7) Module
4-
Lident: C (1,9) Module
5-
Lident: Component (1,13) Module
6-
Lident: Component (4,10) Module
3+
Lident: M (0,7) Namespace
4+
Lident: C (1,9) Namespace
5+
Lident: Component (1,13) Namespace
6+
Lident: Component (4,10) Namespace
77
Lident: _c (4,4) Variable
8-
Ldot: M (6,11) Module
9-
Lident: C (6,13) Module
8+
Ldot: M (6,11) Namespace
9+
Lident: C (6,13) Namespace
1010
Lident: _mc (6,4) Variable
11-
Lident: div (8,10) Variable
11+
Lident: div (8,10) JsxTag
1212
Lident: _d (8,4) Variable
13-
Lident: div (11,3) Variable
14-
Lident: div (16,4) Variable
15-
Ldot: React (12,5) Module
13+
Lident: div (11,3) JsxTag
14+
Lident: div (16,4) JsxTag
15+
Ldot: React (12,5) Namespace
1616
Lident: string (12,11) Variable
17-
Lident: div (13,5) Variable
18-
Lident: div (13,34) Variable
19-
Ldot: React (13,11) Module
17+
Lident: div (13,5) JsxTag
18+
Lident: div (13,34) JsxTag
19+
Ldot: React (13,11) Namespace
2020
Lident: string (13,17) Variable
21-
Ldot: React (14,5) Module
21+
Ldot: React (14,5) Namespace
2222
Lident: string (14,11) Variable
23-
Ldot: React (15,5) Module
23+
Ldot: React (15,5) Namespace
2424
Lident: string (15,11) Variable
2525
Lident: _d2 (10,4) Variable
2626
Type: pair (18,5)->(18,9)
@@ -40,16 +40,16 @@ BinaryExp: (31,14)->(31,16)
4040
BinaryExp: (31,10)->(31,11)
4141
BinaryExp: (31,19)->(31,20)
4242
Lident: MT (33,12) Type
43-
Lident: DDF (34,9) Module
44-
Lident: DDF (39,7) Module
43+
Lident: DDF (34,9) Namespace
44+
Lident: DDF (39,7) Namespace
4545
Lident: MT (39,12) Type
46-
Lident: DDF (40,9) Module
47-
Lident: XX (45,7) Module
48-
Lident: YY (46,9) Module
46+
Lident: DDF (40,9) Namespace
47+
Lident: XX (45,7) Namespace
48+
Lident: YY (46,9) Namespace
4949
Type: t (47,9)->(47,10)
5050
Type: int (47,13)->(47,16)
51-
Ldot: XX (51,5) Module
52-
Lident: YY (51,8) Module
51+
Ldot: XX (51,5) Namespace
52+
Lident: YY (51,8) Namespace
5353
Type: tt (53,5)->(53,7)
5454
Type: t (53,10)->(53,11)
5555

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
"semanticTokenScopes": [
3232
{
3333
"scopes": {
34-
"module-tag": ["entity.name.tag"]
34+
"jsx-tag": ["entity.name.tag"]
3535
}
3636
}
3737
],

server/src/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -760,7 +760,7 @@ function onMessage(msg: m.Message) {
760760
completionProvider: { triggerCharacters: [".", ">", "@", "~", '"'] },
761761
semanticTokensProvider: {
762762
legend: {
763-
tokenTypes: ["keyword", "variable", "type", "module-tag"],
763+
tokenTypes: ["keyword", "variable", "type", "jsx-tag", "namespace"],
764764
tokenModifiers: [],
765765
},
766766
documentSelector: null,

0 commit comments

Comments
 (0)