Skip to content

Commit f83ad50

Browse files
Load bundle for web from unpkg service (microsoft#163641)
* move extensionResourceLoader service into platform * use the ExtensionResourceLoader to load translations from a language pack * do join after * missed a deletion
1 parent 28da8ed commit f83ad50

File tree

22 files changed

+87
-36
lines changed

22 files changed

+87
-36
lines changed
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import { URI } from 'vs/base/common/uri';
77
import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions';
88
import { IFileService } from 'vs/platform/files/common/files';
9-
import { AbstractExtensionResourceLoaderService, IExtensionResourceLoaderService } from 'vs/workbench/services/extensionResourceLoader/common/extensionResourceLoader';
109
import { FileAccess, Schemas } from 'vs/base/common/network';
1110
import { IProductService } from 'vs/platform/product/common/productService';
1211
import { IStorageService } from 'vs/platform/storage/common/storage';
1312
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1413
import { ILogService } from 'vs/platform/log/common/log';
1514
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
15+
import { AbstractExtensionResourceLoaderService, IExtensionResourceLoaderService } from 'vs/platform/extensionResourceLoader/common/extensionResourceLoader';
1616

1717
class ExtensionResourceLoaderService extends AbstractExtensionResourceLoaderService {
1818

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
import { URI } from 'vs/base/common/uri';
77
import { InstantiationType, registerSingleton } from 'vs/platform/instantiation/common/extensions';
88
import { IFileService } from 'vs/platform/files/common/files';
9-
import { AbstractExtensionResourceLoaderService, IExtensionResourceLoaderService } from 'vs/workbench/services/extensionResourceLoader/common/extensionResourceLoader';
109
import { IProductService } from 'vs/platform/product/common/productService';
1110
import { asTextOrError, IRequestService } from 'vs/platform/request/common/request';
1211
import { IStorageService } from 'vs/platform/storage/common/storage';
1312
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1413
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1514
import { CancellationToken } from 'vs/base/common/cancellation';
15+
import { AbstractExtensionResourceLoaderService, IExtensionResourceLoaderService } from 'vs/platform/extensionResourceLoader/common/extensionResourceLoader';
1616

1717
export class ExtensionResourceLoaderService extends AbstractExtensionResourceLoaderService {
1818

src/vs/platform/languagePacks/browser/languagePacks.ts

Lines changed: 62 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,72 @@
33
* Licensed under the MIT License. See License.txt in the project root for license information.
44
*--------------------------------------------------------------------------------------------*/
55

6+
import { CancellationTokenSource } from 'vs/base/common/cancellation';
7+
import { Language } from 'vs/base/common/platform';
68
import { URI } from 'vs/base/common/uri';
9+
import { IExtensionGalleryService } from 'vs/platform/extensionManagement/common/extensionManagement';
10+
import { IExtensionResourceLoaderService } from 'vs/platform/extensionResourceLoader/common/extensionResourceLoader';
711
import { ILanguagePackItem, LanguagePackBaseService } from 'vs/platform/languagePacks/common/languagePacks';
12+
import { ILogService } from 'vs/platform/log/common/log';
813

914
export class WebLanguagePacksService extends LanguagePackBaseService {
10-
// TODO: support builtin extensions using unpkg service
11-
// constructor(
12-
// @IExtensionResourceLoaderService extensionResourceLoaderService: IExtensionResourceLoaderService,
13-
// @IExtensionGalleryService extensionGalleryService: IExtensionGalleryService,
14-
// @ILogService private readonly logService: ILogService
15-
// ) {
16-
// super(extensionGalleryService);
17-
// }
18-
19-
getTranslationsUri(id: string): Promise<URI | undefined> {
20-
return Promise.resolve(undefined);
15+
constructor(
16+
@IExtensionResourceLoaderService private readonly extensionResourceLoaderService: IExtensionResourceLoaderService,
17+
@IExtensionGalleryService extensionGalleryService: IExtensionGalleryService,
18+
@ILogService private readonly logService: ILogService
19+
) {
20+
super(extensionGalleryService);
21+
}
22+
23+
async getBuiltInExtensionTranslationsUri(id: string): Promise<URI | undefined> {
24+
25+
const queryTimeout = new CancellationTokenSource();
26+
setTimeout(() => queryTimeout.cancel(), 1000);
27+
28+
// First get the extensions that supports the language (there should only be one but just in case let's include more results)
29+
let result;
30+
try {
31+
result = await this.extensionGalleryService.query({
32+
text: `tag:"lp-${Language.value()}"`,
33+
pageSize: 5
34+
}, queryTimeout.token);
35+
} catch (err) {
36+
this.logService.error(err);
37+
return undefined;
38+
}
39+
40+
const languagePackExtensions = result.firstPage.find(e => e.properties.localizedLanguages?.length);
41+
if (!languagePackExtensions) {
42+
this.logService.trace(`No language pack found for language ${Language.value()}`);
43+
return undefined;
44+
}
45+
46+
// Then get the manifest for that extension
47+
const manifestTimeout = new CancellationTokenSource();
48+
setTimeout(() => queryTimeout.cancel(), 1000);
49+
const manifest = await this.extensionGalleryService.getManifest(languagePackExtensions, manifestTimeout.token);
50+
51+
// Find the translation from the language pack
52+
const localization = manifest?.contributes?.localizations?.find(l => l.languageId === Language.value());
53+
const translation = localization?.translations.find(t => t.id === id);
54+
if (!translation) {
55+
this.logService.trace(`No translation found for id '${id}, in ${manifest?.name}`);
56+
return undefined;
57+
}
58+
59+
// get the resource uri and return it
60+
const uri = this.extensionResourceLoaderService.getExtensionGalleryResourceURL({
61+
// If translation is defined then manifest should have been defined.
62+
name: manifest!.name,
63+
publisher: manifest!.publisher,
64+
version: manifest!.version
65+
});
66+
if (!uri) {
67+
this.logService.trace('Gallery does not provide extension resources.');
68+
return undefined;
69+
}
70+
71+
return URI.joinPath(uri, translation.path);
2172
}
2273

2374
// Web doesn't have a concept of language packs, so we just return an empty array

src/vs/platform/languagePacks/common/languagePacks.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,18 @@ export interface ILanguagePackService {
2323
readonly _serviceBrand: undefined;
2424
getAvailableLanguages(): Promise<Array<ILanguagePackItem>>;
2525
getInstalledLanguages(): Promise<Array<ILanguagePackItem>>;
26-
getTranslationsUri(id: string): Promise<URI | undefined>;
26+
getBuiltInExtensionTranslationsUri(id: string): Promise<URI | undefined>;
2727
getLocale(extension: IGalleryExtension): string | undefined;
2828
}
2929

3030
export abstract class LanguagePackBaseService extends Disposable implements ILanguagePackService {
3131
declare readonly _serviceBrand: undefined;
3232

33-
constructor(@IExtensionGalleryService private readonly extensionGalleryService: IExtensionGalleryService) {
33+
constructor(@IExtensionGalleryService protected readonly extensionGalleryService: IExtensionGalleryService) {
3434
super();
3535
}
3636

37-
abstract getTranslationsUri(id: string): Promise<URI | undefined>;
37+
abstract getBuiltInExtensionTranslationsUri(id: string): Promise<URI | undefined>;
3838

3939
abstract getInstalledLanguages(): Promise<Array<ILanguagePackItem>>;
4040

src/vs/platform/languagePacks/node/languagePacks.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { areSameExtensions } from 'vs/platform/extensionManagement/common/extens
1616
import { ILogService } from 'vs/platform/log/common/log';
1717
import { ILocalizationContribution } from 'vs/platform/extensions/common/extensions';
1818
import { ILanguagePackItem, LanguagePackBaseService } from 'vs/platform/languagePacks/common/languagePacks';
19-
import { locale } from 'vs/base/common/platform';
19+
import { Language } from 'vs/base/common/platform';
2020
import { URI } from 'vs/base/common/uri';
2121

2222
interface ILanguagePack {
@@ -50,11 +50,11 @@ export class NativeLanguagePackService extends LanguagePackBaseService {
5050
});
5151
}
5252

53-
async getTranslationsUri(id: string): Promise<URI | undefined> {
53+
async getBuiltInExtensionTranslationsUri(id: string): Promise<URI | undefined> {
5454
const packs = await this.cache.getLanguagePacks();
55-
const pack = packs[locale!];
55+
const pack = packs[Language.value()];
5656
if (!pack) {
57-
this.logService.warn(`No language pack found for ${locale}`);
57+
this.logService.warn(`No language pack found for ${Language.value()}`);
5858
return undefined;
5959
}
6060

src/vs/workbench/api/browser/mainThreadLocalization.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export class MainThreadLocalization extends Disposable implements MainThreadLoca
2323

2424
async $fetchBuiltInBundleUri(id: string): Promise<URI | undefined> {
2525
try {
26-
const uri = await this.languagePackService.getTranslationsUri(id);
26+
const uri = await this.languagePackService.getBuiltInExtensionTranslationsUri(id);
2727
return uri;
2828
} catch (e) {
2929
return undefined;

src/vs/workbench/contrib/codeEditor/browser/languageConfigurationExtensionPoint.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { Registry } from 'vs/platform/registry/common/platform';
1616
import { IExtensionService } from 'vs/workbench/services/extensions/common/extensions';
1717
import { ITextMateService } from 'vs/workbench/services/textMate/browser/textMate';
1818
import { getParseErrorMessage } from 'vs/base/common/jsonErrorMessages';
19-
import { IExtensionResourceLoaderService } from 'vs/workbench/services/extensionResourceLoader/common/extensionResourceLoader';
19+
import { IExtensionResourceLoaderService } from 'vs/platform/extensionResourceLoader/common/extensionResourceLoader';
2020
import { hash } from 'vs/base/common/hash';
2121
import { Disposable } from 'vs/base/common/lifecycle';
2222

src/vs/workbench/contrib/snippets/browser/snippetsFile.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import { URI } from 'vs/base/common/uri';
1212
import { IFileService } from 'vs/platform/files/common/files';
1313
import { ExtensionIdentifier, IExtensionDescription } from 'vs/platform/extensions/common/extensions';
1414
import { IdleValue } from 'vs/base/common/async';
15-
import { IExtensionResourceLoaderService } from 'vs/workbench/services/extensionResourceLoader/common/extensionResourceLoader';
15+
import { IExtensionResourceLoaderService } from 'vs/platform/extensionResourceLoader/common/extensionResourceLoader';
1616
import { relativePath } from 'vs/base/common/resources';
1717
import { isObject } from 'vs/base/common/types';
1818
import { Iterable } from 'vs/base/common/iterator';

src/vs/workbench/contrib/snippets/browser/snippetsService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import { Snippet, SnippetFile, SnippetSource } from 'vs/workbench/contrib/snippe
2222
import { ExtensionsRegistry, IExtensionPointUser } from 'vs/workbench/services/extensions/common/extensionsRegistry';
2323
import { languagesExtPoint } from 'vs/workbench/services/language/common/languageService';
2424
import { SnippetCompletionProvider } from './snippetCompletionProvider';
25-
import { IExtensionResourceLoaderService } from 'vs/workbench/services/extensionResourceLoader/common/extensionResourceLoader';
25+
import { IExtensionResourceLoaderService } from 'vs/platform/extensionResourceLoader/common/extensionResourceLoader';
2626
import { ResourceMap } from 'vs/base/common/map';
2727
import { IStorageService, StorageScope, StorageTarget } from 'vs/platform/storage/common/storage';
2828
import { isStringArray } from 'vs/base/common/types';

0 commit comments

Comments
 (0)