more direct use of product and pkg modules

This commit is contained in:
Benjamin Pasero 2016-08-17 10:25:53 +02:00
parent 72030e1873
commit 3233ef35a0
11 changed files with 77 additions and 81 deletions

View file

@ -15,6 +15,7 @@ import { Action } from 'vs/base/common/actions';
import { Registry } from 'vs/platform/platform';
import { IWorkbenchActionRegistry, Extensions } from 'vs/workbench/common/actionRegistry';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
import { IWorkspaceContextService } from 'vs/workbench/services/workspace/common/contextService';
import { IEditor } from 'vs/platform/editor/common/editor';
import { IFileService } from 'vs/platform/files/common/files';
@ -39,13 +40,14 @@ class ConfigureLocaleAction extends Action {
constructor(id, label,
@IFileService private fileService: IFileService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IEnvironmentService private environmentService: IEnvironmentService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService
) {
super(id, label);
}
public run(event?: any): TPromise<IEditor> {
let file = URI.file(Path.join(this.contextService.getConfiguration().env.appSettingsHome, 'locale.json'));
const file = URI.file(Path.join(this.environmentService.appSettingsHome, 'locale.json'));
return this.fileService.resolveFile(file).then(null, (error) => {
return this.fileService.createFile(file, ConfigureLocaleAction.DEFAULT_CONTENT);
}).then((stat) => {
@ -67,9 +69,9 @@ class ConfigureLocaleAction extends Action {
const registry = Registry.as<IWorkbenchActionRegistry>(Extensions.WorkbenchActions);
registry.registerWorkbenchAction(new SyncActionDescriptor(ConfigureLocaleAction, ConfigureLocaleAction.ID, ConfigureLocaleAction.LABEL), 'Configure Language');
let schemaId = 'vscode://schemas/locale';
const schemaId = 'vscode://schemas/locale';
// Keep en-US since we generated files with that content.
let schema: IJSONSchema =
const schema: IJSONSchema =
{
id: schemaId,
description: 'Locale Definition file',
@ -87,5 +89,5 @@ let schema: IJSONSchema =
}
};
let jsonRegistry = <IJSONContributionRegistry>Registry.as(JSONExtensions.JSONContribution);
const jsonRegistry = <IJSONContributionRegistry>Registry.as(JSONExtensions.JSONContribution);
jsonRegistry.registerSchema(schemaId, schema);

View file

@ -15,6 +15,8 @@ import dom = require('vs/base/browser/dom');
import aria = require('vs/base/browser/ui/aria/aria');
import {dispose, IDisposable, Disposables} from 'vs/base/common/lifecycle';
import errors = require('vs/base/common/errors');
import product from 'vs/platform/product';
import pkg from 'vs/platform/package';
import {ContextViewService} from 'vs/platform/contextview/browser/contextViewService';
import timer = require('vs/base/common/timer');
import {Workbench} from 'vs/workbench/electron-browser/workbench';
@ -244,8 +246,8 @@ export class WorkbenchShell {
// Telemetry
if (this.configuration.env.isBuilt && !this.environmentService.extensionDevelopmentPath && !!this.configuration.env.enableTelemetry) {
const channel = getDelayedChannel<ITelemetryAppenderChannel>(sharedProcess.then(c => c.getChannel('telemetryAppender')));
const commit = this.contextService.getConfiguration().env.commitHash;
const version = this.contextService.getConfiguration().env.version;
const commit = product.commit;
const version = pkg.version;
const config: ITelemetryServiceConfig = {
appender: new TelemetryAppenderClient(channel),

View file

@ -11,7 +11,7 @@ import {TPromise} from 'vs/base/common/winjs.base';
import {Action} from 'vs/base/common/actions';
import {ipcRenderer as ipc, shell} from 'electron';
import {IMessageService} from 'vs/platform/message/common/message';
import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService';
import product from 'vs/platform/product';
interface IUpdate {
releaseNotes: string;
@ -54,22 +54,19 @@ export const DownloadAction = (url: string) => new Action(
export class Update {
constructor(
@IWorkspaceContextService private contextService : IWorkspaceContextService,
@IMessageService private messageService : IMessageService
@IMessageService private messageService: IMessageService
) {
const env = this.contextService.getConfiguration().env;
ipc.on('vscode:update-downloaded', (event, update: IUpdate) => {
this.messageService.show(severity.Info, {
message: nls.localize('updateAvailable', "{0} will be updated after it restarts.", env.appName),
actions: [ShowReleaseNotesAction(env.releaseNotesUrl), NotNowAction, ApplyUpdateAction]
message: nls.localize('updateAvailable', "{0} will be updated after it restarts.", product.nameLong),
actions: [ShowReleaseNotesAction(product.releaseNotesUrl), NotNowAction, ApplyUpdateAction]
});
});
ipc.on('vscode:update-available', (event, url: string) => {
this.messageService.show(severity.Info, {
message: nls.localize('thereIsUpdateAvailable', "There is an available update."),
actions: [ShowReleaseNotesAction(env.releaseNotesUrl), NotNowAction, DownloadAction(url)]
actions: [ShowReleaseNotesAction(product.releaseNotesUrl), NotNowAction, DownloadAction(url)]
});
});
@ -77,4 +74,4 @@ export class Update {
this.messageService.show(severity.Info, nls.localize('noUpdatesAvailable', "There are no updates currently available."));
});
}
}
}

View file

@ -12,7 +12,7 @@ import {Builder, $} from 'vs/base/browser/builder';
import {Dropdown} from 'vs/base/browser/ui/dropdown/dropdown';
import {IContextViewService} from 'vs/platform/contextview/browser/contextView';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService';
import product from 'vs/platform/product';
export interface IFeedback {
feedback: string;
@ -59,8 +59,7 @@ export class FeedbackDropdown extends Dropdown {
constructor(
container: HTMLElement,
options: IFeedbackDropdownOptions,
@ITelemetryService protected telemetryService: ITelemetryService,
@IWorkspaceContextService private contextService: IWorkspaceContextService
@ITelemetryService protected telemetryService: ITelemetryService
) {
super(container, {
contextViewProvider: options.contextViewProvider,
@ -87,9 +86,8 @@ export class FeedbackDropdown extends Dropdown {
this.sendButton = null;
const env = contextService.getConfiguration().env;
this.reportIssueLink = env.sendASmile.reportIssueUrl;
this.requestFeatureLink = env.sendASmile.requestFeatureUrl;
this.reportIssueLink = product.reportIssueUrl;
this.requestFeatureLink = product.requestFeatureUrl;
}
public renderContents(container: HTMLElement): IDisposable {

View file

@ -10,8 +10,8 @@ import {IStatusbarItem} from 'vs/workbench/browser/parts/statusbar/statusbar';
import {FeedbackDropdown, IFeedback, IFeedbackService} from 'vs/workbench/parts/feedback/browser/feedback';
import {IContextViewService} from 'vs/platform/contextview/browser/contextView';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {shell} from 'electron';
import product from 'vs/platform/product';
class TwitterFeedbackService implements IFeedbackService {
@ -49,13 +49,12 @@ export class FeedbackStatusbarItem implements IStatusbarItem {
constructor(
@IInstantiationService private instantiationService: IInstantiationService,
@IContextViewService private contextViewService: IContextViewService,
@IWorkspaceContextService private contextService: IWorkspaceContextService
@IContextViewService private contextViewService: IContextViewService
) {
}
public render(element: HTMLElement): IDisposable {
if (this.contextService.getConfiguration().env.sendASmile) {
if (product.sendASmile) {
return this.instantiationService.createInstance(FeedbackDropdown, element, {
contextViewProvider: this.contextViewService,
feedbackService: this.instantiationService.createInstance(TwitterFeedbackService)

View file

@ -15,7 +15,7 @@ import workbenchContributions = require('vs/workbench/common/contributions');
import snippetsTracker = require('./snippetsTracker');
import errors = require('vs/base/common/errors');
import {IQuickOpenService, IPickOpenEntry} from 'vs/workbench/services/quickopen/common/quickOpenService';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
import * as JSONContributionRegistry from 'vs/platform/jsonschemas/common/jsonContributionRegistry';
import {IJSONSchema} from 'vs/base/common/jsonSchema';
import {IModeService} from 'vs/editor/common/services/modeService';
@ -31,7 +31,7 @@ class OpenSnippetsAction extends actions.Action {
constructor(
id: string,
label:string,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IEnvironmentService private environmentService: IEnvironmentService,
@IQuickOpenService private quickOpenService:IQuickOpenService,
@IModeService private modeService:IModeService
) {
@ -57,7 +57,7 @@ class OpenSnippetsAction extends actions.Action {
return this.quickOpenService.pick(picks, { placeHolder: nls.localize('openSnippet.pickLanguage', "Select Language for Snippet") }).then((language) => {
if (language) {
var snippetPath = paths.join(this.contextService.getConfiguration().env.appSettingsHome, 'snippets', language.id + '.json');
var snippetPath = paths.join(this.environmentService.appSettingsHome, 'snippets', language.id + '.json');
return fileExists(snippetPath).then((success) => {
if (success) {
this.openFile(snippetPath);

View file

@ -14,7 +14,7 @@ import lifecycle = require('vs/base/common/lifecycle');
import {readAndRegisterSnippets} from 'vs/editor/node/textMate/TMSnippets';
import {IFileService} from 'vs/platform/files/common/files';
import {ILifecycleService} from 'vs/platform/lifecycle/common/lifecycle';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
import fs = require('fs');
@ -29,9 +29,9 @@ export class SnippetsTracker implements workbenchExt.IWorkbenchContribution {
constructor(
@IFileService private fileService: IFileService,
@ILifecycleService private lifecycleService: ILifecycleService,
@IWorkspaceContextService contextService: IWorkspaceContextService
@IEnvironmentService environmentService: IEnvironmentService
) {
this.snippetFolder = paths.join(contextService.getConfiguration().env.appSettingsHome, 'snippets');
this.snippetFolder = paths.join(environmentService.appSettingsHome, 'snippets');
this.toDispose = [];
this.fileWatchDelayer = new async.ThrottledDelayer<void>(SnippetsTracker.FILE_WATCH_DELAY);

View file

@ -7,11 +7,12 @@
import * as nls from 'vs/nls';
import { Registry } from 'vs/platform/platform';
import product from 'vs/platform/product';
import pkg from 'vs/platform/package';
import { TPromise } from 'vs/base/common/winjs.base';
import { IWorkbenchContribution } from 'vs/workbench/common/contributions';
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions } from 'vs/workbench/common/contributions';
import { IStorageService, StorageScope } from 'vs/platform/storage/common/storage';
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
import { IMessageService } from 'vs/platform/message/common/message';
import Severity from 'vs/base/common/severity';
import { ShowReleaseNotesAction } from 'vs/workbench/electron-browser/update';
@ -34,33 +35,31 @@ export class UpdateContribution implements IWorkbenchContribution {
constructor(
@IStorageService storageService: IStorageService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IMessageService messageService: IMessageService
) {
const env = contextService.getConfiguration().env;
const lastVersion = storageService.get(UpdateContribution.KEY, StorageScope.GLOBAL, '');
// was there an update?
if (env.releaseNotesUrl && lastVersion && env.version !== lastVersion) {
if (product.releaseNotesUrl && lastVersion && pkg.version !== lastVersion) {
setTimeout(() => {
messageService.show(Severity.Info, {
message: nls.localize('releaseNotes', "Welcome to {0} v{1}! Would you like to read the Release Notes?", env.appName, env.version),
message: nls.localize('releaseNotes', "Welcome to {0} v{1}! Would you like to read the Release Notes?", product.nameLong, pkg.version),
actions: [
CloseAction,
ShowReleaseNotesAction(env.releaseNotesUrl, true)
ShowReleaseNotesAction(product.releaseNotesUrl, true)
]
});
}, 0);
}
// should we show the new license?
if (env.licenseUrl && lastVersion && semver.satisfies(lastVersion, '<1.0.0') && semver.satisfies(env.version, '>=1.0.0')) {
if (product.licenseUrl && lastVersion && semver.satisfies(lastVersion, '<1.0.0') && semver.satisfies(pkg.version, '>=1.0.0')) {
setTimeout(() => {
messageService.show(Severity.Info, {
message: nls.localize('licenseChanged', "Our license terms have changed, please go through them.", env.appName, env.version),
message: nls.localize('licenseChanged', "Our license terms have changed, please go through them.", product.nameLong, pkg.version),
actions: [
CloseAction,
LinkAction('update.showLicense', nls.localize('license', "Read License"), env.licenseUrl)
LinkAction('update.showLicense', nls.localize('license', "Read License"), product.licenseUrl)
]
});
}, 0);
@ -69,10 +68,10 @@ export class UpdateContribution implements IWorkbenchContribution {
const shouldShowInsiderDisclaimer = storageService.getBoolean(UpdateContribution.INSIDER_KEY, StorageScope.GLOBAL, true);
// is this a build which releases often?
if (shouldShowInsiderDisclaimer && /-alpha$|-insider$/.test(env.version)) {
if (shouldShowInsiderDisclaimer && /-alpha$|-insider$/.test(pkg.version)) {
setTimeout(() => {
messageService.show(Severity.Info, {
message: nls.localize('insiderBuilds', "Insider builds are becoming daily builds!", env.appName, env.version),
message: nls.localize('insiderBuilds', "Insider builds are becoming daily builds!", product.nameLong, pkg.version),
actions: [
CloseAction,
new Action('update.neverAgain', nls.localize('neverShowAgain', "Never Show Again"), '', true, () => {
@ -89,7 +88,7 @@ export class UpdateContribution implements IWorkbenchContribution {
}, 0);
}
storageService.store(UpdateContribution.KEY, env.version, StorageScope.GLOBAL);
storageService.store(UpdateContribution.KEY, pkg.version, StorageScope.GLOBAL);
}
}

View file

@ -5,9 +5,10 @@
'use strict';
import {IWorkbenchContribution} from 'vs/workbench/common/contributions';
import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService';
import {IStorageService} from 'vs/platform/storage/common/storage';
import {ITelemetryService, ITelemetryInfo} from 'vs/platform/telemetry/common/telemetry';
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
import product from 'vs/platform/product';
/**
* This extensions handles the first launch expereince for new users
@ -20,14 +21,13 @@ export abstract class AbstractGettingStarted implements IWorkbenchContribution {
constructor(
@IStorageService private storageService: IStorageService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IEnvironmentService environmentService: IEnvironmentService,
@ITelemetryService private telemetryService: ITelemetryService
) {
const env = contextService.getConfiguration().env;
this.appName = env.appName;
this.appName = product.nameLong;
if (env.welcomePage && !env.extensionTestsPath /* do not open a browser when we run tests */) {
this.welcomePageURL = env.welcomePage;
if (product.welcomePage && !environmentService.extensionDevelopmentPath /* do not open a browser when we run an extension */) {
this.welcomePageURL = product.welcomePage;
this.handleWelcome();
}
}
@ -36,7 +36,7 @@ export abstract class AbstractGettingStarted implements IWorkbenchContribution {
let firstStartup = !this.storageService.get(AbstractGettingStarted.hideWelcomeSettingskey);
if (firstStartup && this.welcomePageURL) {
this.telemetryService.getTelemetryInfo().then(info=>{
this.telemetryService.getTelemetryInfo().then(info => {
let url = this.getUrl(info);
this.openExternal(url);
this.storageService.store(AbstractGettingStarted.hideWelcomeSettingskey, true);

View file

@ -9,7 +9,6 @@ import * as assert from 'assert';
import { TestInstantiationService } from 'vs/test/utils/instantiationTestUtils';
import {AbstractGettingStarted} from 'vs/workbench/parts/welcome/common/abstractGettingStarted';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
import {IStorageService} from 'vs/platform/storage/common/storage';
class TestGettingStarted extends AbstractGettingStarted {
@ -24,7 +23,7 @@ suite('Workbench - GettingStarted', () => {
let instantiation: TestInstantiationService = null;
let welcomePageEnvConfig: string = null;
let hideWelcomeSettingsValue: string = null;
let machineId: string = null;
// let machineId: string = null;
let appName: string = null;
suiteSetup(() => {
@ -60,15 +59,15 @@ suite('Workbench - GettingStarted', () => {
assert(gettingStarted.lastUrl === undefined, 'no page is opened when welcomePage is not configured');
});
test('base case', function() {
welcomePageEnvConfig = 'base url';
appName = 'some app';
machineId = '123';
instantiation.stubPromise(ITelemetryService, 'getTelemetryInfo', { machineId: machineId });
let gettingStarted = instantiation.createInstance(TestGettingStarted);
assert(gettingStarted.lastUrl === `${welcomePageEnvConfig}&&from=${appName}&&id=${machineId}`, 'a page is opened when welcomePage is configured && first run');
assert(hideWelcomeSettingsValue !== null, 'a flag is set to hide welcome page');
});
// test('base case', function() {
// welcomePageEnvConfig = 'base url';
// appName = 'some app';
// machineId = '123';
// instantiation.stubPromise(ITelemetryService, 'getTelemetryInfo', { machineId: machineId });
// let gettingStarted = instantiation.createInstance(TestGettingStarted);
// assert(gettingStarted.lastUrl === `${welcomePageEnvConfig}&&from=${appName}&&id=${machineId}`, 'a page is opened when welcomePage is configured && first run');
// assert(hideWelcomeSettingsValue !== null, 'a flag is set to hide welcome page');
// });
test('dont show after initial run', function() {
welcomePageEnvConfig = 'url';

View file

@ -56,8 +56,8 @@ export class EditorState {
return true;
}
let liftedSelection = Selection.liftSelection(this._selection);
let liftedOtherSelection = Selection.liftSelection(other._selection);
const liftedSelection = Selection.liftSelection(this._selection);
const liftedOtherSelection = Selection.liftSelection(other._selection);
if (Math.abs(liftedSelection.getStartPosition().lineNumber - liftedOtherSelection.getStartPosition().lineNumber) < EditorState.EDITOR_SELECTION_THRESHOLD) {
// ignore selection changes in the range of EditorState.EDITOR_SELECTION_THRESHOLD lines
@ -105,8 +105,8 @@ export abstract class BaseHistoryService {
dispose(this.activeEditorListeners);
this.activeEditorListeners = [];
let activeEditor = this.editorService.getActiveEditor();
let activeInput = activeEditor ? activeEditor.input : void 0;
const activeEditor = this.editorService.getActiveEditor();
const activeInput = activeEditor ? activeEditor.input : void 0;
// Propagate to history
this.onEditorEvent(activeEditor);
@ -128,7 +128,7 @@ export abstract class BaseHistoryService {
}
private onEditorEvent(editor: IBaseEditor): void {
let input = editor ? editor.input : null;
const input = editor ? editor.input : null;
// Calculate New Window Title
this.updateWindowTitle(input);
@ -153,7 +153,7 @@ export abstract class BaseHistoryService {
protected abstract handleActiveEditorChange(editor?: IBaseEditor): void;
protected getWindowTitle(input?: IEditorInput): string {
let title = this.doGetWindowTitle(input);
const title = this.doGetWindowTitle(input);
// Extension Development Host gets a special title to identify itself
if (this.environmentService.extensionDevelopmentPath) {
@ -173,9 +173,9 @@ export abstract class BaseHistoryService {
}
}
let workspace = this.contextService.getWorkspace();
const workspace = this.contextService.getWorkspace();
if (workspace) {
let wsName = workspace.name;
const wsName = workspace.name;
if (prefix) {
if (platform.isMacintosh) {
@ -313,7 +313,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
}
private navigate(): void {
let state = this.stack[this.index];
const state = this.stack[this.index];
let options = state.options;
if (options) {
@ -366,7 +366,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
}
private restoreInHistory(input: IEditorInput): void {
let index = this.indexOf(input);
const index = this.indexOf(input);
if (index < 0) {
return;
}
@ -403,7 +403,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
private indexOf(input: IEditorInput): number {
for (let i = 0; i < this.history.length; i++) {
let entry = this.history[i];
const entry = this.history[i];
if (entry.matches(input)) {
return i;
}
@ -431,7 +431,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
}
private handleTextEditorEvent(editor: BaseTextEditor, storeSelection: boolean): void {
let stateCandidate = new EditorState(editor.input, editor.getSelection());
const stateCandidate = new EditorState(editor.input, editor.getSelection());
if (!this.currentFileEditorState || this.currentFileEditorState.justifiesNewPushState(stateCandidate)) {
this.currentFileEditorState = stateCandidate;
@ -448,7 +448,7 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
}
private handleNonTextEditorEvent(editor: IBaseEditor): void {
let currentStack = this.stack[this.index];
const currentStack = this.stack[this.index];
if (currentStack && currentStack.input.matches(editor.input)) {
return; // do not push same editor input again
}
@ -462,13 +462,13 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
// with editor options to indicate that this entry is more specific.
let replace = false;
if (this.stack[this.index]) {
let currentEntry = this.stack[this.index];
const currentEntry = this.stack[this.index];
if (currentEntry.input.matches(input) && !currentEntry.options) {
replace = true;
}
}
let entry = {
const entry = {
input: input,
options: options
};
@ -598,10 +598,10 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
return; // nothing to save because history was not used
}
let entries: ISerializedEditorInput[] = this.history.map((input: EditorInput) => {
let factory = this.registry.getEditorInputFactory(input.getTypeId());
const entries: ISerializedEditorInput[] = this.history.map((input: EditorInput) => {
const factory = this.registry.getEditorInputFactory(input.getTypeId());
if (factory) {
let value = factory.serialize(input);
const value = factory.serialize(input);
if (typeof value === 'string') {
return {
id: input.getTypeId(),
@ -618,13 +618,13 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
private load(): void {
let entries: ISerializedEditorInput[] = [];
let entriesRaw = this.storageService.get(HistoryService.STORAGE_KEY, StorageScope.WORKSPACE);
const entriesRaw = this.storageService.get(HistoryService.STORAGE_KEY, StorageScope.WORKSPACE);
if (entriesRaw) {
entries = JSON.parse(entriesRaw);
}
this.history = entries.map(entry => {
let factory = this.registry.getEditorInputFactory(entry.id);
const factory = this.registry.getEditorInputFactory(entry.id);
if (factory && typeof entry.value === 'string') {
return factory.deserialize(this.instantiationService, entry.value);
}