How do we find the definition of a variable using VSCode's Extensions API?

119 Views Asked by At

Is there a way to find the definition of a variable using VSCode's Extensions API for a TSX/TS project if the variable is defined in another file?

For example:

// file_1.tsx

const randomConstantVariable = "Hello World"
// file_2.tsx

import { randomConstantVariable } from "./someFile.ts"

console.log(randomConstantVariable)

I would like to access the definition of the randomConstantVariable in my Hover Provider when I'm working on file_2.tsx, but I'm not sure if there's an built-in way to do it using VSCode's Extensions API.

I tried using vscode.commands.executeCommand("vscode.workspaceSymbolProvider", "randomConstantVariable") but it can't seem to find file_1.tsx.

It seems like it's possible, since when I hover over a variable, VSCode is able to pick up the definition to display on the pop-up. I just wonder if this feature is somewhere in their API that I'm not seeing or if it's just built into VSCode but not exposed to the API.

0

There are 0 best solutions below