@theia/vsx-registry 1.45.0 → 1.46.0-next.72

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 (100) hide show
  1. package/README.md +45 -45
  2. package/lib/browser/recommended-extensions/preference-provider-overrides.d.ts +17 -17
  3. package/lib/browser/recommended-extensions/preference-provider-overrides.js +95 -95
  4. package/lib/browser/recommended-extensions/recommended-extensions-json-schema.d.ts +14 -14
  5. package/lib/browser/recommended-extensions/recommended-extensions-json-schema.js +94 -94
  6. package/lib/browser/recommended-extensions/recommended-extensions-preference-contribution.d.ts +11 -11
  7. package/lib/browser/recommended-extensions/recommended-extensions-preference-contribution.js +59 -59
  8. package/lib/browser/vsx-extension-commands.d.ts +14 -13
  9. package/lib/browser/vsx-extension-commands.d.ts.map +1 -1
  10. package/lib/browser/vsx-extension-commands.js +68 -63
  11. package/lib/browser/vsx-extension-commands.js.map +1 -1
  12. package/lib/browser/vsx-extension-editor-manager.d.ts +9 -9
  13. package/lib/browser/vsx-extension-editor-manager.js +49 -49
  14. package/lib/browser/vsx-extension-editor.d.ts +21 -21
  15. package/lib/browser/vsx-extension-editor.js +109 -109
  16. package/lib/browser/vsx-extension.d.ts +146 -143
  17. package/lib/browser/vsx-extension.d.ts.map +1 -1
  18. package/lib/browser/vsx-extension.js +616 -596
  19. package/lib/browser/vsx-extension.js.map +1 -1
  20. package/lib/browser/vsx-extensions-contribution.d.ts +70 -60
  21. package/lib/browser/vsx-extensions-contribution.d.ts.map +1 -1
  22. package/lib/browser/vsx-extensions-contribution.js +375 -344
  23. package/lib/browser/vsx-extensions-contribution.js.map +1 -1
  24. package/lib/browser/vsx-extensions-model.d.ts +75 -72
  25. package/lib/browser/vsx-extensions-model.d.ts.map +1 -1
  26. package/lib/browser/vsx-extensions-model.js +437 -391
  27. package/lib/browser/vsx-extensions-model.js.map +1 -1
  28. package/lib/browser/vsx-extensions-preferences.d.ts +12 -0
  29. package/lib/browser/vsx-extensions-preferences.d.ts.map +1 -0
  30. package/lib/browser/vsx-extensions-preferences.js +47 -0
  31. package/lib/browser/vsx-extensions-preferences.js.map +1 -0
  32. package/lib/browser/vsx-extensions-search-bar.d.ts +22 -14
  33. package/lib/browser/vsx-extensions-search-bar.d.ts.map +1 -1
  34. package/lib/browser/vsx-extensions-search-bar.js +106 -75
  35. package/lib/browser/vsx-extensions-search-bar.js.map +1 -1
  36. package/lib/browser/vsx-extensions-search-model.d.ts +21 -21
  37. package/lib/browser/vsx-extensions-search-model.js +70 -70
  38. package/lib/browser/vsx-extensions-source.d.ts +19 -19
  39. package/lib/browser/vsx-extensions-source.js +102 -102
  40. package/lib/browser/vsx-extensions-view-container.d.ts +49 -49
  41. package/lib/browser/vsx-extensions-view-container.js +179 -179
  42. package/lib/browser/vsx-extensions-widget.d.ts +35 -34
  43. package/lib/browser/vsx-extensions-widget.d.ts.map +1 -1
  44. package/lib/browser/vsx-extensions-widget.js +164 -156
  45. package/lib/browser/vsx-extensions-widget.js.map +1 -1
  46. package/lib/browser/vsx-language-quick-pick-service.d.ts +15 -15
  47. package/lib/browser/vsx-language-quick-pick-service.js +121 -121
  48. package/lib/browser/vsx-registry-frontend-module.d.ts +4 -4
  49. package/lib/browser/vsx-registry-frontend-module.d.ts.map +1 -1
  50. package/lib/browser/vsx-registry-frontend-module.js +99 -97
  51. package/lib/browser/vsx-registry-frontend-module.js.map +1 -1
  52. package/lib/common/index.d.ts +3 -3
  53. package/lib/common/index.js +25 -25
  54. package/lib/common/ovsx-client-provider.d.ts +13 -13
  55. package/lib/common/ovsx-client-provider.js +29 -29
  56. package/lib/common/vsx-environment.d.ts +9 -9
  57. package/lib/common/vsx-environment.js +20 -20
  58. package/lib/common/vsx-extension-uri.d.ts +3 -3
  59. package/lib/common/vsx-extension-uri.js +20 -20
  60. package/lib/common/vsx-registry-common-module.d.ts +3 -3
  61. package/lib/common/vsx-registry-common-module.js +57 -57
  62. package/lib/node/vsx-cli.d.ts +9 -9
  63. package/lib/node/vsx-cli.js +41 -41
  64. package/lib/node/vsx-environment-impl.d.ts +14 -14
  65. package/lib/node/vsx-environment-impl.js +61 -61
  66. package/lib/node/vsx-extension-resolver.d.ts +20 -20
  67. package/lib/node/vsx-extension-resolver.js +154 -154
  68. package/lib/node/vsx-registry-backend-module.d.ts +3 -3
  69. package/lib/node/vsx-registry-backend-module.js +35 -35
  70. package/lib/package.spec.js +25 -25
  71. package/package.json +12 -12
  72. package/src/browser/recommended-extensions/preference-provider-overrides.ts +99 -99
  73. package/src/browser/recommended-extensions/recommended-extensions-json-schema.ts +74 -74
  74. package/src/browser/recommended-extensions/recommended-extensions-preference-contribution.ts +68 -68
  75. package/src/browser/style/extensions.svg +4 -4
  76. package/src/browser/style/index.css +436 -373
  77. package/src/browser/vsx-extension-commands.ts +68 -63
  78. package/src/browser/vsx-extension-editor-manager.ts +42 -42
  79. package/src/browser/vsx-extension-editor.tsx +96 -96
  80. package/src/browser/vsx-extension.tsx +704 -675
  81. package/src/browser/vsx-extensions-contribution.ts +361 -327
  82. package/src/browser/vsx-extensions-model.ts +436 -389
  83. package/src/browser/vsx-extensions-preferences.ts +58 -0
  84. package/src/browser/vsx-extensions-search-bar.tsx +107 -69
  85. package/src/browser/vsx-extensions-search-model.ts +61 -61
  86. package/src/browser/vsx-extensions-source.ts +83 -83
  87. package/src/browser/vsx-extensions-view-container.ts +179 -179
  88. package/src/browser/vsx-extensions-widget.tsx +165 -156
  89. package/src/browser/vsx-language-quick-pick-service.ts +110 -110
  90. package/src/browser/vsx-registry-frontend-module.ts +108 -106
  91. package/src/common/index.ts +19 -19
  92. package/src/common/ovsx-client-provider.ts +35 -35
  93. package/src/common/vsx-environment.ts +27 -27
  94. package/src/common/vsx-extension-uri.ts +20 -20
  95. package/src/common/vsx-registry-common-module.ts +63 -63
  96. package/src/node/vsx-cli.ts +38 -38
  97. package/src/node/vsx-environment-impl.ts +50 -50
  98. package/src/node/vsx-extension-resolver.ts +125 -125
  99. package/src/node/vsx-registry-backend-module.ts +35 -35
  100. package/src/package.spec.ts +29 -29
@@ -1,156 +1,165 @@
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 { injectable, interfaces, postConstruct, inject } from '@theia/core/shared/inversify';
18
- import { TreeModel, TreeNode } from '@theia/core/lib/browser';
19
- import { SourceTreeWidget } from '@theia/core/lib/browser/source-tree';
20
- import { VSXExtensionsSource, VSXExtensionsSourceOptions } from './vsx-extensions-source';
21
- import { nls } from '@theia/core/lib/common/nls';
22
- import { BadgeWidget } from '@theia/core/lib/browser/view-container';
23
- import { Emitter, Event } from '@theia/core/lib/common';
24
- import { AlertMessage } from '@theia/core/lib/browser/widgets/alert-message';
25
- import * as React from '@theia/core/shared/react';
26
-
27
- @injectable()
28
- export class VSXExtensionsWidgetOptions extends VSXExtensionsSourceOptions {
29
- title?: string;
30
- }
31
-
32
- export const generateExtensionWidgetId = (widgetId: string): string => VSXExtensionsWidget.ID + ':' + widgetId;
33
-
34
- @injectable()
35
- export class VSXExtensionsWidget extends SourceTreeWidget implements BadgeWidget {
36
-
37
- static ID = 'vsx-extensions';
38
-
39
- static createWidget(parent: interfaces.Container, options: VSXExtensionsWidgetOptions): VSXExtensionsWidget {
40
- const child = SourceTreeWidget.createContainer(parent, {
41
- virtualized: false,
42
- scrollIfActive: true
43
- });
44
- child.bind(VSXExtensionsSourceOptions).toConstantValue(options);
45
- child.bind(VSXExtensionsSource).toSelf();
46
- child.unbind(SourceTreeWidget);
47
- child.bind(VSXExtensionsWidgetOptions).toConstantValue(options);
48
- child.bind(VSXExtensionsWidget).toSelf();
49
- return child.get(VSXExtensionsWidget);
50
- }
51
-
52
- protected _badge?: number;
53
- protected onDidChangeBadgeEmitter = new Emitter<void>();
54
-
55
- protected _badgeTooltip?: string;
56
- protected onDidChangeBadgeTooltipEmitter = new Emitter<void>();
57
-
58
- @inject(VSXExtensionsWidgetOptions)
59
- protected readonly options: VSXExtensionsWidgetOptions;
60
-
61
- @inject(VSXExtensionsSource)
62
- protected readonly extensionsSource: VSXExtensionsSource;
63
-
64
- @postConstruct()
65
- protected override init(): void {
66
- super.init();
67
- this.addClass('theia-vsx-extensions');
68
-
69
- this.id = generateExtensionWidgetId(this.options.id);
70
-
71
- this.toDispose.push(this.extensionsSource);
72
- this.source = this.extensionsSource;
73
-
74
- const title = this.options.title ?? this.computeTitle();
75
- this.title.label = title;
76
- this.title.caption = title;
77
-
78
- this.toDispose.push(this.source.onDidChange(async () => {
79
- this.badge = await this.resolveCount();
80
- }));
81
- }
82
-
83
- get onDidChangeBadge(): Event<void> {
84
- return this.onDidChangeBadgeEmitter.event;
85
- }
86
-
87
- get badge(): number | undefined {
88
- return this._badge;
89
- }
90
-
91
- set badge(count: number | undefined) {
92
- this._badge = count;
93
- this.onDidChangeBadgeEmitter.fire();
94
- }
95
-
96
- get onDidChangeBadgeTooltip(): Event<void> {
97
- return this.onDidChangeBadgeTooltipEmitter.event;
98
- }
99
-
100
- get badgeTooltip(): string | undefined {
101
- return this._badgeTooltip;
102
- }
103
-
104
- set badgeTooltip(tooltip: string | undefined) {
105
- this._badgeTooltip = tooltip;
106
- this.onDidChangeBadgeTooltipEmitter.fire();
107
- }
108
-
109
- protected computeTitle(): string {
110
- switch (this.options.id) {
111
- case VSXExtensionsSourceOptions.INSTALLED:
112
- return nls.localizeByDefault('Installed');
113
- case VSXExtensionsSourceOptions.BUILT_IN:
114
- return nls.localizeByDefault('Built-in');
115
- case VSXExtensionsSourceOptions.RECOMMENDED:
116
- return nls.localizeByDefault('Recommended');
117
- case VSXExtensionsSourceOptions.SEARCH_RESULT:
118
- return 'Open VSX Registry';
119
- default:
120
- return '';
121
- }
122
- }
123
-
124
- protected async resolveCount(): Promise<number | undefined> {
125
- if (this.options.id !== VSXExtensionsSourceOptions.SEARCH_RESULT) {
126
- const elements = await this.source?.getElements() || [];
127
- return [...elements].length;
128
- }
129
- return undefined;
130
- }
131
-
132
- protected override tapNode(node?: TreeNode): void {
133
- super.tapNode(node);
134
- this.model.openNode(node);
135
- }
136
-
137
- protected override handleDblClickEvent(): void {
138
- // Don't open the editor view on a double click.
139
- }
140
-
141
- protected override renderTree(model: TreeModel): React.ReactNode {
142
- if (this.options.id === VSXExtensionsSourceOptions.SEARCH_RESULT) {
143
- const searchError = this.extensionsSource.getModel().searchError;
144
- if (!!searchError) {
145
- const message = nls.localize('theia/vsx-registry/errorFetching', 'Error fetching extensions.');
146
- const configurationHint = nls.localize('theia/vsx-registry/errorFetchingConfigurationHint', 'This could be caused by network configuration issues.');
147
- const hint = searchError.includes('ENOTFOUND') ? configurationHint : '';
148
- return <AlertMessage
149
- type='ERROR'
150
- header={`${message} ${searchError} ${hint}`}
151
- />;
152
- }
153
- }
154
- return super.renderTree(model);
155
- }
156
- }
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 { injectable, interfaces, postConstruct, inject } from '@theia/core/shared/inversify';
18
+ import { Message, TreeModel, TreeNode } from '@theia/core/lib/browser';
19
+ import { SourceTreeWidget } from '@theia/core/lib/browser/source-tree';
20
+ import { VSXExtensionsSource, VSXExtensionsSourceOptions } from './vsx-extensions-source';
21
+ import { nls } from '@theia/core/lib/common/nls';
22
+ import { BadgeWidget } from '@theia/core/lib/browser/view-container';
23
+ import { Emitter, Event } from '@theia/core/lib/common';
24
+ import { AlertMessage } from '@theia/core/lib/browser/widgets/alert-message';
25
+ import * as React from '@theia/core/shared/react';
26
+
27
+ @injectable()
28
+ export class VSXExtensionsWidgetOptions extends VSXExtensionsSourceOptions {
29
+ title?: string;
30
+ }
31
+
32
+ export const generateExtensionWidgetId = (widgetId: string): string => VSXExtensionsWidget.ID + ':' + widgetId;
33
+
34
+ @injectable()
35
+ export class VSXExtensionsWidget extends SourceTreeWidget implements BadgeWidget {
36
+
37
+ static ID = 'vsx-extensions';
38
+
39
+ static createWidget(parent: interfaces.Container, options: VSXExtensionsWidgetOptions): VSXExtensionsWidget {
40
+ const child = SourceTreeWidget.createContainer(parent, {
41
+ virtualized: false,
42
+ scrollIfActive: true
43
+ });
44
+ child.bind(VSXExtensionsSourceOptions).toConstantValue(options);
45
+ child.bind(VSXExtensionsSource).toSelf();
46
+ child.unbind(SourceTreeWidget);
47
+ child.bind(VSXExtensionsWidgetOptions).toConstantValue(options);
48
+ child.bind(VSXExtensionsWidget).toSelf();
49
+ return child.get(VSXExtensionsWidget);
50
+ }
51
+
52
+ protected _badge?: number;
53
+ protected onDidChangeBadgeEmitter = new Emitter<void>();
54
+
55
+ protected _badgeTooltip?: string;
56
+ protected onDidChangeBadgeTooltipEmitter = new Emitter<void>();
57
+
58
+ @inject(VSXExtensionsWidgetOptions)
59
+ protected readonly options: VSXExtensionsWidgetOptions;
60
+
61
+ @inject(VSXExtensionsSource)
62
+ protected readonly extensionsSource: VSXExtensionsSource;
63
+
64
+ @postConstruct()
65
+ protected override init(): void {
66
+ super.init();
67
+ this.addClass('theia-vsx-extensions');
68
+
69
+ this.id = generateExtensionWidgetId(this.options.id);
70
+
71
+ this.toDispose.push(this.extensionsSource);
72
+ this.source = this.extensionsSource;
73
+
74
+ const title = this.options.title ?? this.computeTitle();
75
+ this.title.label = title;
76
+ this.title.caption = title;
77
+
78
+ this.toDispose.push(this.source.onDidChange(async () => {
79
+ this.badge = await this.resolveCount();
80
+ }));
81
+ }
82
+
83
+ get onDidChangeBadge(): Event<void> {
84
+ return this.onDidChangeBadgeEmitter.event;
85
+ }
86
+
87
+ get badge(): number | undefined {
88
+ return this._badge;
89
+ }
90
+
91
+ set badge(count: number | undefined) {
92
+ this._badge = count;
93
+ this.onDidChangeBadgeEmitter.fire();
94
+ }
95
+
96
+ get onDidChangeBadgeTooltip(): Event<void> {
97
+ return this.onDidChangeBadgeTooltipEmitter.event;
98
+ }
99
+
100
+ get badgeTooltip(): string | undefined {
101
+ return this._badgeTooltip;
102
+ }
103
+
104
+ set badgeTooltip(tooltip: string | undefined) {
105
+ this._badgeTooltip = tooltip;
106
+ this.onDidChangeBadgeTooltipEmitter.fire();
107
+ }
108
+
109
+ protected computeTitle(): string {
110
+ switch (this.options.id) {
111
+ case VSXExtensionsSourceOptions.INSTALLED:
112
+ return nls.localizeByDefault('Installed');
113
+ case VSXExtensionsSourceOptions.BUILT_IN:
114
+ return nls.localizeByDefault('Built-in');
115
+ case VSXExtensionsSourceOptions.RECOMMENDED:
116
+ return nls.localizeByDefault('Recommended');
117
+ case VSXExtensionsSourceOptions.SEARCH_RESULT:
118
+ return 'Open VSX Registry';
119
+ default:
120
+ return '';
121
+ }
122
+ }
123
+
124
+ protected async resolveCount(): Promise<number | undefined> {
125
+ if (this.options.id !== VSXExtensionsSourceOptions.SEARCH_RESULT) {
126
+ const elements = await this.source?.getElements() || [];
127
+ return [...elements].length;
128
+ }
129
+ return undefined;
130
+ }
131
+
132
+ protected override tapNode(node?: TreeNode): void {
133
+ super.tapNode(node);
134
+ this.model.openNode(node);
135
+ }
136
+
137
+ protected override handleDblClickEvent(): void {
138
+ // Don't open the editor view on a double click.
139
+ }
140
+
141
+ protected override renderTree(model: TreeModel): React.ReactNode {
142
+ if (this.options.id === VSXExtensionsSourceOptions.SEARCH_RESULT) {
143
+ const searchError = this.extensionsSource.getModel().searchError;
144
+ if (!!searchError) {
145
+ const message = nls.localize('theia/vsx-registry/errorFetching', 'Error fetching extensions.');
146
+ const configurationHint = nls.localize('theia/vsx-registry/errorFetchingConfigurationHint', 'This could be caused by network configuration issues.');
147
+ const hint = searchError.includes('ENOTFOUND') ? configurationHint : '';
148
+ return <AlertMessage
149
+ type='ERROR'
150
+ header={`${message} ${searchError} ${hint}`}
151
+ />;
152
+ }
153
+ }
154
+ return super.renderTree(model);
155
+ }
156
+
157
+ protected override onAfterShow(msg: Message): void {
158
+ super.onAfterShow(msg);
159
+ if (this.options.id === VSXExtensionsSourceOptions.INSTALLED) {
160
+ // This is needed when an Extension was installed outside of the extension view.
161
+ // E.g. using explorer context menu.
162
+ this.doUpdateRows();
163
+ }
164
+ }
165
+ }
@@ -1,110 +1,110 @@
1
- // *****************************************************************************
2
- // Copyright (C) 2022 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 { LanguageQuickPickItem, LanguageQuickPickService } from '@theia/core/lib/browser/i18n/language-quick-pick-service';
18
- import { RequestContext, RequestService } from '@theia/core/shared/@theia/request';
19
- import { inject, injectable } from '@theia/core/shared/inversify';
20
- import { LanguageInfo } from '@theia/core/lib/common/i18n/localization';
21
- import { PluginPackage, PluginServer } from '@theia/plugin-ext';
22
- import { OVSXClientProvider } from '../common/ovsx-client-provider';
23
- import { VSXSearchEntry } from '@theia/ovsx-client';
24
- import { VSCodeExtensionUri } from '@theia/plugin-ext-vscode/lib/common/plugin-vscode-uri';
25
- import { nls } from '@theia/core/lib/common/nls';
26
- import { MessageService } from '@theia/core/lib/common/message-service';
27
-
28
- @injectable()
29
- export class VSXLanguageQuickPickService extends LanguageQuickPickService {
30
-
31
- @inject(OVSXClientProvider)
32
- protected readonly clientProvider: OVSXClientProvider;
33
-
34
- @inject(RequestService)
35
- protected readonly requestService: RequestService;
36
-
37
- @inject(PluginServer)
38
- protected readonly pluginServer: PluginServer;
39
-
40
- @inject(MessageService)
41
- protected readonly messageService: MessageService;
42
-
43
- protected override async getAvailableLanguages(): Promise<LanguageQuickPickItem[]> {
44
- const client = await this.clientProvider();
45
- const searchResult = await client.search({
46
- category: 'Language Packs',
47
- sortBy: 'downloadCount',
48
- sortOrder: 'desc',
49
- size: 20
50
- });
51
- if (searchResult.error) {
52
- throw new Error('Error while loading available languages: ' + searchResult.error);
53
- }
54
-
55
- const extensionLanguages = await Promise.all(
56
- searchResult.extensions.map(async extension => ({
57
- extension,
58
- languages: await this.loadExtensionLanguages(extension)
59
- }))
60
- );
61
-
62
- const languages = new Map<string, LanguageQuickPickItem>();
63
-
64
- for (const extension of extensionLanguages) {
65
- for (const localizationContribution of extension.languages) {
66
- if (!languages.has(localizationContribution.languageId)) {
67
- languages.set(localizationContribution.languageId, {
68
- ...this.createLanguageQuickPickItem(localizationContribution),
69
- execute: async () => {
70
- const progress = await this.messageService.showProgress({
71
- text: nls.localizeByDefault('Installing {0} language support...',
72
- localizationContribution.localizedLanguageName ?? localizationContribution.languageName ?? localizationContribution.languageId),
73
- });
74
- try {
75
- const extensionUri = VSCodeExtensionUri.toUri(extension.extension.name, extension.extension.namespace).toString();
76
- await this.pluginServer.deploy(extensionUri);
77
- } finally {
78
- progress.cancel();
79
- }
80
- }
81
- });
82
- }
83
- }
84
- }
85
- return Array.from(languages.values());
86
- }
87
-
88
- protected async loadExtensionLanguages(extension: VSXSearchEntry): Promise<LanguageInfo[]> {
89
- // When searching for extensions on ovsx, we don't receive the `manifest` property.
90
- // This property is only set when querying a specific extension.
91
- // To improve performance, we assume that a manifest exists at `/package.json`.
92
- const downloadUrl = extension.files.download;
93
- const parentUrl = downloadUrl.substring(0, downloadUrl.lastIndexOf('/'));
94
- const manifestUrl = parentUrl + '/package.json';
95
- try {
96
- const manifestRequest = await this.requestService.request({ url: manifestUrl });
97
- const manifestContent = RequestContext.asJson<PluginPackage>(manifestRequest);
98
- const localizations = manifestContent.contributes?.localizations ?? [];
99
- return localizations.map(e => ({
100
- languageId: e.languageId,
101
- languageName: e.languageName,
102
- localizedLanguageName: e.localizedLanguageName,
103
- languagePack: true
104
- }));
105
- } catch {
106
- // The `package.json` file might not actually exist, simply return an empty array
107
- return [];
108
- }
109
- }
110
- }
1
+ // *****************************************************************************
2
+ // Copyright (C) 2022 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 { LanguageQuickPickItem, LanguageQuickPickService } from '@theia/core/lib/browser/i18n/language-quick-pick-service';
18
+ import { RequestContext, RequestService } from '@theia/core/shared/@theia/request';
19
+ import { inject, injectable } from '@theia/core/shared/inversify';
20
+ import { LanguageInfo } from '@theia/core/lib/common/i18n/localization';
21
+ import { PluginPackage, PluginServer } from '@theia/plugin-ext';
22
+ import { OVSXClientProvider } from '../common/ovsx-client-provider';
23
+ import { VSXSearchEntry } from '@theia/ovsx-client';
24
+ import { VSCodeExtensionUri } from '@theia/plugin-ext-vscode/lib/common/plugin-vscode-uri';
25
+ import { nls } from '@theia/core/lib/common/nls';
26
+ import { MessageService } from '@theia/core/lib/common/message-service';
27
+
28
+ @injectable()
29
+ export class VSXLanguageQuickPickService extends LanguageQuickPickService {
30
+
31
+ @inject(OVSXClientProvider)
32
+ protected readonly clientProvider: OVSXClientProvider;
33
+
34
+ @inject(RequestService)
35
+ protected readonly requestService: RequestService;
36
+
37
+ @inject(PluginServer)
38
+ protected readonly pluginServer: PluginServer;
39
+
40
+ @inject(MessageService)
41
+ protected readonly messageService: MessageService;
42
+
43
+ protected override async getAvailableLanguages(): Promise<LanguageQuickPickItem[]> {
44
+ const client = await this.clientProvider();
45
+ const searchResult = await client.search({
46
+ category: 'Language Packs',
47
+ sortBy: 'downloadCount',
48
+ sortOrder: 'desc',
49
+ size: 20
50
+ });
51
+ if (searchResult.error) {
52
+ throw new Error('Error while loading available languages: ' + searchResult.error);
53
+ }
54
+
55
+ const extensionLanguages = await Promise.all(
56
+ searchResult.extensions.map(async extension => ({
57
+ extension,
58
+ languages: await this.loadExtensionLanguages(extension)
59
+ }))
60
+ );
61
+
62
+ const languages = new Map<string, LanguageQuickPickItem>();
63
+
64
+ for (const extension of extensionLanguages) {
65
+ for (const localizationContribution of extension.languages) {
66
+ if (!languages.has(localizationContribution.languageId)) {
67
+ languages.set(localizationContribution.languageId, {
68
+ ...this.createLanguageQuickPickItem(localizationContribution),
69
+ execute: async () => {
70
+ const progress = await this.messageService.showProgress({
71
+ text: nls.localizeByDefault('Installing {0} language support...',
72
+ localizationContribution.localizedLanguageName ?? localizationContribution.languageName ?? localizationContribution.languageId),
73
+ });
74
+ try {
75
+ const extensionUri = VSCodeExtensionUri.toUri(extension.extension.name, extension.extension.namespace).toString();
76
+ await this.pluginServer.deploy(extensionUri);
77
+ } finally {
78
+ progress.cancel();
79
+ }
80
+ }
81
+ });
82
+ }
83
+ }
84
+ }
85
+ return Array.from(languages.values());
86
+ }
87
+
88
+ protected async loadExtensionLanguages(extension: VSXSearchEntry): Promise<LanguageInfo[]> {
89
+ // When searching for extensions on ovsx, we don't receive the `manifest` property.
90
+ // This property is only set when querying a specific extension.
91
+ // To improve performance, we assume that a manifest exists at `/package.json`.
92
+ const downloadUrl = extension.files.download;
93
+ const parentUrl = downloadUrl.substring(0, downloadUrl.lastIndexOf('/'));
94
+ const manifestUrl = parentUrl + '/package.json';
95
+ try {
96
+ const manifestRequest = await this.requestService.request({ url: manifestUrl });
97
+ const manifestContent = RequestContext.asJson<PluginPackage>(manifestRequest);
98
+ const localizations = manifestContent.contributes?.localizations ?? [];
99
+ return localizations.map(e => ({
100
+ languageId: e.languageId,
101
+ languageName: e.languageName,
102
+ localizedLanguageName: e.localizedLanguageName,
103
+ languagePack: true
104
+ }));
105
+ } catch {
106
+ // The `package.json` file might not actually exist, simply return an empty array
107
+ return [];
108
+ }
109
+ }
110
+ }