mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-02-16 18:46:40 -05:00
Merge from master
This commit is contained in:
@@ -2,10 +2,8 @@
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
'use strict';
|
||||
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { Event } from 'vs/base/common/event';
|
||||
|
||||
export interface ILocalization {
|
||||
@@ -21,7 +19,7 @@ export interface ITranslation {
|
||||
path: string;
|
||||
}
|
||||
|
||||
export enum LanguageType {
|
||||
export const enum LanguageType {
|
||||
Core = 1,
|
||||
Contributed
|
||||
}
|
||||
@@ -31,7 +29,7 @@ export interface ILocalizationsService {
|
||||
_serviceBrand: any;
|
||||
|
||||
readonly onDidLanguagesChange: Event<void>;
|
||||
getLanguageIds(type?: LanguageType): TPromise<string[]>;
|
||||
getLanguageIds(type?: LanguageType): Thenable<string[]>;
|
||||
}
|
||||
|
||||
export function isValidLocalization(localization: ILocalization): boolean {
|
||||
|
||||
@@ -8,8 +8,7 @@ import { createHash } from 'crypto';
|
||||
import { IExtensionManagementService, ILocalExtension, IExtensionIdentifier } from 'vs/platform/extensionManagement/common/extensionManagement';
|
||||
import { Disposable } from 'vs/base/common/lifecycle';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { Limiter } from 'vs/base/common/async';
|
||||
import { Queue } from 'vs/base/common/async';
|
||||
import { areSameExtensions, getGalleryExtensionIdFromLocal, getIdFromLocalExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
|
||||
import { ILogService } from 'vs/platform/log/common/log';
|
||||
import { isValidLocalization, ILocalizationsService, LanguageType } from 'vs/platform/localizations/common/localizations';
|
||||
@@ -56,14 +55,14 @@ export class LocalizationsService extends Disposable implements ILocalizationsSe
|
||||
this.extensionManagementService.getInstalled().then(installed => this.cache.update(installed));
|
||||
}
|
||||
|
||||
getLanguageIds(type: LanguageType): TPromise<string[]> {
|
||||
getLanguageIds(type: LanguageType): Thenable<string[]> {
|
||||
if (type === LanguageType.Core) {
|
||||
return TPromise.as([...systemLanguages]);
|
||||
return Promise.resolve([...systemLanguages]);
|
||||
}
|
||||
return this.cache.getLanguagePacks()
|
||||
.then(languagePacks => {
|
||||
const languages = type === LanguageType.Contributed ? Object.keys(languagePacks) : [...systemLanguages, ...Object.keys(languagePacks)];
|
||||
return TPromise.as(distinct(languages));
|
||||
return distinct(languages);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -86,7 +85,7 @@ export class LocalizationsService extends Disposable implements ILocalizationsSe
|
||||
}
|
||||
|
||||
private update(): void {
|
||||
TPromise.join([this.cache.getLanguagePacks(), this.extensionManagementService.getInstalled()])
|
||||
Promise.all([this.cache.getLanguagePacks(), this.extensionManagementService.getInstalled()])
|
||||
.then(([current, installed]) => this.cache.update(installed)
|
||||
.then(updated => {
|
||||
if (!equals(Object.keys(current), Object.keys(updated))) {
|
||||
@@ -100,7 +99,7 @@ class LanguagePacksCache extends Disposable {
|
||||
|
||||
private languagePacks: { [language: string]: ILanguagePack } = {};
|
||||
private languagePacksFilePath: string;
|
||||
private languagePacksFileLimiter: Limiter<void>;
|
||||
private languagePacksFileLimiter: Queue<any>;
|
||||
|
||||
constructor(
|
||||
@IEnvironmentService environmentService: IEnvironmentService,
|
||||
@@ -108,19 +107,19 @@ class LanguagePacksCache extends Disposable {
|
||||
) {
|
||||
super();
|
||||
this.languagePacksFilePath = posix.join(environmentService.userDataPath, 'languagepacks.json');
|
||||
this.languagePacksFileLimiter = new Limiter(1);
|
||||
this.languagePacksFileLimiter = new Queue();
|
||||
}
|
||||
|
||||
getLanguagePacks(): TPromise<{ [language: string]: ILanguagePack }> {
|
||||
getLanguagePacks(): Thenable<{ [language: string]: ILanguagePack }> {
|
||||
// if queue is not empty, fetch from disk
|
||||
if (this.languagePacksFileLimiter.size) {
|
||||
return this.withLanguagePacks()
|
||||
.then(() => this.languagePacks);
|
||||
}
|
||||
return TPromise.as(this.languagePacks);
|
||||
return Promise.resolve(this.languagePacks);
|
||||
}
|
||||
|
||||
update(extensions: ILocalExtension[]): TPromise<{ [language: string]: ILanguagePack }> {
|
||||
update(extensions: ILocalExtension[]): Thenable<{ [language: string]: ILanguagePack }> {
|
||||
return this.withLanguagePacks(languagePacks => {
|
||||
Object.keys(languagePacks).forEach(language => languagePacks[language] = undefined);
|
||||
this.createLanguagePacksFromExtensions(languagePacks, ...extensions);
|
||||
@@ -168,11 +167,11 @@ class LanguagePacksCache extends Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
private withLanguagePacks<T>(fn: (languagePacks: { [language: string]: ILanguagePack }) => T = () => null): TPromise<T> {
|
||||
private withLanguagePacks<T>(fn: (languagePacks: { [language: string]: ILanguagePack }) => T = () => null): Thenable<T> {
|
||||
return this.languagePacksFileLimiter.queue(() => {
|
||||
let result: T = null;
|
||||
let result: T | null = null;
|
||||
return pfs.readFile(this.languagePacksFilePath, 'utf8')
|
||||
.then(null, err => err.code === 'ENOENT' ? TPromise.as('{}') : TPromise.wrapError(err))
|
||||
.then(null, err => err.code === 'ENOENT' ? Promise.resolve('{}') : Promise.reject(err))
|
||||
.then<{ [language: string]: ILanguagePack }>(raw => { try { return JSON.parse(raw); } catch (e) { return {}; } })
|
||||
.then(languagePacks => { result = fn(languagePacks); return languagePacks; })
|
||||
.then(languagePacks => {
|
||||
|
||||
@@ -3,22 +3,11 @@
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
'use strict';
|
||||
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IChannel } from 'vs/base/parts/ipc/common/ipc';
|
||||
import { IChannel, IServerChannel } from 'vs/base/parts/ipc/node/ipc';
|
||||
import { Event, buffer } from 'vs/base/common/event';
|
||||
import { ILocalizationsService, LanguageType } from 'vs/platform/localizations/common/localizations';
|
||||
|
||||
export interface ILocalizationsChannel extends IChannel {
|
||||
listen(event: 'onDidLanguagesChange'): Event<void>;
|
||||
listen<T>(event: string, arg?: any): Event<T>;
|
||||
|
||||
call(command: 'getLanguageIds'): TPromise<string[]>;
|
||||
call(command: string, arg?: any): TPromise<any>;
|
||||
}
|
||||
|
||||
export class LocalizationsChannel implements ILocalizationsChannel {
|
||||
export class LocalizationsChannel implements IServerChannel {
|
||||
|
||||
onDidLanguagesChange: Event<void>;
|
||||
|
||||
@@ -26,19 +15,20 @@ export class LocalizationsChannel implements ILocalizationsChannel {
|
||||
this.onDidLanguagesChange = buffer(service.onDidLanguagesChange, true);
|
||||
}
|
||||
|
||||
listen<T>(event: string): Event<any> {
|
||||
listen(_, event: string): Event<any> {
|
||||
switch (event) {
|
||||
case 'onDidLanguagesChange': return this.onDidLanguagesChange;
|
||||
}
|
||||
|
||||
throw new Error('No event found');
|
||||
throw new Error(`Event not found: ${event}`);
|
||||
}
|
||||
|
||||
call(command: string, arg?: any): TPromise<any> {
|
||||
call(_, command: string, arg?: any): Thenable<any> {
|
||||
switch (command) {
|
||||
case 'getLanguageIds': return this.service.getLanguageIds(arg);
|
||||
}
|
||||
return undefined;
|
||||
|
||||
throw new Error(`Call not found: ${command}`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,11 +36,11 @@ export class LocalizationsChannelClient implements ILocalizationsService {
|
||||
|
||||
_serviceBrand: any;
|
||||
|
||||
constructor(private channel: ILocalizationsChannel) { }
|
||||
constructor(private channel: IChannel) { }
|
||||
|
||||
get onDidLanguagesChange(): Event<void> { return this.channel.listen('onDidLanguagesChange'); }
|
||||
|
||||
getLanguageIds(type?: LanguageType): TPromise<string[]> {
|
||||
getLanguageIds(type?: LanguageType): Thenable<string[]> {
|
||||
return this.channel.call('getLanguageIds', type);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user