@theia/monaco 1.53.0-next.55 → 1.53.0-next.64

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.
Files changed (77) hide show
  1. package/README.md +100 -100
  2. package/data/monaco-nls.json +1379 -1379
  3. package/data/monaco-themes/vscode/dark_plus.json +201 -201
  4. package/data/monaco-themes/vscode/dark_theia.json +5 -5
  5. package/data/monaco-themes/vscode/dark_vs.json +393 -393
  6. package/data/monaco-themes/vscode/hc_black.json +457 -457
  7. package/data/monaco-themes/vscode/hc_light.json +590 -590
  8. package/data/monaco-themes/vscode/hc_theia.json +5 -5
  9. package/data/monaco-themes/vscode/hc_theia_light.json +5 -5
  10. package/data/monaco-themes/vscode/light_plus.json +202 -202
  11. package/data/monaco-themes/vscode/light_theia.json +10 -10
  12. package/data/monaco-themes/vscode/light_vs.json +421 -421
  13. package/lib/browser/monaco-editor-zone-widget.js +1 -1
  14. package/lib/browser/monaco-frontend-application-contribution.js +25 -25
  15. package/lib/browser/simple-monaco-editor.d.ts +3 -1
  16. package/lib/browser/simple-monaco-editor.d.ts.map +1 -1
  17. package/lib/browser/simple-monaco-editor.js +9 -2
  18. package/lib/browser/simple-monaco-editor.js.map +1 -1
  19. package/package.json +8 -8
  20. package/src/browser/index.ts +17 -17
  21. package/src/browser/markdown-renderer/monaco-markdown-renderer.ts +109 -109
  22. package/src/browser/monaco-bulk-edit-service.ts +64 -64
  23. package/src/browser/monaco-color-registry.ts +73 -73
  24. package/src/browser/monaco-command-registry.ts +85 -85
  25. package/src/browser/monaco-command-service.ts +90 -90
  26. package/src/browser/monaco-command.ts +303 -303
  27. package/src/browser/monaco-context-key-service.ts +144 -144
  28. package/src/browser/monaco-context-menu.ts +112 -112
  29. package/src/browser/monaco-diff-editor.ts +141 -141
  30. package/src/browser/monaco-diff-navigator-factory.ts +39 -39
  31. package/src/browser/monaco-editor-model.ts +693 -693
  32. package/src/browser/monaco-editor-peek-view-widget.ts +233 -233
  33. package/src/browser/monaco-editor-provider.ts +455 -455
  34. package/src/browser/monaco-editor-service.ts +152 -152
  35. package/src/browser/monaco-editor-zone-widget.ts +250 -250
  36. package/src/browser/monaco-editor.ts +733 -733
  37. package/src/browser/monaco-formatting-conflicts.ts +116 -116
  38. package/src/browser/monaco-frontend-application-contribution.ts +182 -182
  39. package/src/browser/monaco-frontend-module.ts +319 -319
  40. package/src/browser/monaco-gotoline-quick-access.ts +47 -47
  41. package/src/browser/monaco-gotosymbol-quick-access.ts +53 -53
  42. package/src/browser/monaco-icon-registry.ts +49 -49
  43. package/src/browser/monaco-indexed-db.ts +130 -130
  44. package/src/browser/monaco-init.ts +134 -134
  45. package/src/browser/monaco-keybinding.ts +111 -111
  46. package/src/browser/monaco-keycode-map.ts +171 -171
  47. package/src/browser/monaco-languages.ts +177 -177
  48. package/src/browser/monaco-marker-collection.ts +83 -83
  49. package/src/browser/monaco-menu.ts +147 -147
  50. package/src/browser/monaco-mime-service.ts +71 -71
  51. package/src/browser/monaco-outline-contribution.ts +404 -404
  52. package/src/browser/monaco-outline-decorator.ts +66 -66
  53. package/src/browser/monaco-quick-access-registry.ts +112 -112
  54. package/src/browser/monaco-quick-input-service.ts +701 -701
  55. package/src/browser/monaco-resolved-keybinding.ts +162 -162
  56. package/src/browser/monaco-snippet-suggest-provider.ts +306 -306
  57. package/src/browser/monaco-standalone-theme-service.ts +51 -51
  58. package/src/browser/monaco-status-bar-contribution.ts +110 -110
  59. package/src/browser/monaco-text-model-service.ts +157 -157
  60. package/src/browser/monaco-theming-service.ts +204 -204
  61. package/src/browser/monaco-to-protocol-converter.ts +82 -82
  62. package/src/browser/monaco-undo-redo-handler.ts +64 -64
  63. package/src/browser/monaco-workspace.ts +416 -416
  64. package/src/browser/protocol-to-monaco-converter.ts +158 -158
  65. package/src/browser/simple-monaco-editor.ts +228 -216
  66. package/src/browser/style/index.css +266 -266
  67. package/src/browser/textmate/index.ts +20 -20
  68. package/src/browser/textmate/monaco-textmate-frontend-bindings.ts +90 -90
  69. package/src/browser/textmate/monaco-textmate-service.ts +187 -187
  70. package/src/browser/textmate/monaco-theme-registry.ts +176 -176
  71. package/src/browser/textmate/monaco-theme-types.ts +37 -37
  72. package/src/browser/textmate/textmate-contribution.ts +29 -29
  73. package/src/browser/textmate/textmate-registry.ts +129 -129
  74. package/src/browser/textmate/textmate-snippet-completion-provider.ts +73 -73
  75. package/src/browser/textmate/textmate-tokenizer.ts +84 -84
  76. package/src/browser/workspace-symbol-command.ts +196 -196
  77. package/src/package.spec.ts +28 -28
@@ -1,177 +1,177 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2017 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { SymbolInformation, WorkspaceSymbolParams } from '@theia/core/shared/vscode-languageserver-protocol';
18
- import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
19
- import { ProblemManager } from '@theia/markers/lib/browser/problem/problem-manager';
20
- import URI from '@theia/core/lib/common/uri';
21
- import { MaybePromise, Mutable } from '@theia/core/lib/common/types';
22
- import { Disposable } from '@theia/core/lib/common/disposable';
23
- import { CancellationToken } from '@theia/core/lib/common/cancellation';
24
- import { Language, LanguageService } from '@theia/core/lib/browser/language-service';
25
- import { MonacoMarkerCollection } from './monaco-marker-collection';
26
- import { ProtocolToMonacoConverter } from './protocol-to-monaco-converter';
27
- import * as monaco from '@theia/monaco-editor-core';
28
- import { FileStat } from '@theia/filesystem/lib/common/files';
29
- import { FileStatNode } from '@theia/filesystem/lib/browser';
30
- import { ILanguageService } from '@theia/monaco-editor-core/esm/vs/editor/common/languages/language';
31
- import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
32
-
33
- export interface WorkspaceSymbolProvider {
34
- provideWorkspaceSymbols(params: WorkspaceSymbolParams, token: CancellationToken): MaybePromise<SymbolInformation[] | undefined>;
35
- resolveWorkspaceSymbol?(symbol: SymbolInformation, token: CancellationToken): Thenable<SymbolInformation | undefined>
36
- }
37
-
38
- @injectable()
39
- export class MonacoLanguages extends LanguageService {
40
-
41
- readonly workspaceSymbolProviders: WorkspaceSymbolProvider[] = [];
42
-
43
- protected readonly markers = new Map<string, MonacoMarkerCollection>();
44
- protected readonly icons = new Map<string, string>();
45
-
46
- @inject(ProblemManager) protected readonly problemManager: ProblemManager;
47
- @inject(ProtocolToMonacoConverter) protected readonly p2m: ProtocolToMonacoConverter;
48
-
49
- @postConstruct()
50
- protected init(): void {
51
- this.problemManager.onDidChangeMarkers(uri => this.updateMarkers(uri));
52
- monaco.editor.onDidCreateModel(model => this.updateModelMarkers(model));
53
- }
54
-
55
- updateMarkers(uri: URI): void {
56
- const markers = this.problemManager.findMarkers({ uri });
57
- const uriString = uri.toString();
58
- const collection = this.markers.get(uriString) || new MonacoMarkerCollection(uri, this.p2m);
59
- this.markers.set(uriString, collection);
60
- collection.updateMarkers(markers);
61
- }
62
-
63
- updateModelMarkers(model: monaco.editor.ITextModel): void {
64
- const uriString = model.uri.toString();
65
- const uri = new URI(uriString);
66
- const collection = this.markers.get(uriString) || new MonacoMarkerCollection(uri, this.p2m);
67
- this.markers.set(uriString, collection);
68
- collection.updateModelMarkers(model);
69
- }
70
-
71
- registerWorkspaceSymbolProvider(provider: WorkspaceSymbolProvider): Disposable {
72
- this.workspaceSymbolProviders.push(provider);
73
- return Disposable.create(() => {
74
- const index = this.workspaceSymbolProviders.indexOf(provider);
75
- if (index !== -1) {
76
- this.workspaceSymbolProviders.splice(index, 1);
77
- }
78
- });
79
- }
80
-
81
- override get languages(): Language[] {
82
- return [...this.mergeLanguages(monaco.languages.getLanguages()).values()];
83
- }
84
-
85
- override getLanguage(languageId: string): Language | undefined {
86
- return this.mergeLanguages(monaco.languages.getLanguages().filter(language => language.id === languageId)).get(languageId);
87
- }
88
-
89
- override detectLanguage(obj: unknown): Language | undefined {
90
- if (obj === undefined) {
91
- return undefined;
92
- }
93
- if (typeof obj === 'string') {
94
- return this.detectLanguageByIdOrName(obj) ?? this.detectLanguageByURI(new URI(obj));
95
- }
96
- if (obj instanceof URI) {
97
- return this.detectLanguageByURI(obj);
98
- }
99
- if (FileStat.is(obj)) {
100
- return this.detectLanguageByURI(obj.resource);
101
- }
102
- if (FileStatNode.is(obj)) {
103
- return this.detectLanguageByURI(obj.uri);
104
- }
105
- return undefined;
106
- }
107
-
108
- protected detectLanguageByIdOrName(obj: string): Language | undefined {
109
- const languageById = this.getLanguage(obj);
110
- if (languageById) {
111
- return languageById;
112
- }
113
-
114
- const languageId = this.getLanguageIdByLanguageName(obj);
115
- return languageId ? this.getLanguage(languageId) : undefined;
116
- }
117
-
118
- protected detectLanguageByURI(uri: URI): Language | undefined {
119
- const languageId = StandaloneServices.get(ILanguageService).guessLanguageIdByFilepathOrFirstLine(uri['codeUri']);
120
- return languageId ? this.getLanguage(languageId) : undefined;
121
- }
122
-
123
- getExtension(languageId: string): string | undefined {
124
- return this.getLanguage(languageId)?.extensions.values().next().value;
125
- }
126
-
127
- override registerIcon(languageId: string, iconClass: string): Disposable {
128
- this.icons.set(languageId, iconClass);
129
- this.onDidChangeIconEmitter.fire({ languageId });
130
- return Disposable.create(() => {
131
- this.icons.delete(languageId);
132
- this.onDidChangeIconEmitter.fire({ languageId });
133
- });
134
- }
135
-
136
- override getIcon(obj: unknown): string | undefined {
137
- const language = this.detectLanguage(obj);
138
- return language ? this.icons.get(language.id) : undefined;
139
- }
140
-
141
- getLanguageIdByLanguageName(languageName: string): string | undefined {
142
- return monaco.languages.getLanguages().find(language => language.aliases?.includes(languageName))?.id;
143
- }
144
-
145
- protected mergeLanguages(registered: monaco.languages.ILanguageExtensionPoint[]): Map<string, Mutable<Language>> {
146
- const languages = new Map<string, Mutable<Language>>();
147
- for (const { id, aliases, extensions, filenames } of registered) {
148
- const merged = languages.get(id) || {
149
- id,
150
- name: '',
151
- extensions: new Set(),
152
- filenames: new Set()
153
- };
154
- if (!merged.name && aliases && aliases.length) {
155
- merged.name = aliases[0];
156
- }
157
- if (extensions && extensions.length) {
158
- for (const extension of extensions) {
159
- merged.extensions.add(extension);
160
- }
161
- }
162
- if (filenames && filenames.length) {
163
- for (const filename of filenames) {
164
- merged.filenames.add(filename);
165
- }
166
- }
167
- languages.set(id, merged);
168
- }
169
- for (const [id, language] of languages) {
170
- if (!language.name) {
171
- language.name = id;
172
- }
173
- }
174
- return languages;
175
- }
176
-
177
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2017 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { SymbolInformation, WorkspaceSymbolParams } from '@theia/core/shared/vscode-languageserver-protocol';
18
+ import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
19
+ import { ProblemManager } from '@theia/markers/lib/browser/problem/problem-manager';
20
+ import URI from '@theia/core/lib/common/uri';
21
+ import { MaybePromise, Mutable } from '@theia/core/lib/common/types';
22
+ import { Disposable } from '@theia/core/lib/common/disposable';
23
+ import { CancellationToken } from '@theia/core/lib/common/cancellation';
24
+ import { Language, LanguageService } from '@theia/core/lib/browser/language-service';
25
+ import { MonacoMarkerCollection } from './monaco-marker-collection';
26
+ import { ProtocolToMonacoConverter } from './protocol-to-monaco-converter';
27
+ import * as monaco from '@theia/monaco-editor-core';
28
+ import { FileStat } from '@theia/filesystem/lib/common/files';
29
+ import { FileStatNode } from '@theia/filesystem/lib/browser';
30
+ import { ILanguageService } from '@theia/monaco-editor-core/esm/vs/editor/common/languages/language';
31
+ import { StandaloneServices } from '@theia/monaco-editor-core/esm/vs/editor/standalone/browser/standaloneServices';
32
+
33
+ export interface WorkspaceSymbolProvider {
34
+ provideWorkspaceSymbols(params: WorkspaceSymbolParams, token: CancellationToken): MaybePromise<SymbolInformation[] | undefined>;
35
+ resolveWorkspaceSymbol?(symbol: SymbolInformation, token: CancellationToken): Thenable<SymbolInformation | undefined>
36
+ }
37
+
38
+ @injectable()
39
+ export class MonacoLanguages extends LanguageService {
40
+
41
+ readonly workspaceSymbolProviders: WorkspaceSymbolProvider[] = [];
42
+
43
+ protected readonly markers = new Map<string, MonacoMarkerCollection>();
44
+ protected readonly icons = new Map<string, string>();
45
+
46
+ @inject(ProblemManager) protected readonly problemManager: ProblemManager;
47
+ @inject(ProtocolToMonacoConverter) protected readonly p2m: ProtocolToMonacoConverter;
48
+
49
+ @postConstruct()
50
+ protected init(): void {
51
+ this.problemManager.onDidChangeMarkers(uri => this.updateMarkers(uri));
52
+ monaco.editor.onDidCreateModel(model => this.updateModelMarkers(model));
53
+ }
54
+
55
+ updateMarkers(uri: URI): void {
56
+ const markers = this.problemManager.findMarkers({ uri });
57
+ const uriString = uri.toString();
58
+ const collection = this.markers.get(uriString) || new MonacoMarkerCollection(uri, this.p2m);
59
+ this.markers.set(uriString, collection);
60
+ collection.updateMarkers(markers);
61
+ }
62
+
63
+ updateModelMarkers(model: monaco.editor.ITextModel): void {
64
+ const uriString = model.uri.toString();
65
+ const uri = new URI(uriString);
66
+ const collection = this.markers.get(uriString) || new MonacoMarkerCollection(uri, this.p2m);
67
+ this.markers.set(uriString, collection);
68
+ collection.updateModelMarkers(model);
69
+ }
70
+
71
+ registerWorkspaceSymbolProvider(provider: WorkspaceSymbolProvider): Disposable {
72
+ this.workspaceSymbolProviders.push(provider);
73
+ return Disposable.create(() => {
74
+ const index = this.workspaceSymbolProviders.indexOf(provider);
75
+ if (index !== -1) {
76
+ this.workspaceSymbolProviders.splice(index, 1);
77
+ }
78
+ });
79
+ }
80
+
81
+ override get languages(): Language[] {
82
+ return [...this.mergeLanguages(monaco.languages.getLanguages()).values()];
83
+ }
84
+
85
+ override getLanguage(languageId: string): Language | undefined {
86
+ return this.mergeLanguages(monaco.languages.getLanguages().filter(language => language.id === languageId)).get(languageId);
87
+ }
88
+
89
+ override detectLanguage(obj: unknown): Language | undefined {
90
+ if (obj === undefined) {
91
+ return undefined;
92
+ }
93
+ if (typeof obj === 'string') {
94
+ return this.detectLanguageByIdOrName(obj) ?? this.detectLanguageByURI(new URI(obj));
95
+ }
96
+ if (obj instanceof URI) {
97
+ return this.detectLanguageByURI(obj);
98
+ }
99
+ if (FileStat.is(obj)) {
100
+ return this.detectLanguageByURI(obj.resource);
101
+ }
102
+ if (FileStatNode.is(obj)) {
103
+ return this.detectLanguageByURI(obj.uri);
104
+ }
105
+ return undefined;
106
+ }
107
+
108
+ protected detectLanguageByIdOrName(obj: string): Language | undefined {
109
+ const languageById = this.getLanguage(obj);
110
+ if (languageById) {
111
+ return languageById;
112
+ }
113
+
114
+ const languageId = this.getLanguageIdByLanguageName(obj);
115
+ return languageId ? this.getLanguage(languageId) : undefined;
116
+ }
117
+
118
+ protected detectLanguageByURI(uri: URI): Language | undefined {
119
+ const languageId = StandaloneServices.get(ILanguageService).guessLanguageIdByFilepathOrFirstLine(uri['codeUri']);
120
+ return languageId ? this.getLanguage(languageId) : undefined;
121
+ }
122
+
123
+ getExtension(languageId: string): string | undefined {
124
+ return this.getLanguage(languageId)?.extensions.values().next().value;
125
+ }
126
+
127
+ override registerIcon(languageId: string, iconClass: string): Disposable {
128
+ this.icons.set(languageId, iconClass);
129
+ this.onDidChangeIconEmitter.fire({ languageId });
130
+ return Disposable.create(() => {
131
+ this.icons.delete(languageId);
132
+ this.onDidChangeIconEmitter.fire({ languageId });
133
+ });
134
+ }
135
+
136
+ override getIcon(obj: unknown): string | undefined {
137
+ const language = this.detectLanguage(obj);
138
+ return language ? this.icons.get(language.id) : undefined;
139
+ }
140
+
141
+ getLanguageIdByLanguageName(languageName: string): string | undefined {
142
+ return monaco.languages.getLanguages().find(language => language.aliases?.includes(languageName))?.id;
143
+ }
144
+
145
+ protected mergeLanguages(registered: monaco.languages.ILanguageExtensionPoint[]): Map<string, Mutable<Language>> {
146
+ const languages = new Map<string, Mutable<Language>>();
147
+ for (const { id, aliases, extensions, filenames } of registered) {
148
+ const merged = languages.get(id) || {
149
+ id,
150
+ name: '',
151
+ extensions: new Set(),
152
+ filenames: new Set()
153
+ };
154
+ if (!merged.name && aliases && aliases.length) {
155
+ merged.name = aliases[0];
156
+ }
157
+ if (extensions && extensions.length) {
158
+ for (const extension of extensions) {
159
+ merged.extensions.add(extension);
160
+ }
161
+ }
162
+ if (filenames && filenames.length) {
163
+ for (const filename of filenames) {
164
+ merged.filenames.add(filename);
165
+ }
166
+ }
167
+ languages.set(id, merged);
168
+ }
169
+ for (const [id, language] of languages) {
170
+ if (!language.name) {
171
+ language.name = id;
172
+ }
173
+ }
174
+ return languages;
175
+ }
176
+
177
+ }
@@ -1,83 +1,83 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2020 TypeFox and others.
3
- //
4
- // This program and the accompanying materials are made available under the
5
- // terms of the Eclipse Public License v. 2.0 which is available at
6
- // http://www.eclipse.org/legal/epl-2.0.
7
- //
8
- // This Source Code may also be made available under the following Secondary
9
- // Licenses when the conditions for such availability set forth in the Eclipse
10
- // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
- // with the GNU Classpath Exception which is available at
12
- // https://www.gnu.org/software/classpath/license.html.
13
- //
14
- // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
- // *****************************************************************************
16
-
17
- import { Diagnostic } from '@theia/core/shared/vscode-languageserver-protocol';
18
- import { ProtocolToMonacoConverter } from './protocol-to-monaco-converter';
19
- import * as monaco from '@theia/monaco-editor-core';
20
- import { Marker } from '@theia/markers/lib/common/marker';
21
- import URI from '@theia/core/lib/common/uri';
22
-
23
- export class MonacoMarkerCollection {
24
- protected readonly uri: monaco.Uri;
25
- protected readonly p2m: ProtocolToMonacoConverter;
26
- protected markers: Marker<Diagnostic>[] = [];
27
- protected owners = new Map<string, Diagnostic[]>();
28
- protected didUpdate: boolean = false;
29
-
30
- constructor(
31
- uri: URI,
32
- p2m: ProtocolToMonacoConverter
33
- ) {
34
- this.uri = monaco.Uri.parse(uri.toString());
35
- this.p2m = p2m;
36
- }
37
-
38
- updateMarkers(markers: Marker<Diagnostic>[]): void {
39
- this.markers = markers;
40
- const model = monaco.editor.getModel(this.uri);
41
- this.doUpdateMarkers(model ? model : undefined);
42
- }
43
-
44
- updateModelMarkers(model: monaco.editor.ITextModel): void {
45
- if (!this.didUpdate) {
46
- this.doUpdateMarkers(model);
47
- return;
48
- }
49
- for (const [owner, diagnostics] of this.owners) {
50
- this.setModelMarkers(model, owner, diagnostics);
51
- }
52
- }
53
-
54
- doUpdateMarkers(model: monaco.editor.ITextModel | undefined): void {
55
- if (!model) {
56
- this.didUpdate = false;
57
- return;
58
- }
59
- this.didUpdate = true;
60
- const toClean = new Set<string>(this.owners.keys());
61
- this.owners.clear();
62
- for (const marker of this.markers) {
63
- const diagnostics = this.owners.get(marker.owner) || [];
64
- diagnostics.push(marker.data);
65
- this.owners.set(marker.owner, diagnostics);
66
- }
67
- for (const [owner, diagnostics] of this.owners) {
68
- toClean.delete(owner);
69
- this.setModelMarkers(model, owner, diagnostics);
70
- }
71
- for (const owner of toClean) {
72
- this.clearModelMarkers(model, owner);
73
- }
74
- }
75
-
76
- setModelMarkers(model: monaco.editor.ITextModel, owner: string, diagnostics: Diagnostic[]): void {
77
- monaco.editor.setModelMarkers(model, owner, this.p2m.asDiagnostics(diagnostics));
78
- }
79
-
80
- clearModelMarkers(model: monaco.editor.ITextModel, owner: string): void {
81
- monaco.editor.setModelMarkers(model, owner, []);
82
- }
83
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2020 TypeFox and others.
3
+ //
4
+ // This program and the accompanying materials are made available under the
5
+ // terms of the Eclipse Public License v. 2.0 which is available at
6
+ // http://www.eclipse.org/legal/epl-2.0.
7
+ //
8
+ // This Source Code may also be made available under the following Secondary
9
+ // Licenses when the conditions for such availability set forth in the Eclipse
10
+ // Public License v. 2.0 are satisfied: GNU General Public License, version 2
11
+ // with the GNU Classpath Exception which is available at
12
+ // https://www.gnu.org/software/classpath/license.html.
13
+ //
14
+ // SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
15
+ // *****************************************************************************
16
+
17
+ import { Diagnostic } from '@theia/core/shared/vscode-languageserver-protocol';
18
+ import { ProtocolToMonacoConverter } from './protocol-to-monaco-converter';
19
+ import * as monaco from '@theia/monaco-editor-core';
20
+ import { Marker } from '@theia/markers/lib/common/marker';
21
+ import URI from '@theia/core/lib/common/uri';
22
+
23
+ export class MonacoMarkerCollection {
24
+ protected readonly uri: monaco.Uri;
25
+ protected readonly p2m: ProtocolToMonacoConverter;
26
+ protected markers: Marker<Diagnostic>[] = [];
27
+ protected owners = new Map<string, Diagnostic[]>();
28
+ protected didUpdate: boolean = false;
29
+
30
+ constructor(
31
+ uri: URI,
32
+ p2m: ProtocolToMonacoConverter
33
+ ) {
34
+ this.uri = monaco.Uri.parse(uri.toString());
35
+ this.p2m = p2m;
36
+ }
37
+
38
+ updateMarkers(markers: Marker<Diagnostic>[]): void {
39
+ this.markers = markers;
40
+ const model = monaco.editor.getModel(this.uri);
41
+ this.doUpdateMarkers(model ? model : undefined);
42
+ }
43
+
44
+ updateModelMarkers(model: monaco.editor.ITextModel): void {
45
+ if (!this.didUpdate) {
46
+ this.doUpdateMarkers(model);
47
+ return;
48
+ }
49
+ for (const [owner, diagnostics] of this.owners) {
50
+ this.setModelMarkers(model, owner, diagnostics);
51
+ }
52
+ }
53
+
54
+ doUpdateMarkers(model: monaco.editor.ITextModel | undefined): void {
55
+ if (!model) {
56
+ this.didUpdate = false;
57
+ return;
58
+ }
59
+ this.didUpdate = true;
60
+ const toClean = new Set<string>(this.owners.keys());
61
+ this.owners.clear();
62
+ for (const marker of this.markers) {
63
+ const diagnostics = this.owners.get(marker.owner) || [];
64
+ diagnostics.push(marker.data);
65
+ this.owners.set(marker.owner, diagnostics);
66
+ }
67
+ for (const [owner, diagnostics] of this.owners) {
68
+ toClean.delete(owner);
69
+ this.setModelMarkers(model, owner, diagnostics);
70
+ }
71
+ for (const owner of toClean) {
72
+ this.clearModelMarkers(model, owner);
73
+ }
74
+ }
75
+
76
+ setModelMarkers(model: monaco.editor.ITextModel, owner: string, diagnostics: Diagnostic[]): void {
77
+ monaco.editor.setModelMarkers(model, owner, this.p2m.asDiagnostics(diagnostics));
78
+ }
79
+
80
+ clearModelMarkers(model: monaco.editor.ITextModel, owner: string): void {
81
+ monaco.editor.setModelMarkers(model, owner, []);
82
+ }
83
+ }