问题部分中的VSCODE扩展堆叠输出
有人可以给我一个提示,为什么vScode多次运行时,Vscode在问题部分中堆放了输出(在我们的自制作Vscode扩展程序中,来自同一文本文件)?
类定义:
import { Uri, languages, Range, Diagnostic, Position, DiagnosticCollection } from "vscode";
export class ProblemHelper{
public rangeObj: Range | undefined;
public problemObj: Diagnostic | undefined;
public problemEntries: Array<Diagnostic> = [];
//public static diagnosticCollection: DiagnosticCollection;
constructor(actDocument: Uri| undefined,message: string, severity: number){
console.log("problemhelper const 0 " + this.problemEntries.length);
this.rangeObj = new Range(new Position(1,1),new Position(1,1) );
this.problemObj = new Diagnostic(this.rangeObj,message,severity );
this.problemObj.source = actDocument?.fsPath;
this.problemEntries.push(this.problemObj);
console.log("problemhelper const 1 " + this.problemEntries.length);
}
public setProblems(actDocument: Uri, coll: DiagnosticCollection, mess: string, sev: number) {
this.problemEntries.forEach(e => {
if (this.problemObj?.message === e.message) {
return;
}
});
this.rangeObj = new Range(new Position(1,1),new Position(1,1) );
this.problemObj = new Diagnostic(this.rangeObj,mess,sev );
this.problemEntries.push(this.problemObj);
console.log("problemhelper const 3 " + this.problemEntries.length);
coll.set(actDocument,this.problemEntries);
console.log("problemhelper const 4 " + coll.get(actDocument)?.length);
//ProblemHelper.diagnosticCollection!.set(actDocument,ProblemHelper.problemEntries);
}
public deleteProblems(actDocument: Uri | undefined, coll: DiagnosticCollection) {
console.log("in delete before " + this.problemEntries.length);
coll.delete(actDocument!);
this.problemEntries = [];
console.log("in delete after " + this.problemEntries.length);
//coll.dispose();
}
}
与:
const diagnosticCollection = languages.createDiagnosticCollection(window.activeTextEditor?.document.uri.fsPath);
let temp = new ProblemHelper(window.activeTextEditor?.document.uri,"test", 0);
temp.deleteProblems(window.activeTextEditor?.document.uri,diagnosticCollection);
temp.setProblems(window.activeTextEditor?.document.uri!,diagnosticCollection,"test1",1);
temp.setProblems(window.activeTextEditor?.document.uri!,diagnosticCollection,"test222",2);
console.log("end");
在调试控制台中输出(屏幕截图)来自“扩展开发主机”,可以看出正确的条目数量,但每次都会堆叠起来):
problemhelper const 0 0
problemhelper const 1 1
in delete before 1
in delete after 0
problemhelper const 3 1
problemhelper const 4 1
problemhelper const 3 2
problemhelper const 4 2
end
problemhelper const 0 0
problemhelper const 1 1
in delete before 1
in delete after 0
problemhelper const 3 1
problemhelper const 4 1
problemhelper const 3 2
problemhelper const 4 2
end
VSCODE版本:1.66.0(Win 10)
谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
非常感谢您,您是对的,我完成了两次新课程,所以我在Extension Startup上运行此课程,然后Do clear()而不是删除(xx)。现在我可以前进。
Thank you very much you are right, i made a new class twice, so i run this at extension startup, and do clear() instead of delete(xx). Now i can move forward.