MCPcopy Create free account
hub / github.com/APKLab/APKLab / searchFunctionSegment

Function searchFunctionSegment

src/tools/quark-engine.ts:144–175  ·  view source on GitHub ↗

* Find a specific function in the segment of the given text document. * @param doc The text document from source code file. * @param functionName a string of the function name * @return The function start-line and end-line, return false if not found.

(
    doc: vscode.TextDocument,
    functionName: string,
)

Source from the content-addressed store, hash-verified

142 * @return The function start-line and end-line, return false if not found.
143 */
144function searchFunctionSegment(
145 doc: vscode.TextDocument,
146 functionName: string,
147): number[] | false {
148 const lineCount = doc.lineCount;
149 let foundMethod = false;
150
151 let startLine = -1;
152 let endLine = -1;
153
154 for (let lineNumber = 0; lineNumber < lineCount; lineNumber++) {
155 const lineText = doc.lineAt(lineNumber);
156
157 if (
158 lineText.text.includes(functionName) &&
159 lineText.text.includes(".method")
160 ) {
161 startLine = lineNumber;
162 foundMethod = true;
163 }
164
165 if (foundMethod && lineText.text.includes(".end method")) {
166 endLine = lineNumber;
167 foundMethod = false;
168 }
169 }
170 if ((startLine == -1 && endLine == -1) || startLine >= endLine) {
171 return false;
172 }
173
174 return [startLine, endLine];
175}
176
177/**
178 * Search the position where API called in the given document segment.

Callers 1

navigateSourceCodeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected