Skip to content

Support refactoring documentation - #1334

Merged
fbricon merged 2 commits into
redhat-developer:masterfrom
jdneo:cs/refactoring-doc
Jul 20, 2020
Merged

fbricon merged 2 commits into
redhat-developer:masterfrom
jdneo:cs/refactoring-doc

Conversation

@jdneo

@jdneo jdneo commented Mar 19, 2020 •

Copy link
Copy Markdown
Collaborator

@jdneo
jdneo force-pushed the cs/refactoring-doc branch from 2fde90c to 8f2cc21 Compare March 20, 2020 02:58
@jdneo jdneo mentioned this pull request Mar 20, 2020
3 tasks done
@jdneo

jdneo commented Mar 20, 2020

Copy link
Copy Markdown
Collaborator Author

Since the API is not ready in stable version yet, so we can first start working on the document structure.

@fbricon @snjeza @akaroml @testforstephen @Eskibear Please take a look at the structure and give your feedbacks. Once the structure is determined and checked-in. All the teammates can start filling the content into it.

I'll raise another PR to add the implementation part once the document is finished.

@fbricon

fbricon commented Mar 20, 2020

Copy link
Copy Markdown
Collaborator

Question is: how will you map refactoring ids to markdown anchors, such as #extract-to-constant

@jdneo

jdneo commented Mar 21, 2020

Copy link
Copy Markdown
Collaborator Author

That a good question!

Currently, the API will categorize the document according to the CodeActionKind, which is defined as:

export class CodeActionKind {
    static readonly Empty: CodeActionKind;
    static readonly QuickFix: CodeActionKind;

    // --- refactor start
    static readonly Refactor: CodeActionKind;
    static readonly RefactorExtract: CodeActionKind;
    static readonly RefactorInline: CodeActionKind;
    static readonly RefactorRewrite: CodeActionKind;
    // --- refactor end

    static readonly Source: CodeActionKind;
    static readonly SourceOrganizeImports: CodeActionKind;
    static readonly SourceFixAll: CodeActionKind;
}

This is somehow different from our JavaCodeActionKind, so I think we can prepare a general refactor document as a start.

@jdneo
jdneo marked this pull request as ready for review March 23, 2020 03:05
@akaroml

akaroml commented Mar 23, 2020

Copy link
Copy Markdown
Contributor

I guess a mapping mechanism will be needed in the follow-up PR.

Comment thread src/codeActionProvider.ts Resolved
@fbricon fbricon changed the title Support refactoring document Support refactoring documentation Mar 31, 2020
@jdneo

jdneo commented Jun 29, 2020

Copy link
Copy Markdown
Collaborator Author

Update: the API has been finalized and should be available in the next VS Code stable version, I'll update the PR after the new version released.

@jdneo
jdneo force-pushed the cs/refactoring-doc branch 3 times, most recently from 1a29ef0 to d3412a4 Compare July 10, 2020 07:44
@jdneo

jdneo commented Jul 10, 2020

Copy link
Copy Markdown
Collaborator Author

PR updated...

To navigate to the specific section in the refactoring document, you need to add a keyboard shortcut for a certain refactoring, for example:

{
        "key": "ctrl+shift+alt+e",
        "command": "editor.action.codeAction",
        "args": {
            "kind": "refactor.extract.function",
            "apply": "never"
        }
    }

@fbricon

fbricon commented Jul 16, 2020

Copy link
Copy Markdown
Collaborator

Can you please fix the conflict?

@jdneo

jdneo commented Jul 16, 2020 •

Copy link
Copy Markdown
Collaborator Author

@fbricon Done. Travis linux image failed, seems caused by java 8 runtime.

Should I fix it in this PR?

matrix:
  include:
  - os: linux
    dist: trusty
    jdk: openjdk11
    env:
      - JDK_HOME=~/openjdk11 # force launching JLS using JDK11
  - os: osx
    osx_image: xcode10.1
    jdk: oraclejdk11

@fbricon

fbricon commented Jul 16, 2020

Copy link
Copy Markdown
Collaborator

@jdneo please open a different PR

@jdneo
jdneo force-pushed the cs/refactoring-doc branch from 8a9c0e6 to 1abc1f8 Compare July 20, 2020 05:27
@jdneo

jdneo commented Jul 20, 2020

Copy link
Copy Markdown
Collaborator Author

@fbricon @snjeza The new refactor Introduce Parameter is added. Please take a look.

Comment on lines +302 to +307
context.subscriptions.push(markdownPreviewProvider);
context.subscriptions.push(languages.registerCodeActionsProvider({ scheme: 'file', language: 'java' }, new RefactorDocumentProvider(), RefactorDocumentProvider.metadata));
context.subscriptions.push(commands.registerCommand(Commands.LEARN_MORE_ABOUT_REFACTORING, async (kind: CodeActionKind) => {
const sectionId: string = javaRefactorKinds.get(kind) || '';
markdownPreviewProvider.show(context.asAbsolutePath(path.join('document', `${Commands.LEARN_MORE_ABOUT_REFACTORING}.md`)), 'Java Refactoring', sectionId, context);
}));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we check the new API is available (think Theia/Che) before registering the new provider?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Is there any guidance that we could follow to do such checks?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I assume something along the lines of if (CodeActionProviderMetadata !== null). But I'm no typescript expert

@jdneo jdneo Jul 20, 2020 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

CodeActionProviderMetadata is only used as a prarm when register the code action provider, so probably it's not able to be used for API checking. Using env.appName.includes('VS Code')?

// BTW, will theia/che honor the engines field in package.json?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

env.appName.includes('VS Code') is bad, since we'd need to rerelease vscode-java once Theia/Che support the feature.

// BTW, will theia/che honor the engines field in package.json?

That's a question for @benoitf

I don't understand why we can't do a check on CodeActionProviderMetadata (&& CodeActionProviderMetadata.documentation) like we do for https://github.com/redhat-developer/vscode-java/blob/master/src/semanticTokenProvider.ts#L8

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@jdneo if you link to a vsix build, maybe @benoitf can test it (display the refactoring menu, see there are no errors)

@jdneo jdneo Jul 20, 2020 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hi @benoitf,

Would you mind to help test this feature? Here is the vsix link. To test it, you can open a Java file, right click in the editor and click Learn more about Java refactorings (if it exists in the context menu).

More details can be found in the gif

Thanks

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

refactoring

custom documentation does not appear but it's expected as not yet supported

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Thank you @benoitf!

@fbricon Seems that a RefactorDocumentProvider is registered for nothing.

Screen Shot 2020-07-20 at 9 38 58 PM

@fbricon
fbricon merged commit 00c99be into redhat-developer:master Jul 20, 2020
@fbricon

fbricon commented Jul 20, 2020

Copy link
Copy Markdown
Collaborator

Thanks for the cool feature @jdneo!

@fbricon fbricon added this to the End July 2020 milestone Jul 20, 2020
@jdneo
jdneo deleted the cs/refactoring-doc branch July 20, 2020 23:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants