diff --git a/src/Features/Core/Portable/EmbeddedLanguages/Classification/AbstractEmbeddedLanguageClassificationService.cs b/src/Features/Core/Portable/EmbeddedLanguages/Classification/AbstractEmbeddedLanguageClassificationService.cs index 6b73e38851462..acb8bda57ac91 100644 --- a/src/Features/Core/Portable/EmbeddedLanguages/Classification/AbstractEmbeddedLanguageClassificationService.cs +++ b/src/Features/Core/Portable/EmbeddedLanguages/Classification/AbstractEmbeddedLanguageClassificationService.cs @@ -89,7 +89,7 @@ public void VisitTokens(SyntaxNode node) while (stack.TryPop(out var currentNodeOrToken)) { _cancellationToken.ThrowIfCancellationRequested(); - if (currentNodeOrToken.Span.IntersectsWith(_textSpan)) + if (currentNodeOrToken.FullSpan.IntersectsWith(_textSpan)) { if (currentNodeOrToken.IsNode) { diff --git a/src/Workspaces/CSharp/Portable/Classification/SyntaxClassification/NameSyntaxClassifier.cs b/src/Workspaces/CSharp/Portable/Classification/SyntaxClassification/NameSyntaxClassifier.cs index 3b602d47553c0..2ef45cd853a96 100644 --- a/src/Workspaces/CSharp/Portable/Classification/SyntaxClassification/NameSyntaxClassifier.cs +++ b/src/Workspaces/CSharp/Portable/Classification/SyntaxClassification/NameSyntaxClassifier.cs @@ -29,36 +29,21 @@ public override void AddClassifications( SegmentedList result, CancellationToken cancellationToken) { - if (syntax is NameSyntax name) - { + if (syntax is SimpleNameSyntax name) ClassifyTypeSyntax(name, semanticModel, result, cancellationToken); - } } public override ImmutableArray SyntaxNodeTypes { get; } = [ - typeof(AliasQualifiedNameSyntax), - typeof(GenericNameSyntax), typeof(IdentifierNameSyntax), - typeof(QualifiedNameSyntax), - typeof(SimpleNameSyntax), + typeof(GenericNameSyntax), ]; - protected override int? GetRightmostNameArity(SyntaxNode node) - { - 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 result, CancellationToken cancellationToken) @@ -73,7 +58,7 @@ private void ClassifyTypeSyntax( } private bool TryClassifySymbol( - NameSyntax name, + SimpleNameSyntax name, SymbolInfo symbolInfo, SegmentedList result) { @@ -104,7 +89,7 @@ CandidateReason.Ambiguous or } private static bool TryClassifyAmbiguousSymbol( - NameSyntax name, + SimpleNameSyntax name, SymbolInfo symbolInfo, SegmentedList result) { @@ -138,7 +123,7 @@ private static bool TryClassifyAmbiguousSymbol( } private static bool TryClassifySymbol( - NameSyntax name, + SimpleNameSyntax name, [NotNullWhen(returnValue: true)] ISymbol? symbol, out ClassifiedSpan classifiedSpan) { @@ -146,11 +131,11 @@ private static bool TryClassifySymbol( // 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(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 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 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 result) + private static bool TryClassifySomeContextualKeywordIdentifiersAsKeywords(SimpleNameSyntax name, SymbolInfo symbolInfo, SegmentedList 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 diff --git a/src/Workspaces/Core/Portable/Classification/SyntaxClassification/AbstractNameSyntaxClassifier.cs b/src/Workspaces/Core/Portable/Classification/SyntaxClassification/AbstractNameSyntaxClassifier.cs index 9764597b902f9..6d788161270b0 100644 --- a/src/Workspaces/Core/Portable/Classification/SyntaxClassification/AbstractNameSyntaxClassifier.cs +++ b/src/Workspaces/Core/Portable/Classification/SyntaxClassification/AbstractNameSyntaxClassifier.cs @@ -11,7 +11,6 @@ namespace Microsoft.CodeAnalysis.Classification.Classifiers; internal abstract class AbstractNameSyntaxClassifier : AbstractSyntaxClassifier { - protected abstract int? GetRightmostNameArity(SyntaxNode node); protected abstract bool IsParentAnAttribute(SyntaxNode node); protected ISymbol? TryGetSymbol(SyntaxNode node, SymbolInfo symbolInfo) diff --git a/src/Workspaces/VisualBasic/Portable/Classification/SyntaxClassification/NameSyntaxClassifier.vb b/src/Workspaces/VisualBasic/Portable/Classification/SyntaxClassification/NameSyntaxClassifier.vb index 0cc5c53729020..b7f441c1d32ab 100644 --- a/src/Workspaces/VisualBasic/Portable/Classification/SyntaxClassification/NameSyntaxClassifier.vb +++ b/src/Workspaces/VisualBasic/Portable/Classification/SyntaxClassification/NameSyntaxClassifier.vb @@ -60,14 +60,6 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Classification.Classifiers End If End Sub - Protected Overrides Function GetRightmostNameArity(node As SyntaxNode) As Integer? - If TypeOf (node) Is ExpressionSyntax Then - Return DirectCast(node, ExpressionSyntax).GetRightmostName()?.Arity - End If - - Return Nothing - End Function - Protected Overrides Function IsParentAnAttribute(node As SyntaxNode) As Boolean Return node.IsParentKind(SyntaxKind.Attribute) End Function