Skip to main content

Module: processTargets/modifiers/surroundingPair/findSurroundingPairTextBased

Functions

findSurroundingPairTextBased

findSurroundingPairTextBased(editor, range, allowableRange, delimiters, scopeType): null | SurroundingPairInfo

Implements the version of the surrounding pair finding algorithm that just looks at text. We use this algorithm when we are in a language for which we do not have parser support, or if we have parse tree support but the selection is in a string or comment.

The approach is to create a list of candidate delimiters in the given range, and then pass them to the core algorithm, implemented by findSurroundingPairCore.

To generate a list of delimiters to pass to findSurroundingPairCore, we run a regex on the entire range to find all delimiter texts, using a negative lookbehind to ensure they're not preceded by \.

The main drawbacks of the text-based approach are the following:

  • We can get confused by delimiters whose opening and closing symbol is the same (eg "). Without a parse tree we have to guess whether it is an opening or closing quote.
  • We need to parse the whole range from the start because otherwise it is difficult to handle the case where one delimiter text is a subset of another, eg " and \". We could handle this another way if performance becomes a bottleneck.
  • We cannot understand special features of a language, eg that f" is a form of opening quote in Python.

Parameters

NameTypeDescription
editorTextEditorThe text editor containing the selection
rangeRangeThe selection to find surrounding pair around
allowableRangenull | RangeThe range in which to look for delimiters, or the entire document if null
delimitersSimpleSurroundingPairName[]The acceptable surrounding pair names
scopeTypeSurroundingPairScopeType-

Returns

null | SurroundingPairInfo

The newly expanded selection, including editor info

Defined in

processTargets/modifiers/surroundingPair/findSurroundingPairTextBased.ts:67