Skip to content

Commit 596dd9f

Browse files
antsmartianBridgeAR
authored andcommitted
repl: add autocomplete support for fs.promises
PR-URL: #29400 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Yongsheng Zhang <[email protected]>
1 parent 7bc2f06 commit 596dd9f

File tree

2 files changed

+33
-30
lines changed

2 files changed

+33
-30
lines changed

lib/repl.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,7 @@ ArrayStream.prototype.resume = function() {};
10051005
ArrayStream.prototype.write = function() {};
10061006

10071007
const requireRE = /\brequire\s*\(['"](([\w@./-]+\/)?(?:[\w@./-]*))/;
1008+
const fsAutoCompleteRE = /fs(?:\.promises)?\.\s*[a-z][a-zA-Z]+\(\s*["'](.*)/;
10081009
const simpleExpressionRE =
10091010
/(?:[a-zA-Z_$](?:\w|\$)*\.)*[a-zA-Z_$](?:\w|\$)*\.?$/;
10101011

@@ -1173,7 +1174,7 @@ function complete(line, callback) {
11731174
}
11741175

11751176
completionGroupsLoaded();
1176-
} else if (match = line.match(/fs\.\s*[a-z][a-zA-Z]+\(\s*["'](.*)/)) {
1177+
} else if (match = line.match(fsAutoCompleteRE)) {
11771178

11781179
let filePath = match[1];
11791180
let fileList;

test/parallel/test-repl-tab-complete.js

+31-29
Original file line numberDiff line numberDiff line change
@@ -402,37 +402,39 @@ testMe.complete('obj.', common.mustCall((error, data) => {
402402
putIn.run(['.clear']);
403403
process.chdir(__dirname);
404404

405-
const readFileSync = 'fs.readFileSync("';
406-
const fixturePath = `${readFileSync}../fixtures/test-repl-tab-completion`;
405+
const readFileSyncs = ['fs.readFileSync("', 'fs.promises.readFileSync("'];
407406
if (!common.isWindows) {
408-
testMe.complete(fixturePath, common.mustCall((err, data) => {
409-
assert.strictEqual(err, null);
410-
assert.ok(data[0][0].includes('.hiddenfiles'));
411-
assert.ok(data[0][1].includes('hellorandom.txt'));
412-
assert.ok(data[0][2].includes('helloworld.js'));
413-
}));
407+
readFileSyncs.forEach((readFileSync) => {
408+
const fixturePath = `${readFileSync}../fixtures/test-repl-tab-completion`;
409+
testMe.complete(fixturePath, common.mustCall((err, data) => {
410+
assert.strictEqual(err, null);
411+
assert.ok(data[0][0].includes('.hiddenfiles'));
412+
assert.ok(data[0][1].includes('hellorandom.txt'));
413+
assert.ok(data[0][2].includes('helloworld.js'));
414+
}));
414415

415-
testMe.complete(`${fixturePath}/hello`,
416-
common.mustCall((err, data) => {
417-
assert.strictEqual(err, null);
418-
assert.ok(data[0][0].includes('hellorandom.txt'));
419-
assert.ok(data[0][1].includes('helloworld.js'));
420-
})
421-
);
422-
423-
testMe.complete(`${fixturePath}/.h`,
424-
common.mustCall((err, data) => {
425-
assert.strictEqual(err, null);
426-
assert.ok(data[0][0].includes('.hiddenfiles'));
427-
})
428-
);
429-
430-
testMe.complete(`${readFileSync}./xxxRandom/random`,
431-
common.mustCall((err, data) => {
432-
assert.strictEqual(err, null);
433-
assert.strictEqual(data[0].length, 0);
434-
})
435-
);
416+
testMe.complete(`${fixturePath}/hello`,
417+
common.mustCall((err, data) => {
418+
assert.strictEqual(err, null);
419+
assert.ok(data[0][0].includes('hellorandom.txt'));
420+
assert.ok(data[0][1].includes('helloworld.js'));
421+
})
422+
);
423+
424+
testMe.complete(`${fixturePath}/.h`,
425+
common.mustCall((err, data) => {
426+
assert.strictEqual(err, null);
427+
assert.ok(data[0][0].includes('.hiddenfiles'));
428+
})
429+
);
430+
431+
testMe.complete(`${readFileSync}./xxxRandom/random`,
432+
common.mustCall((err, data) => {
433+
assert.strictEqual(err, null);
434+
assert.strictEqual(data[0].length, 0);
435+
})
436+
);
437+
});
436438
}
437439
}
438440

0 commit comments

Comments
 (0)