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

Preserve Formatting of Symbol Declarations #204

Merged
merged 6 commits into from
Oct 16, 2020

Conversation

mattt
Copy link
Contributor

@mattt mattt commented Oct 16, 2020

Currently, code declarations for symbols are generated from the description of SwiftSemantics objects constructed from syntax nodes. However, this removes any inter-node trivia like newlines that may help break up long lines.

After considering running the code through a formatter like swift-format, I decided that a better approach would be to preserve the existing whitespace, working on the assumption that developers will adopt formatting conventions that look good in their editor.

This PR also tweaks the CSS rules for declarations to better accommodate standard 80 character column widths. Lines up to that width should display without a line break when viewed on desktop browsers at the standard text scale. Longer lines will now wrap according to pre-wrap behavior (see #144 (comment)), instead of overflowing with a scroll bar.

Resolves #201

Before

Screen Shot 2020-10-16 at 10 12 28

After

Screen Shot 2020-10-16 at 10 12 19

Screen Shot 2020-10-16 at 10 13 59

mattt added 3 commits October 16, 2020 09:59
Upgrade SwiftSyntaxHighlighter to 1.1.3
Decrease font size slightly and use white-space: pre-wrap
@mattt mattt added enhancement New feature or request design Functionality with a design component labels Oct 16, 2020
@mattt mattt requested review from MaxDesiatov and kaishin October 16, 2020 17:10
@mattt
Copy link
Contributor Author

mattt commented Oct 16, 2020

One last thing worth mentioning: This change has the incidental benefit of reducing a String -> AST -> HTML conversion step. The current / old way of doing things involved doing a syntactic parse in SourceFile to collect symbols, and then doing a separate parse in the HTML post-processing step to do syntax highlighting. With this PR, we now feed the AST nodes from SourceFile directly into SwiftSyntaxHighlighter, which should make things run a bit faster.

Copy link
Contributor

@MaxDesiatov MaxDesiatov left a comment

Choose a reason for hiding this comment

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

Seems legit 👍

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
design Functionality with a design component enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Avoid horizontal scrolling in formatted code
2 participants