( uri: vscode.Uri, node: Parser.SyntaxNode, ide: IDE, lang: AutocompleteLanguageInfo, )
| 226 | } |
| 227 | |
| 228 | export 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 | }, |
no test coverage detected