Skip to content

Collection item scope provider #2683

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

Merged
merged 43 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
7ad0871
Started working on collection item scope provider
AndreasArvidsson Nov 18, 2024
670afa8
More work
AndreasArvidsson Nov 18, 2024
3acc3a0
Added iteration handler
AndreasArvidsson Nov 18, 2024
d88f370
fix
AndreasArvidsson Nov 18, 2024
9e83dad
Update removal range
AndreasArvidsson Nov 18, 2024
a1c3909
ignore delimiters in string
AndreasArvidsson Nov 18, 2024
3ff0843
Updates
AndreasArvidsson Nov 18, 2024
499f922
Remove old the tests
AndreasArvidsson Nov 18, 2024
e4e8d7b
Merge branch 'main' into collectionItemScopeProvider
AndreasArvidsson Nov 18, 2024
2896e13
Added one off
AndreasArvidsson Nov 18, 2024
2ba4434
Don't yield iteration scope missing delimiters
AndreasArvidsson Nov 19, 2024
45c045b
Update rust
AndreasArvidsson Nov 19, 2024
3b959ae
Update ruby
AndreasArvidsson Nov 19, 2024
ded5c79
Update ruby
AndreasArvidsson Nov 19, 2024
7fb6dc6
Updates support
AndreasArvidsson Nov 19, 2024
78ebe56
Update latex
AndreasArvidsson Nov 19, 2024
99aa3d0
Cleanup latex
AndreasArvidsson Nov 19, 2024
0004e98
Update closuje
AndreasArvidsson Nov 19, 2024
a25d329
Reorder handlers
AndreasArvidsson Nov 19, 2024
4298d59
Update tests
AndreasArvidsson Nov 19, 2024
7630ea1
Added last yielded index
AndreasArvidsson Nov 20, 2024
1ae5c32
Added scope tests
AndreasArvidsson Nov 20, 2024
a390a19
Merge branch 'main' into collectionItemScopeProvider
AndreasArvidsson Dec 13, 2024
295e872
Rename delimiter to separators
AndreasArvidsson Dec 13, 2024
d9c1937
Added fall back and conditional scope handlers
AndreasArvidsson Dec 14, 2024
2b92a3d
Merge branch 'main' into collectionItemScopeProvider
AndreasArvidsson Dec 14, 2024
956d707
Bug fix
AndreasArvidsson Dec 14, 2024
b56f753
Update fixtures
AndreasArvidsson Dec 14, 2024
56172e3
Refactor add scopes
AndreasArvidsson Dec 14, 2024
b4e5b97
Moved iteration scope to separate file
AndreasArvidsson Dec 21, 2024
23ecc35
Extract get interior ranges to separate file
AndreasArvidsson Dec 21, 2024
ff8d1d4
Refactor
AndreasArvidsson Dec 21, 2024
cc6092d
Added tree
AndreasArvidsson Dec 21, 2024
90254ce
Tree fix
AndreasArvidsson Dec 21, 2024
794449a
Added comments
AndreasArvidsson Dec 21, 2024
da66455
Clean up
AndreasArvidsson Dec 22, 2024
e61b532
Merge branch 'main' into collectionItemScopeProvider
AndreasArvidsson Jan 8, 2025
951b947
Merge with main
AndreasArvidsson Jan 8, 2025
e3635ba
Update packages/cursorless-engine/src/processTargets/modifiers/scopeH…
phillco Jan 12, 2025
0333308
Update packages/cursorless-engine/src/processTargets/modifiers/scopeH…
phillco Jan 13, 2025
37107fc
Added changelog
AndreasArvidsson Jan 13, 2025
d7031b6
Update changelog/2025-01-addedCollectionItemScopeProvider.md
phillco Jan 13, 2025
78a4516
[pre-commit.ci lite] apply automatic fixes
pre-commit-ci-lite[bot] Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changelog/2025-01-addedCollectionItemScopeProvider.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
tags: [enhancement]
pullRequest: 2683
---

At long last, collection items have been migrated to our next generation scope framework! This means, within a list of items, you can now use relative navigation (`previous item`), absolute navigation via ordinals (`fifth item`), multiple selection (`two items`, optionally preceded with `previous` or `next`), and lastly, requesting multiple items to be individually selected via `every` (`every two items`)!
31 changes: 0 additions & 31 deletions data/fixtures/recorded/itemTextual/chuckItem4.yml

This file was deleted.

25 changes: 0 additions & 25 deletions data/fixtures/recorded/itemTextual/clearEveryItemToken.yml

This file was deleted.

23 changes: 0 additions & 23 deletions data/fixtures/recorded/itemTextual/clearItem10.yml

This file was deleted.

23 changes: 0 additions & 23 deletions data/fixtures/recorded/itemTextual/clearItem11.yml

This file was deleted.

23 changes: 0 additions & 23 deletions data/fixtures/recorded/itemTextual/clearItem13.yml

This file was deleted.

23 changes: 0 additions & 23 deletions data/fixtures/recorded/itemTextual/clearItem14.yml

This file was deleted.

23 changes: 0 additions & 23 deletions data/fixtures/recorded/itemTextual/clearItem6.yml

This file was deleted.

27 changes: 0 additions & 27 deletions data/fixtures/recorded/itemTextual/clearItemDrip.yml

This file was deleted.

6 changes: 2 additions & 4 deletions data/fixtures/recorded/languages/clojure/chuckItemZip.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ finalState:
documentContents: |-
{
:foo "bar",
;; hello
,
Comment on lines -32 to -33
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as the other ones

}
selections:
- anchor: {line: 4, character: 1}
active: {line: 4, character: 1}
- anchor: {line: 2, character: 1}
active: {line: 2, character: 1}
5 changes: 2 additions & 3 deletions data/fixtures/recorded/languages/clojure/clearEveryItem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ finalState:

{
,
;; hello
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NTS: This is an example of the new code performing worse, but we understand why. This is because textual scope defines the item as:

;; hello
:baz "whatever",

In this case the language does identify that the comment is not part of the item, but we are preferring the textual scope, and as above, we no longer blind take the language server's view.

This will affect every language will you have an inline comment next to an item, we just don't have many tests in our more common languages that show that. There's an issue for improving the handling of comments around items. (Might be #1770?). It's a complex change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NB: the newer code uses more queries and predicates and less imperative TypeScript, so it's also something that would have been easier to monkey patch in the older code, although arguably, for a worse long term outcome

,
}
selections:
- anchor: {line: 2, character: 4}
active: {line: 2, character: 4}
- anchor: {line: 4, character: 4}
active: {line: 4, character: 4}
- anchor: {line: 3, character: 4}
active: {line: 3, character: 4}
9 changes: 6 additions & 3 deletions data/fixtures/recorded/languages/clojure/clearItem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,11 @@ initialState:
finalState:
documentContents: |-
{

:bongo {
:foo "bar",
,
}
}
Comment on lines +29 to 33
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NTS: the old behavior was interesting: the cursor was on the comment so presumably the language server returned the entire :bongo item as the "item".

With the new behavior the textual scope includes the comment as part of the next item (see other thread), which is generally slightly worse, but in this case leads to a better outcome.

selections:
- anchor: {line: 1, character: 4}
active: {line: 1, character: 4}
- anchor: {line: 3, character: 8}
active: {line: 3, character: 8}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ initialState:
start: {line: 0, character: 2}
end: {line: 0, character: 5}
finalState:
documentContents: "{ :baz \"whatever\"}"
documentContents: "{}"
Copy link
Member

@phillco phillco Jan 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NTS: this outcome is worse but there's not much we can do about it at the current time. Problem is that closure does not use explicit list delimiters and the textual base system can obviously not figure out if a space is part of an item or a separator here. The textual system thinks the entire :foo "bar" :baz "whatever" is one "item".

Andreas' idea: allow a language to specify whether it uses explicit delimiters for lists, and if it does not, go back to the old implementation of always taking the language servers opinion.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

selections:
- anchor: {line: 0, character: 1}
active: {line: 0, character: 1}
6 changes: 3 additions & 3 deletions data/fixtures/recorded/languages/rust/changeItemOne.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ initialState:
end: {line: 0, character: 21}
finalState:
documentContents: |
let x = [None, ];
let x = [None, Some()];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NTS: this is an expected change because of way we evaluate the textual and language sources with the change. Previously the language source would always be used if it was available; now we use both (OneOf...) and compare the text ranges as a heuristic.

In this situation the language server says Some(1) is the item, the textual definition says 1 is the item, and we prefer that because of the nuances in this algorithm, which can frequently prefer the shorter range:

(A related example, with the roles reversed, in Python; import x, y, z, the language server will not include the import keyword; the original textual range would think import x is the first item.). The comparison is applied to each item.

This existing comparison logic is already used by all the other scope providers, such as surrounding pairs, so it's pretty well tested. There will be other cases where this changes though since legacy scopes were using a much simpler algorithm that iterates forward and returns the first containing item. This is not a design decision in this change, everything that uses the next generation scope providers uses this comparison function.

NB: Andreas says the Rust language definition possibly shouldn't even have a list item provider, because they're only necessary when the textual definition isn't sufficient (i.e., unusual delimiters); it's not clear why it is necessary but the language definition was provided by a contributor so we're not sure.

selections:
- anchor: {line: 0, character: 15}
active: {line: 0, character: 15}
- anchor: {line: 0, character: 20}
active: {line: 0, character: 20}
27 changes: 0 additions & 27 deletions data/fixtures/recorded/languages/typescript/takeItem4.yml

This file was deleted.

31 changes: 0 additions & 31 deletions data/fixtures/recorded/languages/typescript/takeItemComma.yml

This file was deleted.

Loading
Loading