@codingame/monaco-vscode-multi-diff-editor-service-override 36.2.6 → 37.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@codingame/monaco-vscode-multi-diff-editor-service-override",
3
- "version": "36.2.6",
3
+ "version": "37.0.0",
4
4
  "private": false,
5
5
  "description": "VSCode public API plugged on the monaco editor - multi-diff-editor service-override",
6
6
  "keywords": [],
@@ -15,7 +15,7 @@
15
15
  },
16
16
  "type": "module",
17
17
  "dependencies": {
18
- "@codingame/monaco-vscode-api": "36.2.6"
18
+ "@codingame/monaco-vscode-api": "37.0.0"
19
19
  },
20
20
  "main": "index.js",
21
21
  "module": "index.js",
@@ -4,6 +4,12 @@ export declare class GoToFileAction extends Action2 {
4
4
  constructor();
5
5
  run(accessor: ServicesAccessor, ...args: unknown[]): Promise<void>;
6
6
  }
7
+ export declare class OpenMultiDiffEditorLayoutDebugAction extends Action2 {
8
+ static readonly ID = "multiDiffEditor.openLayoutDebug";
9
+ static readonly TITLE: import("@codingame/monaco-vscode-api/vscode/vs/nls").ILocalizedString;
10
+ constructor();
11
+ run(accessor: ServicesAccessor): Promise<void>;
12
+ }
7
13
  export declare class GoToNextChangeAction extends Action2 {
8
14
  constructor();
9
15
  run(accessor: ServicesAccessor): Promise<void>;
@@ -1,8 +1,12 @@
1
1
 
2
2
  import { Codicon } from '@codingame/monaco-vscode-api/vscode/vs/base/common/codicons';
3
3
  import { KeyMod, KeyCode } from '@codingame/monaco-vscode-api/vscode/vs/base/common/keyCodes';
4
- import { localize2 } from '@codingame/monaco-vscode-api/vscode/vs/nls';
5
- import { Action2, MenuId } from '@codingame/monaco-vscode-api/vscode/vs/platform/actions/common/actions';
4
+ import { Categories } from '@codingame/monaco-vscode-api/vscode/vs/platform/action/common/actionCommonCategories';
5
+ import { EditorContextKeys } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/editorContextKeys';
6
+ import { ILanguageService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/languages/language.service';
7
+ import { IModelService } from '@codingame/monaco-vscode-api/vscode/vs/editor/common/services/model.service';
8
+ import { localize, localize2 } from '@codingame/monaco-vscode-api/vscode/vs/nls';
9
+ import { MenuRegistry, MenuId, Action2 } from '@codingame/monaco-vscode-api/vscode/vs/platform/actions/common/actions';
6
10
  import { ContextKeyExpr } from '@codingame/monaco-vscode-api/vscode/vs/platform/contextkey/common/contextkey';
7
11
  import { TextEditorSelectionRevealType } from '@codingame/monaco-vscode-api/vscode/vs/platform/editor/common/editor';
8
12
  import { KeybindingWeight } from '@codingame/monaco-vscode-api/vscode/vs/platform/keybinding/common/keybindingsRegistry';
@@ -11,14 +15,24 @@ import { resolveCommandsContext } from '@codingame/monaco-vscode-api/vscode/vs/w
11
15
  import { MultiDiffEditor } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/multiDiffEditor/browser/multiDiffEditor';
12
16
  import { MultiDiffEditorInput } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/multiDiffEditor/browser/multiDiffEditorInput';
13
17
  import { IEditorGroupsService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorGroupsService.service';
18
+ import { AUX_WINDOW_GROUP, SIDE_GROUP } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorService';
14
19
  import { IEditorService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/editor/common/editorService.service';
15
20
  import { ActiveEditorContext, IsSessionsWindowContext } from '@codingame/monaco-vscode-api/vscode/vs/workbench/common/contextkeys';
21
+ import { isMultiDiffEditorLayoutDebugStateProvider, createMultiDiffEditorLayoutDebugModel } from './multiDiffEditorLayoutDebug.js';
22
+ import { IWorkbenchEnvironmentService } from '@codingame/monaco-vscode-api/vscode/vs/workbench/services/environment/common/environmentService.service';
16
23
 
24
+ MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
25
+ submenu: MenuId.DiffEditorViewSubmenu,
26
+ title: ( localize(14104, "Diff View")),
27
+ group: "1_diff",
28
+ order: 10,
29
+ when: ( ContextKeyExpr.and(( ActiveEditorContext.isEqualTo(MultiDiffEditor.ID)), ( IsSessionsWindowContext.toNegated())))
30
+ });
17
31
  class GoToFileAction extends Action2 {
18
32
  constructor() {
19
33
  super({
20
34
  id: "multiDiffEditor.goToFile",
21
- title: ( localize2(12343, "Open File")),
35
+ title: ( localize2(14105, "Open File")),
22
36
  icon: Codicon.goToFile,
23
37
  precondition: ( ActiveEditorContext.isEqualTo(MultiDiffEditor.ID)),
24
38
  menu: {
@@ -56,11 +70,55 @@ class GoToFileAction extends Action2 {
56
70
  });
57
71
  }
58
72
  }
73
+ class OpenMultiDiffEditorLayoutDebugAction extends Action2 {
74
+ static {
75
+ this.ID = "multiDiffEditor.openLayoutDebug";
76
+ }
77
+ static {
78
+ this.TITLE = ( localize2(14106, "Open Multi Diff Editor Layout Debug State"));
79
+ }
80
+ constructor() {
81
+ super({
82
+ id: OpenMultiDiffEditorLayoutDebugAction.ID,
83
+ title: OpenMultiDiffEditorLayoutDebugAction.TITLE,
84
+ category: Categories.Developer,
85
+ precondition: ( ContextKeyExpr.or(( ActiveEditorContext.isEqualTo(MultiDiffEditor.ID)), EditorContextKeys.inMultiDiffEditor)),
86
+ f1: true
87
+ });
88
+ }
89
+ async run(accessor) {
90
+ const editorService = accessor.get(IEditorService);
91
+ const environmentService = accessor.get(IWorkbenchEnvironmentService);
92
+ const activeEditorPane = editorService.activeEditorPane;
93
+ if (!isMultiDiffEditorLayoutDebugStateProvider(activeEditorPane)) {
94
+ return;
95
+ }
96
+ const model = createMultiDiffEditorLayoutDebugModel(
97
+ activeEditorPane.getLayoutDebugState(),
98
+ accessor.get(IModelService),
99
+ accessor.get(ILanguageService)
100
+ );
101
+ try {
102
+ const editor = await editorService.openEditor({
103
+ resource: model.uri,
104
+ options: {
105
+ pinned: true
106
+ }
107
+ }, environmentService.isSessionsWindow ? AUX_WINDOW_GROUP : SIDE_GROUP);
108
+ if (!editor) {
109
+ model.dispose();
110
+ }
111
+ } catch (error) {
112
+ model.dispose();
113
+ throw error;
114
+ }
115
+ }
116
+ }
59
117
  class GoToNextChangeAction extends Action2 {
60
118
  constructor() {
61
119
  super({
62
120
  id: "multiDiffEditor.goToNextChange",
63
- title: ( localize2(12344, "Go to Next Change")),
121
+ title: ( localize2(14107, "Go to Next Change")),
64
122
  icon: Codicon.arrowDown,
65
123
  precondition: ( ContextKeyExpr.equals("activeEditor", MultiDiffEditor.ID)),
66
124
  menu: ( [MenuId.EditorTitle, MenuId.CompactWindowEditorTitle].map(id => ({
@@ -90,7 +148,7 @@ class GoToPreviousChangeAction extends Action2 {
90
148
  constructor() {
91
149
  super({
92
150
  id: "multiDiffEditor.goToPreviousChange",
93
- title: ( localize2(12345, "Go to Previous Change")),
151
+ title: ( localize2(14108, "Go to Previous Change")),
94
152
  icon: Codicon.arrowUp,
95
153
  precondition: ( ContextKeyExpr.equals("activeEditor", MultiDiffEditor.ID)),
96
154
  menu: ( [MenuId.EditorTitle, MenuId.CompactWindowEditorTitle].map(id => ({
@@ -120,7 +178,7 @@ class CollapseAllAction extends Action2 {
120
178
  constructor() {
121
179
  super({
122
180
  id: "multiDiffEditor.collapseAll",
123
- title: ( localize2(12346, "Collapse All Diffs")),
181
+ title: ( localize2(14109, "Collapse All Diffs")),
124
182
  icon: Codicon.collapseAll,
125
183
  precondition: ( ContextKeyExpr.and(( ContextKeyExpr.equals("activeEditor", MultiDiffEditor.ID)), ContextKeyExpr.not("multiDiffEditorAllCollapsed"))),
126
184
  menu: [
@@ -168,7 +226,7 @@ class ExpandAllAction extends Action2 {
168
226
  constructor() {
169
227
  super({
170
228
  id: "multiDiffEditor.expandAll",
171
- title: ( localize2(12347, "Expand All Diffs")),
229
+ title: ( localize2(14110, "Expand All Diffs")),
172
230
  icon: Codicon.expandAll,
173
231
  precondition: ( ContextKeyExpr.and(( ContextKeyExpr.equals("activeEditor", MultiDiffEditor.ID)), ( ContextKeyExpr.has("multiDiffEditorAllCollapsed")))),
174
232
  menu: [
@@ -213,4 +271,4 @@ class ExpandAllAction extends Action2 {
213
271
  }
214
272
  }
215
273
 
216
- export { CollapseAllAction, ExpandAllAction, GoToFileAction, GoToNextChangeAction, GoToPreviousChangeAction };
274
+ export { CollapseAllAction, ExpandAllAction, GoToFileAction, GoToNextChangeAction, GoToPreviousChangeAction, OpenMultiDiffEditorLayoutDebugAction };
@@ -8,7 +8,7 @@ import { registerWorkbenchContribution2, WorkbenchPhase } from '@codingame/monac
8
8
  import { EditorExtensions } from '@codingame/monaco-vscode-api/vscode/vs/workbench/common/editor';
9
9
  import { MultiDiffEditor } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/multiDiffEditor/browser/multiDiffEditor';
10
10
  import { MultiDiffEditorResolverContribution, MultiDiffEditorInput, MultiDiffEditorSerializer } from '@codingame/monaco-vscode-api/vscode/vs/workbench/contrib/multiDiffEditor/browser/multiDiffEditorInput';
11
- import { GoToFileAction, GoToNextChangeAction, GoToPreviousChangeAction, CollapseAllAction, ExpandAllAction } from './actions.js';
11
+ import { GoToFileAction, GoToNextChangeAction, GoToPreviousChangeAction, CollapseAllAction, ExpandAllAction, OpenMultiDiffEditorLayoutDebugAction } from './actions.js';
12
12
  import '@codingame/monaco-vscode-api/vscode/vs/base/common/errors';
13
13
  import '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
14
14
  import '@codingame/monaco-vscode-api/vscode/vs/platform/instantiation/common/instantiation';
@@ -20,13 +20,14 @@ registerAction2(GoToNextChangeAction);
20
20
  registerAction2(GoToPreviousChangeAction);
21
21
  registerAction2(CollapseAllAction);
22
22
  registerAction2(ExpandAllAction);
23
+ registerAction2(OpenMultiDiffEditorLayoutDebugAction);
23
24
  registerWorkbenchContribution2(
24
25
  MultiDiffEditorResolverContribution.ID,
25
26
  MultiDiffEditorResolverContribution,
26
27
  WorkbenchPhase.BlockStartup
27
28
  );
28
29
  ( Registry.as(EditorExtensions.EditorPane)).registerEditorPane(
29
- EditorPaneDescriptor.create(MultiDiffEditor, MultiDiffEditor.ID, ( localize(12349, "Multi Diff Editor"))),
30
+ EditorPaneDescriptor.create(MultiDiffEditor, MultiDiffEditor.ID, ( localize(14112, "Multi Diff Editor"))),
30
31
  [( new SyncDescriptor(MultiDiffEditorInput))]
31
32
  );
32
33
  ( Registry.as(EditorExtensions.EditorFactory)).registerEditorSerializer(MultiDiffEditorInput.ID, MultiDiffEditorSerializer);
@@ -0,0 +1,24 @@
1
+ import { JSONPath } from "@codingame/monaco-vscode-api/vscode/vs/base/common/json";
2
+ import { IObservable } from "@codingame/monaco-vscode-api/vscode/vs/base/common/observable";
3
+ import { ITextModel } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/model";
4
+ import { IModelService } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/services/model.service";
5
+ import { ILanguageService } from "@codingame/monaco-vscode-api/vscode/vs/editor/common/languages/language.service";
6
+ import { IMultiDiffEditorLayoutDebugState } from "@codingame/monaco-vscode-api/vscode/vs/editor/browser/widget/multiDiffEditor/multiDiffEditorWidgetImpl";
7
+ type JsonValue = null | boolean | number | string | readonly JsonValue[] | object;
8
+ export type JsonPatchOperation = {
9
+ readonly op: "add" | "replace";
10
+ readonly path: string;
11
+ readonly value: JsonValue;
12
+ } | {
13
+ readonly op: "remove";
14
+ readonly path: string;
15
+ };
16
+ export type JsonPatch = readonly (JsonPatchOperation | JsonPatch)[];
17
+ export interface IMultiDiffEditorLayoutDebugStateProvider {
18
+ getLayoutDebugState(): IObservable<IMultiDiffEditorLayoutDebugState>;
19
+ }
20
+ export declare function isMultiDiffEditorLayoutDebugStateProvider(candidate: object | undefined): candidate is IMultiDiffEditorLayoutDebugStateProvider;
21
+ export declare function createMultiDiffEditorLayoutDebugModel(state: IObservable<IMultiDiffEditorLayoutDebugState>, modelService: IModelService, languageService: ILanguageService): ITextModel;
22
+ export declare function createJsonPatch(previous: JsonValue, next: JsonValue, path?: JSONPath): JsonPatch;
23
+ export declare function applyJsonPatchToText(text: string, patch: JsonPatch): string;
24
+ export {};
@@ -0,0 +1,128 @@
1
+
2
+ import '@codingame/monaco-vscode-api/vscode/vs/base/common/json';
3
+ import { DisposableStore } from '@codingame/monaco-vscode-api/vscode/vs/base/common/lifecycle';
4
+ import { Schemas } from '@codingame/monaco-vscode-api/vscode/vs/base/common/network';
5
+ import '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/index';
6
+ import { generateUuid } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uuid';
7
+ import { URI } from '@codingame/monaco-vscode-api/vscode/vs/base/common/uri';
8
+ import { autorun } from '@codingame/monaco-vscode-api/vscode/vs/base/common/observableInternal/reactions/autorun';
9
+
10
+ function isMultiDiffEditorLayoutDebugStateProvider(candidate) {
11
+ return !!candidate && "getLayoutDebugState" in candidate && typeof candidate.getLayoutDebugState === "function";
12
+ }
13
+ function createMultiDiffEditorLayoutDebugModel(state, modelService, languageService) {
14
+ let previousState = state.get();
15
+ const id = generateUuid();
16
+ const logModel = modelService.createModel(`${JSON.stringify({
17
+ timestamp: Date.now(),
18
+ set: previousState
19
+ })}\n`, languageService.createById("jsonl"), ( URI.from({
20
+ scheme: Schemas.inMemory,
21
+ path: `/multi-diff-editor-layout-${id}.jsonl`
22
+ })));
23
+ const store = ( new DisposableStore());
24
+ store.add(logModel.onWillDispose(() => store.dispose()));
25
+ store.add(autorun(reader => {
26
+ const nextState = state.read(reader);
27
+ const operations = createJsonPatch(previousState, nextState);
28
+ if (!logModel.isDisposed() && operations.length > 0) {
29
+ appendJsonLines(logModel, [{
30
+ timestamp: Date.now(),
31
+ patch: operations
32
+ }]);
33
+ }
34
+ previousState = nextState;
35
+ }));
36
+ return logModel;
37
+ }
38
+ function createJsonPatch(previous, next, path = []) {
39
+ if (Object.is(previous, next)) {
40
+ return [];
41
+ }
42
+ if (Array.isArray(previous) && Array.isArray(next)) {
43
+ if (previous.length !== next.length) {
44
+ return [{
45
+ op: "replace",
46
+ path: toJsonPointer(path),
47
+ value: next
48
+ }];
49
+ }
50
+ const operations = [];
51
+ for (let index = 0; index < previous.length; index++) {
52
+ appendJsonPatchOperations(
53
+ operations,
54
+ createJsonPatch(previous[index], next[index], [...path, index])
55
+ );
56
+ }
57
+ return operations;
58
+ }
59
+ if (isJsonObject(previous) && isJsonObject(next)) {
60
+ const operations = [];
61
+ for (const key of ( Object.keys(previous))) {
62
+ if (previous[key] !== undefined && next[key] === undefined) {
63
+ operations.push({
64
+ op: "remove",
65
+ path: toJsonPointer([...path, key])
66
+ });
67
+ }
68
+ }
69
+ for (const [key, value] of Object.entries(next)) {
70
+ if (value === undefined) {
71
+ continue;
72
+ }
73
+ const previousValue = previous[key];
74
+ if (previousValue === undefined) {
75
+ operations.push({
76
+ op: "add",
77
+ path: toJsonPointer([...path, key]),
78
+ value
79
+ });
80
+ } else {
81
+ appendJsonPatchOperations(operations, createJsonPatch(previousValue, value, [...path, key]));
82
+ }
83
+ }
84
+ return operations;
85
+ }
86
+ return [{
87
+ op: "replace",
88
+ path: toJsonPointer(path),
89
+ value: next
90
+ }];
91
+ }
92
+ function appendJsonPatchOperations(target, patch) {
93
+ forEachJsonPatchOperation(patch, operation => target.push(operation));
94
+ }
95
+ function forEachJsonPatchOperation(patch, callback) {
96
+ for (const entry of patch) {
97
+ if (isJsonPatch(entry)) {
98
+ forEachJsonPatchOperation(entry, callback);
99
+ } else {
100
+ callback(entry);
101
+ }
102
+ }
103
+ }
104
+ function isJsonPatch(value) {
105
+ return Array.isArray(value);
106
+ }
107
+ function appendJsonLines(model, values) {
108
+ const end = model.getPositionAt(model.getValueLength());
109
+ model.applyEdits([{
110
+ range: {
111
+ startLineNumber: end.lineNumber,
112
+ startColumn: end.column,
113
+ endLineNumber: end.lineNumber,
114
+ endColumn: end.column
115
+ },
116
+ text: ( values.map(value => `${JSON.stringify(value)}\n`)).join("")
117
+ }]);
118
+ }
119
+ function isJsonObject(value) {
120
+ return typeof value === "object" && value !== null && !Array.isArray(value);
121
+ }
122
+ function toJsonPointer(path) {
123
+ return ( path.map(
124
+ segment => `/${String(segment).replaceAll("~", "~0").replaceAll("/", "~1")}`
125
+ )).join("");
126
+ }
127
+
128
+ export { createJsonPatch, createMultiDiffEditorLayoutDebugModel, isMultiDiffEditorLayoutDebugStateProvider };