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

fix (kotlin): capture @class.outer on classes without a body #748

Merged
merged 1 commit into from
Apr 6, 2025

Conversation

alphashuro
Copy link
Contributor

@alphashuro alphashuro commented Apr 3, 2025

In Kotlin classes, the body is optional, but the @class text objects were failing to capture classes without a body.
This change makes @class.outer work for those cases, but @class.inner is ignored since these classes does not have an "inner"

In Kotlin data classes, the body is optional, 
This makes `@class.outer` work in those cases
@alphashuro
Copy link
Contributor Author

I see flakey tests but they seem unrelated to my change, are these flakey tests?

@kiyoon
Copy link
Collaborator

kiyoon commented Apr 4, 2025

The tests are broken since nvim 0.11, so ignore those.

Can you explain what bodyless class is? I'm new to Kotlin.

@kiyoon
Copy link
Collaborator

kiyoon commented Apr 4, 2025

For example,

  1. If the class is bodyless, how does @class.inner work?
  2. Does the change not affect the classes with a body?

@alphashuro
Copy link
Contributor Author

alphashuro commented Apr 5, 2025

According to the Kotlin specification, the body of a class is optional.

In practice it just looks like this

class Person

If the class is bodyless, how does @class.inner work?

@class.inner is just ignored, because the class has no "inside". Inspecting the treesitter tree on this class shows this

(class_declaration
  (type_indentifier))

Does the change not affect the classes with a body?

No, it only makes the body optional, but when the body exists it is captured the same way it was before this PR

@alphashuro alphashuro changed the title fix (kotlin): textobj for bodyless class fix (kotlin): capture @class.outer for classes without a body Apr 5, 2025
@alphashuro alphashuro changed the title fix (kotlin): capture @class.outer for classes without a body fix (kotlin): capture @class.outer for classes without a body Apr 5, 2025
@alphashuro alphashuro changed the title fix (kotlin): capture @class.outer for classes without a body fix (kotlin): capture @class.outer on classes without a body Apr 5, 2025
@alphashuro
Copy link
Contributor Author

alphashuro commented Apr 5, 2025

just to be clear, the word "bodyless" is not actually an official term 😅 I updated the PR title to make it clearer

@kiyoon kiyoon merged commit 698b5f8 into nvim-treesitter:master Apr 6, 2025
4 of 6 checks passed
@kiyoon
Copy link
Collaborator

kiyoon commented Apr 6, 2025

Thank you!

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.

2 participants