-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Improve discovery and description of JupyterLab commands #13962
Comments
For what its worth: https://jupyterlab.readthedocs.io/en/latest/user/commands.html#commands-list but this does not give us commands registered in extensions. I do not understand where you propose the actual JSON command to be defined. There are more extensions that could benefit from having this information at runtime: |
An alternative wold be to discover this automatically by writing a TypeScript plugin with a pass-through transformer that would detect Edit: this kind of thing: https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API#using-the-type-checker |
Yep. So, for example, this CommandIds would turn into an entry in {
"name": "name": "@jupyterlab/filebrowser-extension",
// ...
"jupyterlab": {
"extension": true,
"schemaDir": "schema",
"commands": {
// ...
"showBrowser": {
"id": "filebrowser:activate",
"options": {
"describedBy": {
"args": {
"description": "Open the file browser for the provided `path`.",
"type": "object",
"properties": {
"path": {
"description": "the path to open",
"format": "uri",
"type": "string"
}
}
}
}
},
},
// ...
}
}
} Or, as in the alternative, it could go in the plugin under a new key, Either way, the import * as PACKAGE from "../package.json";
const Commands = PACKAGE.jupyterlab.commands; And then installed, probably with a helper which could hoist import { describeCommand } from `@jupyterlab/apputils`;
// ...
commands.addCommand(
Commands.showBrowser.id,
describeCommand(
translator,
{
...Commands.showBrowser.options,
activate: (args) => {...}
}
)
); |
Sure, that's a way to go, too. Got the same argument from the LSP folk who invented a whole new metamodel for describing stuff. Cue xkcd link. I'm still of the mind, for Jupyter, that metadata in an established, language-neutral format in a well-known (or at least describable) locations wins, especially when typescript can natively import it, with decent typing. |
Right, the issue is that today they aren't described (basically all Writing schema-in-TS is of course possible, and could even be quite nice with authoring-type "magic" schema-to-ts by e.g. |
Should we alternatively make it easier for extension authors to expose their standard commands on token inferfaces? I don't think that will be more work than speccing out the args in a schema. |
See all the comments above: the intent is to make the knowledge of commands less driven by jupyterlab-specific implementation details in TypeScript, and more for having a concrete, declarative, human-readable definition in a well-known location. Further, schema provides the ability to constrain things beyond what an
So this codebase could, by example, expose a command set as a But somewhere down the line, these
|
Here you can see the pain of 'command discovery' in order to edit the settings (cell toolbar). jupyterlab-how-to-insert-custom-elements-buttons-commands-in-the-cell-toolbar If there is an easier way to get the list of available commands, I would really love to hear it. |
@Mr-Ruben today:
But for the use case you are highlighting, the commands should really be a list/dropdown in the settings form. |
Problem
JupyterLab commands are at once one of the most powerful, but also one of the most weakly-typed, and ultimately, least discoverable parts of the overall architecture.
Once a command id has actually been discovered (by DOM, source code, or debugger inspection without source maps), it is then sometimes only possible to determine the appropriate
args
by fully tracing the source code from call site to ultimate implementation, as these are sometimes passed asany
down into another part of the application.Proposed Solution
builder/metadata_schema.json#/properties/commands
command
, allow the definition of any of the static members ofICommandOptions
, but require:#/describedBy/args
title
anddescription
id
id
would ultimately be the correct key for this object, having an arbitrary (but unique-per-package) string would allow for transparently shimming existing exportedCommandIds
CommandId
s and hard-coded strings to the location where they are defined (not necessarily registered)package.json
at run/build timecomposite
build this... complicates thingspackages/*/src
would need atsconfig.json
thatreferences: {path: ../}
The payoff for this to be able to statically derive, outside of :
JsonSchemaForm
based on rjsf #13951This technique could then be encouraged in extension-cookiecutter-ts, documentation, etc.
Alternatives
definitions
...schema
folders for packages that don't/can't currently have themAdditional context
The text was updated successfully, but these errors were encountered: