Skip to content
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

use *file* identifier: produces a tree-sitter error #89

Closed
CabalCrow opened this issue May 23, 2024 · 8 comments · Fixed by #90
Closed

use *file* identifier: produces a tree-sitter error #89

CabalCrow opened this issue May 23, 2024 · 8 comments · Fixed by #90
Labels
bug Something isn't working

Comments

@CabalCrow
Copy link
Contributor

Using the pattern use file identifier produces a TS error. This happens when the identifier is not put in a list ex: use file [identifier - this produces no error. Also happens when * is used instead of an identifier.

Picture (look at the highlighting of the use - on the line before the incorrectly highlighted use there is an TS error, which can be seen via the TSPlayground):
image

@fdncred fdncred added the bug Something isn't working label May 23, 2024
@fdncred
Copy link
Collaborator

fdncred commented May 23, 2024

Good catch. Thanks!

@CabalCrow
Copy link
Contributor Author

After testing a bit more I think the issue is not actually in the final argument of the use. The actual issue compes from using a pipeline to get the module name.

For example use std * works properly. However use ('std') * produces a TS error. However it is valid nu syntax.

@fdncred
Copy link
Collaborator

fdncred commented May 23, 2024

This seems like invalid syntax use ('std') *. @kubouch Do you know if this syntax is valid?

@CabalCrow
Copy link
Contributor Author

The syntax definitely works. The whole point of that syntaxs is to be able to use pipes to provide the module name.

@kubouch
Copy link

kubouch commented May 23, 2024

In theory it should be valid, I think we added subexpressions to const eval. Might be a bug.

@CabalCrow
Copy link
Contributor Author

After looking through the grammar.js, I think this could be a potential fix. On line 121 it is originally:

          field("module", choice($.val_string, $.unquoted)),

instead this can be used:

          field("module", choice($.val_string, $.expr_parenthesized, $.unquoted)),

From what I saw looking through the grammar expr_parenthesized is used exactly for this type of expression. I tested this via the treesitter cli (both by running test & also by parsing individual files) and it seems to have fixed the issue.

If someone want to give this change a try with their collection of nushell files to see if this creates any ERRORs or incorrect highlighting, give it a go.

@kubouch
Copy link

kubouch commented May 24, 2024

The module field can be any expression that can be evaluated at parse time, I think the only relevant missing is string interpolation, e.g., use $"('s' + 't' + 'd')".

@CabalCrow
Copy link
Contributor Author

I don't think treesitter can test for expressions that could be evaluated at parse time, but string interpolation can be added in. I will add this to the PR: #90

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants