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

Support refactoring documentation #1334

Merged
merged 2 commits into from
Jul 20, 2020

Conversation

jdneo
Copy link
Collaborator

@jdneo jdneo commented Mar 19, 2020

#1335

Kapture 2020-03-30 at 14 24 47

Note that the two css files highlight.css & markdown.css are all copied from https://github.com/microsoft/vscode/tree/master/extensions/markdown-language-features/media

@jdneo
Copy link
Collaborator Author

jdneo commented Mar 20, 2020

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
Copy link
Collaborator

fbricon commented Mar 20, 2020

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

@jdneo
Copy link
Collaborator Author

jdneo commented Mar 21, 2020

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
Copy link
Contributor

akaroml commented Mar 23, 2020

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

src/codeActionProvider.ts Outdated Show resolved Hide resolved
@fbricon fbricon changed the title Support refactoring document Support refactoring documentation Mar 31, 2020
@jdneo
Copy link
Collaborator Author

jdneo commented Jun 29, 2020

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
Copy link
Collaborator Author

jdneo commented Jul 10, 2020

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
Copy link
Collaborator

fbricon commented Jul 16, 2020

Can you please fix the conflict?

@jdneo
Copy link
Collaborator Author

jdneo commented Jul 16, 2020

@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
Copy link
Collaborator

fbricon commented Jul 16, 2020

@jdneo please open a different PR

@jdneo
Copy link
Collaborator Author

jdneo commented Jul 20, 2020

@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
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
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
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

Copy link
Collaborator Author

@jdneo jdneo Jul 20, 2020

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
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
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)

Copy link
Collaborator Author

@jdneo jdneo Jul 20, 2020

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
Contributor

Choose a reason for hiding this comment

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

Copy link
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
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
Copy link
Collaborator

fbricon commented Jul 20, 2020

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