-
Notifications
You must be signed in to change notification settings - Fork 44
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
Improved kotlin syntax based on latest documentation #137
Conversation
@fwcd , this PR is almost a month old now. Any chance to look at it soon? I don't really have many permissions in this repo. Seems quite reasonable to me though 🙂 |
@fwcd I have added some screenshots to redhat-developer/vscode-java#3407 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Left some quick thoughts below
syntaxes/kotlin.tmLanguage.json
Outdated
} | ||
}, | ||
"variable-declaration": { | ||
"match": "\\b(val|var)\\b\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?", | ||
"match": "\\b(var)\\b\\s*(?<GROUP><([^<>]|\\g<GROUP>)+>)?", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The separation of var
and val
is interesting as it lets us highlight constants differently.
On the other hand, I worry that this duplication will increase the maintainance burden. In general, I think "being liberal" about allowing the same syntactic constructs for var
and val
should be fine for syntax highlighting.
Curious to know how other languages handle this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be honest, I'm not sure where I got the idea to create a separate scope for val. I have checked how the TypeScript grammar handles this, and it combines let, const and var.
C# uses readonly scope, but only for the readonly keyword https://github.com/microsoft/vscode/blob/83127004a87124b1b8b976b9f9022da41814dfd0/extensions/csharp/syntaxes/csharp.tmLanguage.json#L3034
On the other hand, both BuildShip and the RH Java Extension accepted this, so it is up to you if I should revert it.
https://github.com/eclipse/buildship/blob/0800e1c1ea25a3afca2a113a0747efe822a65273/org.eclipse.buildship.kotlindsl.provider/kotlin.tmLanguage.json#L445
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have searched a bit more, and I added the readonly distinction because of the "Semantic Highlight Guide" documentations for VSCode mentions it.
See: https://code.visualstudio.com/api/language-extensions/semantic-highlight-guide
However, it does not look like it is common to be used for the const/val keywords, only for the readonly keyword.
I can revert the change, it you prefer.
I have also made some changes to the definitions for val/var to be more in line with how the java grammar handles local var.
I may be a bit biased when I'm using the Java grammar for guidance, but I'm only using Kotlin in conjunction with Java, so that's what i know.
syntaxes/kotlin.tmLanguage.json
Outdated
@@ -19,10 +19,13 @@ | |||
], | |||
"repository": { | |||
"import": { | |||
"begin": "\\b(import)\\b\\s*", | |||
"begin": "\\b(import)\\b\\s*([\\w+.]*\\w+)?\\s*", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
syntaxes/kotlin.tmLanguage.json
Outdated
} | ||
}, | ||
"variable": { | ||
"match": "\\b(\\w+)(?=\\s*[:=])", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't quite right either, this will match anything on the left-hand side of ==
too, including e.g. numbers:
![image](https://private-user-images.githubusercontent.com/30873659/296874391-08e707ea-771e-4298-bf50-ed33545a75dd.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk0OTIxOTAsIm5iZiI6MTczOTQ5MTg5MCwicGF0aCI6Ii8zMDg3MzY1OS8yOTY4NzQzOTEtMDhlNzA3ZWEtNzcxZS00Mjk4LWJmNTAtZWQzMzU0NWE3NWRkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE0VDAwMTEzMFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTdkNDk2MTg2MTlmN2MxMjM1N2NkZDI2NWFhMTMyMWUyZGU4NGNlNGUxNmJjODIwODdmZjY4NzY0OTQwY2UwNWEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.osGllu9BY1bFb-WFmJjHbAr0hBQcUzQ5vvQaPDI2LYk)
Anything involving =
will likely require being very careful to not accidentally match any equality operators. This includes cases where e.g. the space is left out, i.e. expressions like (x!=3)
...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm removing this definition completely. It need a bit more work to be implemented correctly.
3535583
to
eb7c3a3
Compare
Update syntaxes/kotlin.tmLanguage.json Our suggestion is the same as the one in the built in definition for java, so I guess it's the proper way to do it https://github.com/microsoft/vscode/blob/12443ca030f93843ca5e9dfb5682ad92d2c6400c/extensions/java/syntaxes/java.tmLanguage.json#L53 Co-authored-by: fwcd <30873659+fwcd@users.noreply.github.com> Removed definitions for reassigning varaibles
eb7c3a3
to
ed3baf8
Compare
ed3baf8
to
d95a0a4
Compare
Thanks for all the feedback. I have tried to fix the issues you have found. |
Please rebase onto the latest |
Improved syntax based on documentation from https://kotlinlang.org/
Summary
See: eclipse-buildship/buildship#1273