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

Collection item scope provider #2683

Merged
merged 43 commits into from
Jan 13, 2025
Merged

Collection item scope provider #2683

merged 43 commits into from
Jan 13, 2025

Conversation

AndreasArvidsson
Copy link
Member

@AndreasArvidsson AndreasArvidsson commented Nov 19, 2024

Fixes #1059

Related #1052

Checklist

  • I have added tests
  • [/] I have updated the docs and cheatsheet
  • [/] I have not broken the cheatsheet

@AndreasArvidsson AndreasArvidsson requested a review from a team as a code owner November 19, 2024 13:25
@@ -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

Comment on lines +29 to 33
:bongo {
:foo "bar",
,
}
}
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.

@@ -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.

Comment on lines -32 to -33
;; hello
,
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



[#2 Range] = 1:4-1:19
>---------------<
Copy link
Member

Choose a reason for hiding this comment

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

This syntax is indicating where Cursorless might search for items (Andreas says: that's the definition of iteration scope), although not necessarily were they could be returned. The >/< are not part of the range.

[#1 Range] =
[#1 Domain] = 0:8-0:8
><
0| def foo():
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.

NB: this range is technically empty. We don't consider it worthwhile to omit empty ranges from this test file.

Andreas says: conceivably it could be useful to be able to bootstrap an empty list by saying "pour item" and targeting this range, so empty ranges are not necessarily useless.

1| global bar, baz


[#3 Range] = 1:11-1:19
Copy link
Member

Choose a reason for hiding this comment

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

NB: this is the old range from the language server, it's not marked as such, but you know because it's identical to the old code

Comment on lines +15 to +17
[#2 Domain] = 1:0-1:19
>-------------------<
1| global bar, baz
Copy link
Member

Choose a reason for hiding this comment

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

This domain is extra but we know from the previous code it will be eliminated when items are actually requested (global will be whittled away).

The intent of this type of test file is just to show the iteration search scopes, so this is proper.

@@ -2,12 +2,12 @@ import foo, bar
---

[#1 Content] =
[#1 Domain] = 0:7-0:10
>---<
[#1 Domain] = 0:0-0:10
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.

NB: 1 on the right side is new; the old 1 has become 2, the old 2 has become 3

The new one here is the extra scope generated by the textual source.

As above this won't actually change behavior because when items are actually specifically requested we are going to end up the same list, import won't be included

<


[#2 Range] = 1:4-1:6
Copy link
Member

Choose a reason for hiding this comment

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

NB: all of these ranges are from the textual source


[#1 Removal] = 0:1-0:4
>---<
0| [1, "2, 3"]
Copy link
Member

Choose a reason for hiding this comment

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

There is specific logic to discard stuff inside of strings (text fragments)

…andlers/CollectionItemScopeHandler/createTargetScope.ts
@phillco phillco enabled auto-merge January 13, 2025 18:16
@phillco phillco added this pull request to the merge queue Jan 13, 2025
Merged via the queue into main with commit d98bf09 Jan 13, 2025
15 checks passed
@phillco phillco deleted the collectionItemScopeProvider branch January 13, 2025 18:40
github-merge-queue bot pushed a commit that referenced this pull request Jan 28, 2025
Fix some of the clojure collection item regression from #2683

Related #2723


## Checklist

- [x] 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
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.

Migrate collectionItem to use a scope handler
2 participants