Skip to content
This repository was archived by the owner on Jun 1, 2023. It is now read-only.

Group operators #228

Merged
merged 7 commits into from
Apr 23, 2021
Merged

Group operators #228

merged 7 commits into from
Apr 23, 2021

Conversation

Lukas-Stuehrk
Copy link
Member

With this change, operators are separated from methods. Additionally, they are displayed with only their operator.

In the sidebar of the HTML page:
Screenshot 2021-03-22 at 22 30 51

And in the documentation:
Screenshot 2021-03-22 at 22 30 59

This resolves #123.

Copy link
Contributor

@mattt mattt left a comment

Choose a reason for hiding this comment

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

This is off to a great start!

What are you thinking as far as how to distinguish among prefix / infix / postfix operators in the generated UI?

@Lukas-Stuehrk
Copy link
Member Author

I'm lacking the imagination how the visuals for this could look like.

One idea: We could use the type names display the operators with their type names. E.g. we would display an infix operator == then like LeftType == RightType, a prefix operator <-- would become <--Type and a postfix operator --> would become Type-->.

However, this omits the return type of the operation, but the return type might be rather important for custom DSLs with custom operators.

Regarding the implementation then: My current approach simply changed the name property which we introduced in an extension on Function. This does not feel right for doing this. How do you feel about introducing a displayedNamed property?

Also, it's rather easy to distinguish between prefix, infix and postfix operators. The first and the latter always need to have a modifier in the method implementation. But should we add this kind of logic into swift-doc or should we extend SwiftSemantics?

@mattt mattt added this to the 1.0.0-beta.6 milestone Apr 17, 2021
@mattt
Copy link
Contributor

mattt commented Apr 20, 2021

Thanks again for taking a stab at this, @Lukas-Stuehrk.

After digging into this a bit more, I realized that I'd originally conflated operators with functions that implement an operator. This became a lot clearer when I tried running swift-doc on Euler.

To clarify, this is an operator:

infix operator  : ComparisonPrecedence

...and this is a function implementing that operator:

public func  <T>(lhs: T, rhs: T) -> Bool where T : FloatingPoint {
    return lhs == rhs || lhs.nextDown == rhs || lhs.nextUp == rhs
}

I think your change is the correct — functions that implement an operator should be grouped in type pages.

My latest changes build on this by doing the following:

  • Update SourceFile to collect OperatorDecl syntax nodes
  • Create a new OperatorPage, which names implementations according to their operands (e.g. func ==(lhs: Int, rhs: Int) is shown as Int == Int)
  • Distinguish between infix, prefix, and postfix operators
  • Change the home page to order operators by their kind (prefix, etc.)

I also updated the CSS to add a custom style for operators. Here's what all of that looks like:

Operator page:

Screen Shot 2021-04-20 at 03 33 51

Home page:

Screen Shot 2021-04-20 at 03 40 33

@mattt mattt modified the milestones: 1.0.0-beta.6, 1.0.0-rc1 Apr 20, 2021
@mattt mattt force-pushed the OperatorsGrouping branch from 123d040 to 26dd273 Compare April 23, 2021 19:46
@mattt mattt modified the milestones: 1.0.0-rc1, 1.0.0-beta.6 Apr 23, 2021
@mattt mattt merged commit 5f57067 into SwiftDocOrg:master Apr 23, 2021
@Lukas-Stuehrk Lukas-Stuehrk deleted the OperatorsGrouping branch April 23, 2021 20:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Group operators separately
2 participants