Skip to content

Commit fe497d6

Browse files
authored
Merge pull request #142 from CodinGame/expose-simple-editor-service
Expose simple editor service
2 parents 2a983e6 + 895d0ae commit fe497d6

File tree

2 files changed

+45
-32
lines changed

2 files changed

+45
-32
lines changed

.eslintrc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,14 @@
2929
"worker": "always",
3030
"ts": "always"
3131
}
32+
],
33+
"@typescript-eslint/no-unused-vars": [
34+
"warn", // or "error"
35+
{
36+
"argsIgnorePattern": "^_",
37+
"varsIgnorePattern": "^_",
38+
"caughtErrorsIgnorePattern": "^_"
39+
}
3240
]
3341
},
3442
"ignorePatterns": [

src/service-override/editor.ts

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,23 @@ import { IEditorOverrideServices, StandaloneServices } from 'vs/editor/standalon
33
import { IResolvedTextEditorModel, ITextModelService } from 'vs/editor/common/services/resolverService'
44
import { ICodeEditorService } from 'vs/editor/browser/services/codeEditorService'
55
import { CodeEditorService } from 'vs/workbench/services/editor/browser/codeEditorService'
6-
import { IEditorService, PreferredGroup } from 'vs/workbench/services/editor/common/editorService'
7-
import { IEditorPane, IResourceDiffEditorInput, ITextDiffEditorPane, IUntitledTextResourceEditorInput, IUntypedEditorInput } from 'vs/workbench/common/editor'
6+
import { IEditorService, IEditorsChangeEvent, IOpenEditorsOptions, IRevertAllEditorsOptions, ISaveAllEditorsOptions, ISaveEditorsOptions, ISaveEditorsResult, IUntypedEditorReplacement, PreferredGroup } from 'vs/workbench/services/editor/common/editorService'
7+
import { EditorInputWithOptions, EditorsOrder, GroupIdentifier, IEditorCloseEvent, IEditorIdentifier, IEditorPane, IFindEditorOptions, IResourceDiffEditorInput, IRevertOptions, ITextDiffEditorPane, IUntitledTextResourceEditorInput, IUntypedEditorInput, IVisibleEditorPane } from 'vs/workbench/common/editor'
88
import { Emitter, Event } from 'vs/base/common/event'
99
import { EditorInput } from 'vs/workbench/common/editor/editorInput'
10-
import { IEditorOptions, IResourceEditorInput, ITextResourceEditorInput } from 'vs/platform/editor/common/editor'
10+
import { IEditorOptions, IResourceEditorInput, IResourceEditorInputIdentifier, ITextResourceEditorInput } from 'vs/platform/editor/common/editor'
1111
import { IEditor } from 'vs/editor/common/editorCommon'
1212
import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'
1313
import { Disposable, IReference } from 'vs/base/common/lifecycle'
14-
import { ICodeEditor } from 'vs/editor/browser/editorBrowser'
14+
import { ICodeEditor, IDiffEditor } from 'vs/editor/browser/editorBrowser'
1515
import { ITextEditorService, TextEditorService } from 'vs/workbench/services/textfile/common/textEditorService'
16+
import { ICloseEditorOptions, IEditorGroup, IEditorReplacement } from 'vs/workbench/services/editor/common/editorGroupsService'
17+
import { URI } from 'vs/base/common/uri'
1618
import { OpenEditor, wrapOpenEditor } from './tools/editor'
1719
import { unsupported } from '../tools'
1820
import 'vs/workbench/browser/parts/editor/editor.contribution'
1921

20-
class EditorService extends Disposable implements IEditorService {
22+
class SimpleEditorService extends Disposable implements IEditorService {
2123
public activeTextEditorControl: IEditor | undefined
2224
private _onDidActiveEditorChange = this._register(new Emitter<void>())
2325

@@ -49,47 +51,49 @@ class EditorService extends Disposable implements IEditorService {
4951
}
5052

5153
readonly _serviceBrand: undefined
52-
onDidActiveEditorChange = this._onDidActiveEditorChange.event
53-
onDidVisibleEditorsChange = Event.None
54-
onDidEditorsChange = Event.None
55-
onDidCloseEditor = Event.None
56-
activeEditorPane: undefined
57-
activeEditor: undefined
58-
activeTextEditorLanguageId = undefined
59-
visibleEditorPanes = []
60-
visibleEditors = []
61-
visibleTextEditorControls = []
62-
editors = []
63-
count = 0
64-
getEditors = () => []
54+
onDidActiveEditorChange: Event<void> = this._onDidActiveEditorChange.event
55+
onDidVisibleEditorsChange: Event<void> = Event.None
56+
onDidEditorsChange: Event<IEditorsChangeEvent> = Event.None
57+
onDidCloseEditor: Event<IEditorCloseEvent> = Event.None
58+
activeEditorPane: IVisibleEditorPane | undefined
59+
activeEditor: EditorInput | undefined
60+
activeTextEditorLanguageId: string | undefined
61+
visibleEditorPanes: IVisibleEditorPane[] = []
62+
visibleEditors: EditorInput[] = []
63+
visibleTextEditorControls: Array<ICodeEditor | IDiffEditor> = []
64+
editors: EditorInput[] = []
65+
count: number = 0
66+
getEditors: (order: EditorsOrder, options?: { excludeSticky?: boolean }) => readonly IEditorIdentifier[] = () => []
6567

6668
openEditor(editor: EditorInput, options?: IEditorOptions, group?: PreferredGroup): Promise<IEditorPane | undefined>
6769
openEditor(editor: IUntypedEditorInput, group?: PreferredGroup): Promise<IEditorPane | undefined>
6870
openEditor(editor: IResourceEditorInput, group?: PreferredGroup): Promise<IEditorPane | undefined>
6971
openEditor(editor: ITextResourceEditorInput | IUntitledTextResourceEditorInput, group?: PreferredGroup): Promise<IEditorPane | undefined>
7072
openEditor(editor: IResourceDiffEditorInput, group?: PreferredGroup): Promise<ITextDiffEditorPane | undefined>
7173
openEditor(editor: EditorInput | IUntypedEditorInput, optionsOrPreferredGroup?: IEditorOptions | PreferredGroup, preferredGroup?: PreferredGroup): Promise<IEditorPane | undefined>
72-
async openEditor () {
74+
async openEditor (_editor: EditorInput | IUntypedEditorInput, _optionsOrPreferredGroup?: IEditorOptions | PreferredGroup, _preferredGroup?: PreferredGroup): Promise<IEditorPane | undefined> {
7375
return undefined
7476
}
7577

76-
openEditors = unsupported
77-
replaceEditors = unsupported
78-
isOpened = () => false
79-
isVisible = () => false
80-
findEditors = () => []
81-
save = async () => ({ success: true, editors: [] })
82-
saveAll = async () => ({ success: true, editors: [] })
83-
revert = unsupported
84-
revertAll = unsupported
85-
closeEditor = unsupported
86-
closeEditors = unsupported
78+
openEditors: (editors: Array<EditorInputWithOptions | IUntypedEditorInput>, preferredGroup?: PreferredGroup, options?: IOpenEditorsOptions) => Promise<IEditorPane[]> = unsupported
79+
replaceEditors: (replacements: Array<IEditorReplacement | IUntypedEditorReplacement>, group: IEditorGroup | GroupIdentifier) => Promise<void> = unsupported
80+
isOpened: (editor: IResourceEditorInputIdentifier) => boolean = () => false
81+
isVisible: (editor: EditorInput) => boolean = () => false
82+
findEditors(resource: URI, options?: IFindEditorOptions): readonly IEditorIdentifier[]
83+
findEditors(editor: IResourceEditorInputIdentifier, options?: IFindEditorOptions): readonly IEditorIdentifier[]
84+
findEditors (): readonly IEditorIdentifier[] { return [] }
85+
save: (editors: IEditorIdentifier | IEditorIdentifier[], options?: ISaveEditorsOptions) => Promise<ISaveEditorsResult> = async () => ({ success: true, editors: [] })
86+
saveAll: (options?: ISaveAllEditorsOptions) => Promise<ISaveEditorsResult> = async () => ({ success: true, editors: [] })
87+
revert: (editors: IEditorIdentifier | IEditorIdentifier[], options?: IRevertOptions) => Promise<boolean> = unsupported
88+
revertAll: (options?: IRevertAllEditorsOptions) => Promise<boolean> = unsupported
89+
closeEditor: (editor: IEditorIdentifier, options?: ICloseEditorOptions) => Promise<void> = unsupported
90+
closeEditors: (editors: readonly IEditorIdentifier[], options?: ICloseEditorOptions) => Promise<void> = unsupported
8791
}
8892

8993
export default function getServiceOverride (openEditor: OpenEditor): IEditorOverrideServices {
9094
return {
9195
[ICodeEditorService.toString()]: new SyncDescriptor(CodeEditorService, undefined, true),
92-
[IEditorService.toString()]: new SyncDescriptor(EditorService, [openEditor]),
96+
[IEditorService.toString()]: new SyncDescriptor(SimpleEditorService, [openEditor]),
9397
[ITextEditorService.toString()]: new SyncDescriptor(TextEditorService)
9498
}
9599
}
@@ -98,5 +102,6 @@ export {
98102
OpenEditor,
99103
IEditorOptions,
100104
IResolvedTextEditorModel,
101-
IReference
105+
IReference,
106+
SimpleEditorService
102107
}

0 commit comments

Comments
 (0)