Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
aspeddro opened this issue Aug 12, 2023 · 5 comments

Comments

@aspeddro
Copy link
Contributor

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 #797 (comment)

@aspeddro
Copy link
Contributor Author

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 #797 (comment)

@aspeddro
Copy link
Contributor Author

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.

#797 (comment)

@aspeddro
Copy link
Contributor Author

@cristianoc
Copy link
Collaborator

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.

@aspeddro
Copy link
Contributor Author

PR rescript-lang/rescript#6343

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants