-
-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Properly handle trailing commas in python arguments (#2780)
Fixes #807 ## 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: Phil Cohen <phillip@phillip.io> Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
- Loading branch information
1 parent
62d49eb
commit 33e5368
Showing
11 changed files
with
143 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
def foo( | ||
aaa, | ||
bbb, | ||
): | ||
pass | ||
--- | ||
|
||
[#1 Content] = | ||
[#1 Domain] = 1:4-1:7 | ||
>---< | ||
1| aaa, | ||
|
||
[#1 Removal] = 1:4-2:4 | ||
>---- | ||
1| aaa, | ||
2| bbb, | ||
----< | ||
|
||
[#1 Trailing delimiter] = 1:7-2:4 | ||
>- | ||
1| aaa, | ||
2| bbb, | ||
----< | ||
|
||
[#1 Insertion delimiter] = ",\n" | ||
|
||
|
||
[#2 Content] = | ||
[#2 Domain] = 2:4-2:7 | ||
>---< | ||
2| bbb, | ||
|
||
[#2 Removal] = 1:7-2:7 | ||
>- | ||
1| aaa, | ||
2| bbb, | ||
-------< | ||
|
||
[#2 Leading delimiter] = 1:7-2:4 | ||
>- | ||
1| aaa, | ||
2| bbb, | ||
----< | ||
|
||
[#2 Trailing delimiter] = 2:7-2:8 | ||
>-< | ||
2| bbb, | ||
|
||
[#2 Insertion delimiter] = ",\n" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
...s-engine/src/processTargets/modifiers/scopeHandlers/util/getCollectionItemRemovalRange.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import type { Range, TextEditor } from "@cursorless/common"; | ||
|
||
import { getRangeLength } from "../../../../util/rangeUtils"; | ||
|
||
/** | ||
* Picks which of the leading and trailing delimiter ranges to use for removal when both are present. | ||
*/ | ||
export function getCollectionItemRemovalRange( | ||
isEveryScope: boolean, | ||
editor: TextEditor, | ||
contentRange: Range, | ||
leadingDelimiterRange: Range | undefined, | ||
trailingDelimiterRange: Range | undefined, | ||
): Range | undefined { | ||
if (isEveryScope) { | ||
// Force a fallback to the default behavior (often trailing) | ||
return undefined; | ||
} | ||
// If the leading one is longer/more specific, prefer to use that for removal | ||
if ( | ||
leadingDelimiterRange != null && | ||
trailingDelimiterRange != null && | ||
getRangeLength(editor, leadingDelimiterRange) > | ||
getRangeLength(editor, trailingDelimiterRange) | ||
) { | ||
return contentRange.union(leadingDelimiterRange); | ||
} | ||
return undefined; | ||
} |
10 changes: 10 additions & 0 deletions
10
...es/cursorless-engine/src/processTargets/modifiers/scopeHandlers/util/isHintsEveryScope.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import type { ScopeIteratorRequirements } from "../scopeHandler.types"; | ||
|
||
/** | ||
* Returns whether the hints belong to the every scope modifier. | ||
*/ | ||
export function isEveryScopeModifier( | ||
hints: ScopeIteratorRequirements, | ||
): boolean { | ||
return hints.containment == null && hints.skipAncestorScopes; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters