GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — repl: improve require() autocompletion · nodejs/node@3b9fea0

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib
    • repl.js
  • test/parallel
    • test-repl-tab-complete.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/repl.js‎

Copy file name to clipboardExpand all lines: lib/repl.js
+12-1Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,18 @@ function complete(line, callback) {
870870
filter = match[1];
871871
var dir, files, f, name, base, ext, abs, subfiles, s;
872872
group = [];
873-
var paths = module.paths.concat(Module.globalPaths);
873+
let paths = [];
874+
875+
if (completeOn === '.') {
876+
group = ['./', '../'];
877+
} else if (completeOn === '..') {
878+
group = ['../'];
879+
} else if (/^\.\.?\//.test(completeOn)) {
880+
paths = [process.cwd()];
881+
} else {
882+
paths = module.paths.concat(Module.globalPaths);
883+
}
884+
874885
for (i = 0; i < paths.length; i++) {
875886
dir = path.resolve(paths[i], subdir);
876887
try {
Collapse file

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

Copy file name to clipboardExpand all lines: test/parallel/test-repl-tab-complete.js
+50Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,56 @@ testMe.complete('require(\'n', common.mustCall(function(error, data) {
212212
}));
213213
}
214214

215+
// Test tab completion for require() relative to the current directory
216+
{
217+
putIn.run(['.clear']);
218+
219+
const cwd = process.cwd();
220+
process.chdir(__dirname);
221+
222+
['require(\'.', 'require(".'].forEach((input) => {
223+
testMe.complete(input, common.mustCall((err, data) => {
224+
assert.strictEqual(err, null);
225+
assert.strictEqual(data.length, 2);
226+
assert.strictEqual(data[1], '.');
227+
assert.strictEqual(data[0].length, 2);
228+
assert.ok(data[0].includes('./'));
229+
assert.ok(data[0].includes('../'));
230+
}));
231+
});
232+
233+
['require(\'..', 'require("..'].forEach((input) => {
234+
testMe.complete(input, common.mustCall((err, data) => {
235+
assert.strictEqual(err, null);
236+
assert.deepStrictEqual(data, [['../'], '..']);
237+
}));
238+
});
239+
240+
['./', './test-'].forEach((path) => {
241+
[`require('${path}`, `require("${path}`].forEach((input) => {
242+
testMe.complete(input, common.mustCall((err, data) => {
243+
assert.strictEqual(err, null);
244+
assert.strictEqual(data.length, 2);
245+
assert.strictEqual(data[1], path);
246+
assert.ok(data[0].includes('./test-repl-tab-complete'));
247+
}));
248+
});
249+
});
250+
251+
['../parallel/', '../parallel/test-'].forEach((path) => {
252+
[`require('${path}`, `require("${path}`].forEach((input) => {
253+
testMe.complete(input, common.mustCall((err, data) => {
254+
assert.strictEqual(err, null);
255+
assert.strictEqual(data.length, 2);
256+
assert.strictEqual(data[1], path);
257+
assert.ok(data[0].includes('../parallel/test-repl-tab-complete'));
258+
}));
259+
});
260+
});
261+
262+
process.chdir(cwd);
263+
}
264+
215265
// Make sure tab completion works on context properties
216266
putIn.run(['.clear']);
217267

0 commit comments

Comments
0 (0)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.