VSCode插件开发,onDidChangeActiveTextEditor和onDidOpenTextDocument不触发问题如何解决?

通过ai问答vscode,实现打开文件后触发和切换标签页触发弹出消息框,根据ai提供的代码编写,但是没有达到期望效果,期望效果是vscode打开文件后,切换标签,弹出消息框,显示设置的内容

初次进行vscode 插件开发尝试,先从实现打开文件后触发和切换标签页触发弹出消息框开始,通过chat的ai问答得知可以通过onDidChangeActiveTextEditor和onDidOpenTextDocument分别做到标签页切换和打开文件后进行触发

extension代码如下

// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
const vscode = require('vscode');

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed

/**
 * @param {vscode.ExtensionContext} context
 */
function activate(context) {


    //切换标签页
    let disposable1 = vscode.window.onDidChangeActiveTextEditor((editor) => {
        if (editor) {
            vscode.window.showInformationMessage('Tab switched!');
        }
    });

    let disposable2 = vscode.workspace.onDidOpenTextDocument((document) => {
        vscode.window.showInformationMessage('File opened!');
    });

    context.subscriptions.push(disposable1, disposable2);

}

// This method is called when your extension is deactivated
function deactivate() {}

module.exports = {
    activate,
    deactivate
}

package.json文件部分内容

"activationEvents": [
    "onDidChangeActiveTextEditor",
    "onDidOpenTextDocument"
  ],

运行测试,没有效果,切换标签页和打开文件后没有出现消息框弹出,这个是怎么回事?是哪里没配置对?

阅读 1.2k
1 个回答
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题
logo
Microsoft
子站问答
访问
宣传栏