-
-
Notifications
You must be signed in to change notification settings - Fork 84
add Go branch scope support #1854
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
outstanding:
note also this is a potentially interesting case for #1631 |
Looking at your scope visualizer screenshots from slack, it appears that the problem is that tree-sitter-go includes the trailing newline in the node's range. I'd recommend using our shrink regex predicate operator to exclude it. Hopefully that will fix your various issues. Keep in mind that "chuck branch" will leave an empty line, but pretty much every other scope type has the same problem, and we're planning to fix all tree-sitter whitespace removal using the #855 hammer |
bcd5d31
to
01d83e5
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.
From your screenshots, it appears the newline is still being included.
Fwiw I do wonder if we want to create a "trim" query predicate operator so we don't have to keep reinventing the wheel with whitespace / newline trimming
The same thing can be accomplished with #shrink-to-match!, but this is considerably simpler to use, and meets a common need. Suggested by Pokey during review of #1854.
a8aa19e
to
34a8845
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.
had a quick look and tests / visualizer looks good! left some minor comments; didn't review the .scm
thoroughly as it's a bit tough to read without autoformatter
packages/cursorless-engine/src/languages/TreeSitterQuery/queryPredicateOperators.ts
Show resolved
Hide resolved
added some tests. unfortunately, the behavior in packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/go/cloneBranch2.yml and packages/cursorless-vscode-e2e/src/suite/fixtures/recorded/languages/go/cloneBranch3.yml is bad: it generates invalid code. I am not sure how to fix it. Looks like a line number off-by-one? Because they're hard to read (maybe I really should finish up #1805? there was so little enthusiasm for it), here's an example. Start: if x {
x++
} else if y {
y++
} else {
x--
} Then if x {
x++
else if y {
y++
}
} else if y {
y++
} else {
x--
} Best would be something like: if x {
x++
} else if y {
y++
} else if y {
y++
} else {
x--
} But at a minimum, I'd expect valid syntax, so maybe: if x {
x++
}
else if y {
y++
} else if y {
y++
} else {
x--
} |
Sigh. The precommit failure is due to typescript code I added to the playground to experiment with |
It is unused. I believe that it also contains a latent bug, when the range contains entirely whitespace. Noticed during discussion at #1854 (comment)
Fixed clone. It's not quite perfect, but it's close enough. The weird setting of the insertion delimiter on
But let's just get this in for now? |
PTAL |
I believe this is ready for review. |
Ping. |
It is unused. I believe that it also contains a latent bug, when the range contains entirely whitespace. Noticed during discussion at #1854 (comment) ## Checklist - [-] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [-] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [-] I have not broken the cheatsheet --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
It is unused. I believe that it also contains a latent bug, when the range contains entirely whitespace. Noticed during discussion at cursorless-dev#1854 (comment) ## Checklist - [-] I have added [tests](https://www.cursorless.org/docs/contributing/test-case-recorder/) - [-] I have updated the [docs](https://github.com/cursorless-dev/cursorless/tree/main/docs) and [cheatsheet](https://github.com/cursorless-dev/cursorless/tree/main/cursorless-talon/src/cheatsheet) - [-] I have not broken the cheatsheet --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
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.
Looks good with some minor comments!
consequence: (block) @branch.end.endOf | ||
) @_if @branch.start.startOf | ||
(#not-parent-type? @_if if_statement) | ||
(#insertion-delimiter! @branch.start.startOf " ") |
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.
Is this necessary? I think a space is the default insertion delimiter.
(#insertion-delimiter! @branch.start.startOf " ") |
queries/go.scm
Outdated
alternative: (if_statement | ||
consequence: (block) @branch.end.endOf | ||
) | ||
(#insertion-delimiter! @branch.start.startOf " ") |
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.
As above
(#insertion-delimiter! @branch.start.startOf " ") |
queries/go.scm
Outdated
"else" @branch.start.startOf | ||
alternative: (if_statement | ||
consequence: (block) @branch.end.endOf |
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 pretty sure you don't need the .startOf
/ .endOf
if they're not overlapping and you can rely on the order
"else" @branch.start.startOf | |
alternative: (if_statement | |
consequence: (block) @branch.end.endOf | |
"else" @branch.start | |
alternative: (if_statement | |
consequence: (block) @branch.end |
"else" @branch.start.startOf | ||
alternative: (block) | ||
) @branch.end.endOf | ||
(#insertion-delimiter! @branch.start.startOf " ") |
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.
as above
(#insertion-delimiter! @branch.start.startOf " ") |
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.
Made the final small tweaks to get this one merged in
Thanks! Sorry I'm such a mess at the moment. Really appreciated. |
Not at all! |
Not all the behavior is perfect (I'm looking at you, pour and drink), but it's better than not existing.
The perfect is the enemy of the good.
Checklist