未验证 提交 59a81918 编写于 作者: A Alex Dima

Handle case where the text model is disposed while semantic tokens computation takes place

上级 5eaf74f5
...@@ -455,6 +455,7 @@ class SemanticColoringFeature extends Disposable { ...@@ -455,6 +455,7 @@ class SemanticColoringFeature extends Disposable {
class ModelSemanticColoring extends Disposable { class ModelSemanticColoring extends Disposable {
private _isDisposed: boolean;
private readonly _model: ITextModel; private readonly _model: ITextModel;
private readonly _fetchSemanticTokens: RunOnceScheduler; private readonly _fetchSemanticTokens: RunOnceScheduler;
private _currentResponse: SemanticColoring | null; private _currentResponse: SemanticColoring | null;
...@@ -463,6 +464,7 @@ class ModelSemanticColoring extends Disposable { ...@@ -463,6 +464,7 @@ class ModelSemanticColoring extends Disposable {
constructor(model: ITextModel) { constructor(model: ITextModel) {
super(); super();
this._isDisposed = false;
this._model = model; this._model = model;
this._fetchSemanticTokens = this._register(new RunOnceScheduler(() => this._fetchSemanticTokensNow(), 500)); this._fetchSemanticTokens = this._register(new RunOnceScheduler(() => this._fetchSemanticTokensNow(), 500));
this._currentResponse = null; this._currentResponse = null;
...@@ -474,6 +476,7 @@ class ModelSemanticColoring extends Disposable { ...@@ -474,6 +476,7 @@ class ModelSemanticColoring extends Disposable {
} }
public dispose(): void { public dispose(): void {
this._isDisposed = true;
if (this._currentResponse) { if (this._currentResponse) {
this._currentResponse.dispose(); this._currentResponse.dispose();
this._currentResponse = null; this._currentResponse = null;
...@@ -513,6 +516,13 @@ class ModelSemanticColoring extends Disposable { ...@@ -513,6 +516,13 @@ class ModelSemanticColoring extends Disposable {
this._currentResponse.dispose(); this._currentResponse.dispose();
this._currentResponse = null; this._currentResponse = null;
} }
if (this._isDisposed) {
// disposed!
if (tokens) {
tokens.dispose();
}
return;
}
this._currentResponse = tokens; this._currentResponse = tokens;
if (!this._currentResponse) { if (!this._currentResponse) {
this._model.setSemanticTokens(null); this._model.setSemanticTokens(null);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册