-
-
Notifications
You must be signed in to change notification settings - Fork 79
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 Kotlin. #2432
Add support for Kotlin. #2432
Conversation
Creating a draft pull request as suggested. Please let me know if you have any input on how I'm doing things so far. I'm following the same sequence as Kotlin does not have any list or map literals, or even array literals. Everything is just a function call, and the closest thing to a map literal is use of the "to" infix operator, like so: val map = mapOf(1 to "x", 2 to "y", -1 to "zz")
println(map.get(1)) // {1=x, 2=y, -1=zz} Hence, I guess I don't need to explicitly define Also, should I be supporting and testing |
38d3727
to
71b125c
Compare
I think this is now ready for review. Some open questions:
|
(_) @value | ||
) @_.domain | ||
|
||
;; Disabled due to Cursorless error ("invalid capture") caused by "return@" |
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 can file a bug for 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.
Filed: #2447
":" | ||
. | ||
(_) @type.start | ||
(_) @type.end |
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.
If I could just do (_)? @type.end
I wouldn't need this redundant query, but Cursorless complains when it's missing because I refer to it in a predicate below. I think Cursorless could safely ignore constraints when they don't appear in cases such as this where they are tied to an optional match. My reasoning is that if the predicate must be confirmed, then it shouldn't be an optional match. Should I file a bug for this? There are several places throughout this file where I could simplify my code if this were possible.
Also, I noticed that "drink/pour arg" don't automatically work to add commas. How can I add support for these? |
(annotated_lambda) @argumentOrParameter | ||
) | ||
|
||
;; Note: trailing lambda mixed with regular arguments doesn't work due to bad tree sitter parse. |
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.
Filed bug for this: fwcd/tree-sitter-kotlin#127
Here is the implementation for javascript you can have a look at cursorless/queries/javascript.core.scm Lines 692 to 718 in 089ba0d
|
Thanks @AndreasArvidsson, I added argument delimiter support. |
Ok before you get too much further, it's worth having a look at our updated docs for adding a new language. In particular, we have a new way of writing tests, and we now advocate for many small PRs rather than one big PR. Given that I added those new docs after you had already opened this PR, I won't make it a hard requirement for merging, but going forward, let's a) not add any more scopes to this PR, and We're planning to add a migration assistant for migrating tests to the new format (see #2390), so I don't think it's worth migrating these manually I'll have a look at this PR in the next couple of days, but figured I'd give you a chance to look at those docs in case there's anything you want to tweak before I have a look |
Thanks! I don't think I will have time to make any changes to this pull request within the next couple days, so you should feel free to review. Unfortunately it's a little late to stop adding more scopes because all the scopes have been added 😂. I'm happy to add the metadata files before submitting that describe what scopes are covered. |
Sounds good; will do 😊
Ha no worries
You'd need to migrate your recorded tests to new scope tests as well, because we have checks to ensure that all scope facets marked as supported actually have tests. So if you're not planning to manually migrate those tests (which I'm not sure I'd recommend), I'd leave out the support tables for now |
Okay I won't plan to add the tables then. You can just let me know in the review if there are any other small things I should add as part of this change. |
There are so many test and I'm not a kotlin developer so I most likely have missed something, but I think this looks fine. If you're happy with it then go ahead and merge this so you can start using it. Anything you find we could fix in a follow up. |
I'm excited to try this one out! Thanks for putting it together. |
Fantastic I'll merge it! I've been using it plenty and the only issues I've seen are upstream in the tree sitter grammar. |
Ah I don't have merge permissions so you'll need to do that part. |
Okay here we go! :) |
@wolfmanstout def worth filing those upstream and also keeping a tracker issue here. We can often work around oddnesses / bugs with upstream tree-sitter grammars using tricks in our patterns |
Yep, filed upstream and even sent out PR fixes. I worked around a lot of shortcomings here but these would be extremely awkward to work around and probably introduce other issues. I can create a tracker issue too (a single one for these issues I suppose?). |
Yeah just a single tracker issue would be awesome 🙏 |
What
Adds support for the
kotlin
programming languageChecklist
"change"
/"clear"
instead of"take"
for selection tests to make recorded tests easier to read"chuck"
instead of"change"
to test removal behaviour when it's interesting, especially:"chuck arg"
with single argument in list"chuck arg"
with multiple arguments in list"chuck item"
with single argument in list"chuck item"
with multiple arguments in list@textFragment
captures. Usually you want to put these on comment and string nodes. This enables"take round"
to work within comments and strings."change round"
inside a string, eg"hello (there)"
"type"
both for type annotations (egfoo: string
) and declarations (eginterface Foo {}
) (and added tests for this behaviour 😊)"item"
both for map pairs and list entries (with tests of course)