mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-30 21:41:46 +01:00
Auto convert let -> const in base/node
This commit is contained in:
@@ -24,8 +24,8 @@ export class LineDecoder {
|
||||
}
|
||||
|
||||
public write(buffer: Buffer): string[] {
|
||||
let result: string[] = [];
|
||||
let value = this.remaining
|
||||
const result: string[] = [];
|
||||
const value = this.remaining
|
||||
? this.remaining + this.stringDecoder.write(buffer)
|
||||
: this.stringDecoder.write(buffer);
|
||||
|
||||
@@ -41,7 +41,7 @@ export class LineDecoder {
|
||||
result.push(value.substring(start, idx));
|
||||
idx++;
|
||||
if (idx < value.length) {
|
||||
let lastChar = ch;
|
||||
const lastChar = ch;
|
||||
ch = value.charCodeAt(idx);
|
||||
if ((lastChar === CharCode.CarriageReturn && ch === CharCode.LineFeed) || (lastChar === CharCode.LineFeed && ch === CharCode.CarriageReturn)) {
|
||||
idx++;
|
||||
|
||||
@@ -10,8 +10,8 @@ import * as assert from 'assert';
|
||||
* array to the callback (callback). The resulting errors and results are evaluated by calling the provided callback function.
|
||||
*/
|
||||
export function parallel<T, E>(list: T[], fn: (item: T, callback: (err: Error | null, result: E | null) => void) => void, callback: (err: Array<Error | null> | null, result: E[]) => void): void {
|
||||
let results = new Array(list.length);
|
||||
let errors = new Array<Error | null>(list.length);
|
||||
const results = new Array(list.length);
|
||||
const errors = new Array<Error | null>(list.length);
|
||||
let didErrorOccur = false;
|
||||
let doneCount = 0;
|
||||
|
||||
@@ -68,9 +68,9 @@ export function loop<E>(param: any, fn: (item: any, callback: (error: Error | nu
|
||||
|
||||
// Expect the param to be an array and loop over it
|
||||
else {
|
||||
let results: E[] = [];
|
||||
const results: E[] = [];
|
||||
|
||||
let looper: (i: number) => void = function (i: number): void {
|
||||
const looper: (i: number) => void = function (i: number): void {
|
||||
|
||||
// Still work to do
|
||||
if (i < param.length) {
|
||||
@@ -126,11 +126,11 @@ function Sequence(sequences: { (...param: any[]): void; }[]): void {
|
||||
});
|
||||
|
||||
// Execute in Loop
|
||||
let errorHandler = sequences.splice(0, 1)[0]; //Remove error handler
|
||||
const errorHandler = sequences.splice(0, 1)[0]; //Remove error handler
|
||||
let sequenceResult: any = null;
|
||||
|
||||
loop(sequences, (sequence, clb) => {
|
||||
let sequenceFunction = function (error: any, result: any): void {
|
||||
const sequenceFunction = function (error: any, result: any): void {
|
||||
|
||||
// A method might only send a boolean value as return value (e.g. fs.exists), support this case gracefully
|
||||
if (error === true || error === false) {
|
||||
|
||||
@@ -9,8 +9,8 @@ import * as net from 'net';
|
||||
* @returns Returns a random port between 1025 and 65535.
|
||||
*/
|
||||
export function randomPort(): number {
|
||||
let min = 1025;
|
||||
let max = 65535;
|
||||
const min = 1025;
|
||||
const max = 65535;
|
||||
return min + Math.floor((max - min) * Math.random());
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ function getWindowsCode(status: number): TerminateResponseCode {
|
||||
export function terminateProcess(process: cp.ChildProcess, cwd?: string): TerminateResponse {
|
||||
if (Platform.isWindows) {
|
||||
try {
|
||||
let options: any = {
|
||||
const options: any = {
|
||||
stdio: ['pipe', 'pipe', 'ignore']
|
||||
};
|
||||
if (cwd) {
|
||||
@@ -54,8 +54,8 @@ export function terminateProcess(process: cp.ChildProcess, cwd?: string): Termin
|
||||
}
|
||||
} else if (Platform.isLinux || Platform.isMacintosh) {
|
||||
try {
|
||||
let cmd = getPathFromAmdModule(require, 'vs/base/node/terminateProcess.sh');
|
||||
let result = cp.spawnSync(cmd, [process.pid.toString()]);
|
||||
const cmd = getPathFromAmdModule(require, 'vs/base/node/terminateProcess.sh');
|
||||
const result = cp.spawnSync(cmd, [process.pid.toString()]);
|
||||
if (result.error) {
|
||||
return { success: false, error: result.error };
|
||||
}
|
||||
@@ -113,7 +113,7 @@ export abstract class AbstractProcess<TProgressData> {
|
||||
this.shell = arg3;
|
||||
this.options = arg4;
|
||||
} else {
|
||||
let executable = <Executable>arg1;
|
||||
const executable = <Executable>arg1;
|
||||
this.cmd = executable.command;
|
||||
this.shell = executable.isShellCommand;
|
||||
this.args = executable.args.slice(0);
|
||||
@@ -124,7 +124,7 @@ export abstract class AbstractProcess<TProgressData> {
|
||||
this.terminateRequested = false;
|
||||
|
||||
if (this.options.env) {
|
||||
let newEnv: IStringDictionary<string> = Object.create(null);
|
||||
const newEnv: IStringDictionary<string> = Object.create(null);
|
||||
Object.keys(process.env).forEach((key) => {
|
||||
newEnv[key] = process.env[key]!;
|
||||
});
|
||||
@@ -137,7 +137,7 @@ export abstract class AbstractProcess<TProgressData> {
|
||||
|
||||
public getSanitizedCommand(): string {
|
||||
let result = this.cmd.toLowerCase();
|
||||
let index = result.lastIndexOf(path.sep);
|
||||
const index = result.lastIndexOf(path.sep);
|
||||
if (index !== -1) {
|
||||
result = result.substring(index + 1);
|
||||
}
|
||||
@@ -154,7 +154,7 @@ export abstract class AbstractProcess<TProgressData> {
|
||||
return this.useExec().then((useExec) => {
|
||||
let cc: ValueCallback<SuccessData>;
|
||||
let ee: ErrorCallback;
|
||||
let result = new Promise<any>((c, e) => {
|
||||
const result = new Promise<any>((c, e) => {
|
||||
cc = c;
|
||||
ee = e;
|
||||
});
|
||||
@@ -166,7 +166,7 @@ export abstract class AbstractProcess<TProgressData> {
|
||||
}
|
||||
this.childProcess = cp.exec(cmd, this.options, (error, stdout, stderr) => {
|
||||
this.childProcess = null;
|
||||
let err: any = error;
|
||||
const err: any = error;
|
||||
// This is tricky since executing a command shell reports error back in case the executed command return an
|
||||
// error or the command didn't exist at all. So we can't blindly treat an error as a failed command. So we
|
||||
// always parse the output and report success unless the job got killed.
|
||||
@@ -178,11 +178,11 @@ export abstract class AbstractProcess<TProgressData> {
|
||||
});
|
||||
} else {
|
||||
let childProcess: cp.ChildProcess | null = null;
|
||||
let closeHandler = (data: any) => {
|
||||
const closeHandler = (data: any) => {
|
||||
this.childProcess = null;
|
||||
this.childProcessPromise = null;
|
||||
this.handleClose(data, cc, pp, ee);
|
||||
let result: SuccessData = {
|
||||
const result: SuccessData = {
|
||||
terminated: this.terminateRequested
|
||||
};
|
||||
if (Types.isNumber(data)) {
|
||||
@@ -191,12 +191,12 @@ export abstract class AbstractProcess<TProgressData> {
|
||||
cc(result);
|
||||
};
|
||||
if (this.shell && Platform.isWindows) {
|
||||
let options: any = Objects.deepClone(this.options);
|
||||
const options: any = Objects.deepClone(this.options);
|
||||
options.windowsVerbatimArguments = true;
|
||||
options.detached = false;
|
||||
let quotedCommand: boolean = false;
|
||||
let quotedArg: boolean = false;
|
||||
let commandLine: string[] = [];
|
||||
const commandLine: string[] = [];
|
||||
let quoted = this.ensureQuotes(this.cmd);
|
||||
commandLine.push(quoted.value);
|
||||
quotedCommand = quoted.quoted;
|
||||
@@ -207,7 +207,7 @@ export abstract class AbstractProcess<TProgressData> {
|
||||
quotedArg = quotedArg && quoted.quoted;
|
||||
});
|
||||
}
|
||||
let args: string[] = [
|
||||
const args: string[] = [
|
||||
'/s',
|
||||
'/c',
|
||||
];
|
||||
@@ -287,7 +287,7 @@ export abstract class AbstractProcess<TProgressData> {
|
||||
}
|
||||
return this.childProcessPromise.then((childProcess) => {
|
||||
this.terminateRequested = true;
|
||||
let result = terminateProcess(childProcess, this.options.cwd);
|
||||
const result = terminateProcess(childProcess, this.options.cwd);
|
||||
if (result.success) {
|
||||
this.childProcess = null;
|
||||
}
|
||||
@@ -302,7 +302,7 @@ export abstract class AbstractProcess<TProgressData> {
|
||||
if (!this.shell || !Platform.isWindows) {
|
||||
return c(false);
|
||||
}
|
||||
let cmdShell = cp.spawn(getWindowsShell(), ['/s', '/c']);
|
||||
const cmdShell = cp.spawn(getWindowsShell(), ['/s', '/c']);
|
||||
cmdShell.on('error', (error: Error) => {
|
||||
return c(true);
|
||||
});
|
||||
@@ -326,12 +326,12 @@ export class LineProcess extends AbstractProcess<LineData> {
|
||||
|
||||
protected handleExec(cc: ValueCallback<SuccessData>, pp: ProgressCallback<LineData>, error: Error, stdout: Buffer, stderr: Buffer) {
|
||||
[stdout, stderr].forEach((buffer: Buffer, index: number) => {
|
||||
let lineDecoder = new LineDecoder();
|
||||
let lines = lineDecoder.write(buffer);
|
||||
const lineDecoder = new LineDecoder();
|
||||
const lines = lineDecoder.write(buffer);
|
||||
lines.forEach((line) => {
|
||||
pp({ line: line, source: index === 0 ? Source.stdout : Source.stderr });
|
||||
});
|
||||
let line = lineDecoder.end();
|
||||
const line = lineDecoder.end();
|
||||
if (line) {
|
||||
pp({ line: line, source: index === 0 ? Source.stdout : Source.stderr });
|
||||
}
|
||||
@@ -343,11 +343,11 @@ export class LineProcess extends AbstractProcess<LineData> {
|
||||
this.stdoutLineDecoder = new LineDecoder();
|
||||
this.stderrLineDecoder = new LineDecoder();
|
||||
childProcess.stdout.on('data', (data: Buffer) => {
|
||||
let lines = this.stdoutLineDecoder.write(data);
|
||||
const lines = this.stdoutLineDecoder.write(data);
|
||||
lines.forEach(line => pp({ line: line, source: Source.stdout }));
|
||||
});
|
||||
childProcess.stderr.on('data', (data: Buffer) => {
|
||||
let lines = this.stderrLineDecoder.write(data);
|
||||
const lines = this.stderrLineDecoder.write(data);
|
||||
lines.forEach(line => pp({ line: line, source: Source.stderr }));
|
||||
});
|
||||
}
|
||||
@@ -380,7 +380,7 @@ export function createQueuedSender(childProcess: cp.ChildProcess): IQueuedSender
|
||||
return;
|
||||
}
|
||||
|
||||
let result = childProcess.send(msg, (error: Error) => {
|
||||
const result = childProcess.send(msg, (error: Error) => {
|
||||
if (error) {
|
||||
console.error(error); // unlikely to happen, best we can do is log this error
|
||||
}
|
||||
@@ -412,7 +412,7 @@ export namespace win32 {
|
||||
if (cwd === undefined) {
|
||||
cwd = process.cwd();
|
||||
}
|
||||
let dir = path.dirname(command);
|
||||
const dir = path.dirname(command);
|
||||
if (dir !== '.') {
|
||||
// We have a directory and the directory is relative (see above). Make the path absolute
|
||||
// to the current working directory.
|
||||
|
||||
@@ -151,7 +151,7 @@ export function listProcesses(rootPid: number): Promise<ProcessItem> {
|
||||
rootItem = processItems.get(rootPid);
|
||||
if (rootItem) {
|
||||
processItems.forEach(item => {
|
||||
let parent = processItems.get(item.ppid);
|
||||
const parent = processItems.get(item.ppid);
|
||||
if (parent) {
|
||||
if (!parent.children) {
|
||||
parent.children = [];
|
||||
@@ -186,7 +186,7 @@ export function listProcesses(rootPid: number): Promise<ProcessItem> {
|
||||
|
||||
const lines = stdout.toString().split('\n');
|
||||
for (const line of lines) {
|
||||
let matches = PID_CMD.exec(line.trim());
|
||||
const matches = PID_CMD.exec(line.trim());
|
||||
if (matches && matches.length === 6) {
|
||||
addToTree(parseInt(matches[1]), parseInt(matches[2]), matches[5], parseFloat(matches[3]), parseFloat(matches[4]));
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ export function asText(context: IRequestContext): Promise<string | null> {
|
||||
return c(null);
|
||||
}
|
||||
|
||||
let buffer: string[] = [];
|
||||
const buffer: string[] = [];
|
||||
context.stream.on('data', (d: string) => buffer.push(d));
|
||||
context.stream.on('end', () => c(buffer.join('')));
|
||||
context.stream.on('error', e);
|
||||
|
||||
@@ -21,15 +21,15 @@ export interface WorkspaceStats {
|
||||
}
|
||||
|
||||
function asSortedItems(map: Map<string, number>): WorkspaceStatItem[] {
|
||||
let a: WorkspaceStatItem[] = [];
|
||||
const a: WorkspaceStatItem[] = [];
|
||||
map.forEach((value, index) => a.push({ name: index, count: value }));
|
||||
return a.sort((a, b) => b.count - a.count);
|
||||
}
|
||||
|
||||
export function collectLaunchConfigs(folder: string): Promise<WorkspaceStatItem[]> {
|
||||
let launchConfigs = new Map<string, number>();
|
||||
const launchConfigs = new Map<string, number>();
|
||||
|
||||
let launchConfig = join(folder, '.vscode', 'launch.json');
|
||||
const launchConfig = join(folder, '.vscode', 'launch.json');
|
||||
return new Promise((resolve, reject) => {
|
||||
exists(launchConfig, (doesExist) => {
|
||||
if (doesExist) {
|
||||
@@ -87,8 +87,8 @@ export async function collectWorkspaceStats(folder: string, filter: string[]): P
|
||||
{ 'tag': 'cmake', 'pattern': /^.+\.cmake$/i }
|
||||
];
|
||||
|
||||
let fileTypes = new Map<string, number>();
|
||||
let configFiles = new Map<string, number>();
|
||||
const fileTypes = new Map<string, number>();
|
||||
const configFiles = new Map<string, number>();
|
||||
|
||||
const MAX_FILES = 20000;
|
||||
|
||||
@@ -149,7 +149,7 @@ export async function collectWorkspaceStats(folder: string, filter: string[]): P
|
||||
});
|
||||
}
|
||||
|
||||
let addFileType = (fileType: string) => {
|
||||
const addFileType = (fileType: string) => {
|
||||
if (fileTypes.has(fileType)) {
|
||||
fileTypes.set(fileType, fileTypes.get(fileType)! + 1);
|
||||
}
|
||||
@@ -158,7 +158,7 @@ export async function collectWorkspaceStats(folder: string, filter: string[]): P
|
||||
}
|
||||
};
|
||||
|
||||
let addConfigFiles = (fileName: string) => {
|
||||
const addConfigFiles = (fileName: string) => {
|
||||
for (const each of configFilePatterns) {
|
||||
if (each.pattern.test(fileName)) {
|
||||
if (configFiles.has(each.tag)) {
|
||||
@@ -170,9 +170,9 @@ export async function collectWorkspaceStats(folder: string, filter: string[]): P
|
||||
}
|
||||
};
|
||||
|
||||
let acceptFile = (name: string) => {
|
||||
const acceptFile = (name: string) => {
|
||||
if (name.lastIndexOf('.') >= 0) {
|
||||
let suffix: string | undefined = name.split('.').pop();
|
||||
const suffix: string | undefined = name.split('.').pop();
|
||||
if (suffix) {
|
||||
addFileType(suffix);
|
||||
}
|
||||
@@ -180,13 +180,13 @@ export async function collectWorkspaceStats(folder: string, filter: string[]): P
|
||||
addConfigFiles(name);
|
||||
};
|
||||
|
||||
let token: { count: number, maxReached: boolean } = { count: 0, maxReached: false };
|
||||
const token: { count: number, maxReached: boolean } = { count: 0, maxReached: false };
|
||||
|
||||
return new Promise((resolve, reject) => {
|
||||
walk(folder, filter, token, async (files) => {
|
||||
files.forEach(acceptFile);
|
||||
|
||||
let launchConfigs = await collectLaunchConfigs(folder);
|
||||
const launchConfigs = await collectLaunchConfigs(folder);
|
||||
|
||||
resolve({
|
||||
configFiles: asSortedItems(configFiles),
|
||||
|
||||
@@ -92,7 +92,7 @@ export function readToMatchingString(file: string, matchingString: string, chunk
|
||||
});
|
||||
}
|
||||
|
||||
let buffer = Buffer.allocUnsafe(maximumBytesToRead);
|
||||
const buffer = Buffer.allocUnsafe(maximumBytesToRead);
|
||||
let offset = 0;
|
||||
|
||||
function readChunk(): void {
|
||||
|
||||
@@ -49,7 +49,7 @@ export class ExtractError extends Error {
|
||||
}
|
||||
|
||||
function modeFromEntry(entry: Entry) {
|
||||
let attr = entry.externalFileAttributes >> 16 || 33188;
|
||||
const attr = entry.externalFileAttributes >> 16 || 33188;
|
||||
|
||||
return [448 /* S_IRWXU */, 56 /* S_IRWXG */, 7 /* S_IRWXO */]
|
||||
.map(mask => attr & mask)
|
||||
|
||||
Reference in New Issue
Block a user