Skip to content
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: deprecate REPLServer.prototype.turnOffEditorMode #15136

Closed
wants to merge 4 commits into from
Closed

repl: deprecate REPLServer.prototype.turnOffEditorMode #15136

wants to merge 4 commits into from

Conversation

lance
Copy link
Member

@lance lance commented Sep 1, 2017

This commit exposes REPLServer.prototype.turnOnEditorMode() which handles the necessary internal changes to enter editor mode deprecates REPLServer.prototype.turnOffEditorMode() in the REPL, instead of having them scattered about and consolidates some duplicated code for turning on editor mode as a non-public function.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

repl, doc

@nodejs-github-bot nodejs-github-bot added the repl Issues and PRs related to the REPL subsystem. label Sep 1, 2017
@lance lance added doc Issues and PRs related to the documentations. question Issues that look for answers. labels Sep 1, 2017
@benjamingr
Copy link
Member

Why not make it a function instead of a method if the goal is code duplication?

function turnOnEditorMode(repl) {
  repl.editorMode = true;
  REPLServer.super_.prototype.setPrompt.call(repl, '');
}

@lance
Copy link
Member Author

lance commented Sep 1, 2017

@benjamingr this was my original intent, but then I noticed that turnOffEditorMode already existed on the prototype, so I decided on consistency. TBH, I'd prefer to make both of these just plain old functions and hide them from user land. But now that turnOffEditorMode has been in the wild, that's a bit of a pain.

@mscdex mscdex removed doc Issues and PRs related to the documentations. question Issues that look for answers. labels Sep 1, 2017
@benjamingr
Copy link
Member

Pinging @nodejs/ctc regarding an API addition in a stable module.

@BridgeAR
Copy link
Member

BridgeAR commented Sep 1, 2017

I would definitely prefer this to be a private function. I think a good way to handle it would be to deprecate the current R.p.turnOffEditorMode(). A bit cleaning up might be a good idea.

@lance
Copy link
Member Author

lance commented Sep 1, 2017

OK, it seems there is consensus around keeping this private and not adding to the API. I will modify this PR to make turnOnEditorMode a private function, and deprecate REPLServer.prototype.turnOffEditorMode with the eventual goal to have that as a private function as well.

Refs: #7619

@refack
Copy link
Contributor

refack commented Sep 1, 2017

OK, it seems there is consensus around keeping this private and not adding to the API.

I'm not 100% sold on deprecating this this API. editorMode is a nice feature of the REPL, maybe implementors should have a way to turn it on and off.

/cc @Fishrock123

P.S. I could not find any uses of turnOffEditorMode in either Gzemnid or GitHub search.

@lance
Copy link
Member Author

lance commented Sep 4, 2017

@princejwesley I personally prefer a calling syntax like

function _turnOnEditorMode(repl) {
  // do something with repl
}

So that's how I wrote the function. But that doesn't work as far as I know, with util.deprecate(). When using the deprecate() function on an object's method, you use this to access the caller. So, the internal implementation uses that calling style, e.g.

function _turnOffEditorMode() {
  // `this` is the calling context
}

I could modify _turnOnEditorMode() to be consistent, but tbh I'd rather modify _turnOffEditorMode() to not use this once REPLServer.prototype.turnOffEditorMode() is fully deprecated and gone.

Either way works for me.

@lance
Copy link
Member Author

lance commented Sep 4, 2017

@refack REPLServer.prototype.turnOffEditorMode() was only added a year ago, and without documentation, so it's understandable that there is not wide (or any known) usage of it. Plus, it wasn't very useful as it was without a corresponding REPLServer.prototype.turnOnEditorMode() which does not exist. Unless we really want to add a new feature, I'd lean towards eliminating public API rather than adding one of perhaps questionable usefulness.

@lance
Copy link
Member Author

lance commented Sep 7, 2017

@BridgeAR @princejwesley @refack ping.

I hope I have answered your questions. And if not, let me know what specific actions you think I should take.

@benjamingr as it is now, with my recent changes, this does not add any API to the REPLServer. I'll update the PR description to reflect that. It does deprecate a currently unpublished method on REPLServer.prototype, so I'm not sure what this means with regard to @nodejs/tsc involvement/approval.

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

In general this is the right approach out of my perspective. Having two different kinds of function calls is a bit ugly though and the deprecation must be documented.

lib/repl.js Outdated
};

REPLServer.prototype.turnOffEditorMode = util.deprecate(
_turnOffEditorMode,
Copy link
Member

Choose a reason for hiding this comment

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

I think it would be nicer to have _turnOffEditorMode(this); (or self) instead of _turnOffEditorMode.call(this);
It is weird that turnOn and turnOff works differently.

In that case the prototype function would have to be changed to look somewhat like

function () {
  _turnOffEditorMode(this);
}

lib/repl.js Outdated
REPLServer.prototype.turnOffEditorMode = util.deprecate(
_turnOffEditorMode,
'REPLServer.turnOffEditorMode() is deprecated',
'DEP00XX');
Copy link
Member

Choose a reason for hiding this comment

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

The deprecation must be documented as well in the deprecations.md.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes and deprecations are semver-major.

@BridgeAR BridgeAR added the semver-major PRs that contain breaking changes and should be released in the next major version. label Sep 7, 2017
@lance lance changed the title repl: eliminate code duplication for editorMode repl: deprecate REPLServer.prototype.turnOffEditorMode Sep 8, 2017
@lance
Copy link
Member Author

lance commented Sep 8, 2017

Code updated and deprecation documentation added.
CI: https://ci.nodejs.org/job/node-test-pull-request/10003/


Edit: Single CI failure on smartos seems to be unrelated

not ok 117 parallel/test-benchmark-buffer
  ---
  duration_ms: 120.524
  severity: fail
  stack: |-
    timeout
  ...

Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

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

LGTM % comment

doc/api/repl.md Outdated

An internal method used to turn off editor mode when entering
code in the REPL.

Copy link
Member

Choose a reason for hiding this comment

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

Actually I think we do not have to document this at all. This would create bigger confusion than providing benefit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I think documenting this is the opposite of what we actually want to achieve. I do not really read in that comment that we necessarily have to document this either and I would rather only have the deprecation notice that this was never meant to be exposed and that it is now deprecated but no further documentation.

@jasnell what do you think about this?

Copy link
Member

@BridgeAR BridgeAR Sep 13, 2017

Choose a reason for hiding this comment

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

By the way - the deprecation docs do not cover this part at all. Therefore I think it is safe to remove this.

Copy link
Member Author

Choose a reason for hiding this comment

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

@BridgeAR are you suggesting removing this commit entirely? Or just removing the wording from repl.md?

Copy link
Member

Choose a reason for hiding this comment

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

Only the part from the repl.md.

@BridgeAR
Copy link
Member

This needs some LGs due to being semver-major @nodejs/tsc

@BridgeAR
Copy link
Member

Ping @nodejs/tsc PTAL

@BridgeAR BridgeAR requested a review from a team September 22, 2017 20:59
@BridgeAR BridgeAR requested a review from a team September 24, 2017 15:29
@BridgeAR
Copy link
Member

@lance would you be so kind and rebase?

This commit exposes `REPLServer.prototype.turnOnEditorMode()` which
handles the necessary internal changes required instead of having
them scattered about.
This deprecates the current REPLServer.prototype.turnOffEditorMode
Also, address some concerns from code review.
@lance
Copy link
Member Author

lance commented Sep 27, 2017

@BridgeAR kindness applied! :)

@BridgeAR
Copy link
Member

@lance
Copy link
Member Author

lance commented Sep 28, 2017

Not happy with the results of that CI. I scanned a couple of the failures just briefly, and they seem unrelated. But it's surprising there are so many red dots. Trying again.

CI: https://ci.nodejs.org/job/node-test-pull-request/10300/

@refack
Copy link
Contributor

refack commented Sep 28, 2017

@lance CI is clean, failures are unrelated (even linter)

BridgeAR pushed a commit that referenced this pull request Sep 28, 2017
This deprecates the current REPLServer.prototype.turnOffEditorMode
and adds a private function for turnOffEditorMode which handles the
necessary internal changes required instead of having them scattered
about.

PR-URL: #15136
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
@BridgeAR
Copy link
Member

Landed in e416b3e

I fixed the merge conflicts while landing.

@BridgeAR BridgeAR closed this Sep 28, 2017
BridgeAR added a commit to BridgeAR/node that referenced this pull request Sep 28, 2017
This slipped through while landing.
Ref: nodejs#15136
@BridgeAR BridgeAR mentioned this pull request Sep 28, 2017
4 tasks
addaleax pushed a commit to addaleax/ayo that referenced this pull request Sep 30, 2017
This deprecates the current REPLServer.prototype.turnOffEditorMode
and adds a private function for turnOffEditorMode which handles the
necessary internal changes required instead of having them scattered
about.

PR-URL: nodejs/node#15136
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
BridgeAR added a commit that referenced this pull request Oct 1, 2017
This slipped through while landing.

PR-URL: #15668
Refs: #15136
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
addaleax pushed a commit to addaleax/ayo that referenced this pull request Oct 4, 2017
This slipped through while landing.

PR-URL: nodejs/node#15668
Refs: nodejs/node#15136
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
repl Issues and PRs related to the REPL subsystem. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants