Skip to content

Commit 40ba45c

Browse files
authored
Merge pull request #181 from CodinGame/simulate-editor-group-for-standalone-editors
Simulate an editor group for each standalone editor
2 parents 76ba937 + 5637570 commit 40ba45c

File tree

4 files changed

+624
-176
lines changed

4 files changed

+624
-176
lines changed

src/missing-services.ts

+54-22
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ import { ITestResultService } from 'vs/workbench/contrib/testing/common/testResu
165165
import { IDiagnosticsService, NullDiagnosticsService } from 'vs/platform/diagnostics/common/diagnostics'
166166
import { INotebookSearchService } from 'vs/workbench/contrib/search/browser/notebookSearch'
167167
import { ResourceSet } from 'vs/base/common/map'
168+
import { IEditorGroupView } from 'vs/workbench/browser/parts/editor/editor'
168169
import { unsupported } from './tools'
169170

170171
class NullLoggerService extends AbstractLoggerService {
@@ -268,7 +269,32 @@ registerSingleton(IFileService, class FileService implements IFileService {
268269
}
269270
}, InstantiationType.Eager)
270271

271-
class EmptyEditorGroup implements IEditorGroup {
272+
class EmptyEditorGroup implements IEditorGroup, IEditorGroupView {
273+
onDidFocus = Event.None
274+
onDidOpenEditorFail = Event.None
275+
whenRestored = Promise.resolve()
276+
get titleHeight () {
277+
return unsupported()
278+
}
279+
280+
disposed = false
281+
setActive = unsupported
282+
notifyIndexChanged = unsupported
283+
relayout = unsupported
284+
dispose = unsupported
285+
toJSON = unsupported
286+
preferredWidth?: number | undefined
287+
preferredHeight?: number | undefined
288+
get element () {
289+
return unsupported()
290+
}
291+
292+
minimumWidth = 0
293+
maximumWidth = Number.POSITIVE_INFINITY
294+
minimumHeight = 0
295+
maximumHeight = Number.POSITIVE_INFINITY
296+
onDidChange = Event.None
297+
layout = unsupported
272298
onDidModelChange = Event.None
273299
onWillDispose = Event.None
274300
onDidActiveEditorChange = Event.None
@@ -288,17 +314,17 @@ class EmptyEditorGroup implements IEditorGroup {
288314
isLocked = false
289315
stickyCount = 0
290316
editors = []
291-
get scopedContextKeyService () { return StandaloneServices.get(IContextKeyService) }
292-
getEditors = unsupported
293-
findEditors = unsupported
294-
getEditorByIndex = unsupported
317+
get scopedContextKeyService (): IContextKeyService { return StandaloneServices.get(IContextKeyService) }
318+
getEditors = () => []
319+
findEditors = () => []
320+
getEditorByIndex = () => undefined
295321
getIndexOfEditor = unsupported
296322
openEditor = unsupported
297323
openEditors = unsupported
298-
isPinned = unsupported
299-
isSticky = unsupported
300-
isActive = unsupported
301-
contains = unsupported
324+
isPinned = () => false
325+
isSticky = () => false
326+
isActive = () => false
327+
contains = () => false
302328
moveEditor = unsupported
303329
moveEditors = unsupported
304330
copyEditor = unsupported
@@ -315,12 +341,12 @@ class EmptyEditorGroup implements IEditorGroup {
315341
// ignore
316342
}
317343

318-
isFirst = () => true
319-
isLast = () => true
344+
isFirst = unsupported
345+
isLast = unsupported
320346
}
321347

322348
const fakeActiveGroup = new EmptyEditorGroup()
323-
registerSingleton(IEditorGroupsService, class EditorGroupsService implements IEditorGroupsService {
349+
export class EmptyEditorGroupsService implements IEditorGroupsService {
324350
readonly _serviceBrand = undefined
325351
getLayout = unsupported
326352
onDidChangeActiveGroup = Event.None
@@ -332,37 +358,39 @@ registerSingleton(IEditorGroupsService, class EditorGroupsService implements IEd
332358
onDidScroll = Event.None
333359
onDidChangeGroupIndex = Event.None
334360
onDidChangeGroupLocked = Event.None
335-
get contentDimension () { return unsupported() }
361+
get contentDimension (): never { return unsupported() }
336362
activeGroup = fakeActiveGroup
337-
get sideGroup () { return unsupported() }
363+
get sideGroup (): never { return unsupported() }
338364
groups = [fakeActiveGroup]
339365
count = 0
340366
orientation = GroupOrientation.HORIZONTAL
341367
isReady = false
342368
whenReady = Promise.resolve()
343369
whenRestored = Promise.resolve()
344370
hasRestorableState = false
345-
getGroups = () => []
346-
getGroup = () => undefined
371+
getGroups = (): never[] => []
372+
getGroup = (): undefined => undefined
347373
activateGroup = unsupported
348374
getSize = unsupported
349375
setSize = unsupported
350376
arrangeGroups = unsupported
351377
applyLayout = unsupported
352378
centerLayout = unsupported
353-
isLayoutCentered = () => false
379+
isLayoutCentered = (): boolean => false
354380
setGroupOrientation = unsupported
355-
findGroup = () => undefined
381+
findGroup = (): undefined => undefined
356382
addGroup = unsupported
357383
removeGroup = unsupported
358384
moveGroup = unsupported
359385
mergeGroup = unsupported
360386
mergeAllGroups = unsupported
361387
copyGroup = unsupported
362-
get partOptions () { return unsupported() }
388+
partOptions = {}
363389
onDidChangeEditorPartOptions = Event.None
364390
enforcePartOptions = unsupported
365-
}, InstantiationType.Eager)
391+
}
392+
393+
registerSingleton(IEditorGroupsService, EmptyEditorGroupsService, InstantiationType.Eager)
366394

367395
registerSingleton(IWorkingCopyFileService, WorkingCopyFileService, InstantiationType.Eager)
368396
registerSingleton(IPathService, BrowserPathService, InstantiationType.Delayed)
@@ -1137,8 +1165,12 @@ registerSingleton(IUpdateService, class UpdateService implements IUpdateService
11371165
registerSingleton(IStatusbarService, class StatusbarService implements IStatusbarService {
11381166
_serviceBrand: undefined
11391167
onDidChangeEntryVisibility = Event.None
1140-
addEntry = unsupported
1141-
isEntryVisible = unsupported
1168+
addEntry = () => ({
1169+
dispose: () => {},
1170+
update: () => {}
1171+
})
1172+
1173+
isEntryVisible = () => false
11421174
updateEntryVisibility = unsupported
11431175
focus = unsupported
11441176
focusNextEntry = unsupported

src/service-override/editor.ts

+20-86
Original file line numberDiff line numberDiff line change
@@ -1,96 +1,29 @@
1-
import '../missing-services'
2-
import { IEditorOverrideServices, StandaloneServices } from 'vs/editor/standalone/browser/standaloneServices'
3-
import { IResolvedTextEditorModel, ITextModelService } from 'vs/editor/common/services/resolverService'
1+
import { IEditorOverrideServices } from 'vs/editor/standalone/browser/standaloneServices'
2+
import { IResolvedTextEditorModel } from 'vs/editor/common/services/resolverService'
43
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'
54
import { CodeEditorService } from 'vs/workbench/services/editor/browser/codeEditorService'
6-
import { IEditorService, IEditorsChangeEvent, IOpenEditorsOptions, IRevertAllEditorsOptions, ISaveAllEditorsOptions, ISaveEditorsOptions, ISaveEditorsResult, IUntypedEditorReplacement, PreferredGroup } from 'vs/workbench/services/editor/common/editorService'
7-
import { EditorExtensions, EditorInputWithOptions, EditorsOrder, GroupIdentifier, IEditorCloseEvent, IEditorIdentifier, IFindEditorOptions, IRevertOptions, IVisibleEditorPane } from 'vs/workbench/common/editor'
8-
import type { IEditorFactoryRegistry, IEditorPane, IFileEditorInput, IResourceDiffEditorInput, ITextDiffEditorPane, IUntitledTextResourceEditorInput, IUntypedEditorInput } from 'vs/workbench/common/editor'
9-
import { Emitter, Event } from 'vs/base/common/event'
10-
import { EditorInput } from 'vs/workbench/common/editor/editorInput'
11-
import { IEditorOptions, IResourceEditorInput, IResourceEditorInputIdentifier, ITextResourceEditorInput } from 'vs/platform/editor/common/editor'
12-
import { IEditor } from 'vs/editor/common/editorCommon'
5+
import { IEditorService } from 'vs/workbench/services/editor/common/editorService'
6+
import { EditorExtensions, IEditorFactoryRegistry, IFileEditorInput } from 'vs/workbench/common/editor'
7+
import { IEditorOptions } from 'vs/platform/editor/common/editor'
138
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'
14-
import { Disposable, IReference } from 'vs/base/common/lifecycle'
15-
import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser'
9+
import { IReference } from 'vs/base/common/lifecycle'
1610
import { ITextEditorService, TextEditorService } from 'vs/workbench/services/textfile/common/textEditorService'
17-
import { ICloseEditorOptions, IEditorGroup, IEditorReplacement } from 'vs/workbench/services/editor/common/editorGroupsService'
18-
import { URI } from 'vs/base/common/uri'
1911
import { Registry } from 'vs/platform/registry/common/platform'
2012
import { FILE_EDITOR_INPUT_ID } from 'vs/workbench/contrib/files/common/files'
21-
import { OpenEditor, wrapOpenEditor } from './tools/editor'
13+
import { IEditorGroupsService } from 'vs/workbench/services/editor/common/editorGroupsService'
14+
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation'
15+
import { MonacoDelegateEditorGroupsService, MonacoEditorService, OpenEditor } from './tools/editor'
2216
import { unsupported } from '../tools'
17+
import { EmptyEditorGroupsService } from '../missing-services'
2318
import 'vs/workbench/browser/parts/editor/editor.contribution'
2419

25-
class SimpleEditorService extends Disposable implements IEditorService {
26-
public activeTextEditorControl: IEditor | undefined
27-
private _onDidActiveEditorChange = this._register(new Emitter<void>())
28-
29-
constructor (
30-
_openEditor: OpenEditor,
31-
@ITextModelService textModelService: ITextModelService
32-
) {
33-
super()
34-
35-
setTimeout(() => {
36-
const codeEditorService = StandaloneServices.get(ICodeEditorService)
37-
this.activeTextEditorControl = codeEditorService.getFocusedCodeEditor() ?? undefined
38-
const handleCodeEditor = (editor: ICodeEditor) => {
39-
const onEditorFocused = () => {
40-
const newFocusedEditor = codeEditorService.getFocusedCodeEditor()
41-
if (newFocusedEditor !== this.activeTextEditorControl) {
42-
this.activeTextEditorControl = newFocusedEditor ?? undefined
43-
this._onDidActiveEditorChange.fire()
44-
}
45-
}
46-
editor.onDidFocusEditorText(onEditorFocused)
47-
editor.onDidFocusEditorWidget(onEditorFocused)
48-
}
49-
this._register(codeEditorService.onCodeEditorAdd(handleCodeEditor))
50-
codeEditorService.listCodeEditors().forEach(handleCodeEditor)
51-
})
52-
53-
this.openEditor = wrapOpenEditor(textModelService, this.openEditor.bind(this), _openEditor)
20+
class MonacoEditorGroupsService extends MonacoDelegateEditorGroupsService<EmptyEditorGroupsService> {
21+
constructor (@IInstantiationService instantiationService: IInstantiationService) {
22+
super(
23+
instantiationService.createInstance(EmptyEditorGroupsService),
24+
instantiationService
25+
)
5426
}
55-
56-
readonly _serviceBrand: undefined
57-
onDidActiveEditorChange: Event<void> = this._onDidActiveEditorChange.event
58-
onDidVisibleEditorsChange: Event<void> = Event.None
59-
onDidEditorsChange: Event<IEditorsChangeEvent> = Event.None
60-
onDidCloseEditor: Event<IEditorCloseEvent> = Event.None
61-
activeEditorPane: IVisibleEditorPane | undefined
62-
activeEditor: EditorInput | undefined
63-
activeTextEditorLanguageId: string | undefined
64-
visibleEditorPanes: IVisibleEditorPane[] = []
65-
visibleEditors: EditorInput[] = []
66-
visibleTextEditorControls: Array<IEditor | IDiffEditor> = []
67-
editors: EditorInput[] = []
68-
count: number = 0
69-
getEditors: (order: EditorsOrder, options?: { excludeSticky?: boolean }) => readonly IEditorIdentifier[] = () => []
70-
71-
openEditor(editor: EditorInput, options?: IEditorOptions, group?: PreferredGroup): Promise<IEditorPane | undefined>
72-
openEditor(editor: IUntypedEditorInput, group?: PreferredGroup): Promise<IEditorPane | undefined>
73-
openEditor(editor: IResourceEditorInput, group?: PreferredGroup): Promise<IEditorPane | undefined>
74-
openEditor(editor: ITextResourceEditorInput | IUntitledTextResourceEditorInput, group?: PreferredGroup): Promise<IEditorPane | undefined>
75-
openEditor(editor: IResourceDiffEditorInput, group?: PreferredGroup): Promise<ITextDiffEditorPane | undefined>
76-
openEditor(editor: EditorInput | IUntypedEditorInput, optionsOrPreferredGroup?: IEditorOptions | PreferredGroup, preferredGroup?: PreferredGroup): Promise<IEditorPane | undefined>
77-
async openEditor (_editor: EditorInput | IUntypedEditorInput, _optionsOrPreferredGroup?: IEditorOptions | PreferredGroup, _preferredGroup?: PreferredGroup): Promise<IEditorPane | undefined> {
78-
return undefined
79-
}
80-
81-
openEditors: (editors: Array<EditorInputWithOptions | IUntypedEditorInput>, preferredGroup?: PreferredGroup, options?: IOpenEditorsOptions) => Promise<IEditorPane[]> = unsupported
82-
replaceEditors: (replacements: Array<IEditorReplacement | IUntypedEditorReplacement>, group: IEditorGroup | GroupIdentifier) => Promise<void> = unsupported
83-
isOpened: (editor: IResourceEditorInputIdentifier) => boolean = () => false
84-
isVisible: (editor: EditorInput) => boolean = () => false
85-
findEditors(resource: URI, options?: IFindEditorOptions): readonly IEditorIdentifier[]
86-
findEditors(editor: IResourceEditorInputIdentifier, options?: IFindEditorOptions): readonly IEditorIdentifier[]
87-
findEditors (): readonly IEditorIdentifier[] { return [] }
88-
save: (editors: IEditorIdentifier | IEditorIdentifier[], options?: ISaveEditorsOptions) => Promise<ISaveEditorsResult> = async () => ({ success: true, editors: [] })
89-
saveAll: (options?: ISaveAllEditorsOptions) => Promise<ISaveEditorsResult> = async () => ({ success: true, editors: [] })
90-
revert: (editors: IEditorIdentifier | IEditorIdentifier[], options?: IRevertOptions) => Promise<boolean> = unsupported
91-
revertAll: (options?: IRevertAllEditorsOptions) => Promise<boolean> = unsupported
92-
closeEditor: (editor: IEditorIdentifier, options?: ICloseEditorOptions) => Promise<void> = unsupported
93-
closeEditors: (editors: readonly IEditorIdentifier[], options?: ICloseEditorOptions) => Promise<void> = unsupported
9427
}
9528

9629
/**
@@ -106,8 +39,9 @@ Registry.as<IEditorFactoryRegistry>(EditorExtensions.EditorFactory).registerFile
10639
export default function getServiceOverride (openEditor: OpenEditor): IEditorOverrideServices {
10740
return {
10841
[ICodeEditorService.toString()]: new SyncDescriptor(CodeEditorService, undefined, true),
109-
[IEditorService.toString()]: new SyncDescriptor(SimpleEditorService, [openEditor], true),
110-
[ITextEditorService.toString()]: new SyncDescriptor(TextEditorService, [], false)
42+
[IEditorService.toString()]: new SyncDescriptor(MonacoEditorService, [openEditor, () => false], true),
43+
[ITextEditorService.toString()]: new SyncDescriptor(TextEditorService, [], false),
44+
[IEditorGroupsService.toString()]: new SyncDescriptor(MonacoEditorGroupsService)
11145
}
11246
}
11347

@@ -116,5 +50,5 @@ export {
11650
IEditorOptions,
11751
IResolvedTextEditorModel,
11852
IReference,
119-
SimpleEditorService
53+
MonacoEditorService
12054
}

0 commit comments

Comments
 (0)