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

feat(core,common): add helpers messages to REPL built-in functions #9692

Closed

Conversation

micalevisk
Copy link
Member

@micalevisk micalevisk commented May 30, 2022

PR Checklist

Please check if your PR fulfills the following requirements:

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • CI related changes
  • Other... Please describe:

What is the current behavior?

No built-in helpers on current version of REPL feature (that will be added on #9684).

No way to find out what are the functions available to use for the NestJS app

What is the new behavior?

Users can call help() to view all the available 'native functions' (in an alphabetical order). I call them functions because commands are those displayed when we type .help (and registed by replServer.defineCommand)

Users can type <function>.help (eg: methods.help) if they want to find out what a 'native function' could do (their description and function's signature, which follows the TS function type expression)

Note that aliases should appear after the original function due to how @ReplFn() is evaluated. Supporting the out-of-order definition for function aliases looks trickier but it's feasiable.

Demo:

demo.mp4

(up-to-date version of help() output:)

image

Also, delete <function>.help or <function>.help = () => {} won't take any effect on the original help getter.

Does this PR introduce a breaking change?

  • Yes
  • No

Other

The only issue with in-repl docs is that the typings could be vague (for instance, ClassRef isn't a valid type from @nestjs but I feel it's better than Type for those who don't know Type). But at same time, having then right on in the REPL will improve DX

We can call <function>.help() but we would get an Uncaught TypeError because help is not a function. I don't know how to prevent that error while allowing both .help and .help() usages.

@@ -12,6 +53,7 @@ export async function repl(module: Type) {
});
await app.init();

const ReplContext = CoreReplContext;
Copy link
Member Author

Choose a reason for hiding this comment

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

now we can parametrize this ReplContext variable (so users could write their own 'native functions'), falling back to CoreReplContext

I didn't implement that feature in this PR because I think it would be better to wait for requests instead of implementing something that no one will use. Also because the interface of ReplContext might not be well defined yet

@coveralls
Copy link

coveralls commented May 30, 2022

Pull Request Test Coverage Report for Build 3a4ee23c-cb6b-4f16-aef0-5c9ab7d3cc4c

  • 28 of 38 (73.68%) changed or added relevant lines in 4 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.09%) to 93.998%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/common/utils/cli-colors.util.ts 0 1 0.0%
packages/core/repl/repl-fn.decorator.ts 19 20 95.0%
packages/core/repl/repl-context.ts 8 16 50.0%
Totals Coverage Status
Change from base Build a9d09da6-b7e1-45b9-8303-f0266c9e006a: -0.09%
Covered Lines: 5873
Relevant Lines: 6248

💛 - Coveralls

return this.app.select(token);
}

debug(moduleCls?: Type | string) {
@ReplFn(makeReplFnOpt('', '(moduleCls?: ClassRef | string) => void'))
Copy link
Member Author

Choose a reason for hiding this comment

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

@kamilmysliwiec please help me on writting a description for the debug function

Copy link
Contributor

Choose a reason for hiding this comment

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

@micalevisk, an idea but take it as a "draft":

Allows you to process the identification of the problem in stages, isolating the source of the problem and then correcting the problem or determining a way to solve it.

@micalevisk micalevisk changed the title feat(core,common): add helpers messages on REPL native functions feat(core,common): add helpers messages to REPL built-in functions May 30, 2022
@micalevisk micalevisk force-pushed the feat/repl-improvements branch 2 times, most recently from 1150706 to 9484d3a Compare May 31, 2022 00:04
@micalevisk
Copy link
Member Author

micalevisk commented May 31, 2022

I'm not 100% sure on the interface I've implemented to register those built-in global functions, tho. I mean, feels like ReplContext is doing a lot of things and clearly will increases as we add more and more functions to the REPL :/

@kamilmysliwiec
Copy link
Member

I think the approach proposed here #9695 is somewhat cleaner

@micalevisk micalevisk closed this May 31, 2022
@micalevisk micalevisk deleted the feat/repl-improvements branch June 1, 2022 10:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants