Repository navigation
Description
Problem
Many language/extension implement really cool refactorings, but many users never discover these or figure out how to reliably trigger them.
Proposal
Add a way for an extension to contribute documentation for their refactorings. Our goal here would be to help users reach the documentation and leave the presentation of the documentation up to extensions themselves.
Target UX
Let users explicitly request to see the refactoring documentation from the existing code action refactor menu. This could be as simple as a Learn more entry at the bottom of the refactoring menu.
The learn more action would do the following:
- If we are in a language that only has one refactoring documentation provider, then show that documentation directly
- If we are in a language with multiple refactoring documentation providers, show a quick pick so that users can tell us which documentation they are interested in (this is similar to how our remote documentation works today)
API
Current proposal
The current proposal is the add a documentation field to CodeActionProviderMetadata that let's extension surface a command that shows documentation:
export interface CodeActionProviderMetadata {
/**
* Static documentation for a class of code actions.
*
* The documentation is shown in the code actions menu if either:
*
* - Code actions of `kind` are requested by VS Code. Note that in this case, we always pick the most specific
* documentation. For example, if documentation for both `Refactor` and `RefactorExtract` is provided, and we
* request code actions for `RefactorExtract`, we prefer the more specific documentation for `RefactorExtract`.
*
* - Any code actions of `kind` are returned by the provider.
*/
readonly documentation?: ReadonlyArray<{ readonly kind: CodeActionKind, readonly command: Command }>;
}original proposal
I see two possible ways this could be implemented:
Through a contribution point
Create a new documentation.refactoring contribution point that lets extension define a command that shows the documentation:
"contributes": {
"documentation": {
"refactoring": [
{
"title": "%documentation.refactoring.title%",
"when": "typescript.isManagedFile",
"command": "_typescript.learnMoreAboutRefactorings"
}
]
},
}Through a new refactor.documentation code action kind
Define a special code action kind called refactor.documentation. If an extension returns a code action with this kind, then we could surface this using some special UI in the refactor menu
(extensions would be expected to return the refactor.documentation action whenever refactorings are requested)
/cc Kai Maetzel (@kieferrm)
/cc Johannes Rieken (@jrieken) for api
/cc @misolori for ux
Activity
mjbvz commentedon Dec 12, 2019
Rome Li (@akaroml) Danny Tuppeny (@DanTup) Also interested to hear if this is something you would find helpful for your extensions and if you have and other ideas about how this documentation could be presented
DanTup commentedon Dec 12, 2019
I don't know that I have the data to populate this, though the idea sounds good to me.
I think there many other places that exposing docs would be great - I opened #71541 previously, but there it was resolved as a dupe of another case that never got a concensus on the fix (which is a shame, because I think it's a tiny change with a large impact for users).
kieferrm commentedon Dec 12, 2019
I'm in favor of the contribution point, but both approaches work.
akaroml commentedon Dec 16, 2019
While the static contribution point would work perfectly, the
refactor.documentationcould have more potential by allowing vscode to:This also allows the language server to generate more precise documentation according to the context.
So I prefer the LSP way.
jrieken commentedon Dec 16, 2019
My preference is for something static but similar to the previous approaches we need to make sure that extensions can provide this - tho the approach seems to have the right amount of indirection for this.
I am wondering if there are synergies with the work we are doing around extensions adding "getting started" or "playground parts" etc?
mjbvz commentedon Dec 17, 2019
Danny Tuppeny (@DanTup) If you have a webpage that documents refactorings, you could link users to that. It doesn't need to be anything fancy to start off, just a list and a quick description of what each refactoring does
Rome Li (@akaroml) Good points about the LSP support.
One other consideration with using code actions to return documentation is that other editors would likely not know what to do with the returned
Refactor.documentationitems besides showing them inline in the code action list (which is probably not what you want)Johannes Rieken (@jrieken) I also like the idea of idea of integrating this with our other documentation exploration but worry that may take a while to finalize. Maybe we should try delivering a scoped solution that only handles code actions so that Java and others can play around with the idea, and then look into how this would fit with our larger documentation/getting started experiences?
akaroml commentedon Dec 17, 2019
Johannes Rieken (@jrieken) Thank you for bringing up the synergy idea! I do see those three approaches sharing similar goals. As an extension author, I really appreciate the platform providing a clear picture of how those UI elements can work together and serve different use cases!
And here to share some of the challenges and use cases.
Code Actions Challenges
Provide a full list of what's available. And
CodeAction.disabledwill help serve that purpose.We also find it challenging for the users to figure out how a code action could be triggered. E.g. the "Invert Boolean" could be triggered by placing the cursor inside the expression, then the whole expression will be inverted because we infer the biggest possible from the cursor, or, the users can also select a part of the expression, then only the selected part will be inverted.
The challenge here is how we could educate the users about the differences. I think the discussion in this particular issue can help provide a place to document that behavior explicitly.
Getting Started
This is so important for experienced users. We have enough key binding extensions but the challenge here is that vscode and other editors/ides do not have 1:1 feature parity and we will have missing keystrokes for sure. And as the love for vscode grows, users would want to learn and adapt to vscode conventions.
One idea here is to let the language extension handle the missing key bindings. For example, users may try F8 to start debugging while it does nothing by default. Then the Java extension could respond by hinting the user "Are you trying to start debugging? To do so, press F5 instead.".
We identify common tasks that users would want to perform and provide documentation accordingly. The challenge here is how users can find them. It's like digging something in a library, and a search based tool can help.
The idea here is to allow an extension to contribute getting started documentation and users can locate those entries by typing some keywords.
Rich Tutorial Experience
Students are a large group in our user base. And tutorials are great for them to learn and practice. Now the best we can do is to show the documentation and an editor side by side. It's already working but it could be even better if the documentation can interact with the editor, and I see that a playground.
Matt Bierner (@mjbvz) Agreed. We'll always happy to try new APIs and see how they work.
jrieken commentedon Dec 17, 2019
Matt Bierner (@mjbvz) 👍 for moving fast. Circling in Eric Amodio (@eamodio) for some "getting started" ideas that point in a similar direction
mjbvz commentedon Jan 7, 2020
Johannes Rieken (@jrieken) I've changed the contribution point proposal to be more generic to better support that:
Here's how this is rendered in the editor:
Adding documentation.refactor proposed contribution point
33 remaining items
akaroml commentedon Jun 9, 2020
Matt Bierner (@mjbvz) This change was pushed several times. Can we expect the release in June?
jrieken commentedon Jun 9, 2020
Rome Li (@akaroml) We were kinda waiting for you feedback to know if the proposed API change is sufficient for your need?
akaroml commentedon Jun 9, 2020
Johannes Rieken (@jrieken) I should have pointed out this earlier and Sheng Chen (@jdneo) is from my team and he is the on-point of adopting this new capability. Please check out his comments above.
jdneo commentedon Jun 9, 2020
Johannes Rieken (@jrieken) Matt Bierner (@mjbvz) Just FYI we've already proposed a draft PR for this new API (Attached a gif in that PR).
So far so good! Just one question: When user clicks
Refactoring...in the context menu and gets a list of refactorings which are all the same kind (Let's say:RefactorExtract), is it possible for the new API to returnRefactorExtractinstead ofRefactor?