-
Notifications
You must be signed in to change notification settings - Fork 10.5k
[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
Conversation
76aae2d
to
df62f67
Compare
df62f67
to
2c59d60
Compare
@swift-ci Please smoke test |
1 similar comment
@swift-ci Please smoke test |
fc5320b
to
9efff16
Compare
@swift-ci Please smoke test |
9efff16
to
f1acebc
Compare
@swift-ci Please smoke test |
@swift-ci Please smoke test |
edf8ad5
to
032904c
Compare
@swift-ci Please smoke test |
1 similar comment
@swift-ci Please smoke test |
d2ebc11
to
ff88907
Compare
@swift-ci Please smoke test |
There was a problem hiding this 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.
include/swift/Syntax/RawSyntax.h
Outdated
@@ -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 |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ---------===// |
There was a problem hiding this comment.
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>; |
There was a problem hiding this comment.
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
?
lib/Syntax/RawSyntax.cpp
Outdated
assert(Kind != SyntaxKind::Token && | ||
"'token' syntax node must be constructed with dedicated constructor"); | ||
if (NodeId) { |
There was a problem hiding this comment.
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.
lib/Syntax/SyntaxClassifier.cpp.gyb
Outdated
}% | ||
//// Automatically Generated From SyntaxFactory.cpp.gyb. | ||
//// Do Not Edit Directly! | ||
//===--------- SyntaxFactory.cpp - Syntax Factory implementations ---------===// |
There was a problem hiding this comment.
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.
lib/Syntax/SyntaxClassifier.cpp.gyb
Outdated
/// 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) { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
ff88907
to
5ba3ee1
Compare
@swift-ci Please smoke test |
5ba3ee1
to
a6c94dd
Compare
@swift-ci Please smoke test |
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
a6c94dd
to
af18ead
Compare
@swift-ci Please smoke test |
…n expression as interpolation anchor
af18ead
to
3c4fcc1
Compare
@swift-ci Please test |
Build failed |
Build failed |
/*EnableDiagnostics=*/false, | ||
/*EnableSyntaxTree=*/false, | ||
/*EnableSyntaxReuseInfo=*/false, | ||
/*SyntacticOnly=*/false); |
There was a problem hiding this comment.
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.
…ormation is present
3c4fcc1
to
4b506b2
Compare
/// reused since the last serialization. | ||
enum OutputKind { | ||
Normal, | ||
SyntaxTree |
There was a problem hiding this comment.
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
.
@swift-ci Please test |
Build failed |
Build failed |
70ff791
to
8b037fc
Compare
@swift-ci Please test |
Build failed |
Build failed |
I'll review this today. |
@@ -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 |
There was a problem hiding this comment.
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>) {} |
There was a problem hiding this comment.
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).
Sorry, this PR is too big to review. |
@rintaro I've split the PR will be delivering them in pieces now. |
This is a WIP to perform syntax coloring using libSyntax. With #16340 it should allow incremental syntax coloring.