1
1
import { editor , Uri } from 'monaco-editor' ;
2
2
import { createConfiguredEditor , createConfiguredDiffEditor , createModelReference , ITextFileEditorModel } from 'vscode/monaco' ;
3
3
import { IReference } from 'vscode/service-override/editor' ;
4
- import { WrapperConfig } from './wrapper.js' ;
5
4
import { updateUserConfiguration as vscodeUpdateUserConfiguration } from 'vscode/service-override/configuration' ;
6
- import { EditorAppConfigClassic } from './editorAppClassic.js' ;
7
- import { EditorAppConfigExtended } from './editorAppExtended.js' ;
8
5
9
6
export type ModelUpdate = {
10
7
languageId : string ;
@@ -14,14 +11,21 @@ export type ModelUpdate = {
14
11
codeOriginalUri ?: string ;
15
12
}
16
13
17
- export type EditorAppBaseConfig = ModelUpdate & {
14
+ export type EditorAppType = 'extended' | 'classic' ;
15
+
16
+ export type EditorAppConfigBase = ModelUpdate & {
17
+ $type : EditorAppType ;
18
18
useDiffEditor : boolean ;
19
19
domReadOnly ?: boolean ;
20
20
readOnly ?: boolean ;
21
21
awaitExtensionReadiness ?: Array < ( ) => Promise < void > > ;
22
22
}
23
23
24
- export type EditorAppType = 'extended' | 'classic' ;
24
+ export enum ModelUpdateType {
25
+ none ,
26
+ code ,
27
+ model
28
+ }
25
29
26
30
/**
27
31
* This is the base class for both Monaco Ediotor Apps:
@@ -44,8 +48,9 @@ export abstract class EditorAppBase {
44
48
this . id = id ;
45
49
}
46
50
47
- protected buildConfig ( userAppConfig : EditorAppConfigExtended | EditorAppConfigClassic ) : EditorAppBaseConfig {
51
+ protected buildConfig ( userAppConfig : EditorAppConfigBase ) : EditorAppConfigBase {
48
52
return {
53
+ $type : userAppConfig . $type ,
49
54
languageId : userAppConfig . languageId ,
50
55
code : userAppConfig . code ?? '' ,
51
56
codeOriginal : userAppConfig . codeOriginal ?? '' ,
@@ -214,31 +219,31 @@ export abstract class EditorAppBase {
214
219
return Promise . resolve ( ) ;
215
220
}
216
221
217
- protected async updateUserConfiguration ( json ?: string ) {
222
+ updateMonacoEditorOptions ( options : editor . IEditorOptions & editor . IGlobalEditorOptions ) {
223
+ this . getEditor ( ) ?. updateOptions ( options ) ;
224
+ }
225
+
226
+ async updateUserConfiguration ( json ?: string ) {
218
227
if ( json ) {
219
228
return vscodeUpdateUserConfiguration ( json ) ;
220
229
}
221
230
return Promise . resolve ( ) ;
222
231
}
223
232
224
- abstract getAppType ( ) : string ;
225
233
abstract init ( ) : Promise < void > ;
226
234
abstract specifyService ( ) : editor . IEditorOverrideServices ;
227
235
abstract createEditors ( container : HTMLElement ) : Promise < void > ;
228
- abstract getConfig ( ) : EditorAppConfigClassic | EditorAppConfigExtended ;
236
+ abstract getConfig ( ) : EditorAppConfigBase ;
229
237
abstract disposeApp ( ) : void ;
238
+ abstract isAppConfigDifferent ( orgConfig : EditorAppConfigBase , config : EditorAppConfigBase , includeModelData : boolean ) : boolean ;
230
239
}
231
240
232
- export const isExtendedEditorApp = ( wrapperConfig : WrapperConfig ) => {
233
- return wrapperConfig . editorAppConfig ?. $type === 'extended' ;
234
- } ;
235
-
236
- export const isCodeUpdateRequired = ( config : EditorAppBaseConfig , modelUpdate : ModelUpdate ) => {
241
+ export const isCodeUpdateRequired = ( config : EditorAppConfigBase , modelUpdate : ModelUpdate ) => {
237
242
const updateRequired = ( modelUpdate . code !== undefined && modelUpdate . code !== config . code ) || modelUpdate . codeOriginal !== config . codeOriginal ;
238
243
return updateRequired ? ModelUpdateType . code : ModelUpdateType . none ;
239
244
} ;
240
245
241
- export const isModelUpdateRequired = ( config : EditorAppBaseConfig , modelUpdate : ModelUpdate ) : ModelUpdateType => {
246
+ export const isModelUpdateRequired = ( config : EditorAppConfigBase , modelUpdate : ModelUpdate ) : ModelUpdateType => {
242
247
const codeUpdate = isCodeUpdateRequired ( config , modelUpdate ) ;
243
248
244
249
type ModelUpdateKeys = keyof typeof modelUpdate ;
@@ -249,43 +254,3 @@ export const isModelUpdateRequired = (config: EditorAppBaseConfig, modelUpdate:
249
254
const updateRequired = propsModelUpdate . some ( propCompare ) ;
250
255
return updateRequired ? ModelUpdateType . model : codeUpdate ;
251
256
} ;
252
-
253
- export enum ModelUpdateType {
254
- none ,
255
- code ,
256
- model
257
- }
258
-
259
- export const isAppConfigDifferent = ( orgConfig : EditorAppConfigClassic | EditorAppConfigExtended ,
260
- config : EditorAppConfigClassic | EditorAppConfigExtended , includeModelData : boolean , includeEditorOptions : boolean ) : boolean => {
261
-
262
- let different = includeModelData ? isModelUpdateRequired ( orgConfig , config ) !== ModelUpdateType . none : false ;
263
- if ( orgConfig . $type === config . $type ) {
264
-
265
- type ClassicKeys = keyof typeof orgConfig ;
266
- const propsClassic = [ 'useDiffEditor' , 'readOnly' , 'domReadOnly' , 'awaitExtensionReadiness' , 'automaticLayout' , 'languageDef' , 'languageExtensionConfig' , 'theme' , 'themeData' ] ;
267
- const propsClassicEditorOptions = [ 'editorOptions' , 'diffEditorOptions' ] ;
268
-
269
- const propCompareClassic = ( name : string ) => {
270
- return orgConfig [ name as ClassicKeys ] !== config [ name as ClassicKeys ] ;
271
- } ;
272
-
273
- const propsVscode = [ 'useDiffEditor' , 'readOnly' , 'domReadOnly' , 'awaitExtensionReadiness' , 'userConfiguration' , 'extensions' ] ;
274
- type ExtendedKeys = keyof typeof orgConfig ;
275
- const propCompareExtended = ( name : string ) => {
276
- return orgConfig [ name as ExtendedKeys ] !== config [ name as ExtendedKeys ] ;
277
- } ;
278
-
279
- if ( orgConfig . $type === 'classic' && config . $type === 'classic' ) {
280
- different = different || propsClassic . some ( propCompareClassic ) ;
281
- if ( includeEditorOptions ) {
282
- different = different || propsClassicEditorOptions . some ( propCompareClassic ) ;
283
- }
284
- } else if ( orgConfig . $type === 'extended' && config . $type === 'extended' ) {
285
- different = different || propsVscode . some ( propCompareExtended ) ;
286
- }
287
- } else {
288
- throw new Error ( 'Provided configurations are not of the same type.' ) ;
289
- }
290
- return different ;
291
- } ;
0 commit comments