-
-
Notifications
You must be signed in to change notification settings - Fork 91
Properly handle trailing commas in python arguments #2780
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
Changes from 21 commits
97adc6b
2033b64
63847e9
07371d1
64659ed
172f7e9
34b22e2
432b71a
32eb477
b9c65c2
f7b6f8c
0fcb122
d212a20
8fd363d
a77845d
5390679
97ea33a
b122965
45ee6a6
e0a02ab
e272358
5a5a723
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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" |
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) | ||
Check failure on line 16 in packages/cursorless-engine/src/processTargets/modifiers/scopeHandlers/util/getCollectionItemRemovalRange.ts
|
||
return undefined; | ||
} | ||
phillco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// 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; | ||
phillco marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} |
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; | ||
} |
Uh oh!
There was an error while loading. Please reload this page.