diff --git a/src/vs/base/node/paths.ts b/src/vs/base/node/paths.ts index 8cd14b49f6f643ddf12d9fe927e6f821f399490f..5b1c647bc65b1a2fc0480b44f94d1d9244666dd4 100644 --- a/src/vs/base/node/paths.ts +++ b/src/vs/base/node/paths.ts @@ -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(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(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; diff --git a/src/vs/platform/configuration/common/configurationService.ts b/src/vs/platform/configuration/common/configurationService.ts index 3020f09c25b757afd7e841808762723fc0732995..6ff01b98c892396b9e68283a9737e64070dce304 100644 --- a/src/vs/platform/configuration/common/configurationService.ts +++ b/src/vs/platform/configuration/common/configurationService.ts @@ -48,8 +48,6 @@ export abstract class ConfigurationService implements IConfigurationService, IDi private _onDidUpdateConfiguration = new Emitter(); - 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 = { diff --git a/src/vs/platform/package.ts b/src/vs/platform/package.ts index fff85d911f2d8c95fb743cf594b8534ef00dfd68..d8ba7e07908684f26fab9764c6ec0fe978254765 100644 --- a/src/vs/platform/package.ts +++ b/src/vs/platform/package.ts @@ -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 diff --git a/src/vs/platform/product.ts b/src/vs/platform/product.ts index 31f64376bc275ce659ee07af7687df4d34321884..81e6c30d8d6b719a2b15b040dd156c2d0f3b8188 100644 --- a/src/vs/platform/product.ts +++ b/src/vs/platform/product.ts @@ -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 = { + nameLong: 'Code - OSS', + applicationName: 'code-oss', + dataFolderName: '.vscode-oss' + }; } if (process.env['VSCODE_DEV']) { diff --git a/src/vs/test/utils/servicesTestUtils.ts b/src/vs/test/utils/servicesTestUtils.ts index f97eb1c51c4f7415c206c70d5c93fdaef54ace15..a475aa1a2af36767fde1bb046f7f26c1bff1d21d 100644 --- a/src/vs/test/utils/servicesTestUtils.ts +++ b/src/vs/test/utils/servicesTestUtils.ts @@ -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; diff --git a/src/vs/workbench/electron-browser/main.ts b/src/vs/workbench/electron-browser/main.ts index e2010c9db8bb86f4c9811fb45f47d3a28c2862bd..57e82b49b64d863c060a35c22f29788df6d2b494 100644 --- a/src/vs/workbench/electron-browser/main.ts +++ b/src/vs/workbench/electron-browser/main.ts @@ -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 diff --git a/src/vs/workbench/services/configuration/node/configurationService.ts b/src/vs/workbench/services/configuration/node/configurationService.ts index 5ce1234b5bc194d6034b8fb96e1261e092b7bf29..9e46af9df9a278f0e72ad77a8bc369a724543afd 100644 --- a/src/vs/workbench/services/configuration/node/configurationService.ts +++ b/src/vs/workbench/services/configuration/node/configurationService.ts @@ -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 { - 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' ? ( key).split('.') : key; diff --git a/src/vs/workbench/test/browser/parts/quickOpen/quickopen.perf.test.ts b/src/vs/workbench/test/browser/parts/quickOpen/quickopen.perf.test.ts index 3d0b1c58cf80e15882d240dc612c81e4a1f2ea4f..f28682a9d2ec7bd98448b891ee80dc0af4fbb404 100644 --- a/src/vs/workbench/test/browser/parts/quickOpen/quickopen.perf.test.ts +++ b/src/vs/workbench/test/browser/parts/quickOpen/quickopen.perf.test.ts @@ -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)] ));