Skip to content

Commit

Permalink
debt - declare more services via registerSingleton()
Browse files Browse the repository at this point in the history
  • Loading branch information
bpasero committed Mar 2, 2019
1 parent 4585f69 commit 900d58b
Show file tree
Hide file tree
Showing 19 changed files with 148 additions and 137 deletions.
47 changes: 17 additions & 30 deletions src/vs/base/common/path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
* USE OR OTHER DEALINGS IN THE SOFTWARE.
*/

import { isWindows } from 'vs/base/common/platform';
import * as process from 'vs/base/common/process';

const CHAR_UPPERCASE_A = 65;/* A */
const CHAR_LOWERCASE_A = 97; /* a */
Expand All @@ -41,19 +41,6 @@ const CHAR_BACKWARD_SLASH = 92; /* \ */
const CHAR_COLON = 58; /* : */
const CHAR_QUESTION_MARK = 63; /* ? */

interface IProcess {
cwd(): string;
platform: string;
env: object;
}

declare let process: IProcess;
const safeProcess: IProcess = (typeof process === 'undefined') ? {
cwd() { return '/'; },
env: {},
get platform() { return isWindows ? 'win32' : 'posix'; }
} : process;

class ErrorInvalidArgType extends Error {
code: 'ERR_INVALID_ARG_TYPE';
constructor(name: string, expected: string, actual: string) {
Expand Down Expand Up @@ -219,14 +206,14 @@ export const win32: IPath = {
if (i >= 0) {
path = pathSegments[i];
} else if (!resolvedDevice) {
path = safeProcess.cwd();
path = process.cwd();
} else {
// Windows has the concept of drive-specific current working
// directories. If we've resolved a drive letter but not yet an
// absolute path, get cwd for that drive, or the process cwd if
// the drive cwd is not available. We're sure the device is not
// a UNC path at this points, because UNC paths are always absolute.
path = safeProcess.env['=' + resolvedDevice] || safeProcess.cwd();
path = process.env['=' + resolvedDevice] || process.cwd();

// Verify that a cwd was found and that it actually points
// to our drive. If not, default to the drive's root.
Expand Down Expand Up @@ -1208,7 +1195,7 @@ export const posix: IPath = {
path = pathSegments[i];
}
else {
path = safeProcess.cwd();
path = process.cwd();
}

validateString(path, 'path');
Expand Down Expand Up @@ -1682,16 +1669,16 @@ export const posix: IPath = {
posix.win32 = win32.win32 = win32;
posix.posix = win32.posix = posix;

export const normalize = (safeProcess.platform === 'win32' ? win32.normalize : posix.normalize);
export const isAbsolute = (safeProcess.platform === 'win32' ? win32.isAbsolute : posix.isAbsolute);
export const join = (safeProcess.platform === 'win32' ? win32.join : posix.join);
export const resolve = (safeProcess.platform === 'win32' ? win32.resolve : posix.resolve);
export const relative = (safeProcess.platform === 'win32' ? win32.relative : posix.relative);
export const dirname = (safeProcess.platform === 'win32' ? win32.dirname : posix.dirname);
export const basename = (safeProcess.platform === 'win32' ? win32.basename : posix.basename);
export const extname = (safeProcess.platform === 'win32' ? win32.extname : posix.extname);
export const format = (safeProcess.platform === 'win32' ? win32.format : posix.format);
export const parse = (safeProcess.platform === 'win32' ? win32.parse : posix.parse);
export const toNamespacedPath = (safeProcess.platform === 'win32' ? win32.toNamespacedPath : posix.toNamespacedPath);
export const sep = (safeProcess.platform === 'win32' ? win32.sep : posix.sep);
export const delimiter = (safeProcess.platform === 'win32' ? win32.delimiter : posix.delimiter);
export const normalize = (process.platform === 'win32' ? win32.normalize : posix.normalize);
export const isAbsolute = (process.platform === 'win32' ? win32.isAbsolute : posix.isAbsolute);
export const join = (process.platform === 'win32' ? win32.join : posix.join);
export const resolve = (process.platform === 'win32' ? win32.resolve : posix.resolve);
export const relative = (process.platform === 'win32' ? win32.relative : posix.relative);
export const dirname = (process.platform === 'win32' ? win32.dirname : posix.dirname);
export const basename = (process.platform === 'win32' ? win32.basename : posix.basename);
export const extname = (process.platform === 'win32' ? win32.extname : posix.extname);
export const format = (process.platform === 'win32' ? win32.format : posix.format);
export const parse = (process.platform === 'win32' ? win32.parse : posix.parse);
export const toNamespacedPath = (process.platform === 'win32' ? win32.toNamespacedPath : posix.toNamespacedPath);
export const sep = (process.platform === 'win32' ? win32.sep : posix.sep);
export const delimiter = (process.platform === 'win32' ? win32.delimiter : posix.delimiter);
27 changes: 27 additions & 0 deletions src/vs/base/common/process.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { isWindows, isMacintosh, setImmediate } from 'vs/base/common/platform';

interface IProcess {
platform: string;
env: object;

cwd(): string;
nextTick(callback: (...args: any[]) => void): number;
}

declare let process: IProcess;
const safeProcess: IProcess = (typeof process === 'undefined') ? {
cwd(): string { return '/'; },
env: Object.create(null),
get platform(): string { return isWindows ? 'win32' : isMacintosh ? 'darwin' : 'linux'; },
nextTick(callback: (...args: any[]) => void): number { return setImmediate(callback); }
} : process;

export const cwd = safeProcess.cwd;
export const env = safeProcess.env;
export const platform = safeProcess.platform;
export const nextTick = safeProcess.nextTick;
2 changes: 1 addition & 1 deletion src/vs/workbench/api/node/extHostDebugService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -909,7 +909,7 @@ export class ExtHostVariableResolverService extends AbstractVariableResolverServ
}
return undefined;
}
});
}, process.env);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import { RunOnceScheduler } from 'vs/base/common/async';
import { Disposable } from 'vs/base/common/lifecycle';
import * as process from 'vs/base/common/process';
import * as platform from 'vs/base/common/platform';
import { ICodeEditor, IEditorMouseEvent, MouseTargetType } from 'vs/editor/browser/editorBrowser';
import { registerEditorContribution } from 'vs/editor/browser/editorExtensions';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ export class CodeInsetController implements editorCommon.IEditorContribution {

const widgetPromises = widgetRequests.map(request => {
if (request.resolved) {
return Promise.resolve(void 0);
return Promise.resolve(undefined);
}
let a = new Promise(resolve => {
this._pendingWebviews.set(request.symbol.id, element => {
Expand Down
Loading

0 comments on commit 900d58b

Please sign in to comment.