monaco-languageclient 10.7.0 → 11.0.0-next.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/CHANGELOG.md +13 -4
- package/LICENSE +0 -0
- package/README.md +63 -63
- package/lib/common/commonTypes.d.ts +1 -1
- package/lib/common/commonTypes.d.ts.map +1 -1
- package/lib/common/utils.d.ts.map +1 -1
- package/lib/common/utils.js +2 -2
- package/lib/common/utils.js.map +1 -1
- package/lib/debugger/index.d.ts +1 -1
- package/lib/debugger/index.d.ts.map +1 -1
- package/lib/debugger/index.js +2 -4
- package/lib/debugger/index.js.map +1 -1
- package/lib/editorApp/config.d.ts +11 -11
- package/lib/editorApp/config.d.ts.map +1 -1
- package/lib/editorApp/config.js +0 -1
- package/lib/editorApp/config.js.map +1 -1
- package/lib/editorApp/editorApp.d.ts +5 -5
- package/lib/editorApp/editorApp.d.ts.map +1 -1
- package/lib/editorApp/editorApp.js +21 -23
- package/lib/editorApp/editorApp.js.map +1 -1
- package/lib/fs/definitions.d.ts.map +1 -1
- package/lib/fs/endpoints/defaultEndpoint.d.ts.map +1 -1
- package/lib/fs/endpoints/defaultEndpoint.js.map +1 -1
- package/lib/index.d.ts +1 -1
- package/lib/index.d.ts.map +1 -1
- package/lib/index.js +1 -1
- package/lib/index.js.map +1 -1
- package/lib/vscode/apiWrapper.d.ts +2 -2
- package/lib/vscode/apiWrapper.d.ts.map +1 -1
- package/lib/vscode/apiWrapper.js +18 -20
- package/lib/vscode/apiWrapper.js.map +1 -1
- package/lib/vscode/config.d.ts +4 -4
- package/lib/vscode/config.d.ts.map +1 -1
- package/lib/vscode/config.js +0 -1
- package/lib/vscode/config.js.map +1 -1
- package/lib/vscode/locales.d.ts +1 -1
- package/lib/vscode/locales.d.ts.map +1 -1
- package/lib/vscode/locales.js +35 -18
- package/lib/vscode/locales.js.map +1 -1
- package/lib/vscode/utils.d.ts +3 -3
- package/lib/vscode/utils.d.ts.map +1 -1
- package/lib/vscode/utils.js +3 -10
- package/lib/vscode/utils.js.map +1 -1
- package/lib/vscode/viewsService.d.ts.map +1 -1
- package/lib/vscode/viewsService.js +13 -7
- package/lib/vscode/viewsService.js.map +1 -1
- package/lib/worker/index.d.ts +1 -1
- package/lib/worker/index.d.ts.map +1 -1
- package/lib/worker/index.js.map +1 -1
- package/lib/wrapper/lcconfig.d.ts +2 -2
- package/lib/wrapper/lcconfig.d.ts.map +1 -1
- package/lib/wrapper/lcmanager.d.ts.map +1 -1
- package/lib/wrapper/lcmanager.js.map +1 -1
- package/lib/wrapper/lcwrapper.d.ts +1 -1
- package/lib/wrapper/lcwrapper.d.ts.map +1 -1
- package/lib/wrapper/lcwrapper.js +17 -16
- package/lib/wrapper/lcwrapper.js.map +1 -1
- package/package.json +70 -96
- package/src/common/commonTypes.ts +35 -30
- package/src/common/index.ts +0 -1
- package/src/common/utils.ts +45 -45
- package/src/debugger/index.ts +130 -133
- package/src/editorApp/config.ts +33 -33
- package/src/editorApp/editorApp.ts +382 -370
- package/src/fs/definitions.ts +72 -75
- package/src/fs/endpoints/defaultEndpoint.ts +50 -41
- package/src/index.ts +18 -18
- package/src/vscode/apiWrapper.ts +302 -295
- package/src/vscode/config.ts +30 -30
- package/src/vscode/locales.ts +127 -110
- package/src/vscode/utils.ts +20 -26
- package/src/vscode/viewsService.ts +44 -37
- package/src/worker/index.ts +38 -45
- package/src/wrapper/lcconfig.ts +16 -16
- package/src/wrapper/lcmanager.ts +68 -69
- package/src/wrapper/lcwrapper.ts +256 -249
|
@@ -5,13 +5,21 @@
|
|
|
5
5
|
|
|
6
6
|
import { ConfigurationTarget, IConfigurationService, LogLevel, StandaloneServices } from '@codingame/monaco-vscode-api';
|
|
7
7
|
import { createModelReference, type ITextFileEditorModel } from '@codingame/monaco-vscode-api/monaco';
|
|
8
|
-
import
|
|
8
|
+
import { editor, languages } from '@codingame/monaco-vscode-editor-api';
|
|
9
9
|
import type { IReference } from '@codingame/monaco-vscode-editor-service-override';
|
|
10
10
|
import type { ILogger } from '@codingame/monaco-vscode-log-service-override';
|
|
11
11
|
import { ConsoleLogger } from '@codingame/monaco-vscode-log-service-override';
|
|
12
12
|
import { getEnhancedMonacoEnvironment } from 'monaco-languageclient/vscodeApiWrapper';
|
|
13
13
|
import * as vscode from 'vscode';
|
|
14
|
-
import type {
|
|
14
|
+
import type {
|
|
15
|
+
CallbackDisposeable,
|
|
16
|
+
CodeContent,
|
|
17
|
+
CodeResources,
|
|
18
|
+
DisposableModelRefs,
|
|
19
|
+
EditorAppConfig,
|
|
20
|
+
TextContents,
|
|
21
|
+
TextModels
|
|
22
|
+
} from './config.js';
|
|
15
23
|
import { ModelRefs } from './config.js';
|
|
16
24
|
|
|
17
25
|
/**
|
|
@@ -22,424 +30,428 @@ import { ModelRefs } from './config.js';
|
|
|
22
30
|
* It provides the generic functionality for both implementations.
|
|
23
31
|
*/
|
|
24
32
|
export class EditorApp {
|
|
33
|
+
private id: string;
|
|
34
|
+
private config: EditorAppConfig;
|
|
25
35
|
|
|
26
|
-
|
|
27
|
-
private config: EditorAppConfig;
|
|
36
|
+
protected logger: ILogger = new ConsoleLogger();
|
|
28
37
|
|
|
29
|
-
|
|
38
|
+
private editor: editor.IStandaloneCodeEditor | undefined;
|
|
39
|
+
private diffEditor: editor.IStandaloneDiffEditor | undefined;
|
|
30
40
|
|
|
31
|
-
|
|
32
|
-
private diffEditor: monaco.editor.IStandaloneDiffEditor | undefined;
|
|
41
|
+
private modelRefs: ModelRefs = new ModelRefs();
|
|
33
42
|
|
|
34
|
-
|
|
43
|
+
private onTextChanged?: (textChanges: TextContents) => void;
|
|
44
|
+
private textChangedDisposables: CallbackDisposeable = {};
|
|
45
|
+
private modelDisposables: DisposableModelRefs = {};
|
|
35
46
|
|
|
36
|
-
|
|
37
|
-
private textChangedDisposables: CallbackDisposeable = {};
|
|
38
|
-
private modelDisposables: DisposableModelRefs = {};
|
|
47
|
+
private modelRefDisposeTimeout = -1;
|
|
39
48
|
|
|
40
|
-
|
|
49
|
+
private startingAwait?: Promise<void>;
|
|
41
50
|
|
|
42
|
-
|
|
51
|
+
private disposingAwait?: Promise<void>;
|
|
43
52
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
...userAppConfig?.diffEditorOptions,
|
|
64
|
-
automaticLayout: userAppConfig?.overrideAutomaticLayout ?? true
|
|
65
|
-
};
|
|
66
|
-
this.config.languageDef = userAppConfig?.languageDef;
|
|
67
|
-
this.config.logLevel = userAppConfig?.logLevel ?? LogLevel.Off;
|
|
68
|
-
|
|
69
|
-
this.logger.setLevel(this.config.logLevel);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
isDiffEditor() {
|
|
73
|
-
return this.config.useDiffEditor === true;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
getConfig(): EditorAppConfig {
|
|
77
|
-
return this.config;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
getEditor(): monaco.editor.IStandaloneCodeEditor | undefined {
|
|
81
|
-
return this.editor;
|
|
82
|
-
}
|
|
53
|
+
constructor(userAppConfig?: EditorAppConfig) {
|
|
54
|
+
this.id = userAppConfig?.id ?? Math.floor(Math.random() * 1000001).toString();
|
|
55
|
+
this.config = {
|
|
56
|
+
codeResources: userAppConfig?.codeResources ?? undefined,
|
|
57
|
+
useDiffEditor: userAppConfig?.useDiffEditor ?? false,
|
|
58
|
+
readOnly: userAppConfig?.readOnly ?? false,
|
|
59
|
+
domReadOnly: userAppConfig?.domReadOnly ?? false,
|
|
60
|
+
overrideAutomaticLayout: userAppConfig?.overrideAutomaticLayout ?? true
|
|
61
|
+
};
|
|
62
|
+
this.config.editorOptions = {
|
|
63
|
+
...userAppConfig?.editorOptions,
|
|
64
|
+
automaticLayout: userAppConfig?.overrideAutomaticLayout ?? true
|
|
65
|
+
};
|
|
66
|
+
this.config.diffEditorOptions = {
|
|
67
|
+
...userAppConfig?.diffEditorOptions,
|
|
68
|
+
automaticLayout: userAppConfig?.overrideAutomaticLayout ?? true
|
|
69
|
+
};
|
|
70
|
+
this.config.languageDef = userAppConfig?.languageDef;
|
|
71
|
+
this.config.logLevel = userAppConfig?.logLevel ?? LogLevel.Off;
|
|
83
72
|
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
}
|
|
73
|
+
this.logger.setLevel(this.config.logLevel);
|
|
74
|
+
}
|
|
87
75
|
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
original: this.modelRefs.original?.object.textEditorModel ?? undefined
|
|
92
|
-
};
|
|
93
|
-
}
|
|
76
|
+
isDiffEditor() {
|
|
77
|
+
return this.config.useDiffEditor === true;
|
|
78
|
+
}
|
|
94
79
|
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
80
|
+
getConfig(): EditorAppConfig {
|
|
81
|
+
return this.config;
|
|
82
|
+
}
|
|
98
83
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
84
|
+
getEditor(): editor.IStandaloneCodeEditor | undefined {
|
|
85
|
+
return this.editor;
|
|
86
|
+
}
|
|
102
87
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
88
|
+
getDiffEditor(): editor.IStandaloneDiffEditor | undefined {
|
|
89
|
+
return this.diffEditor;
|
|
90
|
+
}
|
|
106
91
|
|
|
107
|
-
|
|
108
|
-
|
|
92
|
+
getTextModels(): TextModels {
|
|
93
|
+
return {
|
|
94
|
+
modified: this.modelRefs.modified?.object.textEditorModel ?? undefined,
|
|
95
|
+
original: this.modelRefs.original?.object.textEditorModel ?? undefined
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
registerOnTextChangedCallback(onTextChanged?: (textChanges: TextContents) => void) {
|
|
100
|
+
this.onTextChanged = onTextChanged;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public setModelRefDisposeTimeout(modelRefDisposeTimeout: number) {
|
|
104
|
+
this.modelRefDisposeTimeout = modelRefDisposeTimeout;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
isStarting() {
|
|
108
|
+
return this.startingAwait !== undefined;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
getStartingAwait() {
|
|
112
|
+
return this.startingAwait;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
isStarted() {
|
|
116
|
+
return this.editor !== undefined || this.diffEditor !== undefined;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Starts the single editor application.
|
|
121
|
+
*/
|
|
122
|
+
async start(htmlContainer: HTMLElement) {
|
|
123
|
+
if (this.isStarting()) {
|
|
124
|
+
await this.getStartingAwait();
|
|
109
125
|
}
|
|
110
126
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
127
|
+
let startingResolve: (value: void | PromiseLike<void>) => void = () => {};
|
|
128
|
+
this.startingAwait = new Promise<void>((resolve) => {
|
|
129
|
+
startingResolve = resolve;
|
|
130
|
+
});
|
|
114
131
|
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
132
|
+
try {
|
|
133
|
+
const envEnhanced = getEnhancedMonacoEnvironment();
|
|
134
|
+
const viewServiceType = envEnhanced.viewServiceType;
|
|
135
|
+
|
|
136
|
+
// check general error case first
|
|
137
|
+
if (!(envEnhanced.vscodeApiInitialised ?? false)) {
|
|
138
|
+
return Promise.reject('monaco-vscode-api was not initialized. Aborting.');
|
|
139
|
+
}
|
|
140
|
+
if (viewServiceType !== 'EditorService' && viewServiceType !== undefined) {
|
|
141
|
+
return Promise.reject('No EditorService configured. monaco-editor will not be started.');
|
|
142
|
+
}
|
|
143
|
+
if (!this.isDisposed()) {
|
|
144
|
+
return Promise.reject('Start was called without properly disposing the EditorApp first.');
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
const languageDef = this.config.languageDef;
|
|
148
|
+
if (languageDef !== undefined) {
|
|
149
|
+
// register own language first
|
|
150
|
+
languages.register(languageDef.languageExtensionConfig);
|
|
151
|
+
|
|
152
|
+
const languageRegistered = languages.getLanguages().filter((x) => x.id === languageDef.languageExtensionConfig.id);
|
|
153
|
+
if (languageRegistered.length === 0) {
|
|
154
|
+
// this is only meaningful for languages supported by monaco out of the box
|
|
155
|
+
languages.register({
|
|
156
|
+
id: languageDef.languageExtensionConfig.id
|
|
157
|
+
});
|
|
121
158
|
}
|
|
122
159
|
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
160
|
+
// apply monarch definitions
|
|
161
|
+
if (languageDef.monarchLanguage !== undefined) {
|
|
162
|
+
languages.setMonarchTokensProvider(languageDef.languageExtensionConfig.id, languageDef.monarchLanguage);
|
|
163
|
+
}
|
|
127
164
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
// check general error case first
|
|
133
|
-
if (!(envEnhanced.vscodeApiInitialised ?? false)) {
|
|
134
|
-
return Promise.reject('monaco-vscode-api was not initialized. Aborting.');
|
|
135
|
-
}
|
|
136
|
-
if (viewServiceType !== 'EditorService' && viewServiceType !== undefined) {
|
|
137
|
-
return Promise.reject('No EditorService configured. monaco-editor will not be started.');
|
|
138
|
-
}
|
|
139
|
-
if (!this.isDisposed()) {
|
|
140
|
-
return Promise.reject('Start was called without properly disposing the EditorApp first.');
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const languageDef = this.config.languageDef;
|
|
144
|
-
if (languageDef) {
|
|
145
|
-
// register own language first
|
|
146
|
-
monaco.languages.register(languageDef.languageExtensionConfig);
|
|
147
|
-
|
|
148
|
-
const languageRegistered = monaco.languages.getLanguages().filter(x => x.id === languageDef.languageExtensionConfig.id);
|
|
149
|
-
if (languageRegistered.length === 0) {
|
|
150
|
-
// this is only meaningful for languages supported by monaco out of the box
|
|
151
|
-
monaco.languages.register({
|
|
152
|
-
id: languageDef.languageExtensionConfig.id
|
|
153
|
-
});
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
// apply monarch definitions
|
|
157
|
-
if (languageDef.monarchLanguage) {
|
|
158
|
-
monaco.languages.setMonarchTokensProvider(languageDef.languageExtensionConfig.id, languageDef.monarchLanguage);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (languageDef.theme) {
|
|
162
|
-
monaco.editor.defineTheme(languageDef.theme.name, languageDef.theme.data);
|
|
163
|
-
monaco.editor.setTheme(languageDef.theme.name);
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
if (this.config.editorOptions?.['semanticHighlighting.enabled'] !== undefined) {
|
|
168
|
-
StandaloneServices.get(IConfigurationService).updateValue('editor.semanticHighlighting.enabled',
|
|
169
|
-
this.config.editorOptions['semanticHighlighting.enabled'], ConfigurationTarget.USER);
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
await this.createEditors(htmlContainer);
|
|
173
|
-
|
|
174
|
-
// everything is fine at this point
|
|
175
|
-
startingResolve();
|
|
176
|
-
this.logger.info('EditorApp start completed successfully.');
|
|
177
|
-
} catch (e) {
|
|
178
|
-
// in case of further errors (after general ones above)
|
|
179
|
-
// take the error and build a new rejection to complete the promise
|
|
180
|
-
return Promise.reject(e);
|
|
181
|
-
} finally {
|
|
182
|
-
this.startingAwait = undefined;
|
|
165
|
+
if (languageDef.theme !== undefined) {
|
|
166
|
+
editor.defineTheme(languageDef.theme.name, languageDef.theme.data);
|
|
167
|
+
editor.setTheme(languageDef.theme.name);
|
|
183
168
|
}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (this.config.editorOptions?.['semanticHighlighting.enabled'] !== undefined) {
|
|
172
|
+
await StandaloneServices.get(IConfigurationService).updateValue(
|
|
173
|
+
'editor.semanticHighlighting.enabled',
|
|
174
|
+
this.config.editorOptions['semanticHighlighting.enabled'],
|
|
175
|
+
ConfigurationTarget.USER
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
await this.createEditors(htmlContainer);
|
|
180
|
+
|
|
181
|
+
// everything is fine at this point
|
|
182
|
+
startingResolve();
|
|
183
|
+
this.logger.info('EditorApp start completed successfully.');
|
|
184
|
+
} catch (e) {
|
|
185
|
+
// in case of further errors (after general ones above)
|
|
186
|
+
// take the error and build a new rejection to complete the promise
|
|
187
|
+
return Promise.reject(e);
|
|
188
|
+
} finally {
|
|
189
|
+
this.startingAwait = undefined;
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
async createEditors(htmlContainer: HTMLElement): Promise<void> {
|
|
194
|
+
// ensure proper default resources are initialized, uris have to be unique
|
|
195
|
+
const modified = {
|
|
196
|
+
text: this.config.codeResources?.modified?.text ?? '',
|
|
197
|
+
uri: this.config.codeResources?.modified?.uri ?? `default-uri-modified-${this.id}`,
|
|
198
|
+
enforceLanguageId: this.config.codeResources?.modified?.enforceLanguageId ?? undefined
|
|
199
|
+
};
|
|
200
|
+
this.modelRefs.modified = await this.buildModelReference(modified);
|
|
201
|
+
|
|
202
|
+
if (this.isDiffEditor()) {
|
|
203
|
+
const original = {
|
|
204
|
+
text: this.config.codeResources?.original?.text ?? '',
|
|
205
|
+
uri: this.config.codeResources?.original?.uri ?? `default-uri-original-${this.id}`,
|
|
206
|
+
enforceLanguageId: this.config.codeResources?.original?.enforceLanguageId ?? undefined
|
|
207
|
+
};
|
|
208
|
+
this.modelRefs.original = await this.buildModelReference(original);
|
|
184
209
|
}
|
|
185
210
|
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
211
|
+
this.logger.info(`Starting monaco-editor (${this.id})`);
|
|
212
|
+
if (this.isDiffEditor()) {
|
|
213
|
+
this.diffEditor = editor.createDiffEditor(htmlContainer, this.config.diffEditorOptions);
|
|
214
|
+
const modified = this.modelRefs.modified.object.textEditorModel ?? undefined;
|
|
215
|
+
const original = this.modelRefs.original?.object.textEditorModel ?? undefined;
|
|
216
|
+
if (modified !== undefined && original !== undefined) {
|
|
217
|
+
const model = {
|
|
218
|
+
modified,
|
|
219
|
+
original
|
|
192
220
|
};
|
|
193
|
-
this.
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
};
|
|
221
|
-
this.editor = monaco.editor.create(htmlContainer, {
|
|
222
|
-
...this.config.editorOptions,
|
|
223
|
-
model: model.modified
|
|
224
|
-
});
|
|
225
|
-
this.announceModelUpdate(model);
|
|
226
|
-
}
|
|
221
|
+
this.diffEditor.setModel(model);
|
|
222
|
+
this.announceModelUpdate(model);
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
const model = {
|
|
226
|
+
modified: this.modelRefs.modified.object.textEditorModel
|
|
227
|
+
};
|
|
228
|
+
this.editor = editor.create(htmlContainer, {
|
|
229
|
+
...this.config.editorOptions,
|
|
230
|
+
model: model.modified
|
|
231
|
+
});
|
|
232
|
+
this.announceModelUpdate(model);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
updateCode(code: { modified?: string; original?: string }) {
|
|
237
|
+
if (this.isDiffEditor()) {
|
|
238
|
+
if (code.modified !== undefined) {
|
|
239
|
+
this.diffEditor?.getModifiedEditor().setValue(code.modified);
|
|
240
|
+
}
|
|
241
|
+
if (code.original !== undefined) {
|
|
242
|
+
this.diffEditor?.getOriginalEditor().setValue(code.original);
|
|
243
|
+
}
|
|
244
|
+
} else {
|
|
245
|
+
if (code.modified !== undefined) {
|
|
246
|
+
this.editor?.setValue(code.modified);
|
|
247
|
+
}
|
|
227
248
|
}
|
|
249
|
+
}
|
|
228
250
|
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
}
|
|
234
|
-
if (code.original !== undefined) {
|
|
235
|
-
this.diffEditor?.getOriginalEditor().setValue(code.original);
|
|
236
|
-
}
|
|
237
|
-
} else {
|
|
238
|
-
if (code.modified !== undefined) {
|
|
239
|
-
this.editor?.setValue(code.modified);
|
|
240
|
-
}
|
|
251
|
+
async updateCodeResources(codeResources?: CodeResources): Promise<boolean> {
|
|
252
|
+
let updateModified = false;
|
|
253
|
+
let updateOriginal = false;
|
|
254
|
+
let updated = false;
|
|
241
255
|
|
|
242
|
-
|
|
256
|
+
if (codeResources?.modified !== undefined && codeResources.modified.uri !== this.modelRefs.modified?.object.resource.path) {
|
|
257
|
+
this.modelDisposables.modified = this.modelRefs.modified;
|
|
258
|
+
this.modelRefs.modified = await this.buildModelReference(codeResources.modified);
|
|
259
|
+
updateModified = true;
|
|
260
|
+
}
|
|
261
|
+
if (codeResources?.original !== undefined && codeResources.original.uri !== this.modelRefs.original?.object.resource.path) {
|
|
262
|
+
this.modelDisposables.original = this.modelRefs.original;
|
|
263
|
+
this.modelRefs.original = await this.buildModelReference(codeResources.original);
|
|
264
|
+
updateOriginal = true;
|
|
243
265
|
}
|
|
244
266
|
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
updateOriginal = true;
|
|
267
|
+
if (this.isDiffEditor()) {
|
|
268
|
+
if (updateModified || updateOriginal) {
|
|
269
|
+
const modified = this.modelRefs.modified?.object.textEditorModel ?? undefined;
|
|
270
|
+
const original = this.modelRefs.original?.object.textEditorModel ?? undefined;
|
|
271
|
+
if (modified !== undefined && original !== undefined) {
|
|
272
|
+
const model = {
|
|
273
|
+
modified,
|
|
274
|
+
original
|
|
275
|
+
};
|
|
276
|
+
this.diffEditor?.setModel(model);
|
|
277
|
+
this.announceModelUpdate(model);
|
|
278
|
+
await this.disposeModelRefs();
|
|
279
|
+
updated = true;
|
|
259
280
|
}
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
updated = true;
|
|
274
|
-
}
|
|
275
|
-
} else {
|
|
276
|
-
this.logger.info('Diff Editor: Code resources were not updated. They are ether unchanged or undefined.');
|
|
277
|
-
}
|
|
278
|
-
} else {
|
|
279
|
-
if (updateModified) {
|
|
280
|
-
const model = {
|
|
281
|
-
modified: this.modelRefs.modified?.object.textEditorModel
|
|
282
|
-
};
|
|
283
|
-
if (model.modified !== undefined && model.modified !== null) {
|
|
284
|
-
this.editor?.setModel(model.modified);
|
|
285
|
-
this.announceModelUpdate(model);
|
|
286
|
-
await this.disposeModelRefs();
|
|
287
|
-
updated = true;
|
|
288
|
-
}
|
|
289
|
-
} else {
|
|
290
|
-
this.logger.info('Editor: Code resources were not updated. They are either unchanged or undefined.');
|
|
291
|
-
}
|
|
281
|
+
} else {
|
|
282
|
+
this.logger.info('Diff Editor: Code resources were not updated. They are ether unchanged or undefined.');
|
|
283
|
+
}
|
|
284
|
+
} else {
|
|
285
|
+
if (updateModified) {
|
|
286
|
+
const model = {
|
|
287
|
+
modified: this.modelRefs.modified?.object.textEditorModel
|
|
288
|
+
};
|
|
289
|
+
if (model.modified !== undefined && model.modified !== null) {
|
|
290
|
+
this.editor?.setModel(model.modified);
|
|
291
|
+
this.announceModelUpdate(model);
|
|
292
|
+
await this.disposeModelRefs();
|
|
293
|
+
updated = true;
|
|
292
294
|
}
|
|
293
|
-
|
|
295
|
+
} else {
|
|
296
|
+
this.logger.info('Editor: Code resources were not updated. They are either unchanged or undefined.');
|
|
297
|
+
}
|
|
294
298
|
}
|
|
299
|
+
return updated;
|
|
300
|
+
}
|
|
295
301
|
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
302
|
+
async buildModelReference(codeContent: CodeContent): Promise<IReference<ITextFileEditorModel>> {
|
|
303
|
+
const code = codeContent.text;
|
|
304
|
+
const modelRef = await createModelReference(vscode.Uri.parse(codeContent.uri), code);
|
|
299
305
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
}
|
|
304
|
-
const enforceLanguageId = codeContent.enforceLanguageId;
|
|
305
|
-
if (enforceLanguageId !== undefined) {
|
|
306
|
-
modelRef.object.setLanguageId(enforceLanguageId);
|
|
307
|
-
this.logger.info(`Main languageId is enforced: ${enforceLanguageId}`);
|
|
308
|
-
}
|
|
309
|
-
return modelRef;
|
|
310
|
-
};
|
|
311
|
-
|
|
312
|
-
private announceModelUpdate(textModels: TextModels) {
|
|
313
|
-
if (this.onTextChanged !== undefined) {
|
|
314
|
-
let changed = false;
|
|
315
|
-
if (textModels.modified !== undefined && textModels.modified !== null) {
|
|
316
|
-
const old = this.textChangedDisposables.modified;
|
|
317
|
-
this.textChangedDisposables.modified = textModels.modified.onDidChangeContent(() => {
|
|
318
|
-
didModelContentChange(textModels, this.onTextChanged);
|
|
319
|
-
});
|
|
320
|
-
old?.dispose();
|
|
321
|
-
changed = true;
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
if (textModels.original !== undefined && textModels.original !== null) {
|
|
325
|
-
const old = this.textChangedDisposables.original;
|
|
326
|
-
this.textChangedDisposables.original = textModels.original.onDidChangeContent(() => {
|
|
327
|
-
didModelContentChange(textModels, this.onTextChanged);
|
|
328
|
-
});
|
|
329
|
-
old?.dispose();
|
|
330
|
-
changed = true;
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
if (changed) {
|
|
334
|
-
// do it initially
|
|
335
|
-
didModelContentChange(textModels, this.onTextChanged);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
306
|
+
// update the text if different
|
|
307
|
+
if (modelRef.object.textEditorModel?.getValue() !== code) {
|
|
308
|
+
modelRef.object.textEditorModel?.setValue(code);
|
|
338
309
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
310
|
+
const enforceLanguageId = codeContent.enforceLanguageId;
|
|
311
|
+
if (enforceLanguageId !== undefined) {
|
|
312
|
+
modelRef.object.setLanguageId(enforceLanguageId);
|
|
313
|
+
this.logger.info(`Main languageId is enforced: ${enforceLanguageId}`);
|
|
314
|
+
}
|
|
315
|
+
return modelRef;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
private announceModelUpdate(textModels: TextModels) {
|
|
319
|
+
if (this.onTextChanged !== undefined) {
|
|
320
|
+
let changed = false;
|
|
321
|
+
if (textModels.modified !== undefined && textModels.modified !== null) {
|
|
322
|
+
const old = this.textChangedDisposables.modified;
|
|
323
|
+
this.textChangedDisposables.modified = textModels.modified.onDidChangeContent(() => {
|
|
324
|
+
didModelContentChange(textModels, this.onTextChanged);
|
|
347
325
|
});
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
disposingResolve();
|
|
366
|
-
this.disposingAwait = undefined;
|
|
326
|
+
old?.dispose();
|
|
327
|
+
changed = true;
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (textModels.original !== undefined && textModels.original !== null) {
|
|
331
|
+
const old = this.textChangedDisposables.original;
|
|
332
|
+
this.textChangedDisposables.original = textModels.original.onDidChangeContent(() => {
|
|
333
|
+
didModelContentChange(textModels, this.onTextChanged);
|
|
334
|
+
});
|
|
335
|
+
old?.dispose();
|
|
336
|
+
changed = true;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if (changed) {
|
|
340
|
+
// do it initially
|
|
341
|
+
didModelContentChange(textModels, this.onTextChanged);
|
|
342
|
+
}
|
|
367
343
|
}
|
|
344
|
+
}
|
|
368
345
|
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
346
|
+
async dispose() {
|
|
347
|
+
if (this.isDisposing()) {
|
|
348
|
+
await this.getDisposingAwait();
|
|
372
349
|
}
|
|
350
|
+
let disposingResolve: (value: void | PromiseLike<void>) => void = () => {};
|
|
351
|
+
this.disposingAwait = new Promise<void>((resolve) => {
|
|
352
|
+
disposingResolve = resolve;
|
|
353
|
+
});
|
|
373
354
|
|
|
374
|
-
|
|
375
|
-
|
|
355
|
+
if (this.editor !== undefined) {
|
|
356
|
+
this.editor.dispose();
|
|
357
|
+
this.editor = undefined;
|
|
376
358
|
}
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
359
|
+
if (this.diffEditor !== undefined) {
|
|
360
|
+
this.diffEditor.dispose();
|
|
361
|
+
this.diffEditor = undefined;
|
|
380
362
|
}
|
|
381
363
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
364
|
+
this.textChangedDisposables.modified?.dispose();
|
|
365
|
+
this.textChangedDisposables.original?.dispose();
|
|
366
|
+
this.textChangedDisposables.modified = undefined;
|
|
367
|
+
this.textChangedDisposables.original = undefined;
|
|
368
|
+
|
|
369
|
+
await this.disposeModelRefs();
|
|
370
|
+
|
|
371
|
+
disposingResolve();
|
|
372
|
+
this.disposingAwait = undefined;
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
isDisposed(): boolean {
|
|
376
|
+
return (
|
|
377
|
+
this.editor === undefined &&
|
|
378
|
+
this.diffEditor === undefined &&
|
|
379
|
+
this.modelDisposables.original === undefined &&
|
|
380
|
+
this.modelDisposables.modified === undefined
|
|
381
|
+
);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
isDisposing() {
|
|
385
|
+
return this.disposingAwait !== undefined;
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
getDisposingAwait() {
|
|
389
|
+
return this.disposingAwait;
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
async disposeModelRefs() {
|
|
393
|
+
const disposeRefs = () => {
|
|
394
|
+
if (this.logger.getLevel() === LogLevel.Debug) {
|
|
395
|
+
const models = editor.getModels();
|
|
396
|
+
this.logger.debug('Current model URIs:');
|
|
397
|
+
models.forEach((model, _index) => {
|
|
398
|
+
this.logger.debug(`${model.uri.toString()}`);
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
if (this.modelDisposables.modified !== undefined && !this.modelDisposables.modified.object.isDisposed()) {
|
|
403
|
+
this.modelDisposables.modified.dispose();
|
|
404
|
+
this.modelDisposables.modified = undefined;
|
|
405
|
+
}
|
|
406
|
+
if (this.modelDisposables.original !== undefined && !this.modelDisposables.original.object.isDisposed()) {
|
|
407
|
+
this.modelDisposables.original.dispose();
|
|
408
|
+
this.modelDisposables.original = undefined;
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
if (this.logger.getLevel() === LogLevel.Debug) {
|
|
412
|
+
if (this.modelDisposables.modified === undefined && this.modelDisposables.original === undefined) {
|
|
413
|
+
this.logger.debug('All model references are disposed.');
|
|
416
414
|
} else {
|
|
417
|
-
|
|
415
|
+
this.logger.debug('Model references are still available.');
|
|
418
416
|
}
|
|
419
|
-
|
|
417
|
+
}
|
|
418
|
+
};
|
|
420
419
|
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
420
|
+
if (this.modelRefDisposeTimeout > 0) {
|
|
421
|
+
this.logger.debug('Using async dispose of model references');
|
|
422
|
+
await new Promise<void>((resolve) =>
|
|
423
|
+
setTimeout(() => {
|
|
424
|
+
disposeRefs();
|
|
425
|
+
resolve();
|
|
426
|
+
}, this.modelRefDisposeTimeout)
|
|
427
|
+
);
|
|
428
|
+
} else {
|
|
429
|
+
disposeRefs();
|
|
427
430
|
}
|
|
431
|
+
}
|
|
428
432
|
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
return status;
|
|
433
|
+
updateLayout(dimension?: editor.IDimension, postponeRendering?: boolean) {
|
|
434
|
+
if (this.isDiffEditor()) {
|
|
435
|
+
this.diffEditor?.layout(dimension, postponeRendering);
|
|
436
|
+
} else {
|
|
437
|
+
this.editor?.layout(dimension, postponeRendering);
|
|
435
438
|
}
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
reportStatus() {
|
|
442
|
+
const status: string[] = [];
|
|
443
|
+
status.push('EditorApp status:');
|
|
444
|
+
status.push(`Editor: ${this.editor?.getId()}`);
|
|
445
|
+
status.push(`DiffEditor: ${this.diffEditor?.getId()}`);
|
|
446
|
+
return status;
|
|
447
|
+
}
|
|
436
448
|
}
|
|
437
449
|
|
|
438
450
|
export const didModelContentChange = (textModels: TextModels, onTextChanged?: (textChanges: TextContents) => void) => {
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
451
|
+
const modified = textModels.modified?.getValue() ?? '';
|
|
452
|
+
const original = textModels.original?.getValue() ?? '';
|
|
453
|
+
onTextChanged?.({
|
|
454
|
+
modified,
|
|
455
|
+
original
|
|
456
|
+
});
|
|
445
457
|
};
|