repl: add autocomplete support for fs.promises
PR-URL: https://github.com/nodejs/node/pull/29400 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
This commit is contained in:
parent
5de1052dc9
commit
ed0e5c8c74
@ -1005,6 +1005,7 @@ ArrayStream.prototype.resume = function() {};
|
||||
ArrayStream.prototype.write = function() {};
|
||||
|
||||
const requireRE = /\brequire\s*\(['"](([\w@./-]+\/)?(?:[\w@./-]*))/;
|
||||
const fsAutoCompleteRE = /fs(?:\.promises)?\.\s*[a-z][a-zA-Z]+\(\s*["'](.*)/;
|
||||
const simpleExpressionRE =
|
||||
/(?:[a-zA-Z_$](?:\w|\$)*\.)*[a-zA-Z_$](?:\w|\$)*\.?$/;
|
||||
|
||||
@ -1173,7 +1174,7 @@ function complete(line, callback) {
|
||||
}
|
||||
|
||||
completionGroupsLoaded();
|
||||
} else if (match = line.match(/fs\.\s*[a-z][a-zA-Z]+\(\s*["'](.*)/)) {
|
||||
} else if (match = line.match(fsAutoCompleteRE)) {
|
||||
|
||||
let filePath = match[1];
|
||||
let fileList;
|
||||
|
@ -402,37 +402,39 @@ testMe.complete('obj.', common.mustCall((error, data) => {
|
||||
putIn.run(['.clear']);
|
||||
process.chdir(__dirname);
|
||||
|
||||
const readFileSync = 'fs.readFileSync("';
|
||||
const fixturePath = `${readFileSync}../fixtures/test-repl-tab-completion`;
|
||||
const readFileSyncs = ['fs.readFileSync("', 'fs.promises.readFileSync("'];
|
||||
if (!common.isWindows) {
|
||||
testMe.complete(fixturePath, common.mustCall((err, data) => {
|
||||
assert.strictEqual(err, null);
|
||||
assert.ok(data[0][0].includes('.hiddenfiles'));
|
||||
assert.ok(data[0][1].includes('hellorandom.txt'));
|
||||
assert.ok(data[0][2].includes('helloworld.js'));
|
||||
}));
|
||||
readFileSyncs.forEach((readFileSync) => {
|
||||
const fixturePath = `${readFileSync}../fixtures/test-repl-tab-completion`;
|
||||
testMe.complete(fixturePath, common.mustCall((err, data) => {
|
||||
assert.strictEqual(err, null);
|
||||
assert.ok(data[0][0].includes('.hiddenfiles'));
|
||||
assert.ok(data[0][1].includes('hellorandom.txt'));
|
||||
assert.ok(data[0][2].includes('helloworld.js'));
|
||||
}));
|
||||
|
||||
testMe.complete(`${fixturePath}/hello`,
|
||||
common.mustCall((err, data) => {
|
||||
assert.strictEqual(err, null);
|
||||
assert.ok(data[0][0].includes('hellorandom.txt'));
|
||||
assert.ok(data[0][1].includes('helloworld.js'));
|
||||
})
|
||||
);
|
||||
testMe.complete(`${fixturePath}/hello`,
|
||||
common.mustCall((err, data) => {
|
||||
assert.strictEqual(err, null);
|
||||
assert.ok(data[0][0].includes('hellorandom.txt'));
|
||||
assert.ok(data[0][1].includes('helloworld.js'));
|
||||
})
|
||||
);
|
||||
|
||||
testMe.complete(`${fixturePath}/.h`,
|
||||
common.mustCall((err, data) => {
|
||||
assert.strictEqual(err, null);
|
||||
assert.ok(data[0][0].includes('.hiddenfiles'));
|
||||
})
|
||||
);
|
||||
testMe.complete(`${fixturePath}/.h`,
|
||||
common.mustCall((err, data) => {
|
||||
assert.strictEqual(err, null);
|
||||
assert.ok(data[0][0].includes('.hiddenfiles'));
|
||||
})
|
||||
);
|
||||
|
||||
testMe.complete(`${readFileSync}./xxxRandom/random`,
|
||||
common.mustCall((err, data) => {
|
||||
assert.strictEqual(err, null);
|
||||
assert.strictEqual(data[0].length, 0);
|
||||
})
|
||||
);
|
||||
testMe.complete(`${readFileSync}./xxxRandom/random`,
|
||||
common.mustCall((err, data) => {
|
||||
assert.strictEqual(err, null);
|
||||
assert.strictEqual(data[0].length, 0);
|
||||
})
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user