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

Add support for F# package reference + Fix CommentPreproc detection #631

Conversation

MangelMaxime
Copy link
Contributor

Hello,

Disclaimer: I am new to Go, so I am unsure if what I did is all that is needed

This PR adds support for package reference syntax #r "nuget: PacakgeName".

https://docs.microsoft.com/en-us/dotnet/fsharp/tools/fsharp-interactive/#referencing-packages-in-f-interactive

In order, to have the package reference syntax working I had to move the CommentPreproc rule before the Operator.

I believe this is because inside of the Operator there is a match for # char which was preventing the CommentPreproc rule to handle it.

I also needed to no greedly capture the whole line to end otherwise it was capture the whole line as CommentPreproc instead of a mix of CommentPreproc and LiteralString for example.

[
  {"type":"CommentPreproc","value":"#nowarn \"9\""}
]

instead of

[
  {"type":"CommentPreproc","value":"#nowarn"},
  {"type":"Text","value":" "},
  {"type":"LiteralString","value":"\"9\""}
]

Because, I found it to be a dangerous change I decided to add "complex" F# code to serves as a base reference to check that I didn't break anything by mistakes.
The "complex" F# code has been added inside the file lexers\testdata\fsharp\fsharp.actual. That file is a copy coming from https://github.com/ionide/ionide-fsgrammar/blob/master/sample-code/SimpleTypes.fs which is a really robust reference as it is used since 5+ years as a base for the VSCode grammar testing.

If you look at this commit a3b894e you can see that my changes only impacted the wrongly highlighted CommentPreproc.

-  {"type":"Operator","value":"#"},
-  {"type":"Keyword","value":"if"},
+  {"type":"CommentPreproc","value":"#if"},

It changes from an invalid Operator detection to a CommentPreproc.

@alecthomas
Copy link
Owner

This is great, thank you.

@alecthomas alecthomas merged commit 7cc13cf into alecthomas:master Apr 26, 2022
@MangelMaxime MangelMaxime deleted the fix/fsharp_add_package_reference_syntax branch April 26, 2022 18:45
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

Successfully merging this pull request may close these issues.

None yet

2 participants