-
-
Notifications
You must be signed in to change notification settings - Fork 82
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
New representation for scope handler tests #1524
Comments
A few questions:
|
|
//!! scopeType: {type: value}
//!! languageId: typescript
const removalRange = getRelatedRange(match, scopeTypeType, "removal", true);
//! xxx^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//! ----------------------------------------------------------------------------
Mixed feelings. It will be extra noise I think, and while I do agree it can be unintuitive when you're just using Cursorless, in this case the leading / trailing are marked quite clearly visually. But easiest to just show them for now, and then see how annoying it is. If it feels like noise, I think just having a check if removalRange.isRangeEqual(
contentRange.union(trailingDelimiter ?? leadingDelimiter ?? contentRange)
); is easy to do, and should be fairly intuitive
Sounds good |
//!! scopeType: {type: value}
//!! languageId: typescript
const removalRange = getRelatedRange(match, scopeTypeType, "removal", true);
//! @@@^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//! xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
//! ---------------------------------------------------------------------------- |
Yeah fair. I'm happy with that |
I wonder if we should support a compact version of this syntax inside comments in our query definitions 🤔. Eg: (
[
;;!! const foo = "bar";
;;! ^^^
;;! ------------------
;;!! let foo = "bar";
;;! ^^^
;;! ----------------
(lexical_declaration
(variable_declarator
name: (_) @name
)
)
;;!! var foo = "bar";
;;! ^^^
;;! --------------
(variable_declaration
(variable_declarator
name: (_) @name
)
)
] @_.domain
(#not-parent-type? @_.domain export_statement)
;; Handle multiple variable declarators in one statement, eg
;;!! let aaa = "bbb", ccc = "ddd";
;;! ^^^ ^^^
;;! -----------------------------
(#allow-multiple! @name)
) where comments beginning with not sure we'd want all our tests to be inline like this, as it could get pretty verbose, eg for that final one we'd want to test edit: I made a draft of using these style comments in #1535. I didn't go all the way in that PR, because I wanted to preserve some of the convenient notations like edit: Maybe we could support indicating the scope type with something like the following? ;;!! function foo() {}
;;! ^^^^^^^^^^^^^^^^^ namedFunction
;;! ---------^^^----- functionName
(function_declaration
name: (_) @functionName
) @namedFunction @functionName.domain edit: It would be cool if there were some way to check that the match for that test case was actually coming from that pattern 🤔 |
See #1524 (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
Any thoughts about what to do about tabs that are part of ranges? There's no right answer about how many dashes/whatever to use under them. (Can discuss over voice if the answer is long.) |
Yes tabs continue to be the bane of our existence in cursorless. See eg I have no idea how to handle them tbh 😅. For some situations we could possibly read the tab width setting, as suggested here, but I don't think that helps us in this situation, as different users might have different settings, and we're baking in one setting to the recorded test. My instinct is to avoid tabs wherever possible in our tests, but that will potentially cause skew from real usage in the case of Go, where I'm guessing most users will be using tabs due to gofmt Very much open to ideas here |
The only "works always" fix that I am aware of is to fight tabs with tabs: allows tabs anywhere in ranges as a no-op, and put them below any real tabs so that the alignment is always preserved. But that creates all sorts of knock-on problems. Let's kick around a few ideas over voice sometime. |
terrible idea: replace tabs with:
|
not that it helps us, but elastic tab stops are nice: https://nick-gravgaard.com/elastic-tabstops/ |
Another annoying question. (Sorry, thinking through all this stuff a bit.) How will this representation represent comment scopes? The scope system will pick up the annotations as comments themselves... |
FWIW, I think the "fixed but inconvenient length" problem (how do you keep symbol-by-symbol alignment in the face of grapheme clusters) may be easier: use the correct number of zero-width spaces to preserve alignment. And yes, there's a opposite type of this category of problem, which is zero-width spaces in content. Maybe we can assume nobody uses those. 😅 |
That's what the |
We only want nested value scopes if there is more than one declarator in a statement. Before: <img width="186" alt="image" src="https://github.com/cursorless-dev/cursorless/assets/755842/0aaf4491-2c68-4be2-849d-ff5c72ac968a"> After: <img width="185" alt="image" src="https://github.com/cursorless-dev/cursorless/assets/755842/3058a007-73b0-48cc-81dd-6f5b126fa07a"> Unfortunately we have no good way to test this change until we have #1524 **Edit**: I found a way to test it, but it's a bit hacky. ## 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
We only want nested value scopes if there is more than one declarator in a statement. Before: <img width="186" alt="image" src="https://github.com/cursorless-dev/cursorless/assets/755842/0aaf4491-2c68-4be2-849d-ff5c72ac968a"> After: <img width="185" alt="image" src="https://github.com/cursorless-dev/cursorless/assets/755842/3058a007-73b0-48cc-81dd-6f5b126fa07a"> Unfortunately we have no good way to test this change until we have cursorless-dev#1524 **Edit**: I found a way to test it, but it's a bit hacky. ## 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
I have an idea for a really simple format to test scopes
example
An alternative format could be the code follow by a delimiter and then separate ranges. C=Content range, D=Domain etc...
Or even more verbose
Personally I'm quite partial to the last one. If the file only tests a single facet I see no need for them to be so terse. I also like that the indentation is the actual indentation from the code and there are no prefixes on the line. |
Me and @josharian just had discussion about my post above. We are both in agreement that the third and more verbose format is the way to go. We came up with a few thoughts.
|
Started implementing a new scope handler test representation ``` [Content] const name = "Hello world"; ^^^^^^^^^^^^^ ``` Originally I was thinking of doing `^` for each character. That worked fine until @pokey asked the question about empty ranges which we actually has in a few places. So I switch to a multiline representation of `[---]` where the empty range would be `[]`. ``` [Content] function myFunk() { [------------------- } -] ``` I do wonder if we want to start multiline ranges above the source code and end it below. Makes it so the code is actually inside the range endings. ``` [Content] [------------------- function myFunk() { } -] ``` Relevant issues #1524 #2010 ## 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 --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com> Co-authored-by: Pokey Rule <755842+pokey@users.noreply.github.com>
The problem
We need a better way to represent our test cases for scope handlers, because today we end up needing to record a bunch of commands to test edge cases, and the tests aren't easy to read. In addition, once #1523 is merged, we expect that most scope type development will be done by viewing the output of the scope visualizer, so we'd like test cases that mirror the scope visualizer as closely as possible
The solution
We'd like an ascii representation that is readable by humans and parsable by machine. The idea is as follows:
//
), followed by!
//
on the line below, so we couldn't point out the beginning of the line.{^^^}
[---]
(xxx)
<***>
interior
/leadingDelimiter
/trailingDelimiter
interior
is marked by/###\
leadingDelimiter
is marked by«@@@»
trailingDelimiter
is marked by§$$$¶
contentRange
, it does not get a line, as that is the implicit assumption{}
//!2
(or//!3
, etc). Note that ranges are overlapping even if they are 1 character apart, because otherwise there's no room for the bracketsisPreferredOver
; need special tests for thatComponents
{}
), as the internal markers (eg^^^
) are just for readabilityConsiderations
Examples
value
name
statement
namedFunction
collectionKey
token
Here are some alternative representations to consider:
Merge ranges onto one line
value
name
statement
namedFunction
collectionKey
token
Always surrounding brackets
value
name
statement
namedFunction
collectionKey
token
Internal markers on every line of range
value
,name
,statement
, andtoken
(as above)
namedFunction
collectionKey
No internal markers
value
name
statement
namedFunction
collectionKey
token
Using `.` to indicate whitespace
value
name
statement
namedFunction
collectionKey
token
Using `.` only where necessary
value
name
statement
namedFunction
collectionKey
token
Using markers only where necessary
value
name
statement
namedFunction
collectionKey
token
The text was updated successfully, but these errors were encountered: