mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-03-28 15:50:29 -04:00
SQL Operations Studio Public Preview 1 (0.23) release source code
This commit is contained in:
@@ -0,0 +1,140 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the Source EULA. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import { localize } from 'vs/nls';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { distinct } from 'vs/base/common/arrays';
|
||||
import Event, { Emitter } from 'vs/base/common/event';
|
||||
import { IDisposable, dispose } from 'vs/base/common/lifecycle';
|
||||
import { IExtensionManagementService, DidUninstallExtensionEvent, IExtensionEnablementService } from 'vs/platform/extensionManagement/common/extensionManagement';
|
||||
import { adoptToGalleryExtensionId, getIdAndVersionFromLocalExtensionId } from 'vs/platform/extensionManagement/common/extensionManagementUtil';
|
||||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
|
||||
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
|
||||
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
|
||||
|
||||
const DISABLED_EXTENSIONS_STORAGE_PATH = 'extensions/disabled';
|
||||
|
||||
export class ExtensionEnablementService implements IExtensionEnablementService {
|
||||
|
||||
_serviceBrand: any;
|
||||
|
||||
private disposables: IDisposable[] = [];
|
||||
|
||||
private _onEnablementChanged = new Emitter<string>();
|
||||
public onEnablementChanged: Event<string> = this._onEnablementChanged.event;
|
||||
|
||||
constructor(
|
||||
@IStorageService private storageService: IStorageService,
|
||||
@IWorkspaceContextService private contextService: IWorkspaceContextService,
|
||||
@IEnvironmentService private environmentService: IEnvironmentService,
|
||||
@IExtensionManagementService private extensionManagementService: IExtensionManagementService
|
||||
) {
|
||||
extensionManagementService.onDidUninstallExtension(this.onDidUninstallExtension, this, this.disposables);
|
||||
}
|
||||
|
||||
private get hasWorkspace(): boolean {
|
||||
return this.contextService.hasWorkspace();
|
||||
}
|
||||
|
||||
public getGloballyDisabledExtensions(): string[] {
|
||||
return this.getDisabledExtensions(StorageScope.GLOBAL);
|
||||
}
|
||||
|
||||
public getWorkspaceDisabledExtensions(): string[] {
|
||||
return this.getDisabledExtensions(StorageScope.WORKSPACE);
|
||||
}
|
||||
|
||||
public canEnable(identifier: string): boolean {
|
||||
if (this.environmentService.disableExtensions) {
|
||||
return false;
|
||||
}
|
||||
if (this.getGloballyDisabledExtensions().indexOf(identifier) !== -1) {
|
||||
return true;
|
||||
}
|
||||
if (this.getWorkspaceDisabledExtensions().indexOf(identifier) !== -1) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public setEnablement(identifier: string, enable: boolean, workspace: boolean = false): TPromise<boolean> {
|
||||
if (workspace && !this.hasWorkspace) {
|
||||
return TPromise.wrapError<boolean>(new Error(localize('noWorkspace', "No workspace.")));
|
||||
}
|
||||
|
||||
if (this.environmentService.disableExtensions) {
|
||||
return TPromise.wrap(false);
|
||||
}
|
||||
|
||||
if (enable) {
|
||||
if (workspace) {
|
||||
return this.enableExtension(identifier, StorageScope.WORKSPACE);
|
||||
} else {
|
||||
return this.enableExtension(identifier, StorageScope.GLOBAL);
|
||||
}
|
||||
} else {
|
||||
if (workspace) {
|
||||
return this.disableExtension(identifier, StorageScope.WORKSPACE);
|
||||
} else {
|
||||
return this.disableExtension(identifier, StorageScope.GLOBAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private disableExtension(identifier: string, scope: StorageScope): TPromise<boolean> {
|
||||
let disabledExtensions = this.getDisabledExtensions(scope);
|
||||
const index = disabledExtensions.indexOf(identifier);
|
||||
if (index === -1) {
|
||||
disabledExtensions.push(identifier);
|
||||
this.setDisabledExtensions(disabledExtensions, scope, identifier);
|
||||
return TPromise.wrap(true);
|
||||
}
|
||||
return TPromise.wrap(false);
|
||||
}
|
||||
|
||||
private enableExtension(identifier: string, scope: StorageScope, fireEvent = true): TPromise<boolean> {
|
||||
let disabledExtensions = this.getDisabledExtensions(scope);
|
||||
const index = disabledExtensions.indexOf(identifier);
|
||||
if (index !== -1) {
|
||||
disabledExtensions.splice(index, 1);
|
||||
this.setDisabledExtensions(disabledExtensions, scope, identifier, fireEvent);
|
||||
return TPromise.wrap(true);
|
||||
}
|
||||
return TPromise.wrap(false);
|
||||
}
|
||||
|
||||
private getDisabledExtensions(scope: StorageScope): string[] {
|
||||
if (scope === StorageScope.WORKSPACE && !this.hasWorkspace) {
|
||||
return [];
|
||||
}
|
||||
const value = this.storageService.get(DISABLED_EXTENSIONS_STORAGE_PATH, scope, '');
|
||||
return value ? distinct(value.split(',')).map(id => adoptToGalleryExtensionId(id)) : [];
|
||||
}
|
||||
|
||||
private setDisabledExtensions(disabledExtensions: string[], scope: StorageScope, extension: string, fireEvent = true): void {
|
||||
if (disabledExtensions.length) {
|
||||
this.storageService.store(DISABLED_EXTENSIONS_STORAGE_PATH, disabledExtensions.join(','), scope);
|
||||
} else {
|
||||
this.storageService.remove(DISABLED_EXTENSIONS_STORAGE_PATH, scope);
|
||||
}
|
||||
if (fireEvent) {
|
||||
this._onEnablementChanged.fire(extension);
|
||||
}
|
||||
}
|
||||
|
||||
private onDidUninstallExtension({ id, error }: DidUninstallExtensionEvent): void {
|
||||
if (!error) {
|
||||
id = getIdAndVersionFromLocalExtensionId(id).id;
|
||||
if (id) {
|
||||
this.enableExtension(id, StorageScope.WORKSPACE, false);
|
||||
this.enableExtension(id, StorageScope.GLOBAL, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.disposables = dispose(this.disposables);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,303 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { localize } from 'vs/nls';
|
||||
import { TPromise } from 'vs/base/common/winjs.base';
|
||||
import Event from 'vs/base/common/event';
|
||||
import { IPager } from 'vs/base/common/paging';
|
||||
import { createDecorator } from 'vs/platform/instantiation/common/instantiation';
|
||||
|
||||
export const EXTENSION_IDENTIFIER_PATTERN = '^([a-z0-9A-Z][a-z0-9\-A-Z]*)\\.([a-z0-9A-Z][a-z0-9\-A-Z]*)$';
|
||||
export const EXTENSION_IDENTIFIER_REGEX = new RegExp(EXTENSION_IDENTIFIER_PATTERN);
|
||||
|
||||
export interface ICommand {
|
||||
command: string;
|
||||
title: string;
|
||||
category?: string;
|
||||
}
|
||||
|
||||
export interface IConfigurationProperty {
|
||||
description: string;
|
||||
type: string | string[];
|
||||
default?: any;
|
||||
}
|
||||
|
||||
export interface IConfiguration {
|
||||
properties: { [key: string]: IConfigurationProperty; };
|
||||
}
|
||||
|
||||
export interface IDebugger {
|
||||
label?: string;
|
||||
type: string;
|
||||
runtime: string;
|
||||
}
|
||||
|
||||
export interface IGrammar {
|
||||
language: string;
|
||||
}
|
||||
|
||||
export interface IJSONValidation {
|
||||
fileMatch: string;
|
||||
}
|
||||
|
||||
export interface IKeyBinding {
|
||||
command: string;
|
||||
key: string;
|
||||
when?: string;
|
||||
mac?: string;
|
||||
linux?: string;
|
||||
win?: string;
|
||||
}
|
||||
|
||||
export interface ILanguage {
|
||||
id: string;
|
||||
extensions: string[];
|
||||
aliases: string[];
|
||||
}
|
||||
|
||||
export interface IMenu {
|
||||
command: string;
|
||||
alt?: string;
|
||||
when?: string;
|
||||
group?: string;
|
||||
}
|
||||
|
||||
export interface ISnippet {
|
||||
language: string;
|
||||
}
|
||||
|
||||
export interface ITheme {
|
||||
label: string;
|
||||
}
|
||||
|
||||
export interface IView {
|
||||
id: string;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface IExtensionContributions {
|
||||
commands?: ICommand[];
|
||||
configuration?: IConfiguration;
|
||||
debuggers?: IDebugger[];
|
||||
grammars?: IGrammar[];
|
||||
jsonValidation?: IJSONValidation[];
|
||||
keybindings?: IKeyBinding[];
|
||||
languages?: ILanguage[];
|
||||
menus?: { [context: string]: IMenu[] };
|
||||
snippets?: ISnippet[];
|
||||
themes?: ITheme[];
|
||||
views?: { [location: string]: IView[] };
|
||||
}
|
||||
|
||||
export interface IExtensionManifest {
|
||||
name: string;
|
||||
publisher: string;
|
||||
version: string;
|
||||
engines: { vscode: string };
|
||||
displayName?: string;
|
||||
description?: string;
|
||||
main?: string;
|
||||
icon?: string;
|
||||
categories?: string[];
|
||||
activationEvents?: string[];
|
||||
extensionDependencies?: string[];
|
||||
contributes?: IExtensionContributions;
|
||||
}
|
||||
|
||||
export interface IGalleryExtensionProperties {
|
||||
dependencies?: string[];
|
||||
engine?: string;
|
||||
}
|
||||
|
||||
export interface IGalleryExtensionAsset {
|
||||
uri: string;
|
||||
fallbackUri: string;
|
||||
}
|
||||
|
||||
export interface IGalleryExtensionAssets {
|
||||
manifest: IGalleryExtensionAsset;
|
||||
readme: IGalleryExtensionAsset;
|
||||
changelog: IGalleryExtensionAsset;
|
||||
download: IGalleryExtensionAsset;
|
||||
icon: IGalleryExtensionAsset;
|
||||
license: IGalleryExtensionAsset;
|
||||
}
|
||||
|
||||
export interface IGalleryExtension {
|
||||
uuid: string;
|
||||
id: string;
|
||||
name: string;
|
||||
version: string;
|
||||
date: string;
|
||||
displayName: string;
|
||||
publisherId: string;
|
||||
publisher: string;
|
||||
publisherDisplayName: string;
|
||||
description: string;
|
||||
installCount: number;
|
||||
rating: number;
|
||||
ratingCount: number;
|
||||
assets: IGalleryExtensionAssets;
|
||||
properties: IGalleryExtensionProperties;
|
||||
telemetryData: any;
|
||||
}
|
||||
|
||||
export interface IGalleryMetadata {
|
||||
id: string;
|
||||
publisherId: string;
|
||||
publisherDisplayName: string;
|
||||
}
|
||||
|
||||
export enum LocalExtensionType {
|
||||
System,
|
||||
User
|
||||
}
|
||||
|
||||
export interface ILocalExtension {
|
||||
type: LocalExtensionType;
|
||||
id: string;
|
||||
manifest: IExtensionManifest;
|
||||
metadata: IGalleryMetadata;
|
||||
path: string;
|
||||
readmeUrl: string;
|
||||
changelogUrl: string;
|
||||
}
|
||||
|
||||
export const IExtensionManagementService = createDecorator<IExtensionManagementService>('extensionManagementService');
|
||||
export const IExtensionGalleryService = createDecorator<IExtensionGalleryService>('extensionGalleryService');
|
||||
|
||||
export enum SortBy {
|
||||
NoneOrRelevance = 0,
|
||||
LastUpdatedDate = 1,
|
||||
Title = 2,
|
||||
PublisherName = 3,
|
||||
InstallCount = 4,
|
||||
PublishedDate = 5,
|
||||
AverageRating = 6,
|
||||
WeightedRating = 12
|
||||
}
|
||||
|
||||
export enum SortOrder {
|
||||
Default = 0,
|
||||
Ascending = 1,
|
||||
Descending = 2
|
||||
}
|
||||
|
||||
export interface IQueryOptions {
|
||||
text?: string;
|
||||
ids?: string[];
|
||||
names?: string[];
|
||||
pageSize?: number;
|
||||
sortBy?: SortBy;
|
||||
sortOrder?: SortOrder;
|
||||
source?: string;
|
||||
}
|
||||
|
||||
export enum StatisticType {
|
||||
Uninstall = 'uninstall'
|
||||
}
|
||||
|
||||
export interface IExtensionGalleryService {
|
||||
_serviceBrand: any;
|
||||
isEnabled(): boolean;
|
||||
query(options?: IQueryOptions): TPromise<IPager<IGalleryExtension>>;
|
||||
download(extension: IGalleryExtension): TPromise<string>;
|
||||
reportStatistic(publisher: string, name: string, version: string, type: StatisticType): TPromise<void>;
|
||||
getReadme(extension: IGalleryExtension): TPromise<string>;
|
||||
getManifest(extension: IGalleryExtension): TPromise<IExtensionManifest>;
|
||||
getChangelog(extension: IGalleryMetadata): TPromise<string>;
|
||||
loadCompatibleVersion(extension: IGalleryExtension): TPromise<IGalleryExtension>;
|
||||
getAllDependencies(extension: IGalleryExtension): TPromise<IGalleryExtension[]>;
|
||||
}
|
||||
|
||||
export interface InstallExtensionEvent {
|
||||
id: string;
|
||||
zipPath?: string;
|
||||
gallery?: IGalleryExtension;
|
||||
}
|
||||
|
||||
export interface DidInstallExtensionEvent {
|
||||
id: string;
|
||||
zipPath?: string;
|
||||
gallery?: IGalleryExtension;
|
||||
local?: ILocalExtension;
|
||||
error?: Error;
|
||||
}
|
||||
|
||||
export interface DidUninstallExtensionEvent {
|
||||
id: string;
|
||||
error?: Error;
|
||||
}
|
||||
|
||||
export interface IExtensionManagementService {
|
||||
_serviceBrand: any;
|
||||
|
||||
onInstallExtension: Event<InstallExtensionEvent>;
|
||||
onDidInstallExtension: Event<DidInstallExtensionEvent>;
|
||||
onUninstallExtension: Event<string>;
|
||||
onDidUninstallExtension: Event<DidUninstallExtensionEvent>;
|
||||
|
||||
install(zipPath: string): TPromise<void>;
|
||||
installFromGallery(extension: IGalleryExtension, promptToInstallDependencies?: boolean): TPromise<void>;
|
||||
uninstall(extension: ILocalExtension, force?: boolean): TPromise<void>;
|
||||
getInstalled(type?: LocalExtensionType): TPromise<ILocalExtension[]>;
|
||||
}
|
||||
|
||||
export const IExtensionEnablementService = createDecorator<IExtensionEnablementService>('extensionEnablementService');
|
||||
|
||||
// TODO: @sandy: Merge this into IExtensionManagementService when we have a storage service available in Shared process
|
||||
export interface IExtensionEnablementService {
|
||||
_serviceBrand: any;
|
||||
|
||||
/**
|
||||
* Event to listen on for extension enablement changes
|
||||
*/
|
||||
onEnablementChanged: Event<string>;
|
||||
|
||||
/**
|
||||
* Returns all globally disabled extension identifiers.
|
||||
* Returns an empty array if none exist.
|
||||
*/
|
||||
getGloballyDisabledExtensions(): string[];
|
||||
|
||||
/**
|
||||
* Returns all workspace disabled extension identifiers.
|
||||
* Returns an empty array if none exist or workspace does not exist.
|
||||
*/
|
||||
getWorkspaceDisabledExtensions(): string[];
|
||||
|
||||
/**
|
||||
* Returns `true` if given extension can be enabled by calling `setEnablement`, otherwise false`.
|
||||
*/
|
||||
canEnable(identifier: string): boolean;
|
||||
|
||||
/**
|
||||
* Enable or disable the given extension.
|
||||
* if `workspace` is `true` then enablement is done for workspace, otherwise globally.
|
||||
*
|
||||
* Returns a promise that resolves to boolean value.
|
||||
* if resolves to `true` then requires restart for the change to take effect.
|
||||
*
|
||||
* Throws error if enablement is requested for workspace and there is no workspace
|
||||
*/
|
||||
setEnablement(identifier: string, enable: boolean, workspace?: boolean): TPromise<boolean>;
|
||||
}
|
||||
|
||||
export const IExtensionTipsService = createDecorator<IExtensionTipsService>('extensionTipsService');
|
||||
|
||||
export interface IExtensionTipsService {
|
||||
_serviceBrand: any;
|
||||
getRecommendations(): string[];
|
||||
getWorkspaceRecommendations(): TPromise<string[]>;
|
||||
getKeymapRecommendations(): string[];
|
||||
getKeywordsForExtension(extension: string): string[];
|
||||
getRecommendationsForExtension(extension: string): string[];
|
||||
}
|
||||
|
||||
export const ExtensionsLabel = localize('extensions', "Extensions");
|
||||
export const ExtensionsChannelId = 'extensions';
|
||||
export const PreferencesLabel = localize('preferences', "Preferences");
|
||||
@@ -0,0 +1,87 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { TPromise } from 'vs/base/common/winjs.base';
|
||||
import { IChannel, eventToCall, eventFromCall } from 'vs/base/parts/ipc/common/ipc';
|
||||
import { IExtensionManagementService, ILocalExtension, InstallExtensionEvent, DidInstallExtensionEvent, IGalleryExtension, LocalExtensionType, DidUninstallExtensionEvent } from './extensionManagement';
|
||||
import Event, { buffer } from 'vs/base/common/event';
|
||||
|
||||
export interface IExtensionManagementChannel extends IChannel {
|
||||
call(command: 'event:onInstallExtension'): TPromise<void>;
|
||||
call(command: 'event:onDidInstallExtension'): TPromise<void>;
|
||||
call(command: 'event:onUninstallExtension'): TPromise<void>;
|
||||
call(command: 'event:onDidUninstallExtension'): TPromise<void>;
|
||||
call(command: 'install', path: string): TPromise<void>;
|
||||
call(command: 'installFromGallery', extension: IGalleryExtension): TPromise<void>;
|
||||
call(command: 'uninstall', args: [ILocalExtension, boolean]): TPromise<void>;
|
||||
call(command: 'getInstalled'): TPromise<ILocalExtension[]>;
|
||||
call(command: string, arg?: any): TPromise<any>;
|
||||
}
|
||||
|
||||
export class ExtensionManagementChannel implements IExtensionManagementChannel {
|
||||
|
||||
onInstallExtension: Event<InstallExtensionEvent>;
|
||||
onDidInstallExtension: Event<DidInstallExtensionEvent>;
|
||||
onUninstallExtension: Event<string>;
|
||||
onDidUninstallExtension: Event<DidUninstallExtensionEvent>;
|
||||
|
||||
constructor(private service: IExtensionManagementService) {
|
||||
this.onInstallExtension = buffer(service.onInstallExtension, true);
|
||||
this.onDidInstallExtension = buffer(service.onDidInstallExtension, true);
|
||||
this.onUninstallExtension = buffer(service.onUninstallExtension, true);
|
||||
this.onDidUninstallExtension = buffer(service.onDidUninstallExtension, true);
|
||||
}
|
||||
|
||||
call(command: string, arg?: any): TPromise<any> {
|
||||
switch (command) {
|
||||
case 'event:onInstallExtension': return eventToCall(this.onInstallExtension);
|
||||
case 'event:onDidInstallExtension': return eventToCall(this.onDidInstallExtension);
|
||||
case 'event:onUninstallExtension': return eventToCall(this.onUninstallExtension);
|
||||
case 'event:onDidUninstallExtension': return eventToCall(this.onDidUninstallExtension);
|
||||
case 'install': return this.service.install(arg);
|
||||
case 'installFromGallery': return this.service.installFromGallery(arg[0], arg[1]);
|
||||
case 'uninstall': return this.service.uninstall(arg[0], arg[1]);
|
||||
case 'getInstalled': return this.service.getInstalled(arg);
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
|
||||
export class ExtensionManagementChannelClient implements IExtensionManagementService {
|
||||
|
||||
_serviceBrand: any;
|
||||
|
||||
constructor(private channel: IExtensionManagementChannel) { }
|
||||
|
||||
private _onInstallExtension = eventFromCall<InstallExtensionEvent>(this.channel, 'event:onInstallExtension');
|
||||
get onInstallExtension(): Event<InstallExtensionEvent> { return this._onInstallExtension; }
|
||||
|
||||
private _onDidInstallExtension = eventFromCall<DidInstallExtensionEvent>(this.channel, 'event:onDidInstallExtension');
|
||||
get onDidInstallExtension(): Event<DidInstallExtensionEvent> { return this._onDidInstallExtension; }
|
||||
|
||||
private _onUninstallExtension = eventFromCall<string>(this.channel, 'event:onUninstallExtension');
|
||||
get onUninstallExtension(): Event<string> { return this._onUninstallExtension; }
|
||||
|
||||
private _onDidUninstallExtension = eventFromCall<DidUninstallExtensionEvent>(this.channel, 'event:onDidUninstallExtension');
|
||||
get onDidUninstallExtension(): Event<DidUninstallExtensionEvent> { return this._onDidUninstallExtension; }
|
||||
|
||||
install(zipPath: string): TPromise<void> {
|
||||
return this.channel.call('install', zipPath);
|
||||
}
|
||||
|
||||
installFromGallery(extension: IGalleryExtension, promptToInstallDependencies: boolean = true): TPromise<void> {
|
||||
return this.channel.call('installFromGallery', [extension, promptToInstallDependencies]);
|
||||
}
|
||||
|
||||
uninstall(extension: ILocalExtension, force = false): TPromise<void> {
|
||||
return this.channel.call('uninstall', [extension, force]);
|
||||
}
|
||||
|
||||
getInstalled(type: LocalExtensionType = null): TPromise<ILocalExtension[]> {
|
||||
return this.channel.call('getInstalled', type);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { ILocalExtension, IGalleryExtension, IExtensionManifest, EXTENSION_IDENTIFIER_REGEX, IExtensionEnablementService } from 'vs/platform/extensionManagement/common/extensionManagement';
|
||||
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
|
||||
|
||||
export function areSameExtensions(a: { id: string }, b: { id: string }): boolean {
|
||||
if (a.id === b.id) {
|
||||
return true;
|
||||
}
|
||||
return adoptToGalleryExtensionId(a.id) === adoptToGalleryExtensionId(b.id);
|
||||
}
|
||||
|
||||
export function getGalleryExtensionId(publisher: string, name: string): string {
|
||||
return `${publisher}.${name.toLocaleLowerCase()}`;
|
||||
}
|
||||
|
||||
export function getLocalExtensionIdFromGallery(extension: IGalleryExtension, version: string): string {
|
||||
return getLocalExtensionId(extension.id, version);
|
||||
}
|
||||
|
||||
export function getLocalExtensionIdFromManifest(manifest: IExtensionManifest): string {
|
||||
return getLocalExtensionId(getGalleryExtensionId(manifest.publisher, manifest.name), manifest.version);
|
||||
}
|
||||
|
||||
export function getGalleryExtensionIdFromLocal(local: ILocalExtension): string {
|
||||
return getGalleryExtensionId(local.manifest.publisher, local.manifest.name);
|
||||
}
|
||||
|
||||
export function getIdAndVersionFromLocalExtensionId(localExtensionId: string): { id: string, version: string } {
|
||||
const matches = /^([^.]+\..+)-(\d+\.\d+\.\d+)$/.exec(localExtensionId);
|
||||
if (matches && matches[1] && matches[2]) {
|
||||
return { id: adoptToGalleryExtensionId(matches[1]), version: matches[2] };
|
||||
}
|
||||
return {
|
||||
id: adoptToGalleryExtensionId(localExtensionId),
|
||||
version: null
|
||||
};
|
||||
}
|
||||
|
||||
export function adoptToGalleryExtensionId(id: string): string {
|
||||
return id.replace(EXTENSION_IDENTIFIER_REGEX, (match, publisher: string, name: string) => getGalleryExtensionId(publisher, name));
|
||||
}
|
||||
|
||||
function getLocalExtensionId(id: string, version: string): string {
|
||||
return `${id}-${version}`;
|
||||
}
|
||||
|
||||
export function getLocalExtensionTelemetryData(extension: ILocalExtension): any {
|
||||
return {
|
||||
id: getGalleryExtensionIdFromLocal(extension),
|
||||
name: extension.manifest.name,
|
||||
galleryId: null,
|
||||
publisherId: extension.metadata ? extension.metadata.publisherId : null,
|
||||
publisherName: extension.manifest.publisher,
|
||||
publisherDisplayName: extension.metadata ? extension.metadata.publisherDisplayName : null,
|
||||
dependencies: extension.manifest.extensionDependencies && extension.manifest.extensionDependencies.length > 0
|
||||
};
|
||||
}
|
||||
|
||||
export function getGalleryExtensionTelemetryData(extension: IGalleryExtension): any {
|
||||
return {
|
||||
id: extension.id,
|
||||
name: extension.name,
|
||||
galleryId: extension.uuid,
|
||||
publisherId: extension.publisherId,
|
||||
publisherName: extension.publisher,
|
||||
publisherDisplayName: extension.publisherDisplayName,
|
||||
dependencies: extension.properties.dependencies.length > 0,
|
||||
...extension.telemetryData
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
const BetterMergeCheckKey = 'extensions/bettermergecheck';
|
||||
export const BetterMergeDisabledNowKey = 'extensions/bettermergedisablednow';
|
||||
export const BetterMergeId = 'pprice.better-merge';
|
||||
|
||||
/**
|
||||
* Globally disabled extensions, taking care of disabling obsolete extensions.
|
||||
*/
|
||||
export function getGloballyDisabledExtensions(extensionEnablementService: IExtensionEnablementService, storageService: IStorageService, installedExtensions: { id: string; }[]) {
|
||||
const globallyDisabled = extensionEnablementService.getGloballyDisabledExtensions();
|
||||
if (!storageService.getBoolean(BetterMergeCheckKey, StorageScope.GLOBAL, false)) {
|
||||
storageService.store(BetterMergeCheckKey, true);
|
||||
if (globallyDisabled.indexOf(BetterMergeId) === -1 && installedExtensions.some(d => d.id === BetterMergeId)) {
|
||||
globallyDisabled.push(BetterMergeId);
|
||||
extensionEnablementService.setEnablement(BetterMergeId, false);
|
||||
storageService.store(BetterMergeDisabledNowKey, true);
|
||||
}
|
||||
}
|
||||
return globallyDisabled;
|
||||
}
|
||||
33
src/vs/platform/extensionManagement/common/extensionNls.ts
Normal file
33
src/vs/platform/extensionManagement/common/extensionNls.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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 { cloneAndChange } from 'vs/base/common/objects';
|
||||
import { IExtensionManifest } from 'vs/platform/extensionManagement/common/extensionManagement';
|
||||
|
||||
const nlsRegex = /^%([\w\d.]+)%$/i;
|
||||
|
||||
export interface ITranslations {
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
export function localizeManifest(manifest: IExtensionManifest, translations: ITranslations): IExtensionManifest {
|
||||
const patcher = value => {
|
||||
if (typeof value !== 'string') {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const match = nlsRegex.exec(value);
|
||||
|
||||
if (!match) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return translations[match[1]] || value;
|
||||
};
|
||||
|
||||
return cloneAndChange(manifest, patcher);
|
||||
}
|
||||
Reference in New Issue
Block a user