Skip to content

Commit d7ae94f

Browse files
committed
Merge branch 'main' into aiday/internalIssue4180
2 parents 2e2953c + 1899f62 commit d7ae94f

File tree

3 files changed

+123
-1
lines changed

3 files changed

+123
-1
lines changed

src/vs/editor/standalone/browser/standaloneCodeEditor.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import { PLAINTEXT_LANGUAGE_ID } from 'vs/editor/common/languages/modesRegistry'
3737
import { ILanguageConfigurationService } from 'vs/editor/common/languages/languageConfigurationRegistry';
3838
import { IEditorConstructionOptions } from 'vs/editor/browser/config/editorConfiguration';
3939
import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures';
40+
import { DiffEditorWidget2 } from 'vs/editor/browser/widget/diffEditorWidget2/diffEditorWidget2';
4041

4142
/**
4243
* Description of an action contribution
@@ -555,6 +556,89 @@ export class StandaloneDiffEditor extends DiffEditorWidget implements IStandalon
555556
}
556557
}
557558

559+
export class StandaloneDiffEditor2 extends DiffEditorWidget2 implements IStandaloneDiffEditor {
560+
561+
private readonly _configurationService: IConfigurationService;
562+
private readonly _standaloneThemeService: IStandaloneThemeService;
563+
564+
constructor(
565+
domElement: HTMLElement,
566+
_options: Readonly<IStandaloneDiffEditorConstructionOptions> | undefined,
567+
@IInstantiationService instantiationService: IInstantiationService,
568+
@IContextKeyService contextKeyService: IContextKeyService,
569+
@ICodeEditorService codeEditorService: ICodeEditorService,
570+
@IStandaloneThemeService themeService: IStandaloneThemeService,
571+
@INotificationService notificationService: INotificationService,
572+
@IConfigurationService configurationService: IConfigurationService,
573+
@IContextMenuService contextMenuService: IContextMenuService,
574+
@IEditorProgressService editorProgressService: IEditorProgressService,
575+
@IClipboardService clipboardService: IClipboardService
576+
) {
577+
const options = { ..._options };
578+
updateConfigurationService(configurationService, options, true);
579+
const themeDomRegistration = (<StandaloneThemeService>themeService).registerEditorContainer(domElement);
580+
if (typeof options.theme === 'string') {
581+
themeService.setTheme(options.theme);
582+
}
583+
if (typeof options.autoDetectHighContrast !== 'undefined') {
584+
themeService.setAutoDetectHighContrast(Boolean(options.autoDetectHighContrast));
585+
}
586+
587+
super(
588+
domElement,
589+
options,
590+
{},
591+
contextKeyService,
592+
instantiationService,
593+
codeEditorService,
594+
);
595+
596+
this._configurationService = configurationService;
597+
this._standaloneThemeService = themeService;
598+
599+
this._register(themeDomRegistration);
600+
}
601+
602+
public override dispose(): void {
603+
super.dispose();
604+
}
605+
606+
public override updateOptions(newOptions: Readonly<IDiffEditorOptions & IGlobalEditorOptions>): void {
607+
updateConfigurationService(this._configurationService, newOptions, true);
608+
if (typeof newOptions.theme === 'string') {
609+
this._standaloneThemeService.setTheme(newOptions.theme);
610+
}
611+
if (typeof newOptions.autoDetectHighContrast !== 'undefined') {
612+
this._standaloneThemeService.setAutoDetectHighContrast(Boolean(newOptions.autoDetectHighContrast));
613+
}
614+
super.updateOptions(newOptions);
615+
}
616+
617+
protected override _createInnerEditor(instantiationService: IInstantiationService, container: HTMLElement, options: Readonly<IEditorOptions>): CodeEditorWidget {
618+
return instantiationService.createInstance(StandaloneCodeEditor, container, options);
619+
}
620+
621+
public override getOriginalEditor(): IStandaloneCodeEditor {
622+
return <StandaloneCodeEditor>super.getOriginalEditor();
623+
}
624+
625+
public override getModifiedEditor(): IStandaloneCodeEditor {
626+
return <StandaloneCodeEditor>super.getModifiedEditor();
627+
}
628+
629+
public addCommand(keybinding: number, handler: ICommandHandler, context?: string): string | null {
630+
return this.getModifiedEditor().addCommand(keybinding, handler, context);
631+
}
632+
633+
public createContextKey<T extends ContextKeyValue = ContextKeyValue>(key: string, defaultValue: T): IContextKey<T> {
634+
return this.getModifiedEditor().createContextKey(key, defaultValue);
635+
}
636+
637+
public addAction(descriptor: IActionDescriptor): IDisposable {
638+
return this.getModifiedEditor().addAction(descriptor);
639+
}
640+
}
641+
558642
/**
559643
* @internal
560644
*/

src/vs/editor/standalone/browser/standaloneEditor.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { IModelService } from 'vs/editor/common/services/model';
2323
import { createWebWorker as actualCreateWebWorker, IWebWorkerOptions, MonacoWebWorker } from 'vs/editor/browser/services/webWorker';
2424
import * as standaloneEnums from 'vs/editor/common/standalone/standaloneEnums';
2525
import { Colorizer, IColorizerElementOptions, IColorizerOptions } from 'vs/editor/standalone/browser/colorizer';
26-
import { createTextModel, IActionDescriptor, IStandaloneCodeEditor, IStandaloneDiffEditor, IStandaloneDiffEditorConstructionOptions, IStandaloneEditorConstructionOptions, StandaloneDiffEditor, StandaloneEditor } from 'vs/editor/standalone/browser/standaloneCodeEditor';
26+
import { createTextModel, IActionDescriptor, IStandaloneCodeEditor, IStandaloneDiffEditor, IStandaloneDiffEditorConstructionOptions, IStandaloneEditorConstructionOptions, StandaloneDiffEditor, StandaloneDiffEditor2, StandaloneEditor } from 'vs/editor/standalone/browser/standaloneCodeEditor';
2727
import { IEditorOverrideServices, StandaloneKeybindingService, StandaloneServices } from 'vs/editor/standalone/browser/standaloneServices';
2828
import { StandaloneThemeService } from 'vs/editor/standalone/browser/standaloneThemeService';
2929
import { IStandaloneThemeData, IStandaloneThemeService } from 'vs/editor/standalone/common/standaloneTheme';
@@ -98,6 +98,9 @@ export function getDiffEditors(): readonly IDiffEditor[] {
9898
*/
9999
export function createDiffEditor(domElement: HTMLElement, options?: IStandaloneDiffEditorConstructionOptions, override?: IEditorOverrideServices): IStandaloneDiffEditor {
100100
const instantiationService = StandaloneServices.initialize(override || {});
101+
if ((options?.experimental as any)?.useVersion2) {
102+
return instantiationService.createInstance(StandaloneDiffEditor2, domElement, options);
103+
}
101104
return instantiationService.createInstance(StandaloneDiffEditor, domElement, options);
102105
}
103106

src/vs/editor/standalone/browser/standaloneServices.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ import { AudioCue, IAudioCueService, Sound } from 'vs/platform/audioCues/browser
9191
import { LogService } from 'vs/platform/log/common/logService';
9292
import { getEditorFeatures } from 'vs/editor/common/editorFeatures';
9393
import { onUnexpectedError } from 'vs/base/common/errors';
94+
import { ExtensionKind, IEnvironmentService, IExtensionHostDebugParams } from 'vs/platform/environment/common/environment';
9495

9596
class SimpleModel implements IResolvedTextEditorModel {
9697

@@ -201,6 +202,39 @@ class StandaloneProgressService implements IProgressService {
201202
}
202203
}
203204

205+
class StandaloneEnvironmentService implements IEnvironmentService {
206+
207+
declare readonly _serviceBrand: undefined;
208+
209+
readonly stateResource: URI = URI.from({ scheme: 'monaco', authority: 'stateResource' });
210+
readonly userRoamingDataHome: URI = URI.from({ scheme: 'monaco', authority: 'userRoamingDataHome' });
211+
readonly keyboardLayoutResource: URI = URI.from({ scheme: 'monaco', authority: 'keyboardLayoutResource' });
212+
readonly argvResource: URI = URI.from({ scheme: 'monaco', authority: 'argvResource' });
213+
readonly untitledWorkspacesHome: URI = URI.from({ scheme: 'monaco', authority: 'untitledWorkspacesHome' });
214+
readonly workspaceStorageHome: URI = URI.from({ scheme: 'monaco', authority: 'workspaceStorageHome' });
215+
readonly localHistoryHome: URI = URI.from({ scheme: 'monaco', authority: 'localHistoryHome' });
216+
readonly cacheHome: URI = URI.from({ scheme: 'monaco', authority: 'cacheHome' });
217+
readonly userDataSyncHome: URI = URI.from({ scheme: 'monaco', authority: 'userDataSyncHome' });
218+
readonly sync: 'on' | 'off' | undefined = undefined;
219+
readonly continueOn?: string | undefined = undefined;
220+
readonly editSessionId?: string | undefined = undefined;
221+
readonly debugExtensionHost: IExtensionHostDebugParams = { port: null, break: false };
222+
readonly isExtensionDevelopment: boolean = false;
223+
readonly disableExtensions: boolean | string[] = false;
224+
readonly enableExtensions?: readonly string[] | undefined = undefined;
225+
readonly extensionDevelopmentLocationURI?: URI[] | undefined = undefined;
226+
readonly extensionDevelopmentKind?: ExtensionKind[] | undefined = undefined;
227+
readonly extensionTestsLocationURI?: URI | undefined = undefined;
228+
readonly logsHome: URI = URI.from({ scheme: 'monaco', authority: 'logsHome' });
229+
readonly logLevel?: string | undefined = undefined;
230+
readonly extensionLogLevel?: [string, string][] | undefined = undefined;
231+
readonly verbose: boolean = false;
232+
readonly isBuilt: boolean = false;
233+
readonly disableTelemetry: boolean = false;
234+
readonly serviceMachineIdResource: URI = URI.from({ scheme: 'monaco', authority: 'serviceMachineIdResource' });
235+
readonly policyFile?: URI | undefined = undefined;
236+
}
237+
204238
class StandaloneDialogService implements IDialogService {
205239

206240
_serviceBrand: undefined;
@@ -1029,6 +1063,7 @@ registerSingleton(IWorkspaceContextService, StandaloneWorkspaceContextService, I
10291063
registerSingleton(ILabelService, StandaloneUriLabelService, InstantiationType.Eager);
10301064
registerSingleton(ITelemetryService, StandaloneTelemetryService, InstantiationType.Eager);
10311065
registerSingleton(IDialogService, StandaloneDialogService, InstantiationType.Eager);
1066+
registerSingleton(IEnvironmentService, StandaloneEnvironmentService, InstantiationType.Eager);
10321067
registerSingleton(INotificationService, StandaloneNotificationService, InstantiationType.Eager);
10331068
registerSingleton(IMarkerService, MarkerService, InstantiationType.Eager);
10341069
registerSingleton(ILanguageService, StandaloneLanguageService, InstantiationType.Eager);

0 commit comments

Comments
 (0)