Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@

#### :bug: Bug fix

- Fix semantic highlighting for array spreads, array access and dict literals. https://github.com/rescript-lang/rescript/pull/7789
- Preserve `@as(...)` decorator on record fields when creating interface. https://github.com/rescript-lang/rescript/pull/7779
- Fix parse error with nested record types and attributes on the field name that has the nested record type. https://github.com/rescript-lang/rescript/pull/7781
- Fix ppx resolution with package inside monorepo. https://github.com/rescript-lang/rescript/pull/7776
Expand Down
32 changes: 26 additions & 6 deletions analysis/src/SemanticTokens.ml
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,32 @@ let command ~debug ~emitter ~path =
match e.pexp_desc with
| Pexp_ident {txt = lid; loc} ->
if lid <> Lident "not" then
if not loc.loc_ghost then
emitter
|> emitLongident ~pos:(Loc.start loc)
~posEnd:(Some (Loc.end_ loc))
~lid ~debug;
Ast_iterator.default_iterator.expr iterator e
if not loc.loc_ghost then (
(* Don't emit semantic tokens for identifiers not present in source code *)
let should_emit =
match lid with
(* Array spread (`...`) is converted to `Belt.Array.concatMany` with `@res.spread` decorator *)
| Ldot (Ldot (Lident "Belt", "Array"), "concatMany") ->
let has_spread_attr =
e.pexp_attributes
|> List.exists (fun ({Location.txt}, _) -> txt = "res.spread")
in
not has_spread_attr
(* Dict syntax (`dict{...}`) is converted to `Primitive_dict.make` *)
| Ldot (Lident "Primitive_dict", "make") -> false
| Lident "Primitive_dict" -> false
(* Array access (`arr[index]`) is converted to `Array.get` *)
| Ldot (Lident "Array", "get") -> false
(* Array mutation (`arr[index]`) is converted to `Array.set` *)
| Ldot (Lident "Array", "set") -> false
| _ -> true
in
if should_emit then
emitter
|> emitLongident ~pos:(Loc.start loc)
~posEnd:(Some (Loc.end_ loc))
~lid ~debug;
Ast_iterator.default_iterator.expr iterator e)
| Pexp_jsx_element (Jsx_unary_element {jsx_unary_element_tag_name = lident})
->
(*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let xs = [1, 2]
let ys = [...xs, 3]
//^sem
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
let x = xs[0]
let x = xs[index]
//^sem
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
xs[0] = 42
//^sem
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
let d = dict{"foo": bar}
//^sem
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"data":[0,4,2,1,0,1,4,2,1,0,0,9,2,1,0]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"data":[0,4,1,1,0,0,4,2,1,0,1,4,1,1,0,0,4,2,1,0,0,3,5,1,0]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"data":[0,0,2,1,0]}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"data":[0,4,1,1,0,0,16,3,1,0]}
Loading