|
@@ -163,6 +163,15 @@ enum DiagnosticCategory {
|
|
Message = 3
|
|
Message = 3
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * temporary interface until the editor API exposes
|
|
|
|
+ * `IModel.isAttachedToEditor` and `IModel.onDidChangeAttached`
|
|
|
|
+ */
|
|
|
|
+interface IInternalEditorModel extends editor.IModel {
|
|
|
|
+ onDidChangeAttached(listener: () => void): IDisposable;
|
|
|
|
+ isAttachedToEditor(): boolean;
|
|
|
|
+}
|
|
|
|
+
|
|
export class DiagnosticsAdapter extends Adapter {
|
|
export class DiagnosticsAdapter extends Adapter {
|
|
private _disposables: IDisposable[] = [];
|
|
private _disposables: IDisposable[] = [];
|
|
private _listener: { [uri: string]: IDisposable } = Object.create(null);
|
|
private _listener: { [uri: string]: IDisposable } = Object.create(null);
|
|
@@ -175,25 +184,52 @@ export class DiagnosticsAdapter extends Adapter {
|
|
) {
|
|
) {
|
|
super(worker);
|
|
super(worker);
|
|
|
|
|
|
- const onModelAdd = (model: editor.IModel): void => {
|
|
|
|
|
|
+ const onModelAdd = (model: IInternalEditorModel): void => {
|
|
if (model.getModeId() !== _selector) {
|
|
if (model.getModeId() !== _selector) {
|
|
return;
|
|
return;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ const maybeValidate = () => {
|
|
|
|
+ const { onlyVisible } = this._defaults.getDiagnosticsOptions();
|
|
|
|
+ if (onlyVisible) {
|
|
|
|
+ if (model.isAttachedToEditor()) {
|
|
|
|
+ this._doValidate(model);
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ this._doValidate(model);
|
|
|
|
+ }
|
|
|
|
+ };
|
|
|
|
+
|
|
let handle: number;
|
|
let handle: number;
|
|
const changeSubscription = model.onDidChangeContent(() => {
|
|
const changeSubscription = model.onDidChangeContent(() => {
|
|
clearTimeout(handle);
|
|
clearTimeout(handle);
|
|
- handle = setTimeout(() => this._doValidate(model), 500);
|
|
|
|
|
|
+ handle = setTimeout(maybeValidate, 500);
|
|
|
|
+ });
|
|
|
|
+
|
|
|
|
+ const visibleSubscription = model.onDidChangeAttached(() => {
|
|
|
|
+ const { onlyVisible } = this._defaults.getDiagnosticsOptions();
|
|
|
|
+ if (onlyVisible) {
|
|
|
|
+ if (model.isAttachedToEditor()) {
|
|
|
|
+ // this model is now attached to an editor
|
|
|
|
+ // => compute diagnostics
|
|
|
|
+ maybeValidate();
|
|
|
|
+ } else {
|
|
|
|
+ // this model is no longer attached to an editor
|
|
|
|
+ // => clear existing diagnostics
|
|
|
|
+ editor.setModelMarkers(model, this._selector, []);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
});
|
|
});
|
|
|
|
|
|
this._listener[model.uri.toString()] = {
|
|
this._listener[model.uri.toString()] = {
|
|
dispose() {
|
|
dispose() {
|
|
changeSubscription.dispose();
|
|
changeSubscription.dispose();
|
|
|
|
+ visibleSubscription.dispose();
|
|
clearTimeout(handle);
|
|
clearTimeout(handle);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
- this._doValidate(model);
|
|
|
|
|
|
+ maybeValidate();
|
|
};
|
|
};
|
|
|
|
|
|
const onModelRemoved = (model: editor.IModel): void => {
|
|
const onModelRemoved = (model: editor.IModel): void => {
|
|
@@ -205,12 +241,12 @@ export class DiagnosticsAdapter extends Adapter {
|
|
}
|
|
}
|
|
};
|
|
};
|
|
|
|
|
|
- this._disposables.push(editor.onDidCreateModel(onModelAdd));
|
|
|
|
|
|
+ this._disposables.push(editor.onDidCreateModel((model) => onModelAdd(<IInternalEditorModel>model)));
|
|
this._disposables.push(editor.onWillDisposeModel(onModelRemoved));
|
|
this._disposables.push(editor.onWillDisposeModel(onModelRemoved));
|
|
this._disposables.push(
|
|
this._disposables.push(
|
|
editor.onDidChangeModelLanguage((event) => {
|
|
editor.onDidChangeModelLanguage((event) => {
|
|
onModelRemoved(event.model);
|
|
onModelRemoved(event.model);
|
|
- onModelAdd(event.model);
|
|
|
|
|
|
+ onModelAdd(<IInternalEditorModel>event.model);
|
|
})
|
|
})
|
|
);
|
|
);
|
|
|
|
|
|
@@ -226,13 +262,13 @@ export class DiagnosticsAdapter extends Adapter {
|
|
// redo diagnostics when options change
|
|
// redo diagnostics when options change
|
|
for (const model of editor.getModels()) {
|
|
for (const model of editor.getModels()) {
|
|
onModelRemoved(model);
|
|
onModelRemoved(model);
|
|
- onModelAdd(model);
|
|
|
|
|
|
+ onModelAdd(<IInternalEditorModel>model);
|
|
}
|
|
}
|
|
};
|
|
};
|
|
this._disposables.push(this._defaults.onDidChange(recomputeDiagostics));
|
|
this._disposables.push(this._defaults.onDidChange(recomputeDiagostics));
|
|
this._disposables.push(this._defaults.onDidExtraLibsChange(recomputeDiagostics));
|
|
this._disposables.push(this._defaults.onDidExtraLibsChange(recomputeDiagostics));
|
|
|
|
|
|
- editor.getModels().forEach(onModelAdd);
|
|
|
|
|
|
+ editor.getModels().forEach((model) => onModelAdd(<IInternalEditorModel>model));
|
|
}
|
|
}
|
|
|
|
|
|
public dispose(): void {
|
|
public dispose(): void {
|