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

Bracket goto skipping function struct enum union trait impl items and wrongly selecting comments in Rust #3589

Closed
David-Else opened this issue Aug 28, 2022 · 4 comments · Fixed by #3590
Labels
A-tree-sitter Area: Tree-sitter C-bug Category: This is a bug

Comments

@David-Else
Copy link
Contributor

David-Else commented Aug 28, 2022

Summary

// functions1.rs
// Execute `rustlings hint functions1` or use the `hint` watch subcommand for a hint.

// I AM NOT DONE

fn main() {
    call_me(10);
}

fn call_me(x: i32) -> i32 {
    x
}

fn call_me1(x: i32) -> i32 {
    x
}
  • gg]f takes you to the second function, it should be main, the next one down
  • ge[f 3 times results in the first function AND the comments being selected (as shown below):
    Screenshot from 2022-08-28 17-31-19

The exact same thing happens for struct enum union trait and impl items as well.

Reproduction Steps

In summary above

Helix log

n/a

Platform

Linux

Terminal Emulator

Kitty

Helix Version

helix 22.05 (e066782)

@David-Else David-Else added the C-bug Category: This is a bug label Aug 28, 2022
@the-mikedavis
Copy link
Member

I'm not sure why comments are being matched on in the function textobject for rust:

[
(attribute_item)+
(line_comment)+
]*
.

I think it should fix it to just have the textobject be

(function_item
  body: (_) @function.inside) @function.around

Would you like to make a PR?

@the-mikedavis the-mikedavis added the A-tree-sitter Area: Tree-sitter label Aug 28, 2022
@David-Else
Copy link
Contributor Author

I tried changing:

  (function_item
    body: (_) @function.inside)) @function.around

to

(function_item
  body: (_) @function.inside) @function.around

as you suggested, but it doesn't work. Is this what you meant? Sorry, this is the first time I have looked at a text object file.

@the-mikedavis
Copy link
Member

I mean that we can remove the whole outer part and only use the function_item pattern:

-(
-  [
-    (attribute_item)+
-    (line_comment)+
-  ]*
-  .
-  (function_item
-    body: (_) @function.inside)) @function.around
+(function_item
+  body: (_) @function.inside) @function.around

I think we should be able to do that for all of those patterns that start with ([(attribute_item)+ (line_comment)+]* .

@David-Else David-Else changed the title Bracket goto function skipping functions and highlighting comments in Rust Bracket goto skipping function struct enum union trait impl items and wrongly selecting comments in Rust Aug 28, 2022
@David-Else
Copy link
Contributor Author

David-Else commented Aug 28, 2022

@the-mikedavis I have made a PR #3590. Please could you have a look? Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tree-sitter Area: Tree-sitter C-bug Category: This is a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants