javascript - VSCode 扩展在调试时工作,但一旦打包到 VSIX 中就不行
问题描述
我试图学习一些关于为 vscode 构建扩展的知识,但我遇到了障碍。我的扩展只应该根据文件类型从剪贴板粘贴一些额外的文本。(用于快速调试)问题是我在调试时有这个工作但是一旦它被打包我得到一个rejected promise not handled within 1 second: Error: TextEditor#edit not possible on closed editors
这对我来说很有意义,但我不知道如何保持 activeTextEditor 的更新,也不知道为什么打包后它的行为会有所不同。我肯定错过了一些简单的东西。
function activate(context) {
const dbugText = vscode.commands.registerCommand('extension.dbug', () => {
vscode.env.clipboard.readText().then((text) => {
let editor = vscode.window.activeTextEditor;
if(!editor){
return;
}
var document = editor.document;
var selection = editor.selection;
var fileType = document.fileName.split('.')[1];
console.log(text);
if (fileType == 'php') {
text = "dbug(" + text + ");";
} else if (fileType == 'js') {
text = "console.log(" + text + ");";
} else {
console.log('Unknown file type');
return;
}
vscode.window.showInformationMessage(text);
editor.edit((editBuilder) => {
return editBuilder.insert(new vscode.Position(selection.start.line, selection.start.character), text);
})
.catch(err => console.error(err.message));
})
.catch(err => console.error(err.message));
});
context.subscriptions.push(dbugText);
}
解决方案
推荐阅读
- python - setup.py 中的 package_dir 未按预期工作
- batch-file - 将变量从一个批处理文件发送到另一个批处理文件时如何避免累积
- javascript - javascript 为什么我不能使用 javascript 函数将子元素附加到 html div
- php - Laravel 中带小时的摘要分钟
- python - 从 GitBash 执行 pytest
- java - 获取 SQL Server 连接异常
- vb.net - For 循环超出范围
- python - 有效搜索元组的一部分是否存在于元组列表中
- mariadb - 是否可以删除 MariaDB 上的提示历史记录?
- arrays - 重构代码以惯用的方式使用单个通道