-
-
Notifications
You must be signed in to change notification settings - Fork 91
implement "visible" scope #1623
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
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.
Wow great start! Tbh it's almost mergeable as is. But see comment inline
_position: Position, | ||
_direction: Direction, | ||
): Iterable<TargetScope> { | ||
for (const range of editor.visibleRanges) { |
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.
This will interact with folding in an interesting way. If you say "take visible" from one side of a fold, you'll only get up until the fold. If you say "take next visible" you'll get the code between the next fold until the following. To refer to all sections between folds, you'd say "take every visible".
I'd be tempted to either
- yield a single scope whose range is the union all the visible ranges, or
- yield a single scope that returns all the visible regions as a single list in its
getTargets
. I'd consider making the domain of that scope just be the document. Then saying "take visible" from anywhere in the document will give you all the visible ranges
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.
There's a third option, which is to reject visible
as an allowed scope when folds are present. That sidesteps the question of what the correct behavior is, and punts the decision to the future, where we could loosen that constraint.
I lean towards your second option, and will implement that to play with, but am open to guidance. :)
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.
Implemented, played with second option. I'm happy with it. Another use case: fixing variable shadowing. Fold all shadowed inner scopes, work on every instance in what remains visible. (You can do that with take and give and this and that, but folding is more stateful, which can be useful.)
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.
Although that makes me wonder whether visible should be a modifier.
from visible file take every instance air
from visible func fine take every instance air
Nah, probably not.
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 you revert to your original approach, then you could say "from every visible funk" to target all visible ranges that touch the current function. Not necessarily suggesting you do that, but just fwiw
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.
That's true! But on balance, I think I prefer the simpler semantics. I'm happy with what is implemented now.
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.
Brain dump:
- This is the first example of a scope that's not purely a function of the document itself
- Being a scope type here doesn't buy us anything useful over just making it a modifier (eg we can't leverage "every visible", "next visible", etc even tho the grammar now allows them). However that's also true or document scope ("file")
- Having it be a mark would preclude ability to say "visible air" to target visible in another split, so we'd prob want it to at least be a modifier
- Having it be modifier with intersection as you proposed is interesting but might be unintuitive when you have a nonempty selection and say "take visible": that would then intersect your selection with visible
- it might actually be useful to say "next visible" / "first visible" etc. I think the latter does work with your impl fwiw
- There is an interesting parallel here to a hypothetical scope for referring to your selections, eg "first selection", or "selection air" to refer to the selection in the split containing air
What do you mean by
This would be my second proposal in my inline review comment
That's a tough one. We struggle to test visible range stuff because we don't know how big the window is. Probably the best way to test this would be to leverage the fact that the editor is actually an abstract interface, but we haven't done anything like that yet. We will in the future, but I'd be tempted to punt on that. I'd probably just have a test with and without folds and declare victory
I think so. If the test passes you're probably good. In fact you were more thorough than we usually are 😅 |
|
You can ignore. I mistakenly thought that the way to return a disjoint/union range was by yielding each of its pieces. Then I noticed that it behaved wrong, tried to figure out why, in my flailing found docs indicating that the wrong |
Sorry, I didn't understand anything you said after "You can ignore". But I'm happy to leave it there 😄 |
Thanks for all the help. PTAL. Note the new commit message. |
Realized I failed to add this to the docs. Can't figure out in which section it belong, which is not a good sign. 😅 WDYT? |
We rely on VSCode's notion of visibility. Notable, folded code is not considered visible. The testing story is sad. There are two tests that I would like to have included. * Folded code. Unfortunately, the test runner does not recreate initial folded state, and it runs only one command at a time, so you can't fold-then-change. My attempts to upgrade the test runner to recreate initial folded state failed, and given that the test file format is changing anyway, it is probably not a good investment. * Offscreen content. This is the raison d'etre of the visible scope. Unfortunately, we don't know how large the viewport will be so there is no way to write a simple test using the existing infrastructure that will execute correctly. Fixes cursorless-dev#1607
"ss": "boundedNonWhitespaceSequence", | ||
"sa": "argumentOrParameter", | ||
"sl": "url", | ||
"vz": "visible", |
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.
The v
key is already used for the curve
shape below, so this will need to use a different key sequence.
"short paint": "boundedNonWhitespaceSequence", | ||
"link": "url", | ||
"cell": "notebookCell", | ||
"visible": "visible", |
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.
visible
is being added next to document
in other places. The same should be done here for consistency.
If I recall correctly, the decision was to implement this one as a modifier for now? Or just close until we understand it better? I'm fine either way |
yep, we're going to try it as a modifier. Still in my queue! |
@josharian You want me to take this one? Implementing this as a modifier should be easy. |
@AndreasArvidsson great! That’d be lovely. |
@josharian Your wish is my command ;) |
@AndreasArvidsson sudo make me a sandwich! |
Closing this. Thanks again, Andreas. |
You're very welcome :) |
Some progress! But definitely not working yet.
Very much :confused_dog: here. Would love some help,
ideally live at the next community meeting that I can attend.
No need to look at this in advance.
Things to discuss (notes to self):
scope, and it seems like that's what the code says,
but...vscode begs to differ. halp?
indicating that the range is not found
VSCode, which mean does not include folded or partially
visible lines. the value of visible is that it does
exactly what it says on the tin.
Fixes #1607