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

Function getWordAtPosFast

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

Source from the content-addressed store, hash-verified

62}
63
64function getWordAtPosFast(
65 column: number,
66 wordDefinition: RegExp,
67 text: string,
68 textOffset: number
69): IWordAtPosition | null {
70 // find whitespace enclosed text around column and match from there
71
72 const pos = column - 1 - textOffset;
73 const start = text.lastIndexOf(' ', pos - 1) + 1;
74
75 wordDefinition.lastIndex = start;
76 let match: RegExpMatchArray | null = wordDefinition.exec(text);
77 while (match) {
78 const matchIndex = match.index || 0;
79 if (matchIndex <= pos && wordDefinition.lastIndex >= pos) {
80 return {
81 word: match[0],
82 startColumn: textOffset + 1 + matchIndex,
83 endColumn: textOffset + 1 + wordDefinition.lastIndex
84 };
85 }
86 match = wordDefinition.exec(text);
87 }
88
89 return null;
90}
91
92function getWordAtPosSlow(
93 column: number,

Callers 1

getWordAtTextFunction · 0.85

Calls 1

execMethod · 0.65

Tested by

no test coverage detected