MCPcopy Create free account
hub / github.com/deepnote/vscode-deepnote / getWordAtPosSlow

Function getWordAtPosSlow

src/test/datascience/wordHelper.ts:92–123  ·  view source on GitHub ↗
(
    column: number,
    wordDefinition: RegExp,
    text: string,
    textOffset: number
)

Source from the content-addressed store, hash-verified

90}
91
92function getWordAtPosSlow(
93 column: number,
94 wordDefinition: RegExp,
95 text: string,
96 textOffset: number
97): IWordAtPosition | null {
98 // matches all words starting at the beginning
99 // of the input until it finds a match that encloses
100 // the desired column. slow but correct
101
102 const pos = column - 1 - textOffset;
103 wordDefinition.lastIndex = 0;
104
105 let match: RegExpMatchArray | null = wordDefinition.exec(text);
106 while (match) {
107 const matchIndex = match.index || 0;
108 if (matchIndex > pos) {
109 // |nW -> matched only after the pos
110 return null;
111 } else if (wordDefinition.lastIndex >= pos) {
112 // W|W -> match encloses pos
113 return {
114 word: match[0],
115 startColumn: textOffset + 1 + matchIndex,
116 endColumn: textOffset + 1 + wordDefinition.lastIndex
117 };
118 }
119 match = wordDefinition.exec(text);
120 }
121
122 return null;
123}
124
125export function getWordAtText(
126 column: number,

Callers 1

getWordAtTextFunction · 0.85

Calls 1

execMethod · 0.65

Tested by

no test coverage detected