-
Notifications
You must be signed in to change notification settings - Fork 4k
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
More classification perf fixes. #73535
Merged
CyrusNajmabadi
merged 13 commits into
dotnet:main
from
CyrusNajmabadi:classificationExt2
May 17, 2024
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
7a1b12c
Avoid unnecessary allocations while finding token matches in a file
CyrusNajmabadi 6e657be
Merge branch 'main' of https://github.com/CyrusNajmabadi/roslyn
CyrusNajmabadi b21abc4
Seeing what breaks
CyrusNajmabadi 6a613c7
Remove
CyrusNajmabadi 7d66683
Simply name
CyrusNajmabadi c32a40f
full span intersection
CyrusNajmabadi 55c52d1
Merge remote-tracking branch 'upstream/main'
CyrusNajmabadi 409a986
Merge branch 'main' into classificationExt2
CyrusNajmabadi 2d3828e
Update src/Workspaces/CSharp/Portable/Classification/SyntaxClassifica…
CyrusNajmabadi 5b0ff9d
revert
CyrusNajmabadi 951fec5
Merge branch 'classificationExt2' of https://github.com/CyrusNajmabad…
CyrusNajmabadi 15ae93c
Update src/Workspaces/CSharp/Portable/Classification/SyntaxClassifica…
CyrusNajmabadi 4fe82a9
fix
CyrusNajmabadi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,36 +29,21 @@ public override void AddClassifications( | |
SegmentedList<ClassifiedSpan> result, | ||
CancellationToken cancellationToken) | ||
{ | ||
if (syntax is NameSyntax name) | ||
{ | ||
if (syntax is SimpleNameSyntax name) | ||
ClassifyTypeSyntax(name, semanticModel, result, cancellationToken); | ||
} | ||
} | ||
|
||
public override ImmutableArray<Type> SyntaxNodeTypes { get; } = | ||
[ | ||
typeof(AliasQualifiedNameSyntax), | ||
typeof(GenericNameSyntax), | ||
typeof(IdentifierNameSyntax), | ||
typeof(QualifiedNameSyntax), | ||
typeof(SimpleNameSyntax), | ||
typeof(GenericNameSyntax), | ||
]; | ||
|
||
protected override int? GetRightmostNameArity(SyntaxNode node) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. unused method. |
||
{ | ||
if (node is ExpressionSyntax expressionSyntax) | ||
{ | ||
return expressionSyntax.GetRightmostName()?.Arity; | ||
} | ||
|
||
return null; | ||
} | ||
|
||
protected override bool IsParentAnAttribute(SyntaxNode node) | ||
=> node.IsParentKind(SyntaxKind.Attribute); | ||
|
||
private void ClassifyTypeSyntax( | ||
NameSyntax name, | ||
SimpleNameSyntax name, | ||
SemanticModel semanticModel, | ||
SegmentedList<ClassifiedSpan> result, | ||
CancellationToken cancellationToken) | ||
|
@@ -73,7 +58,7 @@ private void ClassifyTypeSyntax( | |
} | ||
|
||
private bool TryClassifySymbol( | ||
NameSyntax name, | ||
SimpleNameSyntax name, | ||
SymbolInfo symbolInfo, | ||
SegmentedList<ClassifiedSpan> result) | ||
{ | ||
|
@@ -104,7 +89,7 @@ CandidateReason.Ambiguous or | |
} | ||
|
||
private static bool TryClassifyAmbiguousSymbol( | ||
NameSyntax name, | ||
SimpleNameSyntax name, | ||
SymbolInfo symbolInfo, | ||
SegmentedList<ClassifiedSpan> result) | ||
{ | ||
|
@@ -138,19 +123,19 @@ private static bool TryClassifyAmbiguousSymbol( | |
} | ||
|
||
private static bool TryClassifySymbol( | ||
NameSyntax name, | ||
SimpleNameSyntax name, | ||
[NotNullWhen(returnValue: true)] ISymbol? symbol, | ||
out ClassifiedSpan classifiedSpan) | ||
{ | ||
// For Namespace parts, we want don't want to classify the QualifiedNameSyntax | ||
// nodes, we instead wait for the each IdentifierNameSyntax node to avoid | ||
// creating overlapping ClassifiedSpans. | ||
if (symbol is INamespaceSymbol namespaceSymbol && | ||
name is IdentifierNameSyntax identifierNameSyntax) | ||
name is IdentifierNameSyntax) | ||
{ | ||
// Do not classify the global:: namespace. It is already syntactically classified as a keyword. | ||
var isGlobalNamespace = namespaceSymbol.IsGlobalNamespace && | ||
identifierNameSyntax.Identifier.IsKind(SyntaxKind.GlobalKeyword); | ||
name.Identifier.IsKind(SyntaxKind.GlobalKeyword); | ||
if (isGlobalNamespace) | ||
{ | ||
classifiedSpan = default; | ||
|
@@ -281,7 +266,7 @@ private static string GetClassificationForMethod(IMethodSymbol methodSymbol) | |
: ClassificationTypeNames.MethodName; | ||
} | ||
|
||
private static bool IsInVarContext(NameSyntax name) | ||
private static bool IsInVarContext(SimpleNameSyntax name) | ||
{ | ||
return | ||
name.CheckParent<RefTypeSyntax>(v => v.Type == name) || | ||
|
@@ -293,18 +278,18 @@ private static bool IsInVarContext(NameSyntax name) | |
} | ||
|
||
private static bool TryClassifyFromIdentifier( | ||
NameSyntax name, | ||
SimpleNameSyntax name, | ||
SymbolInfo symbolInfo, | ||
SegmentedList<ClassifiedSpan> result) | ||
{ | ||
// Okay - it wasn't a type. If the syntax matches "var q = from" or "q = from", and from | ||
// doesn't bind to anything then optimistically color from as a keyword. | ||
if (name is IdentifierNameSyntax identifierName && | ||
identifierName.Identifier.HasMatchingText(SyntaxKind.FromKeyword) && | ||
if (name is IdentifierNameSyntax && | ||
name.Identifier.HasMatchingText(SyntaxKind.FromKeyword) && | ||
symbolInfo.Symbol == null) | ||
{ | ||
var token = identifierName.Identifier; | ||
if (identifierName.IsRightSideOfAnyAssignExpression() || identifierName.IsVariableDeclaratorValue()) | ||
var token = name.Identifier; | ||
if (name.IsRightSideOfAnyAssignExpression() || name.IsVariableDeclaratorValue()) | ||
{ | ||
result.Add(new ClassifiedSpan(token.Span, ClassificationTypeNames.Keyword)); | ||
return true; | ||
|
@@ -315,21 +300,20 @@ private static bool TryClassifyFromIdentifier( | |
} | ||
|
||
private static bool TryClassifyValueIdentifier( | ||
NameSyntax name, | ||
SimpleNameSyntax name, | ||
SymbolInfo symbolInfo, | ||
SegmentedList<ClassifiedSpan> result) | ||
{ | ||
if (name is IdentifierNameSyntax identifierName && | ||
symbolInfo.Symbol.IsImplicitValueParameter()) | ||
if (symbolInfo.Symbol.IsImplicitValueParameter()) | ||
{ | ||
result.Add(new ClassifiedSpan(identifierName.Identifier.Span, ClassificationTypeNames.Keyword)); | ||
result.Add(new ClassifiedSpan(name.Identifier.Span, ClassificationTypeNames.Keyword)); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private static bool TryClassifySomeContextualKeywordIdentifiersAsKeywords(NameSyntax name, SymbolInfo symbolInfo, SegmentedList<ClassifiedSpan> result) | ||
private static bool TryClassifySomeContextualKeywordIdentifiersAsKeywords(SimpleNameSyntax name, SymbolInfo symbolInfo, SegmentedList<ClassifiedSpan> result) | ||
{ | ||
// Simple approach, if the user ever types one of identifiers from the list and it doesn't actually bind to anything, presume that | ||
// they intend to use it as a keyword. This works for all error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
no need to check these other 'composed name types'. We only care about
X
andX<...>
(and we only classifiy the 'X' part of each). Every other name type composes into one of these two name types that we actually classify here.this addresses a lot of callbacks for dotted names that serve no purpose.