Azure / azure-sdk-tools

Tools repository leveraged by the Azure SDK team.
MIT License
114 stars 180 forks source link

[Swift APIView] Improve extension handling #2536

Closed tjprescott closed 1 year ago

tjprescott commented 2 years ago

Currently, extension blocks from the source code appear in the APIView. The "extension Foo" line is not commentable, and how to represent this is tricky. There's not a good way to create a deterministic ID for the block itself.

For example:


class MyClass { }

// A bunch of other code here...

extension myClass {
  public myNewMethod()
}

Clicking "MyClass" will take you to the class definition, but there's no way to link to the extension block.

One idea would be to essentially "collect" all of the extensions and stuff them in as though they were in the class block. That could be difficult and not work for all cases.

tjprescott commented 2 years ago

cc/ @jimchou-dev

jimchou-dev commented 2 years ago

Error for duplicate definition id

image

Repo: https://github.com/Azure/communication-ui-library-ios (reproduced in commit 6afcfcfac25acdc1776f7dee877e152f9373422f)

Scenario 2 subclass both implementing from DrawerContainerViewController with different type, each have an extension on UITableViewDataSource, UITableViewDelegate

tjprescott commented 2 years ago

Original

class SomeClass {
}

extension SomeClass {
  func doSomething() -> String {
    return "Something"
  }
}

Option 1 We would simply collect the extensions within SomeClass and render them as such, even if the syntax isn't technically valid.

class SomeClass {
  extension SomeClass {
    func doSomething() -> String
  }
}

Option 2 Collect the methods/properties defined in the extension and display them as though they were properties of the original class definition. This does lose the context that the method actual came from an extension.

class SomeClass {
  func doSomething() -> String
}
tjprescott commented 1 year ago

After discussion, the way forward will be to render extensions as follows: