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

[SR-7294] Swift local refactoring: adding doc-comment boilerplate automatically via local refactoring #49842

Closed
nkcsgexi opened this issue Mar 28, 2018 · 16 comments
Labels
documentation feature exists Resolution → feature: Feature already exists feature A feature request or implementation good first issue Good for newcomers refactoring Area → source tooling: refactoring source tooling Area: IDE support, SourceKit, and other source tooling

Comments

@nkcsgexi
Copy link
Member

nkcsgexi commented Mar 28, 2018

Previous ID SR-7294
Radar None
Original Reporter @nkcsgexi
Type New Feature
Status Closed
Resolution Won't Do
Additional Detail from JIRA
Votes 0
Component/s Source Tooling
Labels New Feature, Refactoring, StarterBug
Assignee mohit.athwani (JIRA)
Priority Medium

md5: ce091cb81d0d956c3ac1e06cd2c280d6

Issue Description:

Swift doc-comment uses mark-down to describe different parts of a function declaration. The boiler-template of adding these doc-comments can be automated by a local refactoring action, e.g.

// Right-click on the function name addNumber and apply refactoring 
// "add doc-comment template".
func addNumber(first: Int, second: Int) throws -> Int {
  return first + second
}

The user can right-click on the declared function name addNumber and apply a local refactoring "add doc-comment template". This action will transform the above code to:

/**
Function summary
  - Parameter first: Parameter first
  - Parameter second:  Parameter first
  - Throws: Error
  - Returns: The result
*/
func addNumber(first: Int, second: Int) throws -> Int {
  return first + second
}

Notice that the refactoring requires little semantic information of the code snippet after type checking. We may implement it using libSyntax API from the Swift side.

@swift-ci
Copy link
Collaborator

Comment by Mohit Athwani (JIRA)

So this is the second time I will be contributing to this repository and this looks like something well within my skill set... Any suggestions on where to start?

@nkcsgexi
Copy link
Member Author

mohit.athwani (JIRA User) , could you follow the instructions we have in here: https://swift.org/blog/swift-local-refactoring/

The blog post should provide you enough information to start implementation.

@swift-ci
Copy link
Collaborator

Comment by Mohit Athwani (JIRA)

@nkcsgexi thank you so much! I will get started on this later today 🙂

@nkcsgexi
Copy link
Member Author

I'm looking forward to that!👍

@swift-ci
Copy link
Collaborator

Comment by Mohit Athwani (JIRA)

This entry also allows the C++ compiler to generate the class stub for the String Localization refactoring and its callers.

In reference to adding an entry in the .def file, I'm wondering how do I get the compiler to generate the class stubs for me? Do I have to build the target in order to get this done?

@nkcsgexi
Copy link
Member Author

nkcsgexi commented May 1, 2018

mohit.athwani (JIRA User) this code generation should be transparent to the developers. We shouldn't need to perform additional steps for it.

@swift-ci
Copy link
Collaborator

swift-ci commented May 1, 2018

Comment by Mohit Athwani (JIRA)

Thanks @nkcsgexi ! So I stuck in some code that spits out some hard coded string to help me just understand the process and I can build it just fine with Xcode. Could you please guide me on how to go about debugging with breakpoints and also how to invoke the test runner?

@nkcsgexi
Copy link
Member Author

nkcsgexi commented May 1, 2018

Could you try to generate an Xcode project from the repo (using ./utils/build-script -x)? This way you can use the Xcode debugger after opening the Xcode project. Currently, we run the test by invoking "./utils/build-script -t".

@swift-ci
Copy link
Collaborator

swift-ci commented May 1, 2018

Comment by Mohit Athwani (JIRA)

I have the Xcode project built. My question is whether I could set a breakpoint in Xcode and have it hit when the swift-refactor tool picks up my test input file?

@nkcsgexi
Copy link
Member Author

nkcsgexi commented May 1, 2018

in that case, we need to see the actual command line the test invokes and specify the command arguments in Xcode via "Edit scheme"-> "Arguments".

@swift-ci
Copy link
Collaborator

swift-ci commented May 1, 2018

Comment by Mohit Athwani (JIRA)

Thanks for your patience. This is a embarrassing but I'm going to admit that I've been going back and forth within Xcode like a headless chicken!

@nkcsgexi
Copy link
Member Author

nkcsgexi commented May 1, 2018

No worries, mohit.athwani (JIRA User) 🙂 I've had pretty much the same workflow. Running test in command line and copy command line over to Xcode for debugging...

@swift-ci
Copy link
Collaborator

swift-ci commented May 1, 2018

Comment by Mohit Athwani (JIRA)

Here are the steps followed so far:

  1. Built Xcode project by passing the --xcode flag to build-script
  2. Added ALL_BUILD, swift, swift-stdlib and swiftide schemes to the xcode project
  3. Added CURSOR_REFACTORING(DocCommentBoilerplate, "Generate Documentation Comment", doc.comment.boilerplate) to RefactorKinds.def file
  4. Added the following to Refactoring.cpp:
bool RefactoringActionDocCommentBoilerplate::isApplicable(ResolvedCursorInfo Tok, DiagnosticEngine &Diag) {
        return false;
}
bool RefactoringActionDocCommentBoilerplate::performChange() {
        return false;
}

6. Set breakpoints in each of the functions above
7. Ran build-script with -t flag which is now building the whole project and currently waiting on that.

Does it look like I am on the right track?

From googling around, I saw that there is a tool called lit.py that can be used be invoke test. Is there a way I can use that here?

Thanks!

@nkcsgexi
Copy link
Member Author

nkcsgexi commented May 1, 2018

Ya![]( You're on the right track mohit.athwani (JIRA User). I think it is a good idea to open a WIP PR in the Swift repo so we can comment on your changes. Good job sofar)

@swift-ci
Copy link
Collaborator

swift-ci commented May 2, 2018

Comment by Mohit Athwani (JIRA)

Opened a WIP PR at #16297

Thanks!

@nkcsgexi
Copy link
Member Author

We do have this in Xcode via "Editor->Structure->Add Documentation". Adding this as a local refactoring seems to be redundant.

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added will not do Resolution: Will not be worked on feature A feature request or implementation source tooling Area: IDE support, SourceKit, and other source tooling feature exists Resolution → feature: Feature already exists documentation and removed new feature will not do Resolution: Will not be worked on labels Jan 28, 2023
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation feature exists Resolution → feature: Feature already exists feature A feature request or implementation good first issue Good for newcomers refactoring Area → source tooling: refactoring source tooling Area: IDE support, SourceKit, and other source tooling
Projects
None yet
Development

No branches or pull requests

3 participants