-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
repl: include folder extensions in autocomplete #14727
repl: include folder extensions in autocomplete #14727
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM if CI passes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. It might be possible to reuse existing fixtures instead of creating new ones, but not a big deal.
EDIT: Disregard my comment about reusing an existing fixture :-)
lib/repl.js
Outdated
@@ -851,14 +851,15 @@ function complete(line, callback) { | |||
// Exclude versioned names that 'npm' installs. | |||
continue; | |||
} | |||
if (exts.indexOf(ext) !== -1) { | |||
abs = path.resolve(dir, name); | |||
isDirectory = fs.statSync(abs).isDirectory(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking at this again, I'm wondering if this should be moved back into a try-catch to avoid creating an error if the path doesn't exist.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be a race condition that is hart to trigger but as there was a guard for this before I would say it should be kept as it was.
lib/repl.js
Outdated
@@ -851,14 +851,15 @@ function complete(line, callback) { | |||
// Exclude versioned names that 'npm' installs. | |||
continue; | |||
} | |||
if (exts.indexOf(ext) !== -1) { | |||
abs = path.resolve(dir, name); | |||
isDirectory = fs.statSync(abs).isDirectory(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be a race condition that is hart to trigger but as there was a guard for this before I would say it should be kept as it was.
lib/repl.js
Outdated
if (!subdir || base !== 'index') { | ||
group.push(subdir + base); | ||
} | ||
} else { | ||
abs = path.resolve(dir, name); | ||
try { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The try
should be moved into the if statement as it is not necessary for non directories.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM with a nit.
lib/repl.js
Outdated
if (!subdir || base !== 'index') { | ||
group.push(subdir + base); | ||
} | ||
} else { | ||
abs = path.resolve(dir, name); | ||
} else if (isDirectory) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: you could get rid of one of the isDirectory
checks (the churn is there anyway).
if (isDirectory) {
// ...
} else if (exts.includes(ext)) {
// ...
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Still LGTM 👍
31e2174
to
b646a3d
Compare
When autocompleting `require` calls, the repl strips .js file extensions from results. However, stripping an extension from a directory results in an error. Update the autocompletion logic to avoid stripping extensions from directories. PR-URL: nodejs#14727 Fixes: nodejs#14726 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Alexey Orlenko <[email protected]>
Landed in b646a3d |
When autocompleting `require` calls, the repl strips .js file extensions from results. However, stripping an extension from a directory results in an error. Update the autocompletion logic to avoid stripping extensions from directories. PR-URL: #14727 Fixes: #14726 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]> Reviewed-By: Alexey Orlenko <[email protected]>
Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
repl
When autocompleting
require
calls, the repl strips .js file extensions from results. However, stripping an extension from a directory results in an error whenrequire
is called. Update the autocompletion logic to avoid stripping extensions from directories.Fixes: #14726