-
Notifications
You must be signed in to change notification settings - Fork 27.9k
/
editorService.ts
290 lines (244 loc) · 10.6 KB
/
editorService.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
import { IResourceEditorInput, IEditorOptions, IResourceEditorInputIdentifier, ITextResourceEditorInput } from 'vs/platform/editor/common/editor';
import { IEditorPane, GroupIdentifier, IUntitledTextResourceEditorInput, IResourceDiffEditorInput, ITextDiffEditorPane, IEditorIdentifier, ISaveOptions, IRevertOptions, EditorsOrder, IVisibleEditorPane, IEditorCloseEvent, IUntypedEditorInput } from 'vs/workbench/common/editor';
import { EditorInput } from 'vs/workbench/common/editor/editorInput';
import { Event } from 'vs/base/common/event';
import { IEditor, IDiffEditor } from 'vs/editor/common/editorCommon';
import { IEditorGroup, IEditorReplacement, isEditorGroup } from 'vs/workbench/services/editor/common/editorGroupsService';
import { URI } from 'vs/base/common/uri';
import { IGroupModelChangeEvent } from 'vs/workbench/common/editor/editorGroupModel';
export const IEditorService = createDecorator<IEditorService>('editorService');
/**
* Open an editor in the currently active group.
*/
export const ACTIVE_GROUP = -1;
export type ACTIVE_GROUP_TYPE = typeof ACTIVE_GROUP;
/**
* Open an editor to the side of the active group.
*/
export const SIDE_GROUP = -2;
export type SIDE_GROUP_TYPE = typeof SIDE_GROUP;
export type PreferredGroup = IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE;
export function isPreferredGroup(obj: unknown): obj is PreferredGroup {
const candidate = obj as PreferredGroup | undefined;
return typeof obj === 'number' || isEditorGroup(candidate);
}
export interface ISaveEditorsOptions extends ISaveOptions {
/**
* If true, will ask for a location of the editor to save to.
*/
readonly saveAs?: boolean;
}
export interface IUntypedEditorReplacement {
readonly editor: EditorInput;
readonly replacement: IUntypedEditorInput;
/**
* Skips asking the user for confirmation and doesn't
* save the document. Only use this if you really need to!
*/
forceReplaceDirty?: boolean;
}
export interface IBaseSaveRevertAllEditorOptions {
/**
* Whether to include untitled editors as well.
*/
readonly includeUntitled?: boolean;
/**
* Whether to exclude sticky editors.
*/
readonly excludeSticky?: boolean;
}
export interface ISaveAllEditorsOptions extends ISaveEditorsOptions, IBaseSaveRevertAllEditorOptions { }
export interface IRevertAllEditorsOptions extends IRevertOptions, IBaseSaveRevertAllEditorOptions { }
export interface IOpenEditorsOptions {
/**
* Whether to validate trust when opening editors
* that are potentially not inside the workspace.
*/
readonly validateTrust?: boolean;
}
export interface IEditorsChangeEvent extends IGroupModelChangeEvent {
groupId: GroupIdentifier;
}
export interface IEditorService {
readonly _serviceBrand: undefined;
/**
* Emitted when the currently active editor changes.
*
* @see {@link IEditorService.activeEditorPane}
*/
readonly onDidActiveEditorChange: Event<void>;
/**
* Emitted when any of the current visible editors changes.
*
* @see {@link IEditorService.visibleEditorPanes}
*/
readonly onDidVisibleEditorsChange: Event<void>;
/**
* An aggregated event for any change to any editor across
* all groups.
*/
readonly onDidEditorsChange: Event<IEditorsChangeEvent[]>;
/**
* Emitted when an editor is closed.
*/
readonly onDidCloseEditor: Event<IEditorCloseEvent>;
/**
* The currently active editor pane or `undefined` if none. The editor pane is
* the workbench container for editors of any kind.
*
* @see {@link IEditorService.activeEditor} for access to the active editor input
*/
readonly activeEditorPane: IVisibleEditorPane | undefined;
/**
* The currently active editor or `undefined` if none. An editor is active when it is
* located in the currently active editor group. It will be `undefined` if the active
* editor group has no editors open.
*/
readonly activeEditor: EditorInput | undefined;
/**
* The currently active text editor control or `undefined` if there is currently no active
* editor or the active editor widget is neither a text nor a diff editor.
*
* @see {@link IEditorService.activeEditor}
*/
readonly activeTextEditorControl: IEditor | IDiffEditor | undefined;
/**
* The currently active text editor mode or `undefined` if there is currently no active
* editor or the active editor control is neither a text nor a diff editor. If the active
* editor is a diff editor, the modified side's mode will be taken.
*/
readonly activeTextEditorMode: string | undefined;
/**
* All editor panes that are currently visible across all editor groups.
*
* @see {@link IEditorService.visibleEditors} for access to the visible editor inputs
*/
readonly visibleEditorPanes: readonly IVisibleEditorPane[];
/**
* All editors that are currently visible. An editor is visible when it is opened in an
* editor group and active in that group. Multiple editor groups can be opened at the same time.
*/
readonly visibleEditors: readonly EditorInput[];
/**
* All text editor widgets that are currently visible across all editor groups. A text editor
* widget is either a text or a diff editor.
*/
readonly visibleTextEditorControls: readonly (IEditor | IDiffEditor)[];
/**
* All editors that are opened across all editor groups in sequential order
* of appearance.
*
* This includes active as well as inactive editors in each editor group.
*/
readonly editors: readonly EditorInput[];
/**
* The total number of editors that are opened either inactive or active.
*/
readonly count: number;
/**
* All editors that are opened across all editor groups with their group
* identifier.
*
* @param order the order of the editors to use
* @param options whether to exclude sticky editors or not
*/
getEditors(order: EditorsOrder, options?: { excludeSticky?: boolean }): readonly IEditorIdentifier[];
/**
* Open an editor in an editor group.
*
* @param editor the editor to open
* @param options the options to use for the editor
* @param group the target group. If unspecified, the editor will open in the currently
* active group. Use `SIDE_GROUP_TYPE` to open the editor in a new editor group to the side
* of the currently active group.
*
* @returns the editor that opened or `undefined` if the operation failed or the editor was not
* opened to be active.
*/
openEditor(editor: IResourceEditorInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditorPane | undefined>;
openEditor(editor: ITextResourceEditorInput | IUntitledTextResourceEditorInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditorPane | undefined>;
openEditor(editor: IResourceDiffEditorInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<ITextDiffEditorPane | undefined>;
openEditor(editor: IUntypedEditorInput, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditorPane | undefined>;
openEditor(editor: EditorInput, options?: IEditorOptions, group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE): Promise<IEditorPane | undefined>;
/**
* Open editors in an editor group.
*
* @param editors the editors to open with associated options
* @param group the target group. If unspecified, the editor will open in the currently
* active group. Use `SIDE_GROUP_TYPE` to open the editor in a new editor group to the side
* of the currently active group.
*
* @returns the editors that opened. The array can be empty or have less elements for editors
* that failed to open or were instructed to open as inactive.
*/
openEditors(editors: IUntypedEditorInput[], group?: IEditorGroup | GroupIdentifier | SIDE_GROUP_TYPE | ACTIVE_GROUP_TYPE, options?: IOpenEditorsOptions): Promise<readonly IEditorPane[]>;
/**
* Replaces editors in an editor group with the provided replacement.
*
* @param replacements the editors to replace
* @param group the editor group
*
* @returns a promise that is resolved when the replaced active
* editor (if any) has finished loading.
*/
replaceEditors(replacements: IUntypedEditorReplacement[], group: IEditorGroup | GroupIdentifier): Promise<void>;
/**
* @deprecated when using `EditorInput`, please call `group.replaceEditors` directly.
*/
replaceEditors(replacements: IEditorReplacement[], group: IEditorGroup | GroupIdentifier): Promise<void>;
/**
* Find out if the provided editor is opened in any editor group.
*
* Note: An editor can be opened but not actively visible.
*
* Note: This method will return `true` if a side by side editor
* is opened where the `primary` editor matches too.
*/
isOpened(editor: IResourceEditorInputIdentifier): boolean;
/**
* Find out if the provided editor is visible in any editor group.
*/
isVisible(editor: EditorInput): boolean;
/**
* This method will return an entry for each editor that reports
* a `resource` that matches the provided one in the group or
* across all groups.
*
* It is possible that multiple editors are returned in case the
* same resource is opened in different editors. To find the specific
* editor, use the `IResourceEditorInputIdentifier` as input.
*/
findEditors(resource: URI): readonly IEditorIdentifier[];
findEditors(editor: IResourceEditorInputIdentifier): readonly IEditorIdentifier[];
findEditors(resource: URI, group: IEditorGroup | GroupIdentifier): readonly EditorInput[];
findEditors(editor: IResourceEditorInputIdentifier, group: IEditorGroup | GroupIdentifier): EditorInput | undefined;
/**
* Save the provided list of editors.
*
* @returns `true` if all editors saved and `false` otherwise.
*/
save(editors: IEditorIdentifier | IEditorIdentifier[], options?: ISaveEditorsOptions): Promise<boolean>;
/**
* Save all editors.
*
* @returns `true` if all editors saved and `false` otherwise.
*/
saveAll(options?: ISaveAllEditorsOptions): Promise<boolean>;
/**
* Reverts the provided list of editors.
*
* @returns `true` if all editors reverted and `false` otherwise.
*/
revert(editors: IEditorIdentifier | IEditorIdentifier[], options?: IRevertOptions): Promise<boolean>;
/**
* Reverts all editors.
*
* @returns `true` if all editors reverted and `false` otherwise.
*/
revertAll(options?: IRevertAllEditorsOptions): Promise<boolean>;
}