1
>
/*---------------------------------------------------------------------------------------------
workingCopyService.ts
2
>
* Copyright (c) Microsoft Corporation. All rights reserved.
3
>
* Licensed under the MIT License. See License.txt in the project root for license information.
4
>
*--------------------------------------------------------------------------------------------*/
5
>
6
>
import { createDecorator } from '../../../../platform/instantiation/common/instantiation.js';
7
>
import { InstantiationType, registerSingleton } from '../../../../platform/instantiation/common/extensions.js';
8
>
import { Event, Emitter } from '../../../../base/common/event.js';
9
>
import { URI } from '../../../../base/common/uri.js';
10
>
import { Disposable, IDisposable, toDisposable, DisposableStore, DisposableMap } from '../../../../base/common/lifecycle.js';
11
>
import { ResourceMap } from '../../../../base/common/map.js';
12
>
import { IWorkingCopy, IWorkingCopyIdentifier, IWorkingCopySaveEvent as IBaseWorkingCopySaveEvent } from './workingCopy.js';
13
>
import { onUnexpectedError } from '../../../../base/common/errors.js';
14
>
15
>
export const IWorkingCopyService = createDecorator<IWorkingCopyService>('workingCopyService');
16
>
17
>
export interface IWorkingCopySaveEvent extends IBaseWorkingCopySaveEvent {
18
>
19
>
/**
20
>
* The working copy that was saved.
21
>
*/
22
>
readonly workingCopy: IWorkingCopy;
23
>
}
24
>
25
>
export interface IWorkingCopyService {
26
>
27
>
readonly _serviceBrand: undefined;
28
>
29
>
30
>
//#region Events
31
>
32
>
/**
33
>
* An event for when a working copy was registered.
34
>
*/
35
>
readonly onDidRegister: Event<IWorkingCopy>;
36
>
37
>
/**
38
>
* An event for when a working copy was unregistered.
39
>
*/
40
>
readonly onDidUnregister: Event<IWorkingCopy>;
41
>
42
>
/**
43
>
* An event for when a working copy dirty state changed.
44
>
*/
45
>
readonly onDidChangeDirty: Event<IWorkingCopy>;
46
>
47
>
/**
48
>
* An event for when a working copy's content changed.
49
>
*/
50
>
readonly onDidChangeContent: Event<IWorkingCopy>;
51
>
52
>
/**
53
>
* An event for when a working copy was saved.
54
>
*/
55
>
readonly onDidSave: Event<IWorkingCopySaveEvent>;
56
>
57
>
//#endregion
58
>
59
>
60
>
//#region Dirty Tracking
61
>
62
>
/**
63
>
* The number of dirty working copies that are registered.
64
>
*/
65
>
readonly dirtyCount: number;
66
>
67
>
/**
68
>
* All dirty working copies that are registered.
69
>
*/
70
>
readonly dirtyWorkingCopies: readonly IWorkingCopy[];
71
>
72
>
/**
73
>
* The number of modified working copies that are registered,
74
>
* including scratchpads, which are never dirty.
75
>
*/
76
>
readonly modifiedCount: number;
77
>
78
>
/**
79
>
* All working copies with unsaved changes,
80
>
* including scratchpads, which are never dirty.
81
>
*/
82
>
readonly modifiedWorkingCopies: readonly IWorkingCopy[];
83
>
84
>
/**
85
>
* Whether there is any registered working copy that is dirty.
86
>
*/
87
>
readonly hasDirty: boolean;
88
>
89
>
/**
90
>
* Figure out if working copies with the given
91
>
* resource are dirty or not.
92
>
*
93
>
* @param resource the URI of the working copy
94
>
* @param typeId optional type identifier to only
95
>
* consider working copies of that type.
96
>
*/
97
>
isDirty(resource: URI, typeId?: string): boolean;
98
>
99
>
//#endregion
100
>
101
>
102
>
//#region Registry
103
>
104
>
/**
105
>
* All working copies that are registered.
106
>
*/
107
>
readonly workingCopies: readonly IWorkingCopy[];
108
>
109
>
/**
110
>
* Register a new working copy with the service. This method will
111
>
* throw if you try to register a working copy on a resource that
112
>
* has already been registered.
113
>
*
114
>
* Overall there can only ever be 1 working copy with the same
115
>
* resource.
116
>
*/
117
>
registerWorkingCopy(workingCopy: IWorkingCopy): IDisposable;
118
>
119
>
/**
120
>
* Whether a working copy with the given resource or identifier
121
>
* exists.
122
>
*/
123
>
has(identifier: IWorkingCopyIdentifier): boolean;
124
>
has(resource: URI): boolean;
125
>
126
>
/**
127
>
* Returns a working copy with the given identifier or `undefined`
128
>
* if no such working copy exists.
129
>
*/
130
>
get(identifier: IWorkingCopyIdentifier): IWorkingCopy | undefined;
131
>
132
>
/**
133
>
* Returns all working copies with the given resource or `undefined`
134
>
* if no such working copy exists.
135
>
*/
136
>
getAll(resource: URI): readonly IWorkingCopy[] | undefined;
137
>
138
>
//#endregion
139
>
}
140
>
141
>
class WorkingCopyLeakError extends Error {
142
>
143
>
constructor(message: string, stack: string) {
144
super(message);
145