From b52ca1409748de2f00423472da613b4b981cafe2 Mon Sep 17 00:00:00 2001 From: Andreas Arvidsson Date: Mon, 16 Aug 2021 15:24:04 +0200 Subject: [PATCH] Fixed bug with array in pair value --- src/languages/python.ts | 2 +- src/nodeSelectors.ts | 10 +++--- .../languages/python/takeValueZero.yml | 33 +++++++++++++++++++ 3 files changed, 39 insertions(+), 6 deletions(-) create mode 100644 src/test/suite/fixtures/recorded/languages/python/takeValueZero.yml diff --git a/src/languages/python.ts b/src/languages/python.ts index cdd436b5e5..a95b7196f3 100644 --- a/src/languages/python.ts +++ b/src/languages/python.ts @@ -63,7 +63,7 @@ const nodeMatchers: Partial> = { "*[name]", ], collectionItem: argumentMatcher(...dictionaryTypes, ...listTypes), - value: valueMatcher("assignment[right]", "*[value]"), + value: valueMatcher("assignment[right]", "pair[value].*", "*[value]"), argumentOrParameter: argumentMatcher("parameters", "argument_list"), }; diff --git a/src/nodeSelectors.ts b/src/nodeSelectors.ts index a7fddb47ea..d1b88d8b38 100644 --- a/src/nodeSelectors.ts +++ b/src/nodeSelectors.ts @@ -40,12 +40,12 @@ export function selectWithLeadingDelimiter( editor: TextEditor, node: SyntaxNode ): SelectionWithContext { - const leadingDelimiterToken = node.previousSibling!; + const leadingDelimiterToken = node.previousSibling; - const leadingDelimiterRange = makeRange( - leadingDelimiterToken.startPosition, - node.startPosition - ); + const leadingDelimiterRange = + leadingDelimiterToken != null + ? makeRange(leadingDelimiterToken.startPosition, node.startPosition) + : null; return { ...simpleSelectionExtractor(editor, node), diff --git a/src/test/suite/fixtures/recorded/languages/python/takeValueZero.yml b/src/test/suite/fixtures/recorded/languages/python/takeValueZero.yml new file mode 100644 index 0000000000..90dd7d2f7e --- /dev/null +++ b/src/test/suite/fixtures/recorded/languages/python/takeValueZero.yml @@ -0,0 +1,33 @@ +spokenForm: take value zero +languageId: python +command: + actionName: setSelection + partialTargets: + - type: primitive + modifier: {type: containingScope, scopeType: value, includeSiblings: false} + mark: {type: decoratedSymbol, symbolColor: default, character: '0'} + extraArgs: [] +marks: + default.0: + start: {line: 1, character: 15} + end: {line: 1, character: 16} +initialState: + documentContents: |- + { + "foo": bar[0] + } + selections: + - anchor: {line: 0, character: 0} + active: {line: 0, character: 0} +finalState: + documentContents: |- + { + "foo": bar[0] + } + selections: + - anchor: {line: 1, character: 11} + active: {line: 1, character: 17} + thatMark: + - anchor: {line: 1, character: 11} + active: {line: 1, character: 17} +fullTargets: [{type: primitive, mark: {type: decoratedSymbol, symbolColor: default, character: '0'}, selectionType: token, position: contents, modifier: {type: containingScope, scopeType: value, includeSiblings: false}, insideOutsideType: inside}]