summaryrefslogtreecommitdiff
path: root/lib/repl.js
diff options
context:
space:
mode:
authorAnto Aravinth <anto.aravinth.cse@gmail.com>2019-04-25 20:14:47 +0530
committerAnto Aravinth <anto.aravinth.cse@gmail.com>2019-04-29 07:28:27 +0530
commitd69f00465790f1ac7788ac111bb61689543536ae (patch)
tree33bb84b6f50b5d29198bfa82aca628b6d6a28425 /lib/repl.js
parent377939eef847d2475768c0db0b3eb1a699f545f1 (diff)
downloadnode-new-d69f00465790f1ac7788ac111bb61689543536ae.tar.gz
repl: add autocomplete for filesystem modules
PR-URL: https://github.com/nodejs/node/pull/26648 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Diffstat (limited to 'lib/repl.js')
-rw-r--r--lib/repl.js23
1 files changed, 23 insertions, 0 deletions
diff --git a/lib/repl.js b/lib/repl.js
index a7eb22e396..d439d205a4 100644
--- a/lib/repl.js
+++ b/lib/repl.js
@@ -1118,7 +1118,30 @@ function complete(line, callback) {
}
completionGroupsLoaded();
+ } else if (match = line.match(/fs\.\s*[a-z][a-zA-Z]+\(\s*["'](.*)/)) {
+ let filePath = match[1];
+ let fileList;
+ filter = '';
+
+ try {
+ fileList = fs.readdirSync(filePath, { withFileTypes: true });
+ completionGroups.push(fileList.map((dirent) => dirent.name));
+ completeOn = '';
+ } catch {
+ try {
+ const baseName = path.basename(filePath);
+ filePath = path.dirname(filePath);
+ fileList = fs.readdirSync(filePath, { withFileTypes: true });
+ const filteredValue = fileList.filter((d) =>
+ d.name.startsWith(baseName))
+ .map((d) => d.name);
+ completionGroups.push(filteredValue);
+ completeOn = filePath;
+ } catch {}
+ }
+
+ completionGroupsLoaded();
// Handle variable member lookup.
// We support simple chained expressions like the following (no function
// calls, etc.). That is for simplicity and also because we *eval* that