Visual studio code Vscode扩展如何获取变量的值

Visual studio code Vscode扩展如何获取变量的值,visual-studio-code,vscode-extensions,Visual Studio Code,Vscode Extensions,到处寻找,但不确定如何完成这一壮举。我想做点像这样的事。当用户键入类似以下内容时: const hi = 'hello world'; #generate(hi) 并且用户高亮显示#generate(hi),用户可以运行set命令。此命令在扩展名中的编写方式如下: const generateCodeCommand = vscode.commands.registerCommand('extension.generateCode', () => { const editor =

到处寻找,但不确定如何完成这一壮举。我想做点像这样的事。当用户键入类似以下内容时:

const hi = 'hello world';

#generate(hi)
并且用户高亮显示#generate(hi),用户可以运行set命令。此命令在扩展名中的编写方式如下:

const generateCodeCommand = vscode.commands.registerCommand('extension.generateCode', () => {
    const editor = vscode.window.activeTextEditor;

    if (editor) {
        const document = editor.document;
        const selection = editor.selection;

        // get the word within the selection
        const word = document.getText(selection);
        console.log('this is the word', word);
    }
});

在这里,我设法抓住了单词“#generate(hi)”,但我希望通过“hi”引用抓住字符串“hello world”。有什么特别的方法可以做到这一点吗?

创建文件(或编译)的AST并执行到所选文本您知道关于如何实现的任何链接/示例吗?