Это ide на основе vs code(code oss), в ней будет встроенный умный апи роутинг, свой маркет с плагинами(агент харнесс, поддержка java/kotlin/мобильной разработки, командная разработка проектов, orca, оркестратор агентов
//!!! DO NOT modify, this file was COPIED from 'microsoft/vscode'/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/import{ compareBy, numberComparator }from'./arrays';import{ groupBy }from'./collections';import{ SetMap, ResourceMap }from'./map';import{URI}from'./uri';import{ createSingleCallFunction }from'./functional';import{ Iterable }from'./iterator';import{ BugIndicatingError, onUnexpectedError }from'./errors';
disposableTracker IDisposableTracker
disposable IDisposable
child IDisposable parent IDisposable
disposable IDisposable
disposable IDisposable
_registry heldValue
disposable IDisposable
stack stack
_registrydisposable stack disposable
child IDisposable parent IDisposable
parent
_registrychild
child
disposable IDisposable
_registrydisposable
disposable IDisposable
_registrydisposable
value IDisposable
source
parent IDisposable
isSingleton
idx
idx
livingDisposables
d IDisposable DisposableInfo
val livingDisposablesd
val
val parent source isSingleton value d idx DisposableTrackeridx
livingDisposablesd val
val
d IDisposable
data d
datasource
datasource
stack
child IDisposable parent IDisposable
data child
dataparent parent
x IDisposable
livingDisposablesx
disposable IDisposable
disposableisSingleton
data DisposableInfo cache MapDisposableInfo DisposableInfo DisposableInfo
cacheValue cachedata
cacheValue
cacheValue
result dataparent dataparent cache data
cachedata result
result
IDisposable
rootParentCache
leaking livingDisposables
v vsource v rootParentCacheisSingleton
k k
leaking
maxReported preComputedLeaks DisposableInfo leaks DisposableInfo details
uncoveredLeakingObjs DisposableInfo
preComputedLeaks
uncoveredLeakingObjs preComputedLeaks
rootParentCache
leakingObjects livingDisposables
info infosource info rootParentCacheisSingleton
leakingObjectslength
leakingObjsSet leakingObjectso ovalue
uncoveredLeakingObjs leakingObjectsl
lparent leakingObjsSetlparent
uncoveredLeakingObjslength
uncoveredLeakingObjs
leaking DisposableInfo
array linesToRemove RegExp
arraylength linesToRemoveregexp regexp regexp array arrayregexp
array
lines leakingsourcep p l l
lines
lines
stackTraceStarts
leaking uncoveredLeakingObjs
stackTracePath leaking
i i stackTracePathlength i
stackTraceStartsstackTracePath i leaking
uncoveredLeakingObjsl lidx numberComparator
message
i
leaking uncoveredLeakingObjs maxReported
i
stackTracePath leaking
stackTraceFormattedLines
i i stackTracePathlength i
line stackTracePathi
starts stackTraceStartsstackTracePath i
line
prevStarts stackTraceStartsstackTracePath i
continuations prevStartsd di v v
continuationsstackTracePathi
cont set Objectcontinuations
set
stackTraceFormattedLines
stackTraceFormattedLinesline
message
uncoveredLeakingObjslength maxReported
message
leaks uncoveredLeakingObjs details message
tracker IDisposableTracker
disposableTracker tracker
__is_disposable_tracked__
x IDisposable
stack stack
x __is_disposable_tracked__
stack
child IDisposable parent IDisposable
child child DisposableNone
child __is_disposable_tracked__
disposable IDisposable
disposable disposable DisposableNone
disposable __is_disposable_tracked__
disposable IDisposable
x
disposableTrackerx
x
disposable IDisposable
disposableTrackerdisposable
child IDisposable parent IDisposable
disposableTrackerchild parent
children IDisposable parent IDisposable
disposableTracker
child children
disposableTrackerchild parent
singleton
disposableTrackersingleton
singleton
thing thing IDisposable
thing thing IDisposablethingdispose IDisposablethingdisposelength
disposable
disposable
disposables
disposables
disposables ReadonlyArray ReadonlyArray
arg Iterable
Iterablearg
errors
d arg
d
d
e
errorse
errorslength
errors
errorslength
errors
arg arg
arg
arg
arg
disposables
d disposables
d
d
disposables IDisposable IDisposable
parent disposables
disposables parent
parent
_isDisposed
_isDisposed
_fn fn
_isDisposed
_fn
_isDisposed
IDisposable
fn
_toDispose
_isDisposed
_isDisposed
_isDisposed
_isDisposed
_toDisposesize
_toDispose
_toDispose
o
o o DisposableNone
o
o DisposableStore
o
_isDisposed
DisposableStore
stack
_toDisposeo
o
o
o
o DisposableStore
_toDisposeo
o
o
o
_toDisposeo
o
_isDisposed
None Object
_store
_store
_store
o
o Disposable
_storeo
_value
_isDisposed
_isDisposed _value
value
_isDisposed value _value
_value
value
value
_value value
value
_isDisposed
_value
_value
oldValue _value
_value
oldValue
oldValue
oldValue
_disposable
_isDisposed
initialValue
_disposablevalue initialValue
_disposablevalue
value
_isDisposed value _disposablevalue
_disposablevalue value
_isDisposed
_disposable
_counter
_disposable IDisposable
_counter
_counter
_disposable
object
references Map object counter
key args IReference
reference referenceskey
reference
reference counter object key args
referenceskey reference
object reference
dispose
referencecounter
key referenceobject
referenceskey
referencecounter
object dispose
key args
key object
referenceCollection ReferenceCollection
key args IReference
ref referenceCollectionkey args
object refobject
object
ref
error
ref
error
object
store DisposableStore
store
store
store
_store Map
_isDisposed
store Map
_store store
_isDisposed
_storesize
_store
_store
key
_storekey
_storesize
key
_storekey
key value skipDisposeOnOverwrite
_isDisposed
stack
skipDisposeOnOverwrite
_storekey
_storekey value
value
key
_storekey
_storekey
key
value _storekey
value
value
_storekey
value
IterableIterator
_store
IterableIterator
_store
Symboliterator IterableIterator
_storeSymboliterator
_store Set
_isDisposed
store Set
_store store
_isDisposed
_storesize
_store
_store
value
_storevalue
_storesize
value
_isDisposed
stack
_storevalue
value
value
_storevalue
value
value
_storevalue
value
value
IterableIterator
_store
Symboliterator IterableIterator
_storeSymboliterator
promise result IDisposable
disposed
promiseresult
disposed
result
disposed
promise store DisposableStore
promisedisposable
storeisDisposed
disposable
storedisposable
disposable
/**
* Enables logging of potentially leaked disposables.
*
* A disposable is considered leaked if it is not disposed or not registered as the child of
* another disposable. This tracking is very simple an only works for classes that either
* extend Disposable or use a DisposableStore. This means there are a lot of false positives.
*/
const
TRACK_DISPOSABLES
=
false
;
let
:
|
null
=
null
;
export
interface
IDisposableTracker
{
/**
* Is called on construction of a disposable.
*/
trackDisposable
(
:
)
:
void
;
/**
* Is called when a disposable is registered as child of another disposable (e.g. {@link DisposableStore}).
* If parent is `null`, the disposable is removed from its former parent.
*/
setParent
(
:
,
:
|
null
)
:
void
;
/**
* Is called after a disposable is disposed.
*/
markAsDisposed
(
:
)
:
void
;
/**
* Indicates that the given object is a singleton which does not need to be disposed.
*/
markAsSingleton
(
:
)
:
void
;
}
export
class
GCBasedDisposableTracker
implements
IDisposableTracker
{
private
readonly
=
new
FinalizationRegistry<string>
(
=>
{
console
.
warn
(
`[LEAKED DISPOSABLE] ${heldValue}`
)
;
}
)
;
trackDisposable
(
:
)
:
void
{
const
=
new
Error
(
'CREATED via:'
)
.
!
;
this
.
.
register
(
,
,
)
;
}
setParent
(
:
,
:
|
null
)
:
void
{
if
(
)
{
this
.
.
unregister
(
)
;
}
else
{
this
.
trackDisposable
(
)
;
}
}
markAsDisposed
(
:
)
:
void
{
this
.
.
unregister
(
)
;
}
markAsSingleton
(
:
)
:
void
{
this
.
.
unregister
(
)
;
}
}
export
interface
DisposableInfo
{
:
;
:
string
|
null
;
:
|
null
;
:
boolean
;
:
number
;
}
export
class
DisposableTracker
implements
IDisposableTracker
{
private
static
=
0
;
private
readonly
=
new
Map<IDisposable, DisposableInfo>
(
)
;
private
getDisposableData
(
:
)
:
{
let
=
this
.
.
get
(
)
;
if
(
!
)
{
=
{
:
null
,
:
null
,
:
false
,
:
,
:
.
++
}
;
this
.
.
set
(
,
)
;
}
return
;
}
trackDisposable
(
:
)
:
void
{
const
=
this
.
getDisposableData
(
)
;
if
(
!
.
)
{
.
=
new
Error
(
)
.
!
;
}
}
setParent
(
:
,
:
|
null
)
:
void
{
const
=
this
.
getDisposableData
(
)
;
.
=
;
}
markAsDisposed
(
:
)
:
void
{
this
.
.
delete
(
)
;
}
markAsSingleton
(
:
)
:
void
{
this
.
getDisposableData
(
)
.
=
true
;
}
private
getRootParent
(
:
,
:
<
,
>
)
:
{
const
=
.
get
(
)
;
if
(
)
{
return
;
}
const
=
.
?
this
.
getRootParent
(
this
.
getDisposableData
(
.
)
,
)
:
;
.
set
(
,
)
;
return
;
}
getTrackedDisposables
(
)
:
[
]
{
const
=
new
Map<DisposableInfo, DisposableInfo>
(
)
;
const
=
[
...
this
.
.
entries
(
)
]
.
filter
(
(
[
,
]
)
=>
.
!==
null
&&
!
this
.
getRootParent
(
,
)
.
)
.
flatMap
(
(
[
]
)
=>
)
;
return
;
}
computeLeakingDisposables
(
=
10
,
?
:
[
]
)
:
{
:
[
]
;
:
string
}
|
undefined
{
let
:
[
]
|
undefined
;
if
(
)
{
=
;
}
else
{
const
=
new
Map<DisposableInfo, DisposableInfo>
(
)
;
const
=
[
...
this
.
.
values
(
)
]
.
filter
(
(
)
=>
.
!==
null
&&
!
this
.
getRootParent
(
,
)
.
)
;
if
(
.
===
0
)
{
return
;
}
const
=
new
Set
(
.
map
(
=>
.
)
)
;
// Remove all objects that are a child of other leaking objects. Assumes there are no cycles.
=
.
filter
(
=>
{
return
!
(
.
&&
.
has
(
.
)
)
;
}
)
;
if
(
.
===
0
)
{
throw
new
Error
(
'There are cyclic diposable chains!'
)
;
}
}
if
(
!
)
{
return
undefined
;
}
function
getStackTracePath
(
:
)
:
string
[
]
{
function
removePrefix
(
:
string
[
]
,
:
(
string
|
)
[
]
)
{
while
(
.
>
0
&&
.
some
(
=>
typeof
===
'string'
?
===
[
0
]
:
[
0
]
.
match
(
)
)
)
{
.
shift
(
)
;
}
}
const
=
.
!
.
split
(
'\n'
)
.
map
(
=>
.
trim
(
)
.
replace
(
'at '
,
''
)
)
.
filter
(
=>
!==
''
)
;
removePrefix
(
,
[
'Error'
,
/^trackDisposable \(.*\)$/
,
/^DisposableTracker.trackDisposable \(.*\)$/
]
)
;
return
.
reverse
(
)
;
}
const
=
new
SetMap<string, DisposableInfo>
(
)
;
for
(
const
of
)
{
const
=
getStackTracePath
(
)
;
for
(
let
=
0
;
<=
.
;
++
)
{
.
add
(
.
slice
(
0
,
)
.
join
(
'\n'
)
,
)
;
}
}
// Put earlier leaks first
.
sort
(
compareBy
(
=>
.
,
)
)
;
let
=
''
;
let
=
0
;
for
(
const
of
.
slice
(
0
,
)
)
{
++
;
const
=
getStackTracePath
(
)
;
const
=
[
]
;
for
(
let
=
0
;
<
.
;
++
)
{
let
=
[
]
;
const
=
.
get
(
.
slice
(
0
,
+
1
)
.
join
(
'\n'
)
)
;
=
`(shared with ${starts.size}/${uncoveredLeakingObjs.length} leaks) at ${line}`
;
const
=
.
get
(
.
slice
(
0
,
)
.
join
(
'\n'
)
)
;
const
=
groupBy
(
[
...
]
.
map
(
=>
getStackTracePath
(
)
[
]
)
,
=>
)
;
delete
[
[
]
]
;
for
(
const
[
,
]
of
.
entries
(
)
)
{
if
(
)
{
.
unshift
(
` - stacktraces of ${set.length} other leaks continue with ${cont}`
/**
* Indicates that the given object is a singleton which does not need to be disposed.
*/
export
function
markAsSingleton<Textends IDisposable>
(
:
T
)
:
T
{
?.
markAsSingleton
(
)
;
return
;
}
// #endregion
/**
* An object that performs a cleanup operation when `.dispose()` is called.
*
* Some examples of how disposables are used:
*
* - An event listener that removes itself when `.dispose()` is called.
* - A resource such as a file system watcher that cleans up the resource when `.dispose()` is called.
* - The return value from registering a provider. When `.dispose()` is called, the provider is unregistered.
*/
export
interface
IDisposable
{
dispose
(
)
:
void
;
}
/**
* Check if `thing` is {@link IDisposable disposable}.
*/
/**
* Combine multiple disposable values into a single {@link IDisposable}.
*/
export
function
combinedDisposable
(
...
:
[
]
)
:
{
const
=
toDisposable
(
(
)
=>
dispose
(
)
)
;
setParentOfDisposables
(
,
)
;
return
;
}
class
FunctionDisposable
implements
IDisposable
{
private
:
boolean
;
private
readonly
_fn
:
(
)
=>
void
;
constructor
(
fn
:
(
)
=>
void
)
{
this
.
=
false
;
this
.
=
;
trackDisposable
(
this
)
;
}
dispose
(
)
{
if
(
this
.
)
{
return
;
}
if
(
!
this
.
)
{
throw
new
Error
(
`Unbound disposable context: Need to use an arrow function to preserve the value of this`
)
;
}
this
.
=
true
;
markAsDisposed
(
this
)
;
this
.
_fn
(
)
;
}
}
/**
* Turn a function that implements dispose into an {@link IDisposable}.
*
* @paramfn Clean up function, guaranteed to be called only **once**.
*/
export
function
toDisposable
(
fn
:
(
)
=>
void
)
:
{
return
new
FunctionDisposable
(
)
;
}
/**
* Manages a collection of disposable values.
*
* This is the preferred way to manage multiple disposables. A `DisposableStore` is safer to work with than an
* `IDisposable[]` as it considers edge cases, such as registering the same value multiple times or adding an item to a
* store that has already been disposed of.
*/
export
class
DisposableStore
implements
IDisposable
{
static
DISABLE_DISPOSED_WARNING
=
false
;
private
readonly
=
new
Set<IDisposable>
(
)
;
private
=
false
;
constructor
(
)
{
trackDisposable
(
this
)
;
}
/**
* Dispose of all registered disposables and mark this object as disposed.
*
* Any future disposables added to this object will be disposed of on `add`.
*/
public
dispose
(
)
:
void
{
if
(
this
.
)
{
return
;
}
markAsDisposed
(
this
)
;
this
.
=
true
;
this
.
clear
(
)
;
}
/**
* @return `true` if this object has been disposed of.
*/
public
get
isDisposed
(
)
:
boolean
{
return
this
.
;
}
/**
* Dispose of all registered disposables but do not mark this object as disposed.
*/
public
clear
(
)
:
void
{
if
(
this
.
.
===
0
)
{
return
;
}
try
{
dispose
(
this
.
)
;
}
finally
{
this
.
.
clear
(
)
;
}
}
/**
* Add a new {@link IDisposable disposable} to the collection.
*/
public
add<Textends IDisposable>
(
:
T
)
:
T
{
if
(
!
||
===
.
)
{
return
;
}
if
(
(
as
unknown
as
)
===
this
)
{
throw
new
Error
(
'Cannot register a disposable on itself!'
)
;
}
setParentOfDisposable
(
,
this
)
;
if
(
this
.
)
{
if
(
!
.
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!'
)
.
)
;
}
}
else
{
this
.
.
add
(
)
;
}
return
;
}
/**
* Deletes a disposable from store and disposes of it. This will not throw or warn and proceed to dispose the
* disposable even when the disposable is not part in the store.
*/
public
delete
<
T
extends
IDisposable
>
(
:
T
)
:
void
{
if
(
!
)
{
return
;
}
if
(
(
as
unknown
as
)
===
this
)
{
throw
new
Error
(
'Cannot dispose a disposable on itself!'
)
;
}
this
.
.
delete
(
)
;
.
dispose
(
)
;
}
/**
* Deletes the value from the store, but does not dispose it.
*/
public
deleteAndLeak<Textends IDisposable>
(
:
T
)
:
void
{
if
(
!
)
{
return
;
}
if
(
this
.
.
delete
(
)
)
{
setParentOfDisposable
(
,
null
)
;
}
}
public
assertNotDisposed
(
)
:
void
{
if
(
this
.
)
{
onUnexpectedError
(
new
BugIndicatingError
(
'Object disposed'
)
)
;
}
}
}
/**
* Abstract base class for a {@link IDisposable disposable} object.
*
* Subclasses can {@linkcode _register} disposables that will be automatically cleaned up when this object is disposed of.
*/
export
abstract
class
Disposable
implements
IDisposable
{
/**
* A disposable that does nothing when it is disposed of.
*
* TODO: This should not be a static property.
*/
static
readonly
=
.
freeze<IDisposable>
(
{
dispose
(
)
{
}
}
)
;
protected
readonly
=
new
DisposableStore
(
)
;
constructor
(
)
{
trackDisposable
(
this
)
;
setParentOfDisposable
(
this
.
,
this
)
;
}
public
dispose
(
)
:
void
{
markAsDisposed
(
this
)
;
this
.
.
dispose
(
)
;
}
/**
* Adds `o` to the collection of disposables managed by this object.
*/
protected
_register<Textends IDisposable>
(
:
T
)
:
T
{
if
(
(
as
unknown
as
)
===
this
)
{
throw
new
Error
(
'Cannot register a disposable on itself!'
)
;
}
return
this
.
.
add
(
)
;
}
}
/**
* Manages the lifecycle of a disposable value that may be changed.
*
* This ensures that when the disposable value is changed, the previously held disposable is disposed of. You can
* also register a `MutableDisposable` on a `Disposable` to ensure it is automatically cleaned up.
*/
export
class
MutableDisposable<Textends IDisposable>
implements
IDisposable
{
private
?
:
T
;
private
=
false
;
constructor
(
)
{
trackDisposable
(
this
)
;
}
/**
* Get the currently held disposable value, or `undefined` if this MutableDisposable has been disposed
*/
get
value
(
)
:
T
|
undefined
{
return
this
.
?
undefined
:
this
.
;
}
/**
* Set a new disposable value.
*
* Behaviour:
* - If the MutableDisposable has been disposed, the setter is a no-op.
* - If the new value is strictly equal to the current value, the setter is a no-op.
* - Otherwise the previous value (if any) is disposed and the new value is stored.
*
* Related helpers:
* - clear() resets the value to `undefined` (and disposes the previous value).
* - clearAndLeak() returns the old value without disposing it and removes its parent.
*/
set
value
(
:
T
|
undefined
)
{
if
(
this
.
||
===
this
.
)
{
return
;
}
this
.
?.
dispose
(
)
;
if
(
)
{
setParentOfDisposable
(
,
this
)
;
}
this
.
=
;
}
/**
* Resets the stored value and disposed of the previously stored value.
*/
clear
(
)
:
void
{
this
.
=
undefined
;
}
dispose
(
)
:
void
{
this
.
=
true
;
markAsDisposed
(
this
)
;
this
.
?.
dispose
(
)
;
this
.
=
undefined
;
}
/**
* Clears the value, but does not dispose it.
* The old value is returned.
*/
clearAndLeak
(
)
:
T
|
undefined
{
const
=
this
.
;
this
.
=
undefined
;
if
(
)
{
setParentOfDisposable
(
,
null
)
;
}
return
;
}
}
/**
* Manages the lifecycle of a disposable value that may be changed like {@link MutableDisposable}, but the value must
* exist and cannot be undefined.
*/
export
class
MandatoryMutableDisposable<Textends IDisposable>
implements
IDisposable
{
private
readonly
=
new
MutableDisposable<T>
(
)
;
private
=
false
;
constructor
(
:
T
)
{
this
.
.
=
;
}
get
value
(
)
:
T
{
return
this
.
.
!
;
}
set
value
(
:
T
)
{
if
(
this
.
||
===
this
.
.
)
{
return
;
}
this
.
.
=
;
}
dispose
(
)
{
this
.
=
true
;
this
.
.
dispose
(
)
;
}
}
export
class
RefCountedDisposable
{
private
:
number
=
1
;
constructor
(
private
readonly
:
,
)
{
}
acquire
(
)
{
this
.
++
;
return
this
;
}
release
(
)
{
if
(
--
this
.
===
0
)
{
this
.
.
dispose
(
)
;
}
return
this
;
}
}
export
interface
IReference<T>
extends
IDisposable
{
readonly
:
T
;
}
export
abstract
class
ReferenceCollection<T>
{
private
readonly
:
<
string
,
{
readonly
:
T
;
:
number
}
>
=
new
Map
(
)
;
acquire
(
:
string
,
...
:
unknown
[
]
)
:
<
T
>
{
let
=
this
.
.
get
(
)
;
if
(
!
)
{
=
{
:
0
,
:
this
.
createReferencedObject
(
,
...
)
}
;
this
.
.
set
(
,
)
;
}
const
{
}
=
;
const
=
createSingleCallFunction
(
(
)
=>
{
if
(
--
.
===
0
)
{
this
.
destroyReferencedObject
(
,
.
)
;
this
.
.
delete
(
)
;
}
}
)
;
.
++
;
return
{
,
}
;
}
protected
abstract
createReferencedObject
(
:
string
,
...
:
unknown
[
]
)
:
T
;
protected
abstract
destroyReferencedObject
(
:
string
,
:
T
)
:
void
;
}
/**
* Unwraps a reference collection of promised values. Makes sure
* references are disposed whenever promises get rejected.
*/
export
class
AsyncReferenceCollection<T>
{
constructor
(
private
:
<
Promise
<
T
>>
)
{
}
async
acquire
(
:
string
,
...
:
unknown
[
]
)
:
Promise
<
<
T
>>
{
const
=
this
.
.
acquire
(
,
...
)
;
try
{
const
=
await
.
;
return
{
,
dispose
:
(
)
=>
.
dispose
(
)
}
;
}
catch
(
)
{
.
dispose
(
)
;
throw
;
}
}
}
export
class
ImmortalReference<T>
implements
IReference<T>
{
constructor
(
public
:
T
)
{
}
dispose
(
)
:
void
{
/* noop */
}
}
export
function
disposeOnReturn
(
fn
:
(
:
)
=>
void
)
:
void
{
const
=
new
DisposableStore
(
)
;
try
{
fn
(
)
;
}
finally
{
.
dispose
(
)
;
}
}
/**
* A map the manages the lifecycle of the values that it stores.
*/
/**
* Disposes of all stored values and mark this object as disposed.
*
* Trying to use this object after it has been disposed of is an error.
*/
dispose
(
)
:
void
{
markAsDisposed
(
this
)
;
this
.
=
true
;
this
.
clearAndDisposeAll
(
)
;
}
/**
* Disposes of all stored values and clear the map, but DO NOT mark this object as disposed.
*/
clearAndDisposeAll
(
)
:
void
{
if
(
!
this
.
.
)
{
return
;
}
try
{
dispose
(
this
.
.
values
(
)
)
;
}
finally
{
this
.
.
clear
(
)
;
}
}
has
(
:
K
)
:
boolean
{
return
this
.
.
has
(
)
;
}
get
size
(
)
:
number
{
return
this
.
.
;
}
get
(
:
K
)
:
V
|
undefined
{
return
this
.
.
get
(
)
;
}
set
(
:
K
,
:
V
,
=
false
)
:
void
{
if
(
this
.
)
{
console
.
warn
(
new
Error
(
'Trying to add a disposable to a DisposableMap that has already been disposed of. The added object will be leaked!'
)
.
)
;
}
if
(
!
)
{
this
.
.
get
(
)
?.
dispose
(
)
;
}
this
.
.
set
(
,
)
;
setParentOfDisposable
(
,
this
)
;
}
/**
* Delete the value stored for `key` from this map and also dispose of it.
*/
deleteAndDispose
(
:
K
)
:
void
{
this
.
.
get
(
)
?.
dispose
(
)
;
this
.
.
delete
(
)
;
}
/**
* Delete the value stored for `key` from this map but return it. The caller is
* responsible for disposing of the value.
*/
deleteAndLeak
(
:
K
)
:
V
|
undefined
{
const
=
this
.
.
get
(
)
;
if
(
)
{
setParentOfDisposable
(
,
null
)
;
}
this
.
.
delete
(
)
;
return
;
}
keys
(
)
:
<
K
>
{
return
this
.
.
keys
(
)
;
}
values
(
)
:
<
V
>
{
return
this
.
.
values
(
)
;
}
[
.
]
(
)
:
<
[
K
,
V
]
>
{
return
this
.
[
.
]
(
)
;
}
}
/**
* A set that manages the lifecycle of the values that it stores.
*/
export
class
DisposableSet<Vextends IDisposable = IDisposable>
implements
IDisposable
{
private
readonly
:
<
V
>
;
private
=
false
;
constructor
(
:
<
V
>
=
new
Set<V>
(
)
)
{
this
.
=
;
trackDisposable
(
this
)
;
}
/**
* Disposes of all stored values and mark this object as disposed.
*
* Trying to use this object after it has been disposed of is an error.
*/
dispose
(
)
:
void
{
markAsDisposed
(
this
)
;
this
.
=
true
;
this
.
clearAndDisposeAll
(
)
;
}
/**
* Disposes of all stored values and clear the set, but DO NOT mark this object as disposed.
*/
clearAndDisposeAll
(
)
:
void
{
if
(
!
this
.
.
)
{
return
;
}
try
{
dispose
(
this
.
.
values
(
)
)
;
}
finally
{
this
.
.
clear
(
)
;
}
}
has
(
:
V
)
:
boolean
{
return
this
.
.
has
(
)
;
}
get
size
(
)
:
number
{
return
this
.
.
;
}
add
(
:
V
)
:
void
{
if
(
this
.
)
{
console
.
warn
(
new
Error
(
'Trying to add a disposable to a DisposableSet that has already been disposed of. The added object will be leaked!'
)
.
)
;
}
this
.
.
add
(
)
;
setParentOfDisposable
(
,
this
)
;
}
/**
* Delete the value from this set and also dispose of it.
*/
deleteAndDispose
(
:
V
)
:
void
{
if
(
this
.
.
delete
(
)
)
{
.
dispose
(
)
;
}
}
/**
* Delete the value from this set but return it. The caller is
* responsible for disposing of the value.
*/
deleteAndLeak
(
:
V
)
:
V
|
undefined
{
if
(
this
.
.
delete
(
)
)
{
setParentOfDisposable
(
,
null
)
;
return
;
}
return
undefined
;
}
values
(
)
:
<
V
>
{
return
this
.
.
values
(
)
;
}
[
.
]
(
)
:
<
V
>
{
return
this
.
[
.
]
(
)
;
}
}
/**
* Call `then` on a Promise, unless the returned disposable is disposed.
*/
export
function
thenIfNotDisposed<T>
(
:
Promise
<
T
>
,
then
:
(
:
T
)
=>
void
)
:
{
let
=
false
;
.
then
(
=>
{
if
(
)
{
return
;
}
then
(
)
;
}
)
;
return
toDisposable
(
(
)
=>
{
=
true
;
}
)
;
}
/**
* Call `then` on a promise that resolves to a {@link IDisposable}, then either register the
* disposable or register it to the {@link DisposableStore}, depending on whether the store is
* disposed or not.
*/