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

Function getDefinitionsForNode

extensions/vscode/src/autocomplete/lsp.ts:228–358  ·  view source on GitHub ↗
(
  uri: vscode.Uri,
  node: Parser.SyntaxNode,
  ide: IDE,
  lang: AutocompleteLanguageInfo,
)

Source from the content-addressed store, hash-verified

226}
227
228export async function getDefinitionsForNode(
229 uri: vscode.Uri,
230 node: Parser.SyntaxNode,
231 ide: IDE,
232 lang: AutocompleteLanguageInfo,
233): Promise<RangeInFileWithContents[]> {
234 const ranges: (RangeInFile | RangeInFileWithContents)[] = [];
235 switch (node.type) {
236 case "call_expression": {
237 // function call -> function definition
238 const [funDef] = await executeGotoProvider({
239 uri,
240 line: node.startPosition.row,
241 character: node.startPosition.column,
242 name: "vscode.executeDefinitionProvider",
243 });
244 if (!funDef) {
245 return [];
246 }
247
248 // Don't display a function of more than 15 lines
249 // We can of course do something smarter here eventually
250 let funcText = await ide.readRangeInFile(funDef.filepath, funDef.range);
251 if (funcText.split("\n").length > 15) {
252 let truncated = false;
253 const funRootAst = await getAst(funDef.filepath, funcText);
254 if (funRootAst) {
255 const [funNode] = findChildren(
256 funRootAst?.rootNode,
257 (node) => FUNCTION_DECLARATION_NODE_TYPEs.includes(node.type),
258 1,
259 );
260 if (funNode) {
261 const [statementBlockNode] = findChildren(
262 funNode,
263 (node) => FUNCTION_BLOCK_NODE_TYPES.includes(node.type),
264 1,
265 );
266 if (statementBlockNode) {
267 funcText = funRootAst.rootNode.text
268 .slice(0, statementBlockNode.startIndex)
269 .trim();
270 truncated = true;
271 }
272 }
273 }
274 if (!truncated) {
275 funcText = funcText.split("\n")[0];
276 }
277 }
278
279 ranges.push(funDef);
280
281 const typeDefs = await crawlTypes(
282 {
283 ...funDef,
284 contents: funcText,
285 },

Callers 2

expandSnippetFunction · 0.90
getDefinitionsFromLspFunction · 0.85

Calls 7

getAstFunction · 0.90
executeGotoProviderFunction · 0.85
findChildrenFunction · 0.85
crawlTypesFunction · 0.85
isRifWithContentsFunction · 0.85
readRangeInFileMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected