Skip to content

Commit d2a413e

Browse files
author
Benjamin Pasero
committed
more use of IEnvironmentService
1 parent c121936 commit d2a413e

14 files changed

Lines changed: 82 additions & 57 deletions

File tree

src/vs/code/node/cliProcessMain.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { localize } from 'vs/nls';
77
import product from 'vs/platform/product';
88
import pkg from 'vs/platform/package';
99
import * as path from 'path';
10-
import { ParsedArgs } from 'vs/code/node/argv';
10+
import { parseArgs, ParsedArgs } from 'vs/code/node/argv';
1111
import { TPromise } from 'vs/base/common/winjs.base';
1212
import { sequence } from 'vs/base/common/async';
1313
import { IPager } from 'vs/base/common/paging';
@@ -144,7 +144,7 @@ const eventPrefix = 'monacoworkbench';
144144

145145
export function main(argv: ParsedArgs): TPromise<void> {
146146
const services = new ServiceCollection();
147-
services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService));
147+
services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService, parseArgs(process.argv)));
148148

149149
const instantiationService: IInstantiationService = new InstantiationService(services);
150150

src/vs/code/node/sharedProcessMain.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors';
1414
import { InstantiationService } from 'vs/platform/instantiation/common/instantiationService';
1515
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1616
import { EnvironmentService } from 'vs/platform/environment/node/environmentService';
17+
import { parseArgs } from 'vs/code/node/argv';
1718
import { IEventService } from 'vs/platform/event/common/event';
1819
import { EventService } from 'vs/platform/event/common/eventService';
1920
import { ExtensionManagementChannel } from 'vs/platform/extensionManagement/common/extensionManagementIpc';
@@ -57,7 +58,7 @@ function main(server: Server): void {
5758
const services = new ServiceCollection();
5859

5960
services.set(IEventService, new SyncDescriptor(EventService));
60-
services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService));
61+
services.set(IEnvironmentService, new SyncDescriptor(EnvironmentService, parseArgs(process.argv)));
6162
services.set(IConfigurationService, new SyncDescriptor(NodeConfigurationService));
6263
services.set(IRequestService, new SyncDescriptor(RequestService));
6364

src/vs/platform/environment/common/environment.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export interface IEnvironmentService {
1212
_serviceBrand: any;
1313

1414
appRoot: string;
15-
15+
1616
userHome: string;
1717
userDataPath: string;
1818

@@ -24,6 +24,9 @@ export interface IEnvironmentService {
2424
extensionDevelopmentPath: string;
2525

2626
isBuilt: boolean;
27+
verbose: boolean;
28+
29+
debugBrkFileWatcherPort: number;
2730

2831
createPaths(): TPromise<void>;
2932
}

src/vs/platform/environment/node/environmentService.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import pkg from 'vs/platform/package';
1010
import * as os from 'os';
1111
import * as path from 'path';
1212
import {mkdirp} from 'vs/base/node/pfs';
13-
import {parseArgs} from 'vs/code/node/argv';
13+
import {ParsedArgs} from 'vs/code/node/argv';
1414
import URI from 'vs/base/common/uri';
1515
import {TPromise} from 'vs/base/common/winjs.base';
1616

@@ -43,10 +43,11 @@ export class EnvironmentService implements IEnvironmentService {
4343
get extensionDevelopmentPath(): string { return this._extensionDevelopmentPath; }
4444

4545
get isBuilt(): boolean { return !process.env['VSCODE_DEV']; }
46+
get verbose(): boolean { return this.argv.verbose; }
4647

47-
constructor() {
48-
const argv = parseArgs(process.argv);
48+
get debugBrkFileWatcherPort(): number { return typeof this.argv.debugBrkFileWatcherPort === 'string' ? Number(this.argv.debugBrkFileWatcherPort) : void 0; }
4949

50+
constructor(private argv: ParsedArgs) {
5051
this._appRoot = path.dirname(URI.parse(require.toUrl('')).fsPath);
5152
this._userDataPath = paths.getUserDataPath(process.platform, pkg.name, process.argv);
5253

@@ -62,8 +63,7 @@ export class EnvironmentService implements IEnvironmentService {
6263
}
6364

6465
createPaths(): TPromise<void> {
65-
const promises = [this.userHome, this.extensionsPath]
66-
.map(p => mkdirp(p));
66+
const promises = [this.userHome, this.extensionsPath].map(p => mkdirp(p));
6767

6868
return TPromise.join(promises) as TPromise<any>;
6969
}

src/vs/platform/product.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,14 @@ export interface IProductConfiguration {
4747
npsSurveyUrl: string;
4848
}
4949

50-
const rootPath = path.dirname(uri.parse(require.toUrl('')).fsPath);
51-
const productJsonPath = path.join(rootPath, 'product.json');
52-
const product = require.__$__nodeRequire(productJsonPath) as IProductConfiguration;
50+
let product: IProductConfiguration;
51+
try {
52+
const rootPath = path.dirname(uri.parse(require.toUrl('')).fsPath);
53+
const productJsonPath = path.join(rootPath, 'product.json');
54+
product = require.__$__nodeRequire(productJsonPath) as IProductConfiguration;
55+
} catch (error) {
56+
product = Object.create(null); // can happen in environments where product.json is missing (e.g. when used from tests)
57+
}
5358

5459
if (process.env['VSCODE_DEV']) {
5560
product.nameShort += ' Dev';

src/vs/workbench/api/node/mainThreadExtensionService.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ import {IMessage, IExtensionDescription, IExtensionsStatus} from 'vs/platform/ex
1111
import {ExtensionsRegistry} from 'vs/platform/extensions/common/extensionsRegistry';
1212
import {IMessageService} from 'vs/platform/message/common/message';
1313
import {IThreadService} from 'vs/workbench/services/thread/common/threadService';
14-
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
1514
import {ExtHostContext, ExtHostExtensionServiceShape} from './extHost.protocol';
15+
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
1616

1717
/**
1818
* Represents a failed extension in the ext host.
@@ -33,7 +33,7 @@ class MainProcessSuccessExtension extends ActivatedExtension {
3333
}
3434
}
3535

36-
function messageWithSource(msg:IMessage): string {
36+
function messageWithSource(msg: IMessage): string {
3737
return (msg.source ? '[' + msg.source + ']: ' : '') + msg.message;
3838
}
3939

@@ -49,13 +49,12 @@ export class MainProcessExtensionService extends AbstractExtensionService<Activa
4949
* This class is constructed manually because it is a service, so it doesn't use any ctor injection
5050
*/
5151
constructor(
52-
@IWorkspaceContextService contextService: IWorkspaceContextService,
5352
@IThreadService threadService: IThreadService,
54-
@IMessageService messageService: IMessageService
53+
@IMessageService messageService: IMessageService,
54+
@IEnvironmentService private environmentService: IEnvironmentService
5555
) {
5656
super(false);
57-
let config = contextService.getConfiguration();
58-
this._isDev = !config.env.isBuilt || !!config.env.extensionDevelopmentPath;
57+
this._isDev = !environmentService.isBuilt || !!environmentService.extensionDevelopmentPath;
5958

6059
this._messageService = messageService;
6160
this._threadService = threadService;

src/vs/workbench/electron-browser/main.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import uri from 'vs/base/common/uri';
1616
import strings = require('vs/base/common/strings');
1717
import {IResourceInput} from 'vs/platform/editor/common/editor';
1818
import {EventService} from 'vs/platform/event/common/eventService';
19+
import {ParsedArgs, parseArgs} from 'vs/code/node/argv';
1920
import {WorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService';
2021
import {IWorkspace, IConfiguration, IEnvironment} from 'vs/platform/workspace/common/workspace';
2122
import {ConfigurationService} from 'vs/workbench/services/configuration/node/configurationService';
@@ -56,6 +57,12 @@ export interface IMainEnvironment extends IEnvironment {
5657

5758
export function startup(environment: IMainEnvironment, globalSettings: IGlobalSettings): winjs.TPromise<void> {
5859

60+
// Args (TODO@Ben clean up explicit overwrite of args)
61+
const parsedArgs = parseArgs(process.argv);
62+
if (typeof environment.extensionDevelopmentPath === 'string') {
63+
parsedArgs.extensionDevelopmentPath = environment.extensionDevelopmentPath;
64+
}
65+
5966
// Shell Configuration
6067
const shellConfiguration: IConfiguration = {
6168
env: environment
@@ -79,7 +86,7 @@ export function startup(environment: IMainEnvironment, globalSettings: IGlobalSe
7986
}
8087

8188
// Open workbench
82-
return openWorkbench(getWorkspace(environment), shellConfiguration, shellOptions);
89+
return openWorkbench(parsedArgs, getWorkspace(environment), shellConfiguration, shellOptions);
8390
}
8491

8592
function toInputs(paths: IPath[]): IResourceInput[] {
@@ -128,9 +135,9 @@ function getWorkspace(environment: IMainEnvironment): IWorkspace {
128135
};
129136
}
130137

131-
function openWorkbench(workspace: IWorkspace, configuration: IConfiguration, options: IOptions): winjs.TPromise<void> {
138+
function openWorkbench(args: ParsedArgs, workspace: IWorkspace, configuration: IConfiguration, options: IOptions): winjs.TPromise<void> {
132139
const eventService = new EventService();
133-
const environmentService = new EnvironmentService();
140+
const environmentService = new EnvironmentService(args);
134141
const contextService = new WorkspaceContextService(eventService, workspace, configuration, options);
135142
const configurationService = new ConfigurationService(contextService, eventService);
136143

src/vs/workbench/electron-browser/shell.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,12 @@ export class WorkbenchShell {
237237
serviceCollection.set(IWindowService, this.windowService);
238238

239239
// Storage
240-
const disableWorkspaceStorage = this.configuration.env.extensionTestsPath || (!this.workspace && !this.configuration.env.extensionDevelopmentPath); // without workspace or in any extension test, we use inMemory storage unless we develop an extension where we want to preserve state
240+
const disableWorkspaceStorage = this.configuration.env.extensionTestsPath || (!this.workspace && !this.environmentService.extensionDevelopmentPath); // without workspace or in any extension test, we use inMemory storage unless we develop an extension where we want to preserve state
241241
this.storageService = instantiationService.createInstance(Storage, window.localStorage, disableWorkspaceStorage ? inMemoryLocalStorageInstance : window.localStorage);
242242
serviceCollection.set(IStorageService, this.storageService);
243243

244244
// Telemetry
245-
if (this.configuration.env.isBuilt && !this.configuration.env.extensionDevelopmentPath && !!this.configuration.env.enableTelemetry) {
245+
if (this.configuration.env.isBuilt && !this.environmentService.extensionDevelopmentPath && !!this.configuration.env.enableTelemetry) {
246246
const channel = getDelayedChannel<ITelemetryAppenderChannel>(sharedProcess.then(c => c.getChannel('telemetryAppender')));
247247
const commit = this.contextService.getConfiguration().env.commitHash;
248248
const version = this.contextService.getConfiguration().env.version;

src/vs/workbench/parts/files/electron-browser/textFileServices.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import {IEditorGroupService} from 'vs/workbench/services/group/common/groupServi
3232
import {IModelService} from 'vs/editor/common/services/modelService';
3333
import {ModelBuilder} from 'vs/editor/node/model/modelBuilder';
3434
import product from 'vs/platform/product';
35+
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
3536

3637
export class TextFileService extends AbstractTextFileService {
3738

@@ -50,7 +51,8 @@ export class TextFileService extends AbstractTextFileService {
5051
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
5152
@IEditorGroupService editorGroupService: IEditorGroupService,
5253
@IWindowService private windowService: IWindowService,
53-
@IModelService modelService: IModelService
54+
@IModelService modelService: IModelService,
55+
@IEnvironmentService private environmentService: IEnvironmentService
5456
) {
5557
super(contextService, instantiationService, configurationService, telemetryService, editorService, editorGroupService, eventService, fileService, modelService);
5658

@@ -173,7 +175,7 @@ export class TextFileService extends AbstractTextFileService {
173175
}
174176

175177
public confirmSave(resources?: URI[]): ConfirmResult {
176-
if (!!this.contextService.getConfiguration().env.extensionDevelopmentPath) {
178+
if (!!this.environmentService.extensionDevelopmentPath) {
177179
return ConfirmResult.DONT_SAVE; // no veto when we are in extension dev mode because we cannot assum we run interactive (e.g. tests)
178180
}
179181

src/vs/workbench/parts/git/electron-browser/electronGitService.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import { IOutputService } from 'vs/workbench/parts/output/common/output';
1212
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
1313
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
1414
import { IEventService } from 'vs/platform/event/common/event';
15+
import { IEnvironmentService } from 'vs/platform/environment/common/environment';
1516
import { IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
1617
import { IMessageService } from 'vs/platform/message/common/message';
1718
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace';
@@ -202,6 +203,7 @@ export class ElectronGitService extends GitService {
202203
@IWorkspaceContextService contextService: IWorkspaceContextService,
203204
@ILifecycleService lifecycleService: ILifecycleService,
204205
@IStorageService storageService: IStorageService,
206+
@IEnvironmentService environmentService: IEnvironmentService,
205207
@IConfigurationService configurationService: IConfigurationService
206208
) {
207209
const conf = configurationService.getConfiguration<IGitConfiguration>('git');
@@ -218,7 +220,7 @@ export class ElectronGitService extends GitService {
218220
const gitPath = conf.path || null;
219221
const encoding = filesConf.encoding || 'utf8';
220222
const workspaceRoot = workspace.resource.fsPath;
221-
const verbose = !contextService.getConfiguration().env.isBuilt || contextService.getConfiguration().env.verboseLogging;
223+
const verbose = !environmentService.isBuilt || environmentService.verbose;
222224

223225
if (ElectronGitService.USE_REMOTE_PROCESS_SERVICE) {
224226
raw = createRemoteRawGitService(gitPath, workspaceRoot, encoding, verbose);

0 commit comments

Comments
 (0)