MCPcopy Index your code
hub / github.com/continuedev/continue / crawlTypes

Function crawlTypes

extensions/vscode/src/autocomplete/lsp.ts:146–226  ·  view source on GitHub ↗
(
  rif: RangeInFile | RangeInFileWithContents,
  ide: IDE,
  depth: number = 1,
  results: RangeInFileWithContents[] = [],
  searchedLabels: Set<string> = new Set(),
)

Source from the content-addressed store, hash-verified

144}
145
146async function crawlTypes(
147 rif: RangeInFile | RangeInFileWithContents,
148 ide: IDE,
149 depth: number = 1,
150 results: RangeInFileWithContents[] = [],
151 searchedLabels: Set<string> = new Set(),
152): Promise<RangeInFileWithContents[]> {
153 // Get the file contents if not already attached
154 const contents = isRifWithContents(rif)
155 ? rif.contents
156 : await ide.readFile(rif.filepath);
157
158 // Parse AST
159 const ast = await getAst(rif.filepath, contents);
160 if (!ast) {
161 return results;
162 }
163 const astLineCount = ast.rootNode.text.split("\n").length;
164
165 // Find type identifiers
166 const identifierNodes = findTypeIdentifiers(ast.rootNode).filter(
167 (node) => !searchedLabels.has(node.text),
168 );
169 // Don't search for the same type definition more than once
170 // We deduplicate below to be sure, but this saves calls to the LSP
171 identifierNodes.forEach((node) => searchedLabels.add(node.text));
172
173 // Use LSP to get the definitions of those types
174 const definitions = [];
175
176 for (const node of identifierNodes) {
177 const [typeDef] = await executeGotoProvider({
178 uri: vscode.Uri.parse(rif.filepath),
179 // TODO: tree-sitter is zero-indexed, but there seems to be an off-by-one
180 // error at least with the .ts parser sometimes
181 line:
182 rif.range.start.line +
183 Math.min(node.startPosition.row, astLineCount - 1),
184 character: rif.range.start.character + node.startPosition.column,
185 name: "vscode.executeDefinitionProvider",
186 });
187
188 if (!typeDef) {
189 definitions.push(undefined);
190 continue;
191 }
192
193 const contents = await ide.readRangeInFile(typeDef.filepath, typeDef.range);
194
195 definitions.push({
196 ...typeDef,
197 contents,
198 });
199 }
200
201 // TODO: Filter out if not in our code?
202
203 // Filter out duplicates

Callers 1

getDefinitionsForNodeFunction · 0.85

Calls 9

getAstFunction · 0.90
intersectionFunction · 0.90
isRifWithContentsFunction · 0.85
findTypeIdentifiersFunction · 0.85
executeGotoProviderFunction · 0.85
readFileMethod · 0.65
addMethod · 0.65
pushMethod · 0.65
readRangeInFileMethod · 0.65

Tested by

no test coverage detected