Skip to content

Commit

Permalink
Merge branch 'main' into overrideCompletionNint
Browse files Browse the repository at this point in the history
  • Loading branch information
CyrusNajmabadi committed Nov 21, 2023
2 parents 84c91f4 + 1f8ae4c commit 14a70ca
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 72 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2239,7 +2239,7 @@ static void Main()
}
""",
testHost,
Class("var"));
Keyword("var"));
}

[Theory, WorkItem(9513, "DevDiv_Projects/Roslyn")]
Expand Down Expand Up @@ -2877,7 +2877,7 @@ class X<T> where T : unmanaged { }
""",
testHost,
TypeParameter("T"),
Interface("unmanaged"));
Keyword("unmanaged"));
}

[Theory, CombinatorialData]
Expand Down Expand Up @@ -2922,7 +2922,7 @@ void M<T>() where T : unmanaged { }
""",
testHost,
TypeParameter("T"),
Interface("unmanaged"));
Keyword("unmanaged"));
}

[Theory, CombinatorialData]
Expand Down Expand Up @@ -2963,7 +2963,7 @@ interface unmanaged {}
""",
testHost,
TypeParameter("T"),
Interface("unmanaged"));
Keyword("unmanaged"));
}

[Theory, CombinatorialData]
Expand Down Expand Up @@ -3014,7 +3014,7 @@ void M<T>() where T : unmanaged { }
""",
testHost,
TypeParameter("T"),
Interface("unmanaged"));
Keyword("unmanaged"));
}

[Theory, CombinatorialData]
Expand Down Expand Up @@ -3233,7 +3233,7 @@ class X<T> where T : notnull { }
""",
testHost,
TypeParameter("T"),
Interface("notnull"));
Keyword("notnull"));
}

[Theory, CombinatorialData]
Expand Down Expand Up @@ -3278,7 +3278,7 @@ void M<T>() where T : notnull { }
""",
testHost,
TypeParameter("T"),
Interface("notnull"));
Keyword("notnull"));
}

[Theory, CombinatorialData]
Expand Down Expand Up @@ -3319,7 +3319,7 @@ interface notnull {}
""",
testHost,
TypeParameter("T"),
Interface("notnull"));
Keyword("notnull"));
}

[Theory, CombinatorialData]
Expand Down Expand Up @@ -3370,7 +3370,7 @@ void M<T>() where T : notnull { }
""",
testHost,
TypeParameter("T"),
Interface("notnull"));
Keyword("notnull"));
}

[Theory, CombinatorialData]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +549,7 @@ void Goo<var>()
Punctuation.OpenParen,
Punctuation.CloseParen,
Punctuation.OpenCurly,
TypeParameter("var"),
Keyword("var"),
Local("x"),
Punctuation.Semicolon,
Punctuation.CloseCurly,
Expand Down Expand Up @@ -1147,7 +1147,7 @@ class X<T> where T : unmanaged { }
Keyword("where"),
TypeParameter("T"),
Punctuation.Colon,
Interface("unmanaged"),
Keyword("unmanaged"),
Punctuation.OpenCurly,
Punctuation.CloseCurly);
}
Expand Down Expand Up @@ -1241,7 +1241,7 @@ void M<T>() where T : unmanaged { }
Keyword("where"),
TypeParameter("T"),
Punctuation.Colon,
Interface("unmanaged"),
Keyword("unmanaged"),
Punctuation.OpenCurly,
Punctuation.CloseCurly,
Punctuation.CloseCurly);
Expand Down Expand Up @@ -1332,7 +1332,7 @@ interface unmanaged {}
Keyword("where"),
TypeParameter("T"),
Punctuation.Colon,
Interface("unmanaged"),
Keyword("unmanaged"),
Punctuation.Semicolon);
}

Expand Down Expand Up @@ -1444,7 +1444,7 @@ void M<T>() where T : unmanaged { }
Keyword("where"),
TypeParameter("T"),
Punctuation.Colon,
Interface("unmanaged"),
Keyword("unmanaged"),
Punctuation.OpenCurly,
Punctuation.CloseCurly,
Punctuation.CloseCurly,
Expand Down Expand Up @@ -1636,7 +1636,7 @@ class X<T> where T : notnull { }
Keyword("where"),
TypeParameter("T"),
Punctuation.Colon,
Interface("notnull"),
Keyword("notnull"),
Punctuation.OpenCurly,
Punctuation.CloseCurly);
}
Expand Down Expand Up @@ -1730,7 +1730,7 @@ void M<T>() where T : notnull { }
Keyword("where"),
TypeParameter("T"),
Punctuation.Colon,
Interface("notnull"),
Keyword("notnull"),
Punctuation.OpenCurly,
Punctuation.CloseCurly,
Punctuation.CloseCurly);
Expand Down Expand Up @@ -1821,7 +1821,7 @@ interface notnull {}
Keyword("where"),
TypeParameter("T"),
Punctuation.Colon,
Interface("notnull"),
Keyword("notnull"),
Punctuation.Semicolon);
}

Expand Down Expand Up @@ -1933,7 +1933,7 @@ void M<T>() where T : notnull { }
Keyword("where"),
TypeParameter("T"),
Punctuation.Colon,
Interface("notnull"),
Keyword("notnull"),
Punctuation.OpenCurly,
Punctuation.CloseCurly,
Punctuation.CloseCurly,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private void ClassifyTypeSyntax(
var symbolInfo = semanticModel.GetSymbolInfo(name, cancellationToken);

var _ =
TryClassifySymbol(name, symbolInfo, semanticModel, result, cancellationToken) ||
TryClassifySymbol(name, symbolInfo, result) ||
TryClassifyFromIdentifier(name, symbolInfo, result) ||
TryClassifyValueIdentifier(name, symbolInfo, result) ||
TryClassifySomeContextualKeywordIdentifiersAsKeywords(name, symbolInfo, result);
Expand All @@ -68,21 +68,19 @@ private void ClassifyTypeSyntax(
private bool TryClassifySymbol(
NameSyntax name,
SymbolInfo symbolInfo,
SemanticModel semanticModel,
SegmentedList<ClassifiedSpan> result,
CancellationToken cancellationToken)
SegmentedList<ClassifiedSpan> result)
{
if (symbolInfo.CandidateReason is
CandidateReason.Ambiguous or
CandidateReason.MemberGroup)
{
return TryClassifyAmbiguousSymbol(name, symbolInfo, semanticModel, result, cancellationToken);
return TryClassifyAmbiguousSymbol(name, symbolInfo, result);
}

// Only classify if we get one good symbol back, or if it bound to a constructor symbol with
// overload resolution/accessibility errors, or bound to type/constructor and type wasn't creatable.
var symbol = TryGetSymbol(name, symbolInfo);
if (TryClassifySymbol(name, symbol, semanticModel, cancellationToken, out var classifiedSpan))
if (TryClassifySymbol(name, symbol, out var classifiedSpan))
{
result.Add(classifiedSpan);

Expand All @@ -101,17 +99,15 @@ CandidateReason.Ambiguous or
private static bool TryClassifyAmbiguousSymbol(
NameSyntax name,
SymbolInfo symbolInfo,
SemanticModel semanticModel,
SegmentedList<ClassifiedSpan> result,
CancellationToken cancellationToken)
SegmentedList<ClassifiedSpan> result)
{
// If everything classifies the same way, then just pick that classification.
using var _ = PooledHashSet<ClassifiedSpan>.GetInstance(out var set);
var isStatic = false;

foreach (var symbol in symbolInfo.CandidateSymbols)
{
if (TryClassifySymbol(name, symbol, semanticModel, cancellationToken, out var classifiedSpan))
if (TryClassifySymbol(name, symbol, out var classifiedSpan))
{
// If one symbol resolves to static, then just make it bold
isStatic = isStatic || IsStaticSymbol(symbol);
Expand All @@ -137,8 +133,6 @@ private static bool TryClassifyAmbiguousSymbol(
private static bool TryClassifySymbol(
NameSyntax name,
[NotNullWhen(returnValue: true)] ISymbol? symbol,
SemanticModel semanticModel,
CancellationToken cancellationToken,
out ClassifiedSpan classifiedSpan)
{
// For Namespace parts, we want don't want to classify the QualifiedNameSyntax
Expand All @@ -161,21 +155,12 @@ private static bool TryClassifySymbol(
return true;
}

if (name.IsVar &&
IsInVarContext(name))
if (name.IsVar && IsInVarContext(name))
{
var alias = semanticModel.GetAliasInfo(name, cancellationToken);
if (alias == null || alias.Name != "var")
{
if (!IsSymbolWithName(symbol, "var"))
{
// We bound to a symbol. If we bound to a symbol called "var" then we want to
// classify this appropriately as a type. Otherwise, we want to classify this as
// a keyword.
classifiedSpan = new ClassifiedSpan(name.Span, ClassificationTypeNames.Keyword);
return true;
}
}
// Don't do anything further to check if `var` is the contextual keyword here. We do not support code
// squatting on typenames that are all lowercase.
classifiedSpan = new ClassifiedSpan(name.Span, ClassificationTypeNames.Keyword);
return true;
}

if (name is IdentifierNameSyntax { Identifier.Text: "args" } &&
Expand All @@ -196,19 +181,8 @@ private static bool TryClassifySymbol(

if ((name.IsUnmanaged || name.IsNotNull) && name.Parent.IsKind(SyntaxKind.TypeConstraint))
{
var nameToCheck = name.IsUnmanaged ? "unmanaged" : "notnull";
var alias = semanticModel.GetAliasInfo(name, cancellationToken);
if (alias == null || alias.Name != nameToCheck)
{
if (!IsSymbolWithName(symbol, nameToCheck))
{
// We bound to a symbol. If we bound to a symbol called "unmanaged"/"notnull" then we want to
// classify this appropriately as a type. Otherwise, we want to classify this as
// a keyword.
classifiedSpan = new ClassifiedSpan(name.Span, ClassificationTypeNames.Keyword);
return true;
}
}
classifiedSpan = new ClassifiedSpan(name.Span, ClassificationTypeNames.Keyword);
return true;
}

// Use .Equals since we can't rely on object identity for constructed types.
Expand Down Expand Up @@ -363,20 +337,5 @@ private static bool TryClassifySomeContextualKeywordIdentifiersAsKeywords(NameSy

return false;
}

private static bool IsSymbolWithName([NotNullWhen(true)] ISymbol? symbol, string name)
{
if (symbol is null || symbol.Name != name)
{
return false;
}

if (symbol is INamedTypeSymbol namedType)
{
return namedType.Arity == 0;
}

return true;
}
}
}

0 comments on commit 14a70ca

Please sign in to comment.