Skip to content
This repository was archived by the owner on Apr 22, 2023. It is now read-only.

repl: added support for custom completions#8484

Closed
diosney wants to merge 1 commit intonodejs:masterfrom
diosney:repl-add-custom-completion-support
Closed

repl: added support for custom completions#8484
diosney wants to merge 1 commit intonodejs:masterfrom
diosney:repl-add-custom-completion-support

Conversation

@diosney
Copy link
Copy Markdown

@diosney diosney commented Oct 1, 2014

Currently I'm working on a project that uses the REPL to implement a mid complex CLI app found out that the REPL module doesn't have a way to override the default complete() function, which is used for TAB completions of commands.

I think that the REPL module can benefit from this addition, and specifically the repl applications that may wants to use this functionality.

I added the docs & tests, and the tests passed fine in my environment, this is just a little change, after all.

@diosney
Copy link
Copy Markdown
Author

diosney commented Oct 1, 2014

Simple example:

var repl = require('repl')
  .start({
    terminal : true,
    completer: function completer(line) {
      var completions = 'aaa aa1 aa2 bbb ccc ddd eee'.split(' ');

      var hits = completions.filter(function (item) {
        return item.indexOf(line) == 0;
      });

      // Show all completions if none was found.
      return [
        hits.length
          ? hits
          : completions,
        line
      ];
    }
  });

@diosney
Copy link
Copy Markdown
Author

diosney commented Dec 5, 2014

Hi, any decision on this?.

Comment thread lib/repl.js Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just pass line and callback by name?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to avoid in the future if anyone adds more parameters to the original function but forgot to put them there. A little silly but removes complexity by having only one source of truth.

@cjihrig
Copy link
Copy Markdown

cjihrig commented Dec 5, 2014

It's not up to me, but I'm OK with this change (assuming it works).

@diosney
Copy link
Copy Markdown
Author

diosney commented Dec 5, 2014

OK, thanks for your opinion. I added the related tests too, so test if it works can be done automatically.

@diosney
Copy link
Copy Markdown
Author

diosney commented Feb 18, 2015

Hi, any plans to review this? Thanks

@jasnell
Copy link
Copy Markdown
Member

jasnell commented Feb 20, 2015

Also not up to me to accept it or not but this looks like a good addition.

Comment thread test/simple/test-repl-tab-complete.js Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make this ===

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed. Thanks.

@cjihrig
Copy link
Copy Markdown

cjihrig commented Feb 24, 2015

A few comments, but mostly LGTM. Please squash this down to a single commit. If no one has a problem with this, I'll land it.

@diosney diosney force-pushed the repl-add-custom-completion-support branch from 266bd4f to 231d34d Compare June 13, 2015 21:45
@diosney
Copy link
Copy Markdown
Author

diosney commented Jun 13, 2015

@cjihrig Sorry for the delay, somehow I got noticed right now of your comments about this :( I don't know why was until now that my email client delayed the related github notifications o_O.

Thanks for your comments, I fixed all the pointed issues and squashed the commits into a single one, so, do you think that this feature can land now?

Thanks

Comment thread doc/api/repl.markdown Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we forgetting to include a link here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, at the time I made the PR, that was the way in the other docs that the linking was done, maybe this changed in the meantime. Search in https://raw.githubusercontent.com/joyent/node/master/doc/api/https.markdown for [tls.createServer()][] for an example.

If there is other way to do it, just point me in the rigth direction please, but looking at the docs code I didn't found an example of direct linking.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@thefourtheye Well, I ended direct linking to the page, I searched a bit more through the docs I found a way to do it. Compiled the docs and the links worked as expected.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it seems that it had to be the relative path, something like readline.html#readline_readline_createinterface_options.

@diosney diosney force-pushed the repl-add-custom-completion-support branch from 231d34d to 92d779e Compare June 15, 2015 14:01
@diosney
Copy link
Copy Markdown
Author

diosney commented Jun 15, 2015

@cjihrig OK, links in the docs fixed too, waiting for your approval.

Comment thread lib/repl.js Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to self.completer = typeof options.completer === 'function' ? options.completer : complete; just to ensure that completer is a function.

Edit: You may have to split this across lines if it goes past 80 characters.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@diosney diosney force-pushed the repl-add-custom-completion-support branch from 92d779e to 823dacb Compare June 16, 2015 19:05
@diosney
Copy link
Copy Markdown
Author

diosney commented Jun 18, 2015

@cjihrig Is everything okey now? I hope so :D

Comment thread test/simple/test-repl-tab-complete.js Outdated
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you not need to pass an error argument here?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you mean? Can you be more explicit?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most callbacks take an error as their first argument. Is that not the case here?

@cjihrig
Copy link
Copy Markdown

cjihrig commented Jun 24, 2015

Can you please open this PR against io.js. Since this is a new feature, it no longer makes sense to have it in joyent/node.

@cjihrig cjihrig closed this Jun 24, 2015
@cjihrig
Copy link
Copy Markdown

cjihrig commented Jun 24, 2015

LGTM, by the way.

@diosney
Copy link
Copy Markdown
Author

diosney commented Jun 25, 2015

@cjihrig This is really frustrating man. Seriously. It seems that the Contributing docs have to be updated.

@cjihrig
Copy link
Copy Markdown

cjihrig commented Jun 25, 2015

Sorry, I'm not sure how closely you've been following along, but Node.js is moving into a foundation and merging with io.js. This repo (joyent/node) is going to become a maintenance branch. The new repo will live at nodejs/node. However, the converged repo is not quite ready yet, so new features (such as the one in this PR) are going into io.js.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants