提交 84c4c8d4 编写于 作者: B Benjamin Pasero

add meaningful defaults to paths, product and package to survive test runs

上级 d2a413ee
......@@ -4,13 +4,40 @@
*--------------------------------------------------------------------------------------------*/
import uri from 'vs/base/common/uri';
import * as path from 'path';
import * as os from 'os';
interface IPaths {
getAppDataPath(platform: string): string;
getUserDataPath(platform: string, appName: string, args: string[]): string;
}
const pathsPath = uri.parse(require.toUrl('paths')).fsPath;
const paths = require.__$__nodeRequire<IPaths>(pathsPath);
export const getAppDataPath = paths.getAppDataPath;
export const getUserDataPath = paths.getUserDataPath;
function defaultGetAppDataPath(platform) {
switch (platform) {
case 'win32': return process.env['APPDATA'];
case 'darwin': return path.join(os.homedir(), 'Library', 'Application Support');
case 'linux': return process.env['XDG_CONFIG_HOME'] || path.join(os.homedir(), '.config');
default: throw new Error('Platform not supported');
}
}
function defaultGetUserDataPath(platform, appName) {
return path.join(getAppDataPath(platform), appName);
}
let _getAppDataPath: (platform: string) => string;
let _getUserDataPath: (platform: string, appName: string, args: string[]) => string;
try {
const pathsPath = uri.parse(require.toUrl('paths')).fsPath;
const paths = require.__$__nodeRequire<IPaths>(pathsPath);
_getAppDataPath = paths.getAppDataPath;
_getUserDataPath = paths.getUserDataPath;
} catch (error) {
_getAppDataPath = (platform) => defaultGetAppDataPath(platform);
_getUserDataPath = (platform: string, appName: string, args: string[]) => defaultGetUserDataPath(platform, appName);
}
export const getAppDataPath = _getAppDataPath;
export const getUserDataPath = _getUserDataPath;
......@@ -48,8 +48,6 @@ export abstract class ConfigurationService implements IConfigurationService, IDi
private _onDidUpdateConfiguration = new Emitter<IConfigurationServiceEvent>();
protected contextService: IWorkspaceContextService;
protected eventService: IEventService;
protected workspaceSettingsRootFolder: string;
private cachedConfig: ILoadConfigResult;
......@@ -59,10 +57,11 @@ export abstract class ConfigurationService implements IConfigurationService, IDi
private callOnDispose: IDisposable;
private reloadConfigurationScheduler: RunOnceScheduler;
constructor(contextService: IWorkspaceContextService, eventService: IEventService, workspaceSettingsRootFolder: string = '.vscode') {
this.contextService = contextService;
this.eventService = eventService;
constructor(
protected contextService: IWorkspaceContextService,
protected eventService: IEventService,
workspaceSettingsRootFolder: string = '.vscode'
) {
this.workspaceSettingsRootFolder = workspaceSettingsRootFolder;
this.workspaceFilePathToConfiguration = Object.create(null);
this.cachedConfig = {
......
......@@ -11,6 +11,16 @@ export interface IPackageConfiguration {
version: string;
}
const rootPath = path.dirname(uri.parse(require.toUrl('')).fsPath);
const packageJsonPath = path.join(rootPath, 'package.json');
export default require.__$__nodeRequire(packageJsonPath) as IPackageConfiguration;
\ No newline at end of file
let pkg: IPackageConfiguration;
try {
const rootPath = path.dirname(uri.parse(require.toUrl('')).fsPath);
const packageJsonPath = path.join(rootPath, 'package.json');
pkg = require.__$__nodeRequire(packageJsonPath) as IPackageConfiguration;
} catch (error) {
pkg = {
name: 'code-oss-dev',
version: '1.x.x'
};
}
export default pkg;
\ No newline at end of file
......@@ -53,7 +53,11 @@ try {
const productJsonPath = path.join(rootPath, 'product.json');
product = require.__$__nodeRequire(productJsonPath) as IProductConfiguration;
} catch (error) {
product = Object.create(null); // can happen in environments where product.json is missing (e.g. when used from tests)
product = <IProductConfiguration>{
nameLong: 'Code - OSS',
applicationName: 'code-oss',
dataFolderName: '.vscode-oss'
};
}
if (process.env['VSCODE_DEV']) {
......
......@@ -41,6 +41,8 @@ import {IModelService} from 'vs/editor/common/services/modelService';
import {ModelServiceImpl} from 'vs/editor/common/services/modelServiceImpl';
import {IRawTextContent} from 'vs/workbench/parts/files/common/files';
import {RawText} from 'vs/editor/common/model/textModel';
import {parseArgs} from 'vs/code/node/argv';
import {EnvironmentService} from 'vs/platform/environment/node/environmentService';
export const TestWorkspace: IWorkspace = {
resource: URI.file('C:\\testWorkspace'),
......@@ -54,6 +56,8 @@ export const TestConfiguration: IConfiguration = {
env: Object.create(null)
};
export const TestEnvironmentService = new EnvironmentService(parseArgs(process.argv));
export class TestContextService implements WorkspaceContextService.IWorkspaceContextService {
public _serviceBrand: any;
......
......@@ -139,7 +139,7 @@ function openWorkbench(args: ParsedArgs, workspace: IWorkspace, configuration: I
const eventService = new EventService();
const environmentService = new EnvironmentService(args);
const contextService = new WorkspaceContextService(eventService, workspace, configuration, options);
const configurationService = new ConfigurationService(contextService, eventService);
const configurationService = new ConfigurationService(contextService, eventService, environmentService);
// Since the configuration service is one of the core services that is used in so many places, we initialize it
// right before startup of the workbench shell to have its data ready for consumers
......
......@@ -15,6 +15,7 @@ import {IConfigFile} from 'vs/platform/configuration/common/model';
import objects = require('vs/base/common/objects');
import {IStat, IContent, ConfigurationService as CommonConfigurationService} from 'vs/platform/configuration/common/configurationService';
import {IWorkspaceContextService} from 'vs/workbench/services/workspace/common/contextService';
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
import {OptionsChangeEvent, EventType} from 'vs/workbench/common/events';
import {IEventService} from 'vs/platform/event/common/event';
import {IDisposable} from 'vs/base/common/lifecycle';
......@@ -31,7 +32,8 @@ export class ConfigurationService extends CommonConfigurationService {
constructor(
contextService: IWorkspaceContextService,
eventService: IEventService
eventService: IEventService,
private environmentService: IEnvironmentService
) {
super(contextService, eventService);
......@@ -120,8 +122,8 @@ export class ConfigurationService extends CommonConfigurationService {
}
public setUserConfiguration(key: any, value: any) : Thenable<void> {
const appSettingsPath = this.contextService.getConfiguration().env.appSettingsPath;
const appSettingsPath = this.environmentService.appSettingsPath;
return readFile(appSettingsPath, 'utf8').then(content => {
const {tabSize, insertSpaces} = this.getConfiguration<{ tabSize: number; insertSpaces: boolean }>('editor');
const path: JSONPath = typeof key === 'string' ? (<string> key).split('.') : <JSONPath> key;
......
......@@ -21,7 +21,8 @@ import {QuickOpenHandler, IQuickOpenRegistry, Extensions} from 'vs/workbench/bro
import {Registry} from 'vs/platform/platform';
import {SearchService} from 'vs/workbench/services/search/node/searchService';
import {ServiceCollection} from 'vs/platform/instantiation/common/serviceCollection';
import {TestConfiguration, TestEditorService, TestEditorGroupService} from 'vs/test/utils/servicesTestUtils';
import {TestEnvironmentService, TestConfiguration, TestEditorService, TestEditorGroupService} from 'vs/test/utils/servicesTestUtils';
import {IEnvironmentService} from 'vs/platform/environment/common/environment';
import * as Timer from 'vs/base/common/timer';
import {TPromise} from 'vs/base/common/winjs.base';
import URI from 'vs/base/common/uri';
......@@ -51,13 +52,14 @@ suite('QuickOpen performance', () => {
mtime: null
}, TestConfiguration),
telemetryService: telemetryService
telemetryService
};
const services = ensureStaticPlatformServices(overrides);
const instantiationService = services.instantiationService.createChild(new ServiceCollection(
[IWorkbenchEditorService, new TestEditorService()],
[IEditorGroupService, new TestEditorGroupService()],
[IEnvironmentService, TestEnvironmentService],
[IUntitledEditorService, createSyncDescriptor(UntitledEditorService)],
[ISearchService, createSyncDescriptor(SearchService)]
));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册