rescript-vscode icon indicating copy to clipboard operation
rescript-vscode copied to clipboard

Semantic Tokens: tokens are getting called `namespace` using `arr[idx] = value` syntax

Open aspeddro opened this issue 2 years ago • 5 comments

Here is another case where tokens are getting called namespace rather than what it should be (in this case variable). (v1.18.0)

Color is weird: a

Token output:

b dr c

Originally posted by @mooreryan in https://github.com/rescript-lang/rescript-vscode/issues/797#issuecomment-1668660139

aspeddro avatar Aug 12 '23 22:08 aspeddro

let a = []
let abcdefghijklmn = 0
a[abcdefghijklmn] = 1

AST output:

[
  structure_item (/home/pedro/Desktop/learning-rescript/src/Object.res[1,0+0]..[1,0+10])
    Pstr_value Nonrec
    [
      <def>
        pattern (/home/pedro/Desktop/learning-rescript/src/Object.res[1,0+4]..[1,0+5])
          Ppat_var "a" (/home/pedro/Desktop/learning-rescript/src/Object.res[1,0+4]..[1,0+5])
        expression (/home/pedro/Desktop/learning-rescript/src/Object.res[1,0+8]..[1,0+10])
          Pexp_array
          []
    ]
  structure_item (/home/pedro/Desktop/learning-rescript/src/Object.res[2,11+0]..[2,11+22])
    Pstr_value Nonrec
    [
      <def>
        pattern (/home/pedro/Desktop/learning-rescript/src/Object.res[2,11+4]..[2,11+18])
          Ppat_var "abcdefghijklmn" (/home/pedro/Desktop/learning-rescript/src/Object.res[2,11+4]..[2,11+18])
        expression (/home/pedro/Desktop/learning-rescript/src/Object.res[2,11+21]..[2,11+22])
          Pexp_constant PConst_int (0,None)
    ]
  structure_item (/home/pedro/Desktop/learning-rescript/src/Object.res[3,34+0]..[3,34+21])
    Pstr_eval
    expression (/home/pedro/Desktop/learning-rescript/src/Object.res[3,34+0]..[3,34+21])
      Pexp_apply
      expression (/home/pedro/Desktop/learning-rescript/src/Object.res[3,34+1]..[3,34+17])
        Pexp_ident "Array.set" (/home/pedro/Desktop/learning-rescript/src/Object.res[3,34+1]..[3,34+17])
      [
        <arg>
        Nolabel
          expression (/home/pedro/Desktop/learning-rescript/src/Object.res[3,34+0]..[3,34+1])
            Pexp_ident "a" (/home/pedro/Desktop/learning-rescript/src/Object.res[3,34+0]..[3,34+1])
        <arg>
        Nolabel
          expression (/home/pedro/Desktop/learning-rescript/src/Object.res[3,34+2]..[3,34+16])
            Pexp_ident "abcdefghijklmn" (/home/pedro/Desktop/learning-rescript/src/Object.res[3,34+2]..[3,34+16])
        <arg>
        Nolabel
          expression (/home/pedro/Desktop/learning-rescript/src/Object.res[3,34+20]..[3,34+21])
            Pexp_constant PConst_int (1,None)
      ]
]

Originally posted by @aspeddro in https://github.com/rescript-lang/rescript-vscode/issues/797#issuecomment-1668784367

aspeddro avatar Aug 12 '23 22:08 aspeddro

It's probably the location of array set. Which could maybe be made to match "=" at parser time instead of the entire lhs. Or, the whole array set case special cased in the extension.

https://github.com/rescript-lang/rescript-vscode/issues/797#issuecomment-1670584799

aspeddro avatar Aug 12 '23 22:08 aspeddro

If I understand correctly, this should be done in the compiler repo?

Here https://github.com/rescript-lang/rescript-compiler/blob/062c387f86020f72abee3b3aa2c2eaa0f3d67929/jscomp/syntax/src/res_core.ml#L2013-L2023

aspeddro avatar Aug 12 '23 23:08 aspeddro

If I understand correctly, this should be done in the compiler repo?

Here

https://github.com/rescript-lang/rescript-compiler/blob/062c387f86020f72abee3b3aa2c2eaa0f3d67929/jscomp/syntax/src/res_core.ml#L2013-L2023

Yes. First to check that the location is the cause of the issue.

cristianoc avatar Aug 13 '23 09:08 cristianoc

PR https://github.com/rescript-lang/rescript-compiler/pull/6343

aspeddro avatar Aug 17 '23 16:08 aspeddro