提交 255c7d5a 编写于 作者: B Benjamin Pasero

Debug and tasks should fetch latest configuration from disk (fixes #3132)

上级 fe83aa24
......@@ -6,6 +6,7 @@
import {createDecorator, ServiceIdentifier} from 'vs/platform/instantiation/common/instantiation';
import {IEventEmitter} from 'vs/base/common/eventEmitter';
import Event from 'vs/base/common/event';
import {TPromise} from 'vs/base/common/winjs.base';
export const IConfigurationService = createDecorator<IConfigurationService>('configurationService');
......@@ -18,6 +19,12 @@ export interface IConfigurationService extends IEventEmitter {
*/
getConfiguration<T>(section?: string): T;
/**
* Similar to #getConfiguration() but ensures that the latest configuration
* from disk is fetched.
*/
loadConfiguration<T>(section?: string): TPromise<T>;
/**
* Returns iff the workspace has configuration or not.
*/
......
......@@ -90,7 +90,7 @@ export abstract class ConfigurationService extends EventEmitter implements IConf
}
public initialize(): TPromise<void> {
return this.loadConfiguration().then(() => null);
return this.doLoadConfiguration().then(() => null);
}
protected abstract resolveContents(resource: uri[]): TPromise<IContent[]>;
......@@ -117,7 +117,17 @@ export abstract class ConfigurationService extends EventEmitter implements IConf
return result;
}
private loadConfiguration(section?: string): TPromise<any> {
public loadConfiguration(section?: string): TPromise<any> {
// Reset caches to ensure we are hitting the disk
this.bulkFetchFromWorkspacePromise = null;
this.workspaceFilePathToConfiguration = Object.create(null);
// Load configuration
return this.doLoadConfiguration(section);
}
private doLoadConfiguration(section?: string): TPromise<any> {
// Load globals
const globals = this.loadGlobalConfiguration();
......@@ -188,7 +198,7 @@ export abstract class ConfigurationService extends EventEmitter implements IConf
protected handleConfigurationChange(): void {
if (!this.reloadConfigurationScheduler) {
this.reloadConfigurationScheduler = new RunOnceScheduler(() => {
this.loadConfiguration().then((config) => this.emit(ConfigurationServiceEventTypes.UPDATED, { config: config })).done(null, errors.onUnexpectedError);
this.doLoadConfiguration().then((config) => this.emit(ConfigurationServiceEventTypes.UPDATED, { config: config })).done(null, errors.onUnexpectedError);
}, ConfigurationService.RELOAD_CONFIGURATION_DELAY);
}
......
......@@ -42,6 +42,7 @@ import { IViewletService } from 'vs/workbench/services/viewlet/common/viewletSer
import { IPanelService } from 'vs/workbench/services/panel/common/panelService';
import { IPartService } from 'vs/workbench/services/part/common/partService';
import { ITextFileService } from 'vs/workbench/parts/files/common/files';
import { IConfigurationService } from 'vs/platform/configuration/common/configuration';
import { IWorkspaceContextService } from 'vs/workbench/services/workspace/common/contextService';
import { IWorkbenchEditorService } from 'vs/workbench/services/editor/common/editorService';
import { IWindowService, IBroadcast } from 'vs/workbench/services/window/electron-browser/windowService';
......@@ -89,7 +90,8 @@ export class DebugService implements debug.IDebugService {
@IInstantiationService private instantiationService:IInstantiationService,
@IExtensionService private extensionService: IExtensionService,
@IMarkerService private markerService: IMarkerService,
@ITaskService private taskService: ITaskService
@ITaskService private taskService: ITaskService,
@IConfigurationService private configurationService: IConfigurationService
) {
this.toDispose = [];
this.toDisposeOnSessionEnd = [];
......@@ -489,7 +491,8 @@ export class DebugService implements debug.IDebugService {
public createSession(noDebug: boolean, changeViewState = !this.partService.isSideBarHidden()): TPromise<any> {
this.removeReplExpressions();
return this.textFileService.saveAll()
return this.textFileService.saveAll() // make sure all dirty files are saved
.then(() => this.configurationService.loadConfiguration() // make sure configuration is up to date
.then(() => this.extensionService.onReady()
.then(() => this.configurationManager.setConfiguration((this.configurationManager.configurationName))
.then(() => {
......@@ -535,7 +538,7 @@ export class DebugService implements debug.IDebugService {
actions: [CloseAction, this.taskService.configureAction()]
});
});
})));
}))));
}
private doCreateSession(configuration: debug.IConfig, changeViewState: boolean): TPromise<any> {
......
......@@ -753,44 +753,46 @@ class TaskService extends EventEmitter implements ITaskService {
}
private executeTarget(fn: (taskSystem: ITaskSystem) => ITaskRunResult): TPromise<ITaskSummary> {
return this.textFileService.saveAll().then((value) => {
return this.taskSystemPromise.
then((taskSystem) => {
return taskSystem.isActive().then((active) => {
if (!active) {
return fn(taskSystem);
} else {
throw new TaskError(Severity.Warning, nls.localize('TaskSystem.active', 'There is an active running task right now. Terminate it first before executing another task.'), TaskErrors.RunningTask);
}
});
}).
then((runResult: ITaskRunResult) => {
if (runResult.restartOnFileChanges) {
let pattern = runResult.restartOnFileChanges;
this.fileChangesListener = this.eventService.addListener(FileEventType.FILE_CHANGES, (event: FileChangesEvent) => {
let needsRestart = event.changes.some((change) => {
return (change.type === FileChangeType.ADDED || change.type === FileChangeType.DELETED) && !!match(pattern, change.resource.fsPath);
});
if (needsRestart) {
this.terminate().done(() => {
// We need to give the child process a change to stop.
setTimeout(() => {
this.executeTarget(fn);
}, 2000);
});
return this.textFileService.saveAll().then((value) => { // make sure all dirty files are saved
return this.configurationService.loadConfiguration().then(() => { // make sure configuration is up to date
return this.taskSystemPromise.
then((taskSystem) => {
return taskSystem.isActive().then((active) => {
if (!active) {
return fn(taskSystem);
} else {
throw new TaskError(Severity.Warning, nls.localize('TaskSystem.active', 'There is an active running task right now. Terminate it first before executing another task.'), TaskErrors.RunningTask);
}
});
}
return runResult.promise.then((value) => {
if (this.clearTaskSystemPromise) {
this._taskSystemPromise = null;
this.clearTaskSystemPromise = false;
}).
then((runResult: ITaskRunResult) => {
if (runResult.restartOnFileChanges) {
let pattern = runResult.restartOnFileChanges;
this.fileChangesListener = this.eventService.addListener(FileEventType.FILE_CHANGES, (event: FileChangesEvent) => {
let needsRestart = event.changes.some((change) => {
return (change.type === FileChangeType.ADDED || change.type === FileChangeType.DELETED) && !!match(pattern, change.resource.fsPath);
});
if (needsRestart) {
this.terminate().done(() => {
// We need to give the child process a change to stop.
setTimeout(() => {
this.executeTarget(fn);
}, 2000);
});
}
});
}
return value;
return runResult.promise.then((value) => {
if (this.clearTaskSystemPromise) {
this._taskSystemPromise = null;
this.clearTaskSystemPromise = false;
}
return value;
});
}, (err: any) => {
this.handleError(err);
});
}, (err: any) => {
this.handleError(err);
});
});
});
}
......
......@@ -453,6 +453,10 @@ export const TestFileService = {
export class TestConfigurationService extends EventEmitter.EventEmitter implements IConfigurationService {
public serviceId = IConfigurationService;
public loadConfiguration<T>(section?: string): TPromise<T> {
return TPromise.as(this.getConfiguration());
}
public getConfiguration(): any {
return {};
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册