diff --git a/monaco-lsp-client/src/IDisposable.ts b/monaco-lsp-client/src/IDisposable.ts new file mode 100644 index 0000000000..00905499ac --- /dev/null +++ b/monaco-lsp-client/src/IDisposable.ts @@ -0,0 +1,75 @@ +export interface IDisposable { + dispose(): void; +} + +export class Disposable implements IDisposable { + static None = Object.freeze({ dispose() { } }); + + private _store = new DisposableStore(); + + constructor() { } + + public dispose(): void { + this._store.dispose(); + } + + protected _register(t: T): T { + if ((t as any) === this) { + throw new Error('Cannot register a disposable on itself!'); + } + return this._store.add(t); + } +} + +export class DisposableStore implements IDisposable { + static DISABLE_DISPOSED_WARNING = false; + + private _toDispose = new Set(); + private _isDisposed = false; + + public dispose(): void { + if (this._isDisposed) { + return; + } + + this._isDisposed = true; + this.clear(); + } + + public clear(): void { + if (this._toDispose.size === 0) { + return; + } + + try { + for (const item of this._toDispose) { + item.dispose(); + } + } finally { + this._toDispose.clear(); + } + } + + public add(t: T): T { + if (!t) { + return t; + } + if ((t as any) === this) { + throw new Error('Cannot register a disposable on itself!'); + } + + if (this._isDisposed) { + if (!DisposableStore.DISABLE_DISPOSED_WARNING) { + console.warn( + new Error( + 'Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!' + ).stack + ); + } + } else { + this._toDispose.add(t); + } + + return t; + } +} diff --git a/monaco-lsp-client/src/utils.ts b/monaco-lsp-client/src/utils.ts index 00905499ac..8b13789179 100644 --- a/monaco-lsp-client/src/utils.ts +++ b/monaco-lsp-client/src/utils.ts @@ -1,75 +1 @@ -export interface IDisposable { - dispose(): void; -} -export class Disposable implements IDisposable { - static None = Object.freeze({ dispose() { } }); - - private _store = new DisposableStore(); - - constructor() { } - - public dispose(): void { - this._store.dispose(); - } - - protected _register(t: T): T { - if ((t as any) === this) { - throw new Error('Cannot register a disposable on itself!'); - } - return this._store.add(t); - } -} - -export class DisposableStore implements IDisposable { - static DISABLE_DISPOSED_WARNING = false; - - private _toDispose = new Set(); - private _isDisposed = false; - - public dispose(): void { - if (this._isDisposed) { - return; - } - - this._isDisposed = true; - this.clear(); - } - - public clear(): void { - if (this._toDispose.size === 0) { - return; - } - - try { - for (const item of this._toDispose) { - item.dispose(); - } - } finally { - this._toDispose.clear(); - } - } - - public add(t: T): T { - if (!t) { - return t; - } - if ((t as any) === this) { - throw new Error('Cannot register a disposable on itself!'); - } - - if (this._isDisposed) { - if (!DisposableStore.DISABLE_DISPOSED_WARNING) { - console.warn( - new Error( - 'Trying to add a disposable to a DisposableStore that has already been disposed of. The added object will be leaked!' - ).stack - ); - } - } else { - this._toDispose.add(t); - } - - return t; - } -} diff --git a/package.json b/package.json index 52777cde3c..41d91cb5c5 100644 --- a/package.json +++ b/package.json @@ -1,4 +1,38 @@ { +<<<<<<< HEAD + "name": "monaco-editor", + "private": true, + "version": "0.9.0", + "description": "A browser based code editor", + "author": "Microsoft Corporation", + "license": "MIT", + "scripts": { + "simpleserver": "gulp simpleserver", + "release": "gulp release", + "website": "gulp website" + }, + "typings": "./monaco.d.ts", + "repository": { + "type": "git", + "url": "https://github.com/Microsoft/monaco-editor" + }, + "devDependencies": { + "clean-css": "^3.4.20", + "event-stream": "^3.3.2", + "gulp": "^3.9.1", + "gulp-typedoc": "^2.0.0", + "http-server": "^0.9.0", + "monaco-css": "1.3.2", + "monaco-editor-core": "0.9.0", + "monaco-html": "1.3.1", + "monaco-json": "1.3.1", + "monaco-languages": "0.8.0", + "monaco-typescript": "2.2.0", + "rimraf": "^2.5.2", + "typedoc": "^0.5.0", + "uncss": "^0.14.1" + } +======= "name": "monaco-editor", "version": "0.56.0", "vscodeRef": "f487add297079a02eb836810185b165e50cadabc", @@ -103,4 +137,5 @@ "process": false, "buffer": false } +>>>>>>> main }