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AE,UAAU,EAAE,CAAM;IAE1C,IAAI,WAAW,IAAI,UAAU,EAAE,CAE9B;IAED,IAAI,WAAW,CAAC,WAAW,EAAE,UAAU,EAAE,EAIxC;IAED,OAAO,IAAI,IAAI;IAKf,kBAAkB,IAAI,IAAI;IAK1B,SAAS,CAAC,oBAAoB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI;CAKlE","file":"../../src/browser/monaco-diagnostic-collection.d.ts","sourcesContent":["/********************************************************************************\r\n * Copyright (C) 2020 TypeFox and others.\r\n *\r\n * This program and the accompanying materials are made available under the\r\n * terms of the Eclipse Public License v. 2.0 which is available at\r\n * http://www.eclipse.org/legal/epl-2.0.\r\n *\r\n * This Source Code may also be made available under the following Secondary\r\n * Licenses when the conditions for such availability set forth in the Eclipse\r\n * Public License v. 2.0 are satisfied: GNU General Public License, version 2\r\n * with the GNU Classpath Exception which is available at\r\n * https://www.gnu.org/software/classpath/license.html.\r\n *\r\n * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0\r\n ********************************************************************************/\r\n\r\nimport {Diagnostic} from 'vscode-languageserver-types';\r\nimport {Disposable, DisposableCollection} from '@tartjs/core/lib/common/disposable';\r\nimport {ProtocolToMonacoConverter} from './protocol-to-monaco-converter';\r\nimport IModel = monaco.editor.IModel;\r\nimport IMarkerData = monaco.editor.IMarkerData;\r\n\r\nexport class MonacoDiagnosticCollection implements Disposable {\r\n\r\n    protected readonly diagnostics = new Map<string, MonacoModelDiagnostics | undefined>();\r\n    protected readonly toDispose = new DisposableCollection();\r\n\r\n    constructor(\r\n        protected readonly name: string,\r\n        protected readonly p2m: ProtocolToMonacoConverter) {\r\n    }\r\n\r\n    dispose(): void {\r\n        this.toDispose.dispose();\r\n    }\r\n\r\n    get(uri: string): Diagnostic[] {\r\n        const diagnostics = this.diagnostics.get(uri);\r\n        return !!diagnostics ? diagnostics.diagnostics : [];\r\n    }\r\n\r\n    set(uri: string, diagnostics: Diagnostic[]): void {\r\n        const existing = this.diagnostics.get(uri);\r\n        if (existing) {\r\n            existing.diagnostics = diagnostics;\r\n        } else {\r\n            const modelDiagnostics = new MonacoModelDiagnostics(uri, diagnostics, this.name, this.p2m);\r\n            this.diagnostics.set(uri, modelDiagnostics);\r\n            this.toDispose.push(Disposable.create(() => {\r\n                this.diagnostics.delete(uri);\r\n                modelDiagnostics.dispose();\r\n            }));\r\n        }\r\n    }\r\n\r\n}\r\n\r\nexport class MonacoModelDiagnostics implements Disposable {\r\n    readonly uri: monaco.Uri;\r\n\r\n    constructor(\r\n        uri: string,\r\n        diagnostics: Diagnostic[],\r\n        readonly owner: string,\r\n        protected readonly p2m: ProtocolToMonacoConverter\r\n    ) {\r\n        this.uri = monaco.Uri.parse(uri);\r\n        this.diagnostics = diagnostics;\r\n        monaco.editor.onDidCreateModel(model => this.doUpdateModelMarkers(model));\r\n    }\r\n\r\n    protected _markers: IMarkerData[] = [];\r\n\r\n    get markers(): ReadonlyArray<IMarkerData> {\r\n        return this._markers;\r\n    }\r\n\r\n    protected _diagnostics: Diagnostic[] = [];\r\n\r\n    get diagnostics(): Diagnostic[] {\r\n        return this._diagnostics;\r\n    }\r\n\r\n    set diagnostics(diagnostics: Diagnostic[]) {\r\n        this._diagnostics = diagnostics;\r\n        this._markers = this.p2m.asDiagnostics(diagnostics);\r\n        this.updateModelMarkers();\r\n    }\r\n\r\n    dispose(): void {\r\n        this._markers = [];\r\n        this.updateModelMarkers();\r\n    }\r\n\r\n    updateModelMarkers(): void {\r\n        const model = monaco.editor.getModel(this.uri);\r\n        this.doUpdateModelMarkers(model ? model : undefined);\r\n    }\r\n\r\n    protected doUpdateModelMarkers(model: IModel | undefined): void {\r\n        if (model && this.uri.toString() === model.uri.toString()) {\r\n            monaco.editor.setModelMarkers(model, this.owner, this._markers);\r\n        }\r\n    }\r\n}\r\n"]}