-
Notifications
You must be signed in to change notification settings - Fork 58
Optional braces, part 2 #62
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
Conversation
Problem ------- Currently Scala 3 optional braces syntax does not work. Solution -------- This implements initial attempt on dealing with colon instead of braces. Note that this does not implement any indent/outdent tracking so the second `val` onwards will not be added in `template_body` but it should improve the highlighting a bit.
282080f
to
78608c7
Compare
Problem ------- Currently CI is failing on windows-latest. Solution -------- Downgrade to windows-2019 so node-gyp can be installed.
40272ff
to
38ac6e9
Compare
Problem ------- Currently Scala 3 optional braces syntax does not work. Specifically, in this PR I want to address decls/defns not properly grouped under the right owner in part 1. Solution -------- 1. This brings in indent/outdent impl by keynmol 2. Introduce `_indentable_expression`. This allows us to limit where indent/outdent shows up without confusing tree-sitter too much. To start, val/def/var defn and if-expressions are given indentable expression.
95269aa
to
d1287dd
Compare
Problem ------- Given something like class A: def a() = () def a() = 1 the scanner only outdents once, so it fails to parse the above. Solution -------- Track `last_indentation_size` in the payload to indicate last outdent (default: -1). If it's not -1 that means there was an outdent. This then checks if the last_indentation_size qualified for another outdent.
Problem ------- Given something like class A: def l: Int = 1 def m = () the scanner doesn't inject automatic semicolon since the newline has been consumed by outdenting, and it fails to parse the code. Solution -------- Track `last_newline_count` in the payload, which represents the newline_count at the time out outdent. This then is recovered so automatic semicolon can use it only if the column position hasn't moved.
d1287dd
to
606b37d
Compare
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.
For later record keeping, I described some of the changes in this PR in https://eed3si9n.com/fast-scala3-parsing-with-tree-sitter/ post as well. I think the next challenge would be handling fewer braces syntax, since likely newlines starts to add semantics, and thus can't be ignored globally. |
I think before that (=fewer braces) we'll need to run this on a larger codebases - I.e. I've been using your fork and it still has problems in quite a few places, so I would suggest ignoring fewerBraces completely and instead getting the number of correctly parsed files up on something like Dotty codebase. There are several of my PRs for Scala 3 I will now revive and ensure that they work with your changes as well, which should improve things. Additionally, would be good to keep track of Scala 2 as well, for which we can also use the code of Scala 2 compiler as a bench. To get that locally, you can use this command (thanks to @ckipp01 for showing me the light):
|
Yea I'm in agreement here. Even without fewer braces I still hit on a lot of issues. I think if we get your stuff revived and in @keynmol I can start paying way more attention to errors in the tree and reporting them now that I feel more confident that we can get things merged in. |
Yea. Generally I agree that we should try to go after lower hanging Scala 3 constructs first, but I was replying to the "need some more C work" part. |
Ref #43
Problem
Currently Scala 3 optional braces syntax does not work.
Specifically, in this PR I want to address decls/defns not properly grouped under the right owner in part 1 (#61).
Solution
_indentable_expression
.This allows us to limit where indent/outdent shows up without
confusing tree-sitter too much.
Internally I've made a change to track
last_indentation_size
in the payload to indicate lastoutdent (default: -1). If it's not -1 that means there was an outdent.
This then checks if the last_indentation_size qualified for another outdent.
The test cases for these are:
Demo
Here's a demonstration of before and after using Sonokai. The theme is a bit too color happy, but it's good for checking what changed:
Before #61
Note:
def run
is not recognized as a method.After this PR
def run
is highlighted as a method. The body ofdef dealiasBaseDirectory
improved as well, sinceval
is now acceptable without{ ... }
.