MCPcopy
hub / github.com/VSCodeVim/Vim / allMatches

Method allMatches

src/vimscript/pattern.ts:71–179  ·  view source on GitHub ↗

* Every range in the document that matches the search string. * * This might not be 100% complete - @see Pattern::MAX_SEARCH_RANGES

(
    vimState: VimState,
    args:
      | {
          fromPosition: Position;
        }
      | {
          lineRange: LineRange;
        },
  )

Source from the content-addressed store, hash-verified

69 * This might not be 100% complete - @see Pattern::MAX_SEARCH_RANGES
70 */
71 public allMatches(
72 vimState: VimState,
73 args:
74 | {
75 fromPosition: Position;
76 }
77 | {
78 lineRange: LineRange;
79 },
80 ): PatternMatch[] {
81 if (this.emptyBranch) {
82 // HACK: This pattern matches each character, but for purposes of perf when highlighting, merge them.
83 return [
84 {
85 range: TextEditor.getDocumentRange(vimState.document),
86 groups: [],
87 },
88 ];
89 }
90
91 let fromPosition: Position;
92 let lineRange:
93 | {
94 start: number;
95 end: number;
96 }
97 | undefined;
98 if ('lineRange' in args) {
99 // TODO: We should be able to get away with only getting part of the document text in this case
100 lineRange = args.lineRange.resolve(vimState);
101 fromPosition = new Position(lineRange.start, 0);
102 } else {
103 fromPosition = args.fromPosition;
104 }
105
106 let haystack: string;
107 let searchOffset: number;
108 let startOffset: number;
109 if (this.inSelection && vimState.lastVisualSelection) {
110 // TODO: This is not exactly how Vim implements in-selection search (\%V), see :help \%V for more info.
111 const searchRange = new Range(
112 vimState.lastVisualSelection.start,
113 vimState.lastVisualSelection.end,
114 );
115 haystack = vimState.document.getText(searchRange);
116 searchOffset = vimState.document.offsetAt(vimState.lastVisualSelection.start);
117 startOffset = searchRange.contains(fromPosition)
118 ? vimState.document.offsetAt(fromPosition) - searchOffset
119 : 0;
120 } else {
121 haystack = vimState.document.getText();
122 searchOffset = 0;
123 startOffset = vimState.document.offsetAt(fromPosition) - searchOffset;
124 }
125
126 this.regex.lastIndex = startOffset;
127
128 const start = Date.now();

Callers 3

executeWithRangeMethod · 0.80

Calls 5

getDocumentRangeMethod · 0.80
getTextMethod · 0.80
resolveMethod · 0.65
execMethod · 0.65
concatMethod · 0.45

Tested by

no test coverage detected