提交 0d096fed 编写于 作者: B Benjamin Pasero

avoid input creation for checking for dirty state

上级 b61ae53c
......@@ -389,6 +389,9 @@ export class Workbench implements IPartService {
// History
serviceCollection.set(IHistoryService, this.instantiationService.createInstance(HistoryService));
// Text File Service
serviceCollection.set(ITextFileService, this.instantiationService.createInstance(TextFileService));
// Configuration Editing
serviceCollection.set(IConfigurationEditingService, this.instantiationService.createInstance(ConfigurationEditingService));
......@@ -403,9 +406,6 @@ export class Workbench implements IPartService {
this.toShutdown.push(this.quickOpen);
serviceCollection.set(IQuickOpenService, this.quickOpen);
// Text File Service
serviceCollection.set(ITextFileService, this.instantiationService.createInstance(TextFileService));
// Contributed services
const contributedServices = getServices();
for (let contributedService of contributedServices) {
......
......@@ -12,11 +12,11 @@ import * as json from 'vs/base/common/json';
import * as encoding from 'vs/base/node/encoding';
import strings = require('vs/base/common/strings');
import {getConfigurationKeys} from 'vs/platform/configuration/common/model';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {setProperty} from 'vs/base/common/jsonEdit';
import {applyEdits} from 'vs/base/common/jsonFormatter';
import {IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
import {ITextFileService} from 'vs/workbench/services/textfile/common/textfiles';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {WORKSPACE_CONFIG_DEFAULT_PATH} from 'vs/workbench/services/configuration/common/configuration';
import {IFileService} from 'vs/platform/files/common/files';
......@@ -47,7 +47,7 @@ export class ConfigurationEditingService implements IConfigurationEditingService
@IWorkspaceContextService private contextService: IWorkspaceContextService,
@IEnvironmentService private environmentService: IEnvironmentService,
@IFileService private fileService: IFileService,
@IWorkbenchEditorService private editorService: IWorkbenchEditorService
@ITextFileService private textFileService: ITextFileService
) {
}
......@@ -160,33 +160,31 @@ export class ConfigurationEditingService implements IConfigurationEditingService
// Target cannot be dirty
const resource = operation.target;
return this.editorService.createInput({ resource }).then(typedInput => {
if (typedInput.isDirty()) {
return { error: ConfigurationEditingErrorCode.ERROR_CONFIGURATION_FILE_DIRTY };
}
if (this.textFileService.isDirty(resource)) {
return TPromise.as({ error: ConfigurationEditingErrorCode.ERROR_CONFIGURATION_FILE_DIRTY });
}
return this.fileService.existsFile(resource).then(exists => {
if (!exists) {
return { exists };
}
return this.fileService.existsFile(resource).then(exists => {
if (!exists) {
return { exists };
}
return this.fileService.resolveContent(resource, { acceptTextOnly: true, encoding: encoding.UTF8 }).then(content => {
return this.fileService.resolveContent(resource, { acceptTextOnly: true, encoding: encoding.UTF8 }).then(content => {
// If we write to a workspace standalone file and replace the entire contents (no key provided)
// we can return here because any parse errors can safely be ignored since all contents are replaced
if (operation.isWorkspaceStandalone && !operation.key) {
return { exists, contents: content.value };
}
// If we write to a workspace standalone file and replace the entire contents (no key provided)
// we can return here because any parse errors can safely be ignored since all contents are replaced
if (operation.isWorkspaceStandalone && !operation.key) {
return { exists, contents: content.value };
}
// Target cannot contain JSON errors
const parseErrors = [];
json.parse(content.value, parseErrors);
if (parseErrors.length > 0) {
return { error: ConfigurationEditingErrorCode.ERROR_INVALID_CONFIGURATION };
}
// Target cannot contain JSON errors
const parseErrors = [];
json.parse(content.value, parseErrors);
if (parseErrors.length > 0) {
return { error: ConfigurationEditingErrorCode.ERROR_INVALID_CONFIGURATION };
}
return { exists, contents: content.value };
});
return { exists, contents: content.value };
});
});
}
......
......@@ -13,10 +13,10 @@ import * as json from 'vs/base/common/json';
import {TPromise} from 'vs/base/common/winjs.base';
import {Registry} from 'vs/platform/platform';
import {ParsedArgs, parseArgs} from 'vs/platform/environment/node/argv';
import {WorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {WorkspaceContextService, IWorkspaceContextService} from 'vs/platform/workspace/common/workspace';
import {EnvironmentService} from 'vs/platform/environment/node/environmentService';
import extfs = require('vs/base/node/extfs');
import {TestEventService, TestEditorService} from 'vs/test/utils/servicesTestUtils';
import {TestEventService, workbenchInstantiationService, TestTextFileService} from 'vs/test/utils/servicesTestUtils';
import uuid = require('vs/base/common/uuid');
import {IConfigurationRegistry, Extensions as ConfigurationExtensions} from 'vs/platform/configuration/common/configurationRegistry';
import {WorkspaceConfigurationService} from 'vs/workbench/services/configuration/node/configurationService';
......@@ -25,7 +25,14 @@ import utils = require('vs/workbench/services/files/test/node/utils');
import {FileService} from 'vs/workbench/services/files/node/fileService';
import {ConfigurationEditingService, WORKSPACE_STANDALONE_CONFIGURATIONS} from 'vs/workbench/services/configuration/node/configurationEditingService';
import {ConfigurationTarget, IConfigurationEditingError, ConfigurationEditingErrorCode} from 'vs/workbench/services/configuration/common/configurationEditing';
import {IResourceInput} from 'vs/platform/editor/common/editor';
import {IEditorGroupService} from 'vs/workbench/services/group/common/groupService';
import {IFileService} from 'vs/platform/files/common/files';
import {IWorkbenchEditorService} from 'vs/workbench/services/editor/common/editorService';
import {IInstantiationService} from 'vs/platform/instantiation/common/instantiation';
import {IConfigurationService} from 'vs/platform/configuration/common/configuration';
import {IUntitledEditorService} from 'vs/workbench/services/untitled/common/untitledEditorService';
import {ILifecycleService} from 'vs/platform/lifecycle/common/lifecycle';
import {ITelemetryService} from 'vs/platform/telemetry/common/telemetry';
class SettingsTestEnvironmentService extends EnvironmentService {
......@@ -36,19 +43,25 @@ class SettingsTestEnvironmentService extends EnvironmentService {
get appSettingsPath(): string { return this.customAppSettingsHome; }
}
class TestWorkbenchEditorService extends TestEditorService {
constructor(private dirty: boolean) {
super();
class TestDirtyTextFileService extends TestTextFileService {
constructor(
private dirty: boolean,
@ILifecycleService lifecycleService: ILifecycleService,
@IWorkspaceContextService contextService: IWorkspaceContextService,
@IConfigurationService configurationService: IConfigurationService,
@ITelemetryService telemetryService: ITelemetryService,
@IWorkbenchEditorService editorService: IWorkbenchEditorService,
@IEditorGroupService editorGroupService: IEditorGroupService,
@IFileService fileService: IFileService,
@IUntitledEditorService untitledEditorService: IUntitledEditorService,
@IInstantiationService instantiationService: IInstantiationService
) {
super(lifecycleService, contextService, configurationService, telemetryService, editorService, editorGroupService, fileService, untitledEditorService, instantiationService);
}
public createInput(input: IResourceInput): TPromise<any> {
return TPromise.as({
getName: () => 'name',
getDescription: () => 'description',
isDirty: () => this.dirty,
matches: () => false
});
public isDirty(resource?: URI): boolean {
return this.dirty;
}
}
......@@ -70,14 +83,14 @@ suite('WorkspaceConfigurationEditingService - Node', () => {
const workspaceContextService = new WorkspaceContextService(noWorkspace ? null : { resource: URI.file(workspaceDir) });
const environmentService = new SettingsTestEnvironmentService(parseArgs(process.argv), process.execPath, globalSettingsFile);
const configurationService = new WorkspaceConfigurationService(workspaceContextService, new TestEventService(), environmentService);
const editorService = new TestWorkbenchEditorService(dirty);
const textFileService = workbenchInstantiationService().createInstance(TestDirtyTextFileService, dirty);
const events = new utils.TestEventService();
const fileService = new FileService(noWorkspace ? null : workspaceDir, { disableWatcher: true }, events);
return configurationService.initialize().then(() => {
return {
configurationEditingService: new ConfigurationEditingService(configurationService, workspaceContextService, environmentService, fileService, editorService),
configurationService: configurationService
configurationEditingService: new ConfigurationEditingService(configurationService, workspaceContextService, environmentService, fileService, textFileService),
configurationService
};
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册