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() {};
|
ArrayStream.prototype.write = function() {};
|
||||||
|
|
||||||
const requireRE = /\brequire\s*\(['"](([\w@./-]+\/)?(?:[\w@./-]*))/;
|
const requireRE = /\brequire\s*\(['"](([\w@./-]+\/)?(?:[\w@./-]*))/;
|
||||||
|
const fsAutoCompleteRE = /fs(?:\.promises)?\.\s*[a-z][a-zA-Z]+\(\s*["'](.*)/;
|
||||||
const simpleExpressionRE =
|
const simpleExpressionRE =
|
||||||
/(?:[a-zA-Z_$](?:\w|\$)*\.)*[a-zA-Z_$](?:\w|\$)*\.?$/;
|
/(?:[a-zA-Z_$](?:\w|\$)*\.)*[a-zA-Z_$](?:\w|\$)*\.?$/;
|
||||||
|
|
||||||
@ -1173,7 +1174,7 @@ function complete(line, callback) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
completionGroupsLoaded();
|
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 filePath = match[1];
|
||||||
let fileList;
|
let fileList;
|
||||||
|
@ -402,37 +402,39 @@ testMe.complete('obj.', common.mustCall((error, data) => {
|
|||||||
putIn.run(['.clear']);
|
putIn.run(['.clear']);
|
||||||
process.chdir(__dirname);
|
process.chdir(__dirname);
|
||||||
|
|
||||||
const readFileSync = 'fs.readFileSync("';
|
const readFileSyncs = ['fs.readFileSync("', 'fs.promises.readFileSync("'];
|
||||||
const fixturePath = `${readFileSync}../fixtures/test-repl-tab-completion`;
|
|
||||||
if (!common.isWindows) {
|
if (!common.isWindows) {
|
||||||
testMe.complete(fixturePath, common.mustCall((err, data) => {
|
readFileSyncs.forEach((readFileSync) => {
|
||||||
assert.strictEqual(err, null);
|
const fixturePath = `${readFileSync}../fixtures/test-repl-tab-completion`;
|
||||||
assert.ok(data[0][0].includes('.hiddenfiles'));
|
testMe.complete(fixturePath, common.mustCall((err, data) => {
|
||||||
assert.ok(data[0][1].includes('hellorandom.txt'));
|
assert.strictEqual(err, null);
|
||||||
assert.ok(data[0][2].includes('helloworld.js'));
|
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`,
|
testMe.complete(`${fixturePath}/hello`,
|
||||||
common.mustCall((err, data) => {
|
common.mustCall((err, data) => {
|
||||||
assert.strictEqual(err, null);
|
assert.strictEqual(err, null);
|
||||||
assert.ok(data[0][0].includes('hellorandom.txt'));
|
assert.ok(data[0][0].includes('hellorandom.txt'));
|
||||||
assert.ok(data[0][1].includes('helloworld.js'));
|
assert.ok(data[0][1].includes('helloworld.js'));
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
testMe.complete(`${fixturePath}/.h`,
|
testMe.complete(`${fixturePath}/.h`,
|
||||||
common.mustCall((err, data) => {
|
common.mustCall((err, data) => {
|
||||||
assert.strictEqual(err, null);
|
assert.strictEqual(err, null);
|
||||||
assert.ok(data[0][0].includes('.hiddenfiles'));
|
assert.ok(data[0][0].includes('.hiddenfiles'));
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
testMe.complete(`${readFileSync}./xxxRandom/random`,
|
testMe.complete(`${readFileSync}./xxxRandom/random`,
|
||||||
common.mustCall((err, data) => {
|
common.mustCall((err, data) => {
|
||||||
assert.strictEqual(err, null);
|
assert.strictEqual(err, null);
|
||||||
assert.strictEqual(data[0].length, 0);
|
assert.strictEqual(data[0].length, 0);
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user