bdiloreto
bdiloreto

Reputation: 274

In a VS Code extension, how can I identify all functions in a file, including anonymous functions that are assigned to a variable?

I call the command vscode.executeDocumentSymbolProvider to get the symbols in a file, but anonymous functions which are assigned to a variable are not reported as functions.

For example, in the following Typescript code, the variable functionVariable is reported by the Typescript language server as a variable, and there is no indication that it is a function.

const functionVariable = async (req: Request, res: Response) => {}

So how can I properly identify these variables as functions?

My current solution, which seems questionable, is to say that a variable is actually a function if it has child symbols which are not properties (as they would be if the symbol was an object or struct). Is there a better way?

Upvotes: 1

Views: 29

Answers (0)

Related Questions