more use of IEnvironmentService

This commit is contained in:
Benjamin Pasero
2016-08-17 07:22:02 +02:00
parent c121936678
commit d2a413ee9a
14 changed files with 82 additions and 57 deletions

View File

@@ -20,6 +20,7 @@ import {IEventService} from 'vs/platform/event/common/event';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {Action} from 'vs/base/common/actions';
import {IMessageService, IMessageWithAction, Severity} from 'vs/platform/message/common/message';
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
import {shell} from 'electron';
@@ -38,14 +39,14 @@ export class FileService implements IFileService {
@IConfigurationService private configurationService: IConfigurationService,
@IEventService private eventService: IEventService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IEnvironmentService private environmentService: IEnvironmentService,
@IMessageService private messageService: IMessageService
) {
const configuration = this.configurationService.getConfiguration<IFilesConfiguration>();
const env = this.contextService.getConfiguration().env;
// adjust encodings (TODO@Ben knowledge on settings location ('.vscode') is hardcoded)
// adjust encodings
let encodingOverride: IEncodingOverride[] = [];
encodingOverride.push({ resource: uri.file(env.appSettingsHome), encoding: encoding.UTF8 });
encodingOverride.push({ resource: uri.file(environmentService.appSettingsHome), encoding: encoding.UTF8 });
if (this.contextService.getWorkspace()) {
encodingOverride.push({ resource: uri.file(paths.join(this.contextService.getWorkspace().resource.fsPath, '.vscode')), encoding: encoding.UTF8 });
}
@@ -61,12 +62,12 @@ export class FileService implements IFileService {
encoding: configuration.files && configuration.files.encoding,
encodingOverride: encodingOverride,
watcherIgnoredPatterns: watcherIgnoredPatterns,
verboseLogging: env.verboseLogging,
debugBrkFileWatcherPort: env.debugBrkFileWatcherPort
verboseLogging: environmentService.verbose,
debugBrkFileWatcherPort: environmentService.debugBrkFileWatcherPort
};
if (typeof env.debugBrkFileWatcherPort === 'number') {
console.warn(`File Watcher STOPPED on first line for debugging on port ${env.debugBrkFileWatcherPort}`);
if (typeof environmentService.debugBrkFileWatcherPort === 'number') {
console.warn(`File Watcher STOPPED on first line for debugging on port ${environmentService.debugBrkFileWatcherPort}`);
}
// create service

View File

@@ -25,6 +25,7 @@ import {ILifecycleService} from 'vs/platform/lifecycle/common/lifecycle';
import {Registry} from 'vs/platform/platform';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IEditorGroupService} from 'vs/workbench/services/group/common/groupService';
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
/**
* Stores the selection & view state of an editor and allows to compare it to other selection states.
@@ -85,7 +86,8 @@ export abstract class BaseHistoryService {
private eventService: IEventService,
protected editorGroupService: IEditorGroupService,
protected editorService: IWorkbenchEditorService,
protected contextService: IWorkspaceContextService
protected contextService: IWorkspaceContextService,
private environmentService: IEnvironmentService
) {
this.toUnbind = [];
this.activeEditorListeners = [];
@@ -154,7 +156,7 @@ export abstract class BaseHistoryService {
let title = this.doGetWindowTitle(input);
// Extension Development Host gets a special title to identify itself
if (this.contextService.getConfiguration().env.extensionDevelopmentPath) {
if (this.environmentService.extensionDevelopmentPath) {
return nls.localize('devExtensionWindowTitle', "[Extension Development Host] - {0}", title);
}
@@ -234,12 +236,13 @@ export class HistoryService extends BaseHistoryService implements IHistoryServic
@IEventService eventService: IEventService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IEditorGroupService editorGroupService: IEditorGroupService,
@IEnvironmentService environmentService: IEnvironmentService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IStorageService private storageService: IStorageService,
@ILifecycleService private lifecycleService: ILifecycleService,
@IInstantiationService private instantiationService: IInstantiationService
) {
super(eventService, editorGroupService, editorService, contextService);
super(eventService, editorGroupService, editorService, contextService, environmentService);
this.index = -1;
this.stack = [];

View File

@@ -19,6 +19,7 @@ import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {IRawSearch, ISerializedSearchComplete, ISerializedSearchProgressItem, ISerializedFileMatch, IRawSearchService} from './search';
import {ISearchChannel, SearchChannelClient} from './searchIpc';
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
export class SearchService implements ISearchService {
public _serviceBrand: any;
@@ -28,11 +29,11 @@ export class SearchService implements ISearchService {
constructor(
@IModelService private modelService: IModelService,
@IUntitledEditorService private untitledEditorService: IUntitledEditorService,
@IEnvironmentService private environmentService: IEnvironmentService,
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IConfigurationService private configurationService: IConfigurationService
) {
let config = contextService.getConfiguration();
this.diskSearch = new DiskSearch(!config.env.isBuilt || config.env.verboseLogging);
this.diskSearch = new DiskSearch(!environmentService.isBuilt || environmentService.verbose);
}
public search(query: ISearchQuery): PPromise<ISearchComplete, ISearchProgressItem> {

View File

@@ -18,11 +18,12 @@ import {IMainProcessExtHostIPC, create} from 'vs/platform/extensions/common/ipcR
import {IMessageService, Severity} from 'vs/platform/message/common/message';
import {AbstractThreadService} from 'vs/workbench/services/thread/common/abstractThreadService';
import {ILifecycleService, ShutdownEvent} from 'vs/platform/lifecycle/common/lifecycle';
import {IConfiguration, IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IWindowService} from 'vs/workbench/services/window/electron-browser/windowService';
import {ChildProcess, fork} from 'child_process';
import {ipcRenderer as ipc} from 'electron';
import {IThreadService} from 'vs/workbench/services/thread/common/threadService';
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
export const EXTENSION_LOG_BROADCAST_CHANNEL = 'vscode:extensionLog';
export const EXTENSION_ATTACH_BROADCAST_CHANNEL = 'vscode:extensionAttach';
@@ -47,11 +48,12 @@ export class MainThreadService extends AbstractThreadService implements IThreadS
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IMessageService messageService: IMessageService,
@IWindowService windowService: IWindowService,
@IEnvironmentService private environmentService: IEnvironmentService,
@ILifecycleService lifecycleService: ILifecycleService
) {
super(true);
this.extensionHostProcessManager = new ExtensionHostProcessManager(contextService, messageService, windowService, lifecycleService);
this.extensionHostProcessManager = new ExtensionHostProcessManager(contextService, messageService, windowService, lifecycleService, environmentService);
let logCommunication = logExtensionHostCommunication || contextService.getConfiguration().env.logExtensionHostCommunication;
@@ -82,7 +84,7 @@ export class MainThreadService extends AbstractThreadService implements IThreadS
this.extensionHostProcessManager.terminate();
}
protected _callOnRemote(proxyId: string, path: string, args:any[]): TPromise<any> {
protected _callOnRemote(proxyId: string, path: string, args: any[]): TPromise<any> {
return this.remoteCom.callOnRemote(proxyId, path, args);
}
}
@@ -105,12 +107,13 @@ class ExtensionHostProcessManager {
private contextService: IWorkspaceContextService,
private messageService: IMessageService,
private windowService: IWindowService,
private lifecycleService: ILifecycleService
private lifecycleService: ILifecycleService,
private environmentService: IEnvironmentService
) {
// handle extension host lifecycle a bit special when we know we are developing an extension that runs inside
const config = this.contextService.getConfiguration();
this.isExtensionDevelopmentHost = !!config.env.extensionDevelopmentPath;
this.isExtensionDevelopmentHost = !!environmentService.extensionDevelopmentPath;
this.isExtensionDevelopmentDebugging = !!config.env.debugBrkExtensionHost;
this.isExtensionDevelopmentTestFromCli = this.isExtensionDevelopmentHost && !!config.env.extensionTestsPath && !config.env.debugBrkExtensionHost;
@@ -120,14 +123,12 @@ class ExtensionHostProcessManager {
}
public startExtensionHostProcess(onExtensionHostMessage: (msg: any) => void): void {
let config = this.contextService.getConfiguration();
let opts: any = {
env: objects.mixin(objects.clone(process.env), { AMD_ENTRYPOINT: 'vs/workbench/node/extensionHostProcess', PIPE_LOGGING: 'true', VERBOSE_LOGGING: true })
};
// Help in case we fail to start it
if (!config.env.isBuilt || this.isExtensionDevelopmentHost) {
if (!this.environmentService.isBuilt || this.isExtensionDevelopmentHost) {
this.initializeTimer = setTimeout(() => {
const msg = this.isExtensionDevelopmentDebugging ? nls.localize('extensionHostProcess.startupFailDebug', "Extension host did not start in 10 seconds, it might be stopped on the first line and needs a debugger to continue.") : nls.localize('extensionHostProcess.startupFail', "Extension host did not start in 10 seconds, that might be a problem.");
@@ -139,7 +140,7 @@ class ExtensionHostProcessManager {
this.initializeExtensionHostProcess = new TPromise<ChildProcess>((c, e) => {
// Resolve additional execution args (e.g. debug)
return this.resolveDebugPort(config, (port) => {
return this.resolveDebugPort(this.contextService.getConfiguration().env.debugExtensionHostPort, port => {
if (port) {
opts.execArgv = ['--nolazy', (this.isExtensionDevelopmentDebugging ? '--debug-brk=' : '--debug=') + port];
}
@@ -154,7 +155,7 @@ class ExtensionHostProcessManager {
payload: {
port: port
}
}, config.env.extensionDevelopmentPath /* target */);
}, this.environmentService.extensionDevelopmentPath /* target */);
}
// Messages from Extension host
@@ -220,11 +221,11 @@ class ExtensionHostProcessManager {
}
// Broadcast to other windows if we are in development mode
else if (!config.env.isBuilt || this.isExtensionDevelopmentHost) {
else if (!this.environmentService.isBuilt || this.isExtensionDevelopmentHost) {
this.windowService.broadcast({
channel: EXTENSION_LOG_BROADCAST_CHANNEL,
payload: logEntry
}, config.env.extensionDevelopmentPath /* target */);
}, this.environmentService.extensionDevelopmentPath /* target */);
}
}
@@ -278,19 +279,19 @@ class ExtensionHostProcessManager {
}, () => this.terminate());
}
private resolveDebugPort(config: IConfiguration, clb: (port: number) => void): void {
private resolveDebugPort(extensionHostPort: number, clb: (port: number) => void): void {
// Check for a free debugging port
if (typeof config.env.debugExtensionHostPort === 'number') {
return findFreePort(config.env.debugExtensionHostPort, 10 /* try 10 ports */, 5000 /* try up to 5 seconds */, (port) => {
if (typeof extensionHostPort === 'number') {
return findFreePort(extensionHostPort, 10 /* try 10 ports */, 5000 /* try up to 5 seconds */, (port) => {
if (!port) {
console.warn('%c[Extension Host] %cCould not find a free port for debugging', 'color: blue', 'color: black');
return clb(void 0);
}
if (port !== config.env.debugExtensionHostPort) {
console.warn('%c[Extension Host] %cProvided debugging port ' + config.env.debugExtensionHostPort + ' is not free, using ' + port + ' instead.', 'color: blue', 'color: black');
if (port !== extensionHostPort) {
console.warn('%c[Extension Host] %cProvided debugging port ' + extensionHostPort + ' is not free, using ' + port + ' instead.', 'color: blue', 'color: black');
}
if (this.isExtensionDevelopmentDebugging) {
@@ -329,7 +330,7 @@ class ExtensionHostProcessManager {
}
}
private _onWillShutdown(event: ShutdownEvent): void{
private _onWillShutdown(event: ShutdownEvent): void {
// If the extension development host was started without debugger attached we need
// to communicate this back to the main side to terminate the debug session
@@ -337,7 +338,7 @@ class ExtensionHostProcessManager {
this.windowService.broadcast({
channel: EXTENSION_TERMINATE_BROADCAST_CHANNEL,
payload: true
}, this.contextService.getConfiguration().env.extensionDevelopmentPath /* target */);
}, this.environmentService.extensionDevelopmentPath /* target */);
event.veto(TPromise.timeout(100 /* wait a bit for IPC to get delivered */).then(() => false));
}