Skip to content

[libSyntax] Syntax coloring using libSyntax #16636

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

Closed
wants to merge 25 commits into from

Conversation

ahoppen
Copy link
Member

@ahoppen ahoppen commented May 15, 2018

This is a WIP to perform syntax coloring using libSyntax. With #16340 it should allow incremental syntax coloring.

@ahoppen ahoppen force-pushed the libsyntax-coloring branch 2 times, most recently from 76aae2d to df62f67 Compare May 22, 2018 16:37
@ahoppen ahoppen force-pushed the libsyntax-coloring branch from df62f67 to 2c59d60 Compare June 11, 2018 21:26
@ahoppen
Copy link
Member Author

ahoppen commented Jun 11, 2018

@swift-ci Please smoke test

1 similar comment
@ahoppen
Copy link
Member Author

ahoppen commented Jun 12, 2018

@swift-ci Please smoke test

@ahoppen ahoppen force-pushed the libsyntax-coloring branch from fc5320b to 9efff16 Compare June 12, 2018 22:52
@ahoppen
Copy link
Member Author

ahoppen commented Jun 12, 2018

@swift-ci Please smoke test

@ahoppen ahoppen force-pushed the libsyntax-coloring branch from 9efff16 to f1acebc Compare June 13, 2018 22:23
@ahoppen
Copy link
Member Author

ahoppen commented Jun 13, 2018

@swift-ci Please smoke test

@ahoppen ahoppen changed the title [WIP] Syntax coloring using libSyntax [libSyntax] Syntax coloring using libSyntax Jun 13, 2018
@ahoppen
Copy link
Member Author

ahoppen commented Jun 18, 2018

@swift-ci Please smoke test

2 similar comments
@ahoppen
Copy link
Member Author

ahoppen commented Jun 18, 2018

@swift-ci Please smoke test

@ahoppen
Copy link
Member Author

ahoppen commented Jun 19, 2018

@swift-ci Please smoke test

@ahoppen ahoppen force-pushed the libsyntax-coloring branch from edf8ad5 to 032904c Compare June 25, 2018 18:39
@ahoppen
Copy link
Member Author

ahoppen commented Jun 25, 2018

@swift-ci Please smoke test

1 similar comment
@ahoppen
Copy link
Member Author

ahoppen commented Jun 26, 2018

@swift-ci Please smoke test

@ahoppen ahoppen force-pushed the libsyntax-coloring branch from d2ebc11 to ff88907 Compare June 26, 2018 16:48
@ahoppen
Copy link
Member Author

ahoppen commented Jun 26, 2018

@swift-ci Please smoke test

Copy link
Contributor

@nkcsgexi nkcsgexi left a comment

Choose a reason for hiding this comment

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

Looking good over all! Some minor comments so far.

@@ -270,13 +277,17 @@ class RawSyntax final
}

/// Constructor for creating layout nodes
/// If NodeId is 0, the next free NodeId is used, if it is passed, the caller
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't Optional<unsigned> more readable to describe these two situations?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that's probably better. I'll change it.

/// thus pass serialization options
enum OutputKind {
Normal,
SyntaxTree
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we have some documentation here for the differences? a.k.a. why do we need node id in one case however not in the other.

Copy link
Member Author

Choose a reason for hiding this comment

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

I added some documentation. I don't want to go into detail on how to the subclasses here because it's not really the point where I'd look for it.

}%
//// Automatically Generated From SyntaxVisitor.h.gyb.
//// Do Not Edit Directly!
//===---------------- SyntaxVisitor.h - SyntaxVisitor definitions ---------===//
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: the type should be updated and the year.


/// First is the classification all identifiers shall inherit, if seconds is
/// set to \c true, all tokens will be forced to receive that classification
using ContextStackEntry = std::pair<SyntaxClassification, bool>;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we define a new struct here instead of using std::pair?

assert(Kind != SyntaxKind::Token &&
"'token' syntax node must be constructed with dedicated constructor");
if (NodeId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Again, using Optional<unsigned> for NodeId can be more self-explanatory.

}%
//// Automatically Generated From SyntaxFactory.cpp.gyb.
//// Do Not Edit Directly!
//===--------- SyntaxFactory.cpp - Syntax Factory implementations ---------===//
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: update title, years and documentation in the comments.

/// inside a special context. Returns \c None if the token has no nativie
/// classification and should always inherit from the context.
llvm::Optional<SyntaxClassification>
getNativeClassificationForToken(TokenSyntax TokenNode) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we rename it to getContextFreeClassificationForToken?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, that name is better. Changed it.

@ahoppen ahoppen force-pushed the libsyntax-coloring branch from ff88907 to 5ba3ee1 Compare June 26, 2018 19:47
@ahoppen
Copy link
Member Author

ahoppen commented Jun 26, 2018

@swift-ci Please smoke test

@ahoppen ahoppen force-pushed the libsyntax-coloring branch from 5ba3ee1 to a6c94dd Compare June 26, 2018 20:26
@ahoppen
Copy link
Member Author

ahoppen commented Jun 26, 2018

@swift-ci Please smoke test

ahoppen added 4 commits June 26, 2018 14:05
The id is meant to be stable across incremental parses
Since nodes have unique IDs now, we cannot reuse the nodes at multiple
locations in the source file
@ahoppen ahoppen force-pushed the libsyntax-coloring branch from a6c94dd to af18ead Compare June 26, 2018 21:05
@ahoppen
Copy link
Member Author

ahoppen commented Jun 26, 2018

@swift-ci Please smoke test

@ahoppen ahoppen force-pushed the libsyntax-coloring branch from af18ead to 3c4fcc1 Compare June 26, 2018 22:42
@ahoppen
Copy link
Member Author

ahoppen commented Jun 26, 2018

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - f1acebc34037f6b3187bd7f321b4e4c4fa590906

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - f1acebc34037f6b3187bd7f321b4e4c4fa590906

/*EnableDiagnostics=*/false,
/*EnableSyntaxTree=*/false,
/*EnableSyntaxReuseInfo=*/false,
/*SyntacticOnly=*/false);
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we define a struct like EditorConsumerOptions to incorporate all these boolean values? Stacking them up like this can be error-prone.

@nkcsgexi nkcsgexi requested a review from rintaro June 26, 2018 23:40
@ahoppen ahoppen force-pushed the libsyntax-coloring branch from 3c4fcc1 to 4b506b2 Compare June 27, 2018 17:24
/// reused since the last serialization.
enum OutputKind {
Normal,
SyntaxTree
Copy link
Contributor

Choose a reason for hiding this comment

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

It's still kind of weird that the serialization util knows syntax tree :( . Can we define a 32-bit field in Output whose meaning can be interpreted while serializing? For instance, we can use the first bit to indicate whether shouldIncludeNodeIds.

@ahoppen
Copy link
Member Author

ahoppen commented Jun 27, 2018

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 3c4fcc1485a83314eee775689cc787107efa6f65

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 3c4fcc1485a83314eee775689cc787107efa6f65

@ahoppen ahoppen force-pushed the libsyntax-coloring branch from 70ff791 to 8b037fc Compare June 27, 2018 22:08
@ahoppen
Copy link
Member Author

ahoppen commented Jun 27, 2018

@swift-ci Please test

@swift-ci
Copy link
Contributor

Build failed
Swift Test Linux Platform
Git Sha - 70ff7919cf6703a6ff47e28e252ced46b138011e

@swift-ci
Copy link
Contributor

Build failed
Swift Test OS X Platform
Git Sha - 70ff7919cf6703a6ff47e28e252ced46b138011e

@rintaro
Copy link
Member

rintaro commented Jun 28, 2018

I'll review this today.

@rintaro rintaro self-assigned this Jun 28, 2018
@@ -163,18 +168,18 @@ func foo(n: Float) -> Int {
}

///- returns: single-line, no space
// CHECK: ///- <doc-comment-field>returns</doc-comment-field>: single-line, no space
// CHECK-OLD: ///- <doc-comment-field>returns</doc-comment-field>: single-line, no space
Copy link
Member

Choose a reason for hiding this comment

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

Could you add CHECK-NEW check?

@@ -592,7 +611,8 @@ func keywordAsLabel4(_: Int) {}
func keywordAsLabel5(_: Int, for: Int) {}
// CHECK: <kw>func</kw> keywordAsLabel5(<kw>_</kw>: <type>Int</type>, for: <type>Int</type>) {}
func keywordAsLabel6(if let: Int) {}
// CHECK: <kw>func</kw> keywordAsLabel6(if <kw>let</kw>: <type>Int</type>) {}
// CHECK-OLD: <kw>func</kw> keywordAsLabel6(if <kw>let</kw>: <type>Int</type>) {}
// CHECK-NEW: <kw>func</kw> keywordAsLabel6(<kw>if</kw> <kw>let</kw>: <type>Int</type>) {}
Copy link
Member

Choose a reason for hiding this comment

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

Coloring as <kw>if</kw> here doesn't look right to me. (<kw>let</kw> too).

@rintaro
Copy link
Member

rintaro commented Jun 28, 2018

Sorry, this PR is too big to review.
Is it possible to implement "Syntax coloring using libSyntax" without incremental parsing first, then make it incremental?

@rintaro rintaro removed their assignment Jun 28, 2018
@ahoppen
Copy link
Member Author

ahoppen commented Jun 28, 2018

@rintaro I've split the PR will be delivering them in pieces now.

@ahoppen ahoppen closed this Jun 28, 2018
@ahoppen ahoppen deleted the libsyntax-coloring branch July 19, 2018 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants