未验证 提交 288d9497 编写于 作者: S Shyam-Gupta 提交者: GitHub

Merge pull request #25116 from dotnet/merges/dev15.7.x-to-features/compiler

Merge dev15.7.x to features/compiler
......@@ -330,9 +330,11 @@ private BoundExpression CreateStackAllocConversion(SyntaxNode syntax, BoundExpre
switch (conversion.Kind)
{
case ConversionKind.StackAllocToPointerType:
ReportUnsafeIfNotAllowed(syntax.Location, diagnostics);
stackAllocType = new PointerTypeSymbol(elementType);
break;
case ConversionKind.StackAllocToSpanType:
CheckFeatureAvailability(syntax, MessageID.IDS_FeatureRefStructs, diagnostics);
stackAllocType = Compilation.GetWellKnownType(WellKnownType.System_Span_T).Construct(elementType);
break;
default:
......
......@@ -3127,7 +3127,6 @@ private void BindArrayInitializerExpressions(InitializerExpressionSyntax initial
if (inLegalPosition && !node.IsVariableDeclarationInitialization())
{
CheckFeatureAvailability(node, MessageID.IDS_FeatureRefStructs, diagnostics);
GetWellKnownTypeMember(Compilation, WellKnownMember.System_Span_T__ctor, diagnostics, syntax: node);
var spanType = GetWellKnownType(WellKnownType.System_Span_T, diagnostics, node);
if (!spanType.IsErrorType())
......
......@@ -2091,19 +2091,6 @@ internal static bool CheckFeatureAvailability(SyntaxTree tree, MessageID feature
return false;
}
internal static bool CheckFeatureAvailability(SyntaxNode syntax, MessageID feature, ref HashSet<DiagnosticInfo> useSiteDiagnostics)
{
CSDiagnosticInfo error = GetFeatureAvailabilityDiagnosticInfo(syntax.SyntaxTree, feature);
if (error is null)
{
return true;
}
HashSetExtensions.InitializeAndAdd(ref useSiteDiagnostics, error);
return false;
}
private static CSDiagnosticInfo GetFeatureAvailabilityDiagnosticInfo(SyntaxTree tree, MessageID feature)
{
CSharpParseOptions options = (CSharpParseOptions)tree.Options;
......
......@@ -27,20 +27,6 @@ internal bool ReportUnsafeIfNotAllowed(SyntaxNode node, DiagnosticBag diagnostic
return ReportUnsafeIfNotAllowed(node.Location, diagnostics, sizeOfTypeOpt);
}
/// <returns>True if a diagnostic was reported</returns>
internal bool ReportUnsafeIfNotAllowed(Location location, ref HashSet<DiagnosticInfo> useSiteDiagnostics, TypeSymbol sizeOfTypeOpt = null)
{
var diagnosticInfo = GetUnsafeDiagnosticInfo(sizeOfTypeOpt: sizeOfTypeOpt);
if (diagnosticInfo is null)
{
return false;
}
HashSetExtensions.InitializeAndAdd(ref useSiteDiagnostics, diagnosticInfo);
return true;
}
/// <returns>True if a diagnostic was reported</returns>
internal bool ReportUnsafeIfNotAllowed(Location location, DiagnosticBag diagnostics, TypeSymbol sizeOfTypeOpt = null)
{
......
......@@ -304,15 +304,11 @@ public override Conversion GetStackAllocConversion(BoundStackAllocArrayCreation
Debug.Assert((object)sourceExpression.Type == null);
Debug.Assert(sourceExpression.ElementType != null);
var pointerConversion = default(Conversion);
var sourceAsPointer = new PointerTypeSymbol(sourceExpression.ElementType);
pointerConversion = ClassifyImplicitConversionFromType(sourceAsPointer, destination, ref useSiteDiagnostics);
var pointerConversion = ClassifyImplicitConversionFromType(sourceAsPointer, destination, ref useSiteDiagnostics);
if (pointerConversion.IsValid)
{
// Report unsafe errors
_binder.ReportUnsafeIfNotAllowed(sourceExpression.Syntax.Location, ref useSiteDiagnostics);
return Conversion.MakeStackAllocToPointerType(pointerConversion);
}
else
......@@ -325,11 +321,6 @@ public override Conversion GetStackAllocConversion(BoundStackAllocArrayCreation
if (spanConversion.Exists)
{
// Report errors if Span ctor is missing, or using an older C# version
Binder.CheckFeatureAvailability(sourceExpression.Syntax, MessageID.IDS_FeatureRefStructs, ref useSiteDiagnostics);
Binder.GetWellKnownTypeMember(_binder.Compilation, WellKnownMember.System_Span_T__ctor, out DiagnosticInfo memberDiagnosticInfo);
HashSetExtensions.InitializeAndAdd(ref useSiteDiagnostics, memberDiagnosticInfo);
return Conversion.MakeStackAllocToSpanType(spanConversion);
}
}
......
......@@ -62,7 +62,8 @@ public sealed class CSharpCompilationOptions : CompilationOptions, IEquatable<CS
MetadataReferenceResolver metadataReferenceResolver = null,
AssemblyIdentityComparer assemblyIdentityComparer = null,
StrongNameProvider strongNameProvider = null,
bool publicSign = false)
bool publicSign = false,
MetadataImportOptions metadataImportOptions = MetadataImportOptions.Public)
: this(outputKind, reportSuppressedDiagnostics, moduleName, mainTypeName, scriptClassName,
usings, optimizationLevel, checkOverflow, allowUnsafe,
cryptoKeyContainer, cryptoKeyFile, cryptoPublicKey, delaySign, platform,
......@@ -75,13 +76,56 @@ public sealed class CSharpCompilationOptions : CompilationOptions, IEquatable<CS
metadataReferenceResolver: metadataReferenceResolver,
assemblyIdentityComparer: assemblyIdentityComparer,
strongNameProvider: strongNameProvider,
metadataImportOptions: MetadataImportOptions.Public,
metadataImportOptions: metadataImportOptions,
referencesSupersedeLowerVersions: false,
publicSign: publicSign,
topLevelBinderFlags: BinderFlags.None)
{
}
// 15.6 BACKCOMPAT OVERLOAD -- DO NOT TOUCH
[EditorBrowsable(EditorBrowsableState.Never)]
public CSharpCompilationOptions(
OutputKind outputKind,
bool reportSuppressedDiagnostics,
string moduleName,
string mainTypeName,
string scriptClassName,
IEnumerable<string> usings,
OptimizationLevel optimizationLevel,
bool checkOverflow,
bool allowUnsafe,
string cryptoKeyContainer,
string cryptoKeyFile,
ImmutableArray<byte> cryptoPublicKey,
bool? delaySign,
Platform platform,
ReportDiagnostic generalDiagnosticOption,
int warningLevel,
IEnumerable<KeyValuePair<string, ReportDiagnostic>> specificDiagnosticOptions,
bool concurrentBuild,
bool deterministic,
XmlReferenceResolver xmlReferenceResolver,
SourceReferenceResolver sourceReferenceResolver,
MetadataReferenceResolver metadataReferenceResolver,
AssemblyIdentityComparer assemblyIdentityComparer,
StrongNameProvider strongNameProvider,
bool publicSign)
: this(outputKind, reportSuppressedDiagnostics, moduleName, mainTypeName, scriptClassName,
usings, optimizationLevel, checkOverflow, allowUnsafe,
cryptoKeyContainer, cryptoKeyFile, cryptoPublicKey, delaySign, platform,
generalDiagnosticOption, warningLevel,
specificDiagnosticOptions, concurrentBuild, deterministic,
xmlReferenceResolver,
sourceReferenceResolver,
metadataReferenceResolver,
assemblyIdentityComparer,
strongNameProvider,
publicSign,
MetadataImportOptions.Public)
{
}
// Expects correct arguments.
internal CSharpCompilationOptions(
OutputKind outputKind,
......@@ -588,6 +632,11 @@ internal override void ValidateOptions(ArrayBuilder<Diagnostic> builder)
builder.Add(Diagnostic.Create(MessageProvider.Instance, (int)ErrorCode.ERR_BadPrefer32OnLib));
}
if (!MetadataImportOptions.IsValid())
{
builder.Add(Diagnostic.Create(MessageProvider.Instance, (int)ErrorCode.ERR_BadCompilationOptionValue, nameof(MetadataImportOptions), MetadataImportOptions.ToString()));
}
// TODO: add check for
// (kind == 'arm' || kind == 'appcontainer' || kind == 'winmdobj') &&
// (version >= "6.2")
......
......@@ -323,7 +323,6 @@ public override BoundNode VisitSwitchSection(BoundSwitchSection node, bool lastS
var boundLabel = node.SwitchLabels.Last();
Diagnostics.Add(lastSection ? ErrorCode.ERR_SwitchFallOut : ErrorCode.ERR_SwitchFallThrough,
new SourceLocation(boundLabel.Syntax), boundLabel.Label.Name);
this.State.Reported = true;
}
return null;
......@@ -344,7 +343,6 @@ protected override void VisitPatternSwitchSection(BoundPatternSwitchSection node
var syntax = node.SwitchLabels.Last().Pattern.Syntax;
Diagnostics.Add(isLastSection ? ErrorCode.ERR_SwitchFallOut : ErrorCode.ERR_SwitchFallThrough,
new SourceLocation(syntax), syntax.ToString());
this.State.Reported = true;
}
}
}
......
......@@ -39,14 +39,26 @@ public override BoundNode VisitStackAllocArrayCreation(BoundStackAllocArrayCreat
var stackSize = RewriteStackAllocCountToSize(countTemp, elementType);
stackAllocNode = new BoundConvertedStackAllocExpression(stackAllocNode.Syntax, elementType, stackSize, spanType);
var spanCtor = (MethodSymbol)_compilation.GetWellKnownTypeMember(WellKnownMember.System_Span_T__ctor).SymbolAsMember(spanType);
var ctorCall = _factory.New(spanCtor, stackAllocNode, countTemp);
BoundExpression constructorCall;
if (TryGetWellKnownTypeMember(stackAllocNode.Syntax, WellKnownMember.System_Span_T__ctor, out MethodSymbol spanConstructor))
{
constructorCall = _factory.New((MethodSymbol)spanConstructor.SymbolAsMember(spanType), stackAllocNode, countTemp);
}
else
{
constructorCall = new BoundBadExpression(
syntax: stackAllocNode.Syntax,
resultKind: LookupResultKind.NotInvocable,
symbols: ImmutableArray<Symbol>.Empty,
childBoundNodes: ImmutableArray<BoundExpression>.Empty,
type: ErrorTypeSymbol.UnknownResultType);
}
return new BoundSequence(
syntax: stackAllocNode.Syntax,
locals: ImmutableArray.Create(countTemp.LocalSymbol),
sideEffects: ImmutableArray.Create<BoundExpression>(countTempAssignment),
value: ctorCall,
value: constructorCall,
type: spanType);
}
else
......
......@@ -3,6 +3,9 @@
*REMOVED*Microsoft.CodeAnalysis.CSharp.Syntax.CrefParameterSyntax.Update(Microsoft.CodeAnalysis.SyntaxToken refOrOutKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax type) -> Microsoft.CodeAnalysis.CSharp.Syntax.CrefParameterSyntax
*REMOVED*static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.Argument(Microsoft.CodeAnalysis.CSharp.Syntax.NameColonSyntax nameColon, Microsoft.CodeAnalysis.SyntaxToken refOrOutKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.ExpressionSyntax expression) -> Microsoft.CodeAnalysis.CSharp.Syntax.ArgumentSyntax
*REMOVED*static Microsoft.CodeAnalysis.CSharp.SyntaxFactory.CrefParameter(Microsoft.CodeAnalysis.SyntaxToken refOrOutKeyword, Microsoft.CodeAnalysis.CSharp.Syntax.TypeSyntax type) -> Microsoft.CodeAnalysis.CSharp.Syntax.CrefParameterSyntax
Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions.CSharpCompilationOptions(Microsoft.CodeAnalysis.OutputKind outputKind, bool reportSuppressedDiagnostics = false, string moduleName = null, string mainTypeName = null, string scriptClassName = null, System.Collections.Generic.IEnumerable<string> usings = null, Microsoft.CodeAnalysis.OptimizationLevel optimizationLevel = Microsoft.CodeAnalysis.OptimizationLevel.Debug, bool checkOverflow = false, bool allowUnsafe = false, string cryptoKeyContainer = null, string cryptoKeyFile = null, System.Collections.Immutable.ImmutableArray<byte> cryptoPublicKey = default(System.Collections.Immutable.ImmutableArray<byte>), bool? delaySign = null, Microsoft.CodeAnalysis.Platform platform = Microsoft.CodeAnalysis.Platform.AnyCpu, Microsoft.CodeAnalysis.ReportDiagnostic generalDiagnosticOption = Microsoft.CodeAnalysis.ReportDiagnostic.Default, int warningLevel = 4, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, Microsoft.CodeAnalysis.ReportDiagnostic>> specificDiagnosticOptions = null, bool concurrentBuild = true, bool deterministic = false, Microsoft.CodeAnalysis.XmlReferenceResolver xmlReferenceResolver = null, Microsoft.CodeAnalysis.SourceReferenceResolver sourceReferenceResolver = null, Microsoft.CodeAnalysis.MetadataReferenceResolver metadataReferenceResolver = null, Microsoft.CodeAnalysis.AssemblyIdentityComparer assemblyIdentityComparer = null, Microsoft.CodeAnalysis.StrongNameProvider strongNameProvider = null, bool publicSign = false, Microsoft.CodeAnalysis.MetadataImportOptions metadataImportOptions = Microsoft.CodeAnalysis.MetadataImportOptions.Public) -> void
*REMOVED*Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions.CSharpCompilationOptions(Microsoft.CodeAnalysis.OutputKind outputKind, bool reportSuppressedDiagnostics = false, string moduleName = null, string mainTypeName = null, string scriptClassName = null, System.Collections.Generic.IEnumerable<string> usings = null, Microsoft.CodeAnalysis.OptimizationLevel optimizationLevel = Microsoft.CodeAnalysis.OptimizationLevel.Debug, bool checkOverflow = false, bool allowUnsafe = false, string cryptoKeyContainer = null, string cryptoKeyFile = null, System.Collections.Immutable.ImmutableArray<byte> cryptoPublicKey = default(System.Collections.Immutable.ImmutableArray<byte>), bool? delaySign = null, Microsoft.CodeAnalysis.Platform platform = Microsoft.CodeAnalysis.Platform.AnyCpu, Microsoft.CodeAnalysis.ReportDiagnostic generalDiagnosticOption = Microsoft.CodeAnalysis.ReportDiagnostic.Default, int warningLevel = 4, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, Microsoft.CodeAnalysis.ReportDiagnostic>> specificDiagnosticOptions = null, bool concurrentBuild = true, bool deterministic = false, Microsoft.CodeAnalysis.XmlReferenceResolver xmlReferenceResolver = null, Microsoft.CodeAnalysis.SourceReferenceResolver sourceReferenceResolver = null, Microsoft.CodeAnalysis.MetadataReferenceResolver metadataReferenceResolver = null, Microsoft.CodeAnalysis.AssemblyIdentityComparer assemblyIdentityComparer = null, Microsoft.CodeAnalysis.StrongNameProvider strongNameProvider = null, bool publicSign = false) -> void
Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions.CSharpCompilationOptions(Microsoft.CodeAnalysis.OutputKind outputKind, bool reportSuppressedDiagnostics, string moduleName, string mainTypeName, string scriptClassName, System.Collections.Generic.IEnumerable<string> usings, Microsoft.CodeAnalysis.OptimizationLevel optimizationLevel, bool checkOverflow, bool allowUnsafe, string cryptoKeyContainer, string cryptoKeyFile, System.Collections.Immutable.ImmutableArray<byte> cryptoPublicKey, bool? delaySign, Microsoft.CodeAnalysis.Platform platform, Microsoft.CodeAnalysis.ReportDiagnostic generalDiagnosticOption, int warningLevel, System.Collections.Generic.IEnumerable<System.Collections.Generic.KeyValuePair<string, Microsoft.CodeAnalysis.ReportDiagnostic>> specificDiagnosticOptions, bool concurrentBuild, bool deterministic, Microsoft.CodeAnalysis.XmlReferenceResolver xmlReferenceResolver, Microsoft.CodeAnalysis.SourceReferenceResolver sourceReferenceResolver, Microsoft.CodeAnalysis.MetadataReferenceResolver metadataReferenceResolver, Microsoft.CodeAnalysis.AssemblyIdentityComparer assemblyIdentityComparer, Microsoft.CodeAnalysis.StrongNameProvider strongNameProvider, bool publicSign) -> void
Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions.WithMetadataImportOptions(Microsoft.CodeAnalysis.MetadataImportOptions value) -> Microsoft.CodeAnalysis.CSharp.CSharpCompilationOptions
Microsoft.CodeAnalysis.CSharp.DeconstructionInfo
Microsoft.CodeAnalysis.CSharp.DeconstructionInfo.Conversion.get -> Microsoft.CodeAnalysis.CSharp.Conversion?
......
......@@ -5744,6 +5744,50 @@ void M(int x)
Assert.Equal("this, x, a, y", GetSymbolNamesJoined(analysis.WrittenOutside));
}
[Fact, WorkItem(25043, "https://github.com/dotnet/roslyn/issues/25043")]
public void FallThroughInSwitch_01()
{
var analysis = CompileAndAnalyzeControlFlowStatements(@"
class C
{
void M()
{
/*<bind>*/
switch (true)
{
case true:
void f()
{
}
}
/*</bind>*/
}
}");
Assert.Equal(0, analysis.EntryPoints.Count());
}
[Fact, WorkItem(25043, "https://github.com/dotnet/roslyn/issues/25043")]
public void FallThroughInSwitch_02()
{
var analysis = CompileAndAnalyzeControlFlowStatements(@"
class C
{
void M()
{
/*<bind>*/
switch (true)
{
case true when true:
void f()
{
}
}
/*</bind>*/
}
}");
Assert.Equal(0, analysis.EntryPoints.Count());
}
#endregion
}
}
......@@ -220,7 +220,7 @@ void M()
Span<int> a = stackalloc int [10];
}
}
}").VerifyDiagnostics(
}").VerifyEmitDiagnostics(
// (11,27): error CS0656: Missing compiler required member 'System.Span`1..ctor'
// Span<int> a = stackalloc int [10];
Diagnostic(ErrorCode.ERR_MissingPredefinedMember, "stackalloc int [10]").WithArguments("System.Span`1", ".ctor").WithLocation(11, 27));
......@@ -347,7 +347,7 @@ void M()
}
[Fact]
public void NewStackAllocSpanSyntaxProducesErrorsOnEarlierVersions()
public void NewStackAllocSpanSyntaxProducesErrorsOnEarlierVersions_Statements()
{
var parseOptions = new CSharpParseOptions().WithLanguageVersion(LanguageVersion.CSharp7);
......@@ -365,6 +365,29 @@ void M()
Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "stackalloc int[10]").WithArguments("ref structs", "7.2").WithLocation(7, 23));
}
[Fact]
public void NewStackAllocSpanSyntaxProducesErrorsOnEarlierVersions_Expressions()
{
var parseOptions = new CSharpParseOptions().WithLanguageVersion(LanguageVersion.CSharp7);
CreateCompilationWithMscorlibAndSpan(@"
class Test
{
void M(bool condition)
{
var x = condition
? stackalloc int[10]
: stackalloc int[100];
}
}", options: TestOptions.UnsafeReleaseDll, parseOptions: parseOptions).VerifyDiagnostics(
// (7,15): error CS8107: Feature 'ref structs' is not available in C# 7.0. Please use language version 7.2 or greater.
// ? stackalloc int[10]
Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "stackalloc int[10]").WithArguments("ref structs", "7.2").WithLocation(7, 15),
// (8,15): error CS8107: Feature 'ref structs' is not available in C# 7.0. Please use language version 7.2 or greater.
// : stackalloc int[100];
Diagnostic(ErrorCode.ERR_FeatureNotAvailableInVersion7, "stackalloc int[100]").WithArguments("ref structs", "7.2").WithLocation(8, 15));
}
[Fact]
public void StackAllocSyntaxProducesUnsafeErrorInSafeCode()
{
......
......@@ -672,26 +672,45 @@ class Test
}
[Fact]
public void TestMetadataImportOptions()
public void TestMetadataImportOptions_01()
{
var expectedDiagnostics = new[]
{
// error CS7088: Invalid 'MetadataImportOptions' value: '255'.
Diagnostic(ErrorCode.ERR_BadCompilationOptionValue).WithArguments("MetadataImportOptions", "255").WithLocation(1, 1)
};
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary);
Assert.Equal(MetadataImportOptions.Public, options.MetadataImportOptions);
options.VerifyErrors();
options = options.WithMetadataImportOptions(MetadataImportOptions.Internal);
Assert.Equal(MetadataImportOptions.Internal, options.MetadataImportOptions);
options.VerifyErrors();
options = options.WithMetadataImportOptions(MetadataImportOptions.All);
Assert.Equal(MetadataImportOptions.All, options.MetadataImportOptions);
options.VerifyErrors();
options = options.WithMetadataImportOptions(MetadataImportOptions.Public);
Assert.Equal(MetadataImportOptions.Public, options.MetadataImportOptions);
options.VerifyErrors();
options = options.WithMetadataImportOptions((MetadataImportOptions)byte.MaxValue);
Assert.Equal((MetadataImportOptions)byte.MaxValue, options.MetadataImportOptions);
options.VerifyErrors(expectedDiagnostics);
var commonOptions = (CompilationOptions)options;
commonOptions = commonOptions.WithMetadataImportOptions(MetadataImportOptions.Internal);
Assert.Equal(MetadataImportOptions.Internal, ((CSharpCompilationOptions)commonOptions).MetadataImportOptions);
((CSharpCompilationOptions)commonOptions).VerifyErrors();
commonOptions = commonOptions.WithMetadataImportOptions(MetadataImportOptions.All);
Assert.Equal(MetadataImportOptions.All, ((CSharpCompilationOptions)commonOptions).MetadataImportOptions);
((CSharpCompilationOptions)commonOptions).VerifyErrors();
commonOptions = commonOptions.WithMetadataImportOptions(MetadataImportOptions.Public);
Assert.Equal(MetadataImportOptions.Public, ((CSharpCompilationOptions)commonOptions).MetadataImportOptions);
((CSharpCompilationOptions)commonOptions).VerifyErrors();
commonOptions = commonOptions.WithMetadataImportOptions((MetadataImportOptions)byte.MaxValue);
Assert.Equal((MetadataImportOptions)byte.MaxValue, ((CSharpCompilationOptions)commonOptions).MetadataImportOptions);
((CSharpCompilationOptions)commonOptions).VerifyErrors(expectedDiagnostics);
var source = @"
public class C
......@@ -709,18 +728,84 @@ public class C
Assert.NotEmpty(c.GetMembers("P1"));
Assert.Empty(c.GetMembers("P2"));
Assert.Empty(c.GetMembers("P3"));
CompileAndVerify(compilation);
compilation = compilation.WithOptions(options.WithMetadataImportOptions(MetadataImportOptions.Internal));
c = compilation.GetTypeByMetadataName("C");
Assert.NotEmpty(c.GetMembers("P1"));
Assert.NotEmpty(c.GetMembers("P2"));
Assert.Empty(c.GetMembers("P3"));
CompileAndVerify(compilation);
compilation = compilation.WithOptions(options.WithMetadataImportOptions(MetadataImportOptions.All));
c = compilation.GetTypeByMetadataName("C");
Assert.NotEmpty(c.GetMembers("P1"));
Assert.NotEmpty(c.GetMembers("P2"));
Assert.NotEmpty(c.GetMembers("P3"));
CompileAndVerify(compilation);
compilation = compilation.WithOptions(options.WithMetadataImportOptions((MetadataImportOptions)byte.MaxValue));
c = compilation.GetTypeByMetadataName("C");
Assert.NotEmpty(c.GetMembers("P1"));
Assert.NotEmpty(c.GetMembers("P2"));
Assert.Empty(c.GetMembers("P3"));
compilation.VerifyEmitDiagnostics(expectedDiagnostics);
compilation.VerifyDiagnostics(expectedDiagnostics);
}
[Fact]
public void TestMetadataImportOptions_02()
{
var expectedDiagnostics = new[]
{
// error CS7088: Invalid 'MetadataImportOptions' value: '255'.
Diagnostic(ErrorCode.ERR_BadCompilationOptionValue).WithArguments("MetadataImportOptions", "255").WithLocation(1, 1)
};
var options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions: MetadataImportOptions.Internal);
Assert.Equal(MetadataImportOptions.Internal, options.MetadataImportOptions);
options.VerifyErrors();
options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions: MetadataImportOptions.All);
Assert.Equal(MetadataImportOptions.All, options.MetadataImportOptions);
options.VerifyErrors();
options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions: MetadataImportOptions.Public);
Assert.Equal(MetadataImportOptions.Public, options.MetadataImportOptions);
options.VerifyErrors();
options = new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions: (MetadataImportOptions)byte.MaxValue);
Assert.Equal((MetadataImportOptions)byte.MaxValue, options.MetadataImportOptions);
options.VerifyErrors(expectedDiagnostics);
var source = @"
public class C
{
public int P1 {get; set;}
internal int P2 {get; set;}
private int P3 {get; set;}
}
";
var compilation0 = CreateCompilation(source);
var compilation = CreateCompilation("", options: new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions: MetadataImportOptions.Internal), references: new[] { compilation0.EmitToImageReference() });
var c = compilation.GetTypeByMetadataName("C");
Assert.NotEmpty(c.GetMembers("P1"));
Assert.NotEmpty(c.GetMembers("P2"));
Assert.Empty(c.GetMembers("P3"));
CompileAndVerify(compilation);
compilation = compilation.WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions: MetadataImportOptions.All));
c = compilation.GetTypeByMetadataName("C");
Assert.NotEmpty(c.GetMembers("P1"));
Assert.NotEmpty(c.GetMembers("P2"));
Assert.NotEmpty(c.GetMembers("P3"));
CompileAndVerify(compilation);
compilation = compilation.WithOptions(new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions: (MetadataImportOptions)byte.MaxValue));
c = compilation.GetTypeByMetadataName("C");
Assert.NotEmpty(c.GetMembers("P1"));
Assert.NotEmpty(c.GetMembers("P2"));
Assert.Empty(c.GetMembers("P3"));
compilation.VerifyEmitDiagnostics(expectedDiagnostics);
compilation.VerifyDiagnostics(expectedDiagnostics);
}
}
}
......@@ -24,4 +24,12 @@ public enum MetadataImportOptions : byte
/// </summary>
All = 2,
}
internal static partial class EnumBounds
{
internal static bool IsValid(this MetadataImportOptions value)
{
return value >= MetadataImportOptions.Public && value <= MetadataImportOptions.All;
}
}
}
Microsoft.CodeAnalysis.VisualBasic.VisualBasicCompilationOptions.New(outputKind As Microsoft.CodeAnalysis.OutputKind, moduleName As String = Nothing, mainTypeName As String = Nothing, scriptClassName As String = "Script", globalImports As System.Collections.Generic.IEnumerable(Of Microsoft.CodeAnalysis.VisualBasic.GlobalImport) = Nothing, rootNamespace As String = Nothing, optionStrict As Microsoft.CodeAnalysis.VisualBasic.OptionStrict = Microsoft.CodeAnalysis.VisualBasic.OptionStrict.Off, optionInfer As Boolean = True, optionExplicit As Boolean = True, optionCompareText As Boolean = False, parseOptions As Microsoft.CodeAnalysis.VisualBasic.VisualBasicParseOptions = Nothing, embedVbCoreRuntime As Boolean = False, optimizationLevel As Microsoft.CodeAnalysis.OptimizationLevel = Microsoft.CodeAnalysis.OptimizationLevel.Debug, checkOverflow As Boolean = True, cryptoKeyContainer As String = Nothing, cryptoKeyFile As String = Nothing, cryptoPublicKey As System.Collections.Immutable.ImmutableArray(Of Byte) = Nothing, delaySign As Boolean? = Nothing, platform As Microsoft.CodeAnalysis.Platform = Microsoft.CodeAnalysis.Platform.AnyCpu, generalDiagnosticOption As Microsoft.CodeAnalysis.ReportDiagnostic = Microsoft.CodeAnalysis.ReportDiagnostic.Default, specificDiagnosticOptions As System.Collections.Generic.IEnumerable(Of System.Collections.Generic.KeyValuePair(Of String, Microsoft.CodeAnalysis.ReportDiagnostic)) = Nothing, concurrentBuild As Boolean = True, deterministic As Boolean = False, xmlReferenceResolver As Microsoft.CodeAnalysis.XmlReferenceResolver = Nothing, sourceReferenceResolver As Microsoft.CodeAnalysis.SourceReferenceResolver = Nothing, metadataReferenceResolver As Microsoft.CodeAnalysis.MetadataReferenceResolver = Nothing, assemblyIdentityComparer As Microsoft.CodeAnalysis.AssemblyIdentityComparer = Nothing, strongNameProvider As Microsoft.CodeAnalysis.StrongNameProvider = Nothing, publicSign As Boolean = False, reportSuppressedDiagnostics As Boolean = False, metadataImportOptions As Microsoft.CodeAnalysis.MetadataImportOptions = Microsoft.CodeAnalysis.MetadataImportOptions.Public) -> Void
*REMOVED*Microsoft.CodeAnalysis.VisualBasic.VisualBasicCompilationOptions.New(outputKind As Microsoft.CodeAnalysis.OutputKind, moduleName As String = Nothing, mainTypeName As String = Nothing, scriptClassName As String = "Script", globalImports As System.Collections.Generic.IEnumerable(Of Microsoft.CodeAnalysis.VisualBasic.GlobalImport) = Nothing, rootNamespace As String = Nothing, optionStrict As Microsoft.CodeAnalysis.VisualBasic.OptionStrict = Microsoft.CodeAnalysis.VisualBasic.OptionStrict.Off, optionInfer As Boolean = True, optionExplicit As Boolean = True, optionCompareText As Boolean = False, parseOptions As Microsoft.CodeAnalysis.VisualBasic.VisualBasicParseOptions = Nothing, embedVbCoreRuntime As Boolean = False, optimizationLevel As Microsoft.CodeAnalysis.OptimizationLevel = Microsoft.CodeAnalysis.OptimizationLevel.Debug, checkOverflow As Boolean = True, cryptoKeyContainer As String = Nothing, cryptoKeyFile As String = Nothing, cryptoPublicKey As System.Collections.Immutable.ImmutableArray(Of Byte) = Nothing, delaySign As Boolean? = Nothing, platform As Microsoft.CodeAnalysis.Platform = Microsoft.CodeAnalysis.Platform.AnyCpu, generalDiagnosticOption As Microsoft.CodeAnalysis.ReportDiagnostic = Microsoft.CodeAnalysis.ReportDiagnostic.Default, specificDiagnosticOptions As System.Collections.Generic.IEnumerable(Of System.Collections.Generic.KeyValuePair(Of String, Microsoft.CodeAnalysis.ReportDiagnostic)) = Nothing, concurrentBuild As Boolean = True, deterministic As Boolean = False, xmlReferenceResolver As Microsoft.CodeAnalysis.XmlReferenceResolver = Nothing, sourceReferenceResolver As Microsoft.CodeAnalysis.SourceReferenceResolver = Nothing, metadataReferenceResolver As Microsoft.CodeAnalysis.MetadataReferenceResolver = Nothing, assemblyIdentityComparer As Microsoft.CodeAnalysis.AssemblyIdentityComparer = Nothing, strongNameProvider As Microsoft.CodeAnalysis.StrongNameProvider = Nothing, publicSign As Boolean = False, reportSuppressedDiagnostics As Boolean = False) -> Void
Microsoft.CodeAnalysis.VisualBasic.VisualBasicCompilationOptions.New(outputKind As Microsoft.CodeAnalysis.OutputKind, moduleName As String, mainTypeName As String, scriptClassName As String, globalImports As System.Collections.Generic.IEnumerable(Of Microsoft.CodeAnalysis.VisualBasic.GlobalImport), rootNamespace As String, optionStrict As Microsoft.CodeAnalysis.VisualBasic.OptionStrict, optionInfer As Boolean, optionExplicit As Boolean, optionCompareText As Boolean, parseOptions As Microsoft.CodeAnalysis.VisualBasic.VisualBasicParseOptions, embedVbCoreRuntime As Boolean, optimizationLevel As Microsoft.CodeAnalysis.OptimizationLevel, checkOverflow As Boolean, cryptoKeyContainer As String, cryptoKeyFile As String, cryptoPublicKey As System.Collections.Immutable.ImmutableArray(Of Byte), delaySign As Boolean?, platform As Microsoft.CodeAnalysis.Platform, generalDiagnosticOption As Microsoft.CodeAnalysis.ReportDiagnostic, specificDiagnosticOptions As System.Collections.Generic.IEnumerable(Of System.Collections.Generic.KeyValuePair(Of String, Microsoft.CodeAnalysis.ReportDiagnostic)), concurrentBuild As Boolean, deterministic As Boolean, xmlReferenceResolver As Microsoft.CodeAnalysis.XmlReferenceResolver, sourceReferenceResolver As Microsoft.CodeAnalysis.SourceReferenceResolver, metadataReferenceResolver As Microsoft.CodeAnalysis.MetadataReferenceResolver, assemblyIdentityComparer As Microsoft.CodeAnalysis.AssemblyIdentityComparer, strongNameProvider As Microsoft.CodeAnalysis.StrongNameProvider, publicSign As Boolean, reportSuppressedDiagnostics As Boolean) -> Void
Microsoft.CodeAnalysis.VisualBasic.VisualBasicCompilationOptions.WithMetadataImportOptions(value As Microsoft.CodeAnalysis.MetadataImportOptions) -> Microsoft.CodeAnalysis.VisualBasic.VisualBasicCompilationOptions
\ No newline at end of file
' Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
Imports System.Collections.Immutable
Imports System.ComponentModel
Imports Microsoft.CodeAnalysis
Imports Microsoft.CodeAnalysis.PooledObjects
......@@ -27,6 +28,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Private _ignoreCorLibraryDuplicatedTypes As Boolean
#Disable Warning RS0026 ' Do not add multiple overloads with optional parameters
''' <summary>
''' Initializes a new instance of the VisualBasicCompilationOptions type with various options.
''' </summary>
......@@ -59,6 +61,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
''' <param name="strongNameProvider">An optional parameter to specify <see cref="CodeAnalysis.StrongNameProvider"/>.</param>
''' <param name="publicSign">An optional parameter to specify whether the assembly will be public signed.</param>
''' <param name="reportSuppressedDiagnostics">An optional parameter to specify whether or not suppressed diagnostics should be reported.</param>
''' <param name="metadataImportOptions">An optional parameter to specify metadata import options.</param>
Public Sub New(
outputKind As OutputKind,
Optional moduleName As String = Nothing,
......@@ -89,7 +92,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Optional assemblyIdentityComparer As AssemblyIdentityComparer = Nothing,
Optional strongNameProvider As StrongNameProvider = Nothing,
Optional publicSign As Boolean = False,
Optional reportSuppressedDiagnostics As Boolean = False)
Optional reportSuppressedDiagnostics As Boolean = False,
Optional metadataImportOptions As MetadataImportOptions = MetadataImportOptions.Public)
MyClass.New(
outputKind,
......@@ -125,11 +129,81 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
metadataReferenceResolver:=metadataReferenceResolver,
assemblyIdentityComparer:=assemblyIdentityComparer,
strongNameProvider:=strongNameProvider,
metadataImportOptions:=MetadataImportOptions.Public,
metadataImportOptions:=metadataImportOptions,
referencesSupersedeLowerVersions:=False,
ignoreCorLibraryDuplicatedTypes:=False)
End Sub
#Enable Warning RS0026 ' Do not add multiple overloads with optional parameters
'' 15.6 BACKCOMPAT OVERLOAD -- DO NOT TOUCH
<EditorBrowsable(EditorBrowsableState.Never)>
Public Sub New(
outputKind As OutputKind,
moduleName As String,
mainTypeName As String,
scriptClassName As String,
globalImports As IEnumerable(Of GlobalImport),
rootNamespace As String,
optionStrict As OptionStrict,
optionInfer As Boolean,
optionExplicit As Boolean,
optionCompareText As Boolean,
parseOptions As VisualBasicParseOptions,
embedVbCoreRuntime As Boolean,
optimizationLevel As OptimizationLevel,
checkOverflow As Boolean,
cryptoKeyContainer As String,
cryptoKeyFile As String,
cryptoPublicKey As ImmutableArray(Of Byte),
delaySign As Boolean?,
platform As Platform,
generalDiagnosticOption As ReportDiagnostic,
specificDiagnosticOptions As IEnumerable(Of KeyValuePair(Of String, ReportDiagnostic)),
concurrentBuild As Boolean,
deterministic As Boolean,
xmlReferenceResolver As XmlReferenceResolver,
sourceReferenceResolver As SourceReferenceResolver,
metadataReferenceResolver As MetadataReferenceResolver,
assemblyIdentityComparer As AssemblyIdentityComparer,
strongNameProvider As StrongNameProvider,
publicSign As Boolean,
reportSuppressedDiagnostics As Boolean)
MyClass.New(
outputKind,
moduleName,
mainTypeName,
scriptClassName,
globalImports,
rootNamespace,
optionStrict,
optionInfer,
optionExplicit,
optionCompareText,
parseOptions,
embedVbCoreRuntime,
optimizationLevel,
checkOverflow,
cryptoKeyContainer,
cryptoKeyFile,
cryptoPublicKey,
delaySign,
platform,
generalDiagnosticOption,
specificDiagnosticOptions,
concurrentBuild,
deterministic,
xmlReferenceResolver,
sourceReferenceResolver,
metadataReferenceResolver,
assemblyIdentityComparer,
strongNameProvider,
publicSign,
reportSuppressedDiagnostics,
MetadataImportOptions.Public)
End Sub
Private Sub New(
outputKind As OutputKind,
......@@ -971,6 +1045,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
builder.Add(Diagnostic.Create(MessageProvider.Instance, ERRID.ERR_LibAnycpu32bitPreferredConflict, NameOf(Platform), Platform.ToString()))
End If
If Not MetadataImportOptions.IsValid() Then
builder.Add(Diagnostic.Create(MessageProvider.Instance, ERRID.ERR_InvalidSwitchValue, NameOf(MetadataImportOptions), MetadataImportOptions.ToString()))
End If
' TODO: add check for
' (kind == 'arm' || kind == 'appcontainer' || kind == 'winmdobj') &&
' (version >= "6.2")
......@@ -1035,6 +1113,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Function
'' 1.1 BACKCOMPAT OVERLOAD -- DO NOT TOUCH
<EditorBrowsable(EditorBrowsableState.Never)>
Public Sub New(
outputKind As OutputKind,
moduleName As String,
......@@ -1099,6 +1178,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Sub
' 1.0 BACKCOMPAT OVERLOAD -- DO NOT TOUCH
<EditorBrowsable(EditorBrowsableState.Never)>
Public Sub New(
outputKind As OutputKind,
moduleName As String,
......@@ -1159,9 +1239,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
strongNameProvider:=strongNameProvider)
End Sub
#Disable Warning RS0027 ' Public API with optional parameter(s) should have the most parameters amongst its public overloads
'' Bad constructor, do not use!
'' Violates the rules for optional parameter overloads detailed at
'' https://github.com/dotnet/roslyn/blob/e8fdb391703dcb5712ff6a5b83d768d784cba4cf/docs/Adding%20Optional%20Parameters%20in%20Public%20API.md
<EditorBrowsable(EditorBrowsableState.Never)>
Public Sub New(
outputKind As OutputKind,
reportSuppressedDiagnostics As Boolean,
......@@ -1232,6 +1314,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
ignoreCorLibraryDuplicatedTypes:=False)
End Sub
#Enable Warning RS0027 ' Public API with optional parameter(s) should have the most parameters amongst its public overloads
Protected Overrides Function CommonWithModuleName(moduleName As String) As CompilationOptions
Return WithModuleName(moduleName)
......
......@@ -929,25 +929,43 @@ End Class
End Sub
<Fact>
Public Sub TestMetadataImportOptions()
Public Sub TestMetadataImportOptions_01()
Dim expectedDiagnostics =
<expected>
BC2014: the value '255' is invalid for option 'MetadataImportOptions'
</expected>
Dim options = New VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
Assert.Equal(MetadataImportOptions.Public, options.MetadataImportOptions)
options.Errors.Verify()
options = options.WithMetadataImportOptions(MetadataImportOptions.Internal)
Assert.Equal(MetadataImportOptions.Internal, options.MetadataImportOptions)
options.Errors.Verify()
options = options.WithMetadataImportOptions(MetadataImportOptions.All)
Assert.Equal(MetadataImportOptions.All, options.MetadataImportOptions)
options.Errors.Verify()
options = options.WithMetadataImportOptions(MetadataImportOptions.Public)
Assert.Equal(MetadataImportOptions.Public, options.MetadataImportOptions)
options.Errors.Verify()
options = options.WithMetadataImportOptions(CType(Byte.MaxValue, MetadataImportOptions))
Assert.Equal(CType(Byte.MaxValue, MetadataImportOptions), options.MetadataImportOptions)
AssertTheseDiagnostics(options.Errors, expectedDiagnostics)
Dim commonOptions = DirectCast(options, CompilationOptions)
commonOptions = commonOptions.WithMetadataImportOptions(MetadataImportOptions.Internal)
Assert.Equal(MetadataImportOptions.Internal, DirectCast(commonOptions, VisualBasicCompilationOptions).MetadataImportOptions)
commonOptions.Errors.Verify()
commonOptions = commonOptions.WithMetadataImportOptions(MetadataImportOptions.All)
Assert.Equal(MetadataImportOptions.All, DirectCast(commonOptions, VisualBasicCompilationOptions).MetadataImportOptions)
commonOptions.Errors.Verify()
commonOptions = commonOptions.WithMetadataImportOptions(MetadataImportOptions.Public)
Assert.Equal(MetadataImportOptions.Public, DirectCast(commonOptions, VisualBasicCompilationOptions).MetadataImportOptions)
commonOptions.Errors.Verify()
commonOptions = commonOptions.WithMetadataImportOptions(CType(Byte.MaxValue, MetadataImportOptions))
Assert.Equal(CType(Byte.MaxValue, MetadataImportOptions), DirectCast(commonOptions, VisualBasicCompilationOptions).MetadataImportOptions)
AssertTheseDiagnostics(commonOptions.Errors, expectedDiagnostics)
Dim compilation0 = CreateCompilationWithMscorlib(
<compilation>
......@@ -966,18 +984,87 @@ End Class
Assert.NotEmpty(c.GetMembers("P1"))
Assert.Empty(c.GetMembers("P2"))
Assert.Empty(c.GetMembers("P3"))
CompileAndVerify(compilation)
compilation = compilation.WithOptions(options.WithMetadataImportOptions(MetadataImportOptions.Internal))
c = compilation.GetTypeByMetadataName("C")
Assert.NotEmpty(c.GetMembers("P1"))
Assert.NotEmpty(c.GetMembers("P2"))
Assert.Empty(c.GetMembers("P3"))
CompileAndVerify(compilation)
compilation = compilation.WithOptions(options.WithMetadataImportOptions(MetadataImportOptions.All))
c = compilation.GetTypeByMetadataName("C")
Assert.NotEmpty(c.GetMembers("P1"))
Assert.NotEmpty(c.GetMembers("P2"))
Assert.NotEmpty(c.GetMembers("P3"))
CompileAndVerify(compilation)
compilation = compilation.WithOptions(options.WithMetadataImportOptions(CType(Byte.MaxValue, MetadataImportOptions)))
c = compilation.GetTypeByMetadataName("C")
Assert.NotEmpty(c.GetMembers("P1"))
Assert.NotEmpty(c.GetMembers("P2"))
Assert.Empty(c.GetMembers("P3"))
compilation.AssertTheseEmitDiagnostics(expectedDiagnostics)
compilation.AssertTheseDiagnostics(expectedDiagnostics)
End Sub
<Fact>
Public Sub TestMetadataImportOptions_02()
Dim expectedDiagnostics =
<expected>
BC2014: the value '255' is invalid for option 'MetadataImportOptions'
</expected>
Dim options = New VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary)
Assert.Equal(MetadataImportOptions.Public, options.MetadataImportOptions)
options.Errors.Verify()
options = New VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions:=MetadataImportOptions.Internal)
Assert.Equal(MetadataImportOptions.Internal, options.MetadataImportOptions)
options.Errors.Verify()
options = New VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions:=MetadataImportOptions.All)
Assert.Equal(MetadataImportOptions.All, options.MetadataImportOptions)
options.Errors.Verify()
options = New VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions:=MetadataImportOptions.Public)
Assert.Equal(MetadataImportOptions.Public, options.MetadataImportOptions)
options.Errors.Verify()
options = New VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions:=CType(Byte.MaxValue, MetadataImportOptions))
Assert.Equal(CType(Byte.MaxValue, MetadataImportOptions), options.MetadataImportOptions)
AssertTheseDiagnostics(options.Errors, expectedDiagnostics)
Dim compilation0 = CreateCompilationWithMscorlib(
<compilation>
<file name="a.vb">
Public Class C
Public Property P1 As Integer
Friend Property P2 As Integer
Private Property P3 As Integer
End Class
</file>
</compilation>, options:=TestOptions.DebugDll)
Dim compilation = CreateCompilationWithMscorlib("", options:=New VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions:=MetadataImportOptions.Internal), references:={compilation0.EmitToImageReference()})
Dim c = compilation.GetTypeByMetadataName("C")
Assert.NotEmpty(c.GetMembers("P1"))
Assert.NotEmpty(c.GetMembers("P2"))
Assert.Empty(c.GetMembers("P3"))
CompileAndVerify(compilation)
compilation = compilation.WithOptions(New VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions:=MetadataImportOptions.All))
c = compilation.GetTypeByMetadataName("C")
Assert.NotEmpty(c.GetMembers("P1"))
Assert.NotEmpty(c.GetMembers("P2"))
Assert.NotEmpty(c.GetMembers("P3"))
CompileAndVerify(compilation)
compilation = compilation.WithOptions(New VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary, metadataImportOptions:=CType(Byte.MaxValue, MetadataImportOptions)))
c = compilation.GetTypeByMetadataName("C")
Assert.NotEmpty(c.GetMembers("P1"))
Assert.NotEmpty(c.GetMembers("P2"))
Assert.Empty(c.GetMembers("P3"))
compilation.AssertTheseEmitDiagnostics(expectedDiagnostics)
compilation.AssertTheseDiagnostics(expectedDiagnostics)
End Sub
End Class
......
......@@ -68,7 +68,7 @@ public async Task RefVar()
{
await TestInMethodAsync(
code: @"int i = 0; ref var x = ref i;",
expected: Keyword("var"));
expected: Classifications(Keyword("var"), Local("i")));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -518,7 +518,12 @@ void M()
}
}",
Class("N"),
Class("N"));
Class("N"),
Property("N"),
Property("N"),
Local("n"),
Property("N"),
Property("N"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -582,8 +587,10 @@ class Derived : Base
}",
Class("Base"),
Class("My"),
Method("My"),
Class("Derived"),
Class("My"),
Method("My"),
Class("Attribute"),
Class("Base"));
}
......@@ -603,7 +610,9 @@ void M()
B(C: null);
}
}",
Class("C"));
Class("C"),
Method("B"),
Parameter("C"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -656,6 +665,7 @@ public async Task ColorColor2()
}",
Class("T"),
Class("T"),
Field("T"),
Class("T"));
}
......@@ -675,7 +685,9 @@ public async Task ColorColor3()
}
}",
Class("T"),
Class("T"));
Class("T"),
Field("T"),
Method("M"));
}
/// <summary>
......@@ -695,7 +707,9 @@ void M()
T.T = null;
}
}",
Class("T"));
Class("T"),
Field("T"),
Field("T"));
}
/// <summary>
......@@ -716,7 +730,8 @@ void M()
}
}",
Class("T"),
Class("T"));
Class("T"),
Field("T"));
}
/// <summary>
......@@ -737,7 +752,9 @@ void M()
}
}",
Class("T"),
Class("T"));
Class("T"),
Local("T"),
Field("field"));
}
/// <summary>
......@@ -759,7 +776,8 @@ void M()
}",
Class("T"),
Class("T"),
Class("T"));
Class("T"),
Field("field"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -780,7 +798,9 @@ void M2()
}",
Class("T"),
Class("T"),
Class("T"));
Class("T"),
Method("M"),
Local("T"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -797,7 +817,9 @@ T M(T T)
}",
Class("T"),
Class("T"),
Class("T"));
Parameter("T"),
Class("T"),
Parameter("T"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -815,6 +837,7 @@ void M()
}",
Keyword("var"),
Class("T"),
Local("T"),
Class("T"));
}
......@@ -831,6 +854,7 @@ void M()
}
}",
Keyword("var"),
Local("T"),
Class("T"));
}
......@@ -884,7 +908,8 @@ void M()
}",
Class("T"),
Class("T"),
Class("T"));
Class("T"),
Local("T"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -936,6 +961,7 @@ void M<T>()
}
}",
TypeParameter("T"),
Method("M"),
TypeParameter("T"));
}
......@@ -981,7 +1007,8 @@ void M()
}",
Class("T"),
Class("H"),
Class("T"));
Class("T"),
Field("f"));
}
/// <summary>
......@@ -1017,6 +1044,8 @@ class B
{
}
}",
Method("F"),
Method("G"),
Class("A"),
Class("B"));
}
......@@ -1032,7 +1061,8 @@ class C
void M()
{
var x = new { String = "" }; } }",
Keyword("var"));
Keyword("var"),
Property("String"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -1052,7 +1082,8 @@ IEnumerable<yield> M()
Interface("IEnumerable"),
Class("yield"),
Class("yield"),
Class("yield"));
Class("yield"),
Local("yield"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -1231,6 +1262,8 @@ public async Task NAQEventSubscription()
@"global::System.AppDomain.CurrentDomain.AssemblyLoad +=
delegate (object sender, System.AssemblyLoadEventArgs args) {};",
Class("AppDomain"),
Property("CurrentDomain"),
Event("AssemblyLoad"),
Class("AssemblyLoadEventArgs"));
}
......@@ -1267,7 +1300,8 @@ public async Task NAQSameFileClass()
await TestAsync(code,
code,
Class("C"));
Class("C"),
Method("M"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -1279,7 +1313,8 @@ public async Task InteractiveNAQSameFileClass()
code,
Options.Script,
Class("Script"),
Class("C"));
Class("C"),
Method("M"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -1298,7 +1333,8 @@ static void M()
}
}
}",
Class("C"));
Class("C"),
Method("M"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -1317,7 +1353,8 @@ static void M()
}
}
}",
Class("C"));
Class("C"),
Method("M"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -1336,7 +1373,8 @@ static void M()
}
}
}",
Class("C"));
Class("C"),
Method("M"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -1355,7 +1393,8 @@ static void M()
}
}
}",
Class("C"));
Class("C"),
Method("M"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -1374,7 +1413,8 @@ static void M()
}
}
}",
Class("C"));
Class("C"),
Method("M"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -1500,11 +1540,15 @@ enum MyEnum
}
}",
Class("MyClass2"),
Method("method"),
Class("MyClass2"),
Event("myEvent"),
Enum("MyEnum"),
Struct("MyStruct"),
Class("MyClass2"),
Property("MyProp"),
Class("MyClass2"),
Field("myField"),
Class("MyClass2"),
Delegate("MyDelegate"),
Delegate("MyDelegate"));
......@@ -1531,7 +1575,9 @@ void M()
}
}",
Class("A"),
Class("A"));
Class("A"),
Local("a"),
Field("B"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -1552,7 +1598,9 @@ void M()
}
}",
Class("Console"),
Class("Console"));
Method("WriteLine"),
Class("Console"),
Method("WriteLine"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -1593,7 +1641,7 @@ void M()
{
C = 0;
}
}");
}", Field("C"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -1714,7 +1762,7 @@ public async Task EnumFieldWithSameNameShouldBePreferredToType()
{
E,
F = E
}");
}", EnumField("E"));
}
[WorkItem(541150, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/541150")]
......@@ -1805,9 +1853,13 @@ void M()
}",
Enum("E"),
Enum("E"),
EnumField("A"),
Enum("E"),
EnumField("B"),
Enum("E"),
Enum("E"));
EnumField("B"),
Enum("E"),
EnumField("A"));
}
[WorkItem(542368, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542368")]
......@@ -1877,6 +1929,7 @@ static void Main()
}",
Class("var"),
Keyword("var"),
Method("GetVarT"),
Keyword("var"),
Class("var"));
}
......@@ -1895,7 +1948,8 @@ void Main(string[] args)
}
}
}",
Keyword("var"));
Keyword("var"),
Parameter("args"));
}
[WorkItem(542778, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542778")]
......@@ -1934,6 +1988,7 @@ public async Task OptimisticallyColorFromInAssignment()
q = from",
Keyword("var"),
Local("q"),
Keyword("from"));
}
......@@ -1952,7 +2007,8 @@ public async Task DontColorThingsOtherThanFromInAssignment()
@"var q = 3;
q = fro",
Keyword("var"));
Keyword("var"),
Local("q"));
}
[WorkItem(542685, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542685")]
......@@ -1963,7 +2019,8 @@ public async Task DontColorFromWhenBoundInDeclaration()
@"var from = 3;
var q = from",
Keyword("var"),
Keyword("var"));
Keyword("var"),
Local("from"));
}
[WorkItem(542685, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/542685")]
......@@ -1976,7 +2033,9 @@ public async Task DontColorFromWhenBoundInAssignment()
q = from",
Keyword("var"),
Keyword("var"));
Keyword("var"),
Local("q"),
Local("from"));
}
[WorkItem(543404, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/543404")]
......@@ -2053,6 +2112,7 @@ class C
static extern void M();
}",
Class("DllImport"),
Field("CallingConvention"),
Enum("CallingConvention"));
}
......@@ -2216,7 +2276,7 @@ public async Task DevDiv261049RegressionTest()
await TestInMethodAsync(
source,
Keyword("var"));
Keyword("var"), Local("a"), Local("a"));
}
[WorkItem(633, "https://github.com/dotnet/roslyn/issues/633")]
......@@ -2249,7 +2309,7 @@ class MyClass
public MyClass(int x)
{
}
}");
}", Method("MyClass"));
}
[WorkItem(633, "https://github.com/dotnet/roslyn/issues/633")]
......@@ -2266,7 +2326,8 @@ public MyClass(int x)
{
}
}",
Class("MyClass"));
Class("MyClass"),
Method("MyClass"));
}
[WorkItem(13174, "https://github.com/dotnet/roslyn/issues/13174")]
......@@ -2286,7 +2347,7 @@ static void Main(string[] args)
Debug.Assert(args?.Length < 2);
}
}
}", Class("Debug"));
}", Class("Debug"), Method("Assert"), Parameter("args"), Property("Length"));
}
[WorkItem(18956, "https://github.com/dotnet/roslyn/issues/18956")]
......@@ -2303,7 +2364,7 @@ void Main(string s)
{
}
}
}", Keyword("var"));
}", Parameter("s"), Keyword("var"));
}
[WorkItem(18956, "https://github.com/dotnet/roslyn/issues/18956")]
......@@ -2321,7 +2382,7 @@ void Main(string s)
case var v:
}
}
}", Keyword("var"));
}", Parameter("s"), Keyword("var"));
}
[WorkItem(23940, "https://github.com/dotnet/roslyn/issues/23940")]
......
......@@ -385,11 +385,11 @@ public async Task PP_If8()
PPKeyword("#"),
PPKeyword("else"),
Identifier("aoeu"),
Identifier("aoeu"),
Field("aoeu"),
Identifier("aou"),
PPKeyword("#"),
PPKeyword("endif"),
Identifier("aeu"));
Field("aeu"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -411,12 +411,12 @@ public async Task PP_If9()
PPKeyword("else"),
Comment("//Goo2"),
Identifier("aoeu"),
Identifier("aoeu"),
Field("aoeu"),
Identifier("aou"),
PPKeyword("#"),
PPKeyword("endif"),
Comment("//Goo3"),
Identifier("aeu"));
Field("aeu"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -970,7 +970,7 @@ public async Task ShortDiscardInDeconstruction()
{
await TestInMethodAsync(
code: @"int x; (_, x) = (1, 2);",
expected: Classifications(Keyword("int"), Identifier("x"), Punctuation.Semicolon, Punctuation.OpenParen,
expected: Classifications(Keyword("int"), Local("x"), Punctuation.Semicolon, Punctuation.OpenParen,
Identifier("_"), Punctuation.Comma, Identifier("x"), Punctuation.CloseParen, Operators.Equals,
Punctuation.OpenParen, Number("1"), Punctuation.Comma, Number("2"), Punctuation.CloseParen,
Punctuation.Semicolon));
......@@ -997,7 +997,7 @@ public async Task ShortDiscardInAssignment()
public async Task UnderscoreInAssignment()
{
await TestInMethodAsync(code: @"int _; _ = 1;" ,
expected: Classifications(Keyword("int"), Identifier("_"), Punctuation.Semicolon, Identifier("_"), Operators.Equals,
expected: Classifications(Keyword("int"), Local("_"), Punctuation.Semicolon, Identifier("_"), Operators.Equals,
Number("1"), Punctuation.Semicolon));
}
}
......
......@@ -82,7 +82,7 @@ public async Task Bug17819()
///<param name='_
}",
Identifier("_"),
Identifier("_"),
Method("_"),
Punctuation.OpenParen,
Punctuation.CloseParen,
Punctuation.OpenCurly,
......@@ -233,7 +233,7 @@ static dynamic dynamic<partial>()
Punctuation.OpenCurly,
Keyword("static"),
Keyword("dynamic"),
Identifier("dynamic"),
Method("dynamic"),
Punctuation.OpenAngle,
TypeParameter("partial"),
Punctuation.CloseAngle,
......@@ -241,7 +241,7 @@ static dynamic dynamic<partial>()
Punctuation.CloseParen,
Punctuation.OpenCurly,
Keyword("return"),
Identifier("dynamic"),
Method("dynamic"),
Punctuation.OpenAngle,
Keyword("dynamic"),
Punctuation.CloseAngle,
......@@ -260,7 +260,7 @@ public async Task VarInForeach()
Keyword("foreach"),
Punctuation.OpenParen,
Keyword("var"),
Identifier("v"),
Local("v"),
Keyword("in"),
Identifier("args"),
Punctuation.CloseParen,
......@@ -286,16 +286,16 @@ int P
Class("C"),
Punctuation.OpenCurly,
Keyword("int"),
Identifier("P"),
Property("P"),
Punctuation.OpenCurly,
Keyword("set"),
Punctuation.OpenCurly,
Keyword("var"),
Identifier("t"),
Local("t"),
Operators.Equals,
Keyword("new"),
Punctuation.OpenCurly,
Identifier("value"),
Property("value"),
Operators.Equals,
Keyword("value"),
Punctuation.CloseCurly,
......@@ -324,7 +324,7 @@ public async Task TestValueInEvent()
Keyword("event"),
Keyword("int"),
Identifier("Bar"),
Event("Bar"),
Punctuation.OpenCurly,
Keyword("add"),
Punctuation.OpenCurly,
......@@ -365,7 +365,7 @@ public async Task TestValueInProperty()
}
}",
Keyword("int"),
Identifier("Goo"),
Property("Goo"),
Punctuation.OpenCurly,
Keyword("get"),
Punctuation.OpenCurly,
......@@ -401,7 +401,7 @@ public async Task ValueFieldInSetterAccessedThroughThis()
}
}",
Keyword("int"),
Identifier("P"),
Property("P"),
Punctuation.OpenCurly,
Keyword("set"),
Punctuation.OpenCurly,
......@@ -421,7 +421,7 @@ public async Task NewOfInterface()
await TestInMethodAsync(
@"object o = new System.IDisposable();",
Keyword("object"),
Identifier("o"),
Local("o"),
Operators.Equals,
Keyword("new"),
Identifier("System"),
......@@ -448,7 +448,7 @@ void Main()
Class("var"),
Punctuation.OpenCurly,
Keyword("void"),
Identifier("Main"),
Method("Main"),
Punctuation.OpenParen,
Punctuation.CloseParen,
Punctuation.OpenCurly,
......@@ -477,7 +477,7 @@ void Goo<var>()
Class("X"),
Punctuation.OpenCurly,
Keyword("void"),
Identifier("Goo"),
Method("Goo"),
Punctuation.OpenAngle,
TypeParameter("var"),
Punctuation.CloseAngle,
......@@ -485,7 +485,7 @@ void Goo<var>()
Punctuation.CloseParen,
Punctuation.OpenCurly,
TypeParameter("var"),
Identifier("x"),
Local("x"),
Punctuation.Semicolon,
Punctuation.CloseCurly,
Punctuation.CloseCurly);
......@@ -563,12 +563,12 @@ static void Main()
Punctuation.OpenCurly,
Keyword("static"),
Keyword("void"),
Identifier("Main"),
Method("Main"),
Punctuation.OpenParen,
Punctuation.CloseParen,
Punctuation.OpenCurly,
Keyword("var"),
Identifier("tree"),
Local("tree"),
Operators.Equals,
Class("Console"),
Punctuation.CloseCurly,
......@@ -622,14 +622,14 @@ void Goo(int x)
XmlDoc.AttributeName("name"),
XmlDoc.Delimiter("="),
XmlDoc.AttributeQuotes("\""),
Identifier("x"),
Parameter("x"),
XmlDoc.AttributeQuotes("\""),
XmlDoc.Delimiter("/>"),
Keyword("void"),
Identifier("Goo"),
Method("Goo"),
Punctuation.OpenParen,
Keyword("int"),
Identifier("x"),
Parameter("x"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Punctuation.CloseCurly,
......@@ -668,7 +668,7 @@ void Goo()
Punctuation.CloseAngle,
Punctuation.OpenCurly,
Keyword("void"),
Identifier("Goo"),
Method("Goo"),
Punctuation.OpenParen,
Punctuation.CloseParen,
Punctuation.OpenCurly,
......@@ -722,7 +722,7 @@ public async Task InterfacePropertyWithSameNameShouldBePreferredToType()
Interface("IGoo"),
Punctuation.OpenCurly,
Keyword("int"),
Identifier("IGoo"),
Property("IGoo"),
Punctuation.OpenCurly,
Keyword("get"),
Punctuation.Semicolon,
......@@ -730,12 +730,12 @@ public async Task InterfacePropertyWithSameNameShouldBePreferredToType()
Punctuation.Semicolon,
Punctuation.CloseCurly,
Keyword("void"),
Identifier("Bar"),
Method("Bar"),
Punctuation.OpenParen,
Keyword("int"),
Identifier("x"),
Parameter("x"),
Operators.Equals,
Identifier("IGoo"),
Property("IGoo"),
Punctuation.CloseParen,
Punctuation.Semicolon,
Punctuation.CloseCurly);
......@@ -770,7 +770,7 @@ public MyClass(int x)
XmlDoc.AttributeQuotes("\""),
Class("MyClass"),
Operators.Dot,
Identifier("MyClass"),
Method("MyClass"),
Punctuation.OpenParen,
Keyword("int"),
Punctuation.CloseParen,
......@@ -788,7 +788,7 @@ public MyClass(int x)
Identifier("MyClass"),
Punctuation.OpenParen,
Keyword("int"),
Identifier("x"),
Parameter("x"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Punctuation.CloseCurly,
......@@ -849,5 +849,89 @@ class Program : IReadOnlyCollection<int,string>
Punctuation.OpenCurly,
Punctuation.CloseCurly);
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
public async Task TestExtensionMethodDeclaration()
{
await TestAsync(
@"static class ExtMethod
{
public static void TestMethod(this C c)
{
}
}
",
Keyword("static"),
Keyword("class"),
Class("ExtMethod"),
Punctuation.OpenCurly,
Keyword("public"),
Keyword("static"),
Keyword("void"),
ExtensionMethod("TestMethod"),
Punctuation.OpenParen,
Keyword("this"),
Identifier("C"),
Parameter("c"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Punctuation.CloseCurly,
Punctuation.CloseCurly);
}
[Fact(Skip = "Extension method usage doesn't seem to work."), Trait(Traits.Feature, Traits.Features.Classification)]
public async Task TestExtensionMethodUsage()
{
await TestAsync(
@"static class ExtMethod
{
public static void TestMethod(this C c)
{
}
}
class C
{
void Test()
{
TestMethod(new C());
}
}
",
Keyword("static"),
Keyword("class"),
Class("ExtMethod"),
Punctuation.OpenCurly,
Keyword("public"),
Keyword("static"),
Keyword("void"),
ExtensionMethod("TestMethod"),
Punctuation.OpenParen,
Keyword("this"),
Class("C"),
Parameter("c"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Punctuation.CloseCurly,
Punctuation.CloseCurly,
Keyword("class"),
Class("C"),
Punctuation.OpenCurly,
Keyword("void"),
Method("Test"),
Punctuation.OpenParen,
Punctuation.CloseParen,
Punctuation.OpenCurly,
ExtensionMethod("TestMethod"),
Punctuation.OpenParen,
Keyword("new"),
Class("C"),
Punctuation.OpenParen,
Punctuation.CloseParen,
Punctuation.CloseParen,
Punctuation.Semicolon,
Punctuation.CloseCurly,
Punctuation.CloseCurly);
}
}
}
......@@ -13,10 +13,10 @@ public async Task DynamicAsParamTypeAndDefault()
{
await TestInClassAsync(@"void M(dynamic d = default(dynamic",
Keyword("void"),
Identifier("M"),
Method("M"),
Punctuation.OpenParen,
Keyword("dynamic"),
Identifier("d"),
Parameter("d"),
Operators.Equals,
Keyword("default"),
Punctuation.OpenParen,
......@@ -29,7 +29,7 @@ public async Task DynamicExplicitConversion()
await TestInMethodAsync(
@"dynamic d = (dynamic)a;",
Keyword("dynamic"),
Identifier("d"),
Local("d"),
Operators.Equals,
Punctuation.OpenParen,
Keyword("dynamic"),
......@@ -59,7 +59,7 @@ public async Task DynamicNullable()
await TestInMethodAsync(@"dynamic? a",
Keyword("dynamic"),
Operators.QuestionMark,
Identifier("a"));
Local("a"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -152,7 +152,7 @@ class C
Identifier("dynamic"),
Operators.Text("::"),
Identifier("Goo"),
Identifier("a"),
Field("a"),
Punctuation.Semicolon,
Punctuation.CloseCurly);
}
......@@ -177,7 +177,7 @@ public async Task DynamicAsDelegateReturnTypeAndParam()
Delegate("MyDelegate"),
Punctuation.OpenParen,
Keyword("dynamic"),
Identifier("d"),
Parameter("d"),
Punctuation.CloseParen);
}
......@@ -194,19 +194,19 @@ public async Task DynamicAsDelegateLocalVariable()
Punctuation.OpenAngle,
Keyword("string"),
Punctuation.CloseAngle,
Identifier("f"),
Local("f"),
Operators.Equals,
Keyword("delegate"),
Punctuation.OpenCurly,
Keyword("int"),
Identifier("dynamic"),
Local("dynamic"),
Operators.Equals,
Number("10"),
Punctuation.Semicolon,
Keyword("return"),
Identifier("dynamic"),
Local("dynamic"),
Operators.Dot,
Identifier("ToString"),
Method("ToString"),
Punctuation.OpenParen,
Punctuation.CloseParen,
Punctuation.Semicolon,
......@@ -241,7 +241,7 @@ class C
Punctuation.OpenAngle,
Keyword("int"),
Punctuation.CloseAngle,
Identifier("d"),
Field("d"),
Punctuation.Semicolon,
Punctuation.CloseCurly);
}
......@@ -261,7 +261,7 @@ public async Task DynamicAsGenericField()
Punctuation.CloseAngle,
Punctuation.OpenCurly,
TypeParameter("T"),
Identifier("dynamic"),
Field("dynamic"),
Punctuation.Semicolon,
Punctuation.CloseCurly);
}
......@@ -274,7 +274,7 @@ public async Task DynamicAsIndexerTypeAndParameter()
Keyword("this"),
Punctuation.OpenBracket,
Keyword("dynamic"),
Identifier("i"),
Parameter("i"),
Punctuation.CloseBracket);
}
......@@ -288,7 +288,7 @@ public async Task DynamicAsOperatorTypeAndParameter()
Operators.Text("+"),
Punctuation.OpenParen,
Keyword("dynamic"),
Identifier("d1"),
Parameter("d1"),
Punctuation.CloseParen);
}
......@@ -302,7 +302,7 @@ public async Task DynamicAsOperatorName()
Keyword("dynamic"),
Punctuation.OpenParen,
Keyword("dynamic"),
Identifier("s"),
Parameter("s"),
Punctuation.CloseParen);
}
......@@ -311,7 +311,7 @@ public async Task DynamicAsPropertyTypeAndName()
{
await TestInClassAsync(@"dynamic dynamic { get; set; }",
Keyword("dynamic"),
Identifier("dynamic"),
Property("dynamic"),
Punctuation.OpenCurly,
Keyword("get"),
Punctuation.Semicolon,
......@@ -326,7 +326,7 @@ public async Task DynamicAsEventName()
await TestInClassAsync(@"event Action dynamic",
Keyword("event"),
Identifier("Action"),
Identifier("dynamic"));
Event("dynamic"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -334,7 +334,7 @@ public async Task DynamicAsLinqLocalVariable()
{
await TestInMethodAsync(@"var v = from dynamic in names",
Keyword("var"),
Identifier("v"),
Local("v"),
Operators.Equals,
Keyword("from"),
Identifier("dynamic"),
......@@ -349,7 +349,7 @@ public async Task DynamicAsAnonymousTypePropertyName()
@"var v = from dynamic in names
select new { dynamic = dynamic };",
Keyword("var"),
Identifier("v"),
Local("v"),
Operators.Equals,
Keyword("from"),
Identifier("dynamic"),
......@@ -358,7 +358,7 @@ public async Task DynamicAsAnonymousTypePropertyName()
Keyword("select"),
Keyword("new"),
Punctuation.OpenCurly,
Identifier("dynamic"),
Property("dynamic"),
Operators.Equals,
Identifier("dynamic"),
Punctuation.CloseCurly,
......@@ -371,15 +371,15 @@ public async Task DynamicAsArgumentToLambdaExpression()
await TestInMethodAsync(
@"var p = names.Select(dynamic => dynamic.Length);",
Keyword("var"),
Identifier("p"),
Local("p"),
Operators.Equals,
Identifier("names"),
Operators.Dot,
Identifier("Select"),
Punctuation.OpenParen,
Identifier("dynamic"),
Parameter("dynamic"),
Operators.Text("=>"),
Identifier("dynamic"),
Parameter("dynamic"),
Operators.Dot,
Identifier("Length"),
Punctuation.CloseParen,
......@@ -396,19 +396,19 @@ public async Task DynamicAsAnonymousMethodLocalVariable()
return dynamic.Length;
};",
Identifier("D"),
Identifier("f"),
Local("f"),
Operators.Equals,
Keyword("delegate"),
Punctuation.OpenCurly,
Keyword("string"),
Identifier("dynamic"),
Local("dynamic"),
Operators.Equals,
String(@"""a"""),
Punctuation.Semicolon,
Keyword("return"),
Identifier("dynamic"),
Local("dynamic"),
Operators.Dot,
Identifier("Length"),
Property("Length"),
Punctuation.Semicolon,
Punctuation.CloseCurly,
Punctuation.Semicolon);
......@@ -422,7 +422,7 @@ public async Task DynamicAsMethodName()
{
}",
Keyword("dynamic"),
Identifier("dynamic"),
Method("dynamic"),
Punctuation.OpenParen,
Punctuation.CloseParen,
Punctuation.OpenCurly,
......@@ -438,13 +438,13 @@ public async Task DynamicAsStaticMethodTypeAndParams()
}",
Keyword("static"),
Keyword("dynamic"),
Identifier("dynamic"),
Method("dynamic"),
Punctuation.OpenParen,
Keyword("params"),
Keyword("dynamic"),
Punctuation.OpenBracket,
Punctuation.CloseBracket,
Identifier("dynamic"),
Parameter("dynamic"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Punctuation.CloseCurly);
......@@ -460,18 +460,18 @@ public async Task DynamicArraysInMethodSignature()
Keyword("dynamic"),
Punctuation.OpenBracket,
Punctuation.CloseBracket,
Identifier("M"),
Method("M"),
Punctuation.OpenParen,
Keyword("dynamic"),
Punctuation.OpenBracket,
Punctuation.CloseBracket,
Identifier("p"),
Parameter("p"),
Punctuation.Comma,
Keyword("params"),
Keyword("dynamic"),
Punctuation.OpenBracket,
Punctuation.CloseBracket,
Identifier("pa"),
Parameter("pa"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Punctuation.CloseCurly);
......@@ -488,18 +488,18 @@ public async Task DynamicInPartialMethods()
}",
Keyword("partial"),
Keyword("void"),
Identifier("F"),
Method("F"),
Punctuation.OpenParen,
Keyword("dynamic"),
Identifier("d"),
Parameter("d"),
Punctuation.CloseParen,
Punctuation.Semicolon,
Keyword("partial"),
Keyword("void"),
Identifier("F"),
Method("F"),
Punctuation.OpenParen,
Keyword("dynamic"),
Identifier("d"),
Parameter("d"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Punctuation.CloseCurly);
......@@ -513,15 +513,15 @@ public async Task DynamicRefAndOutParameters()
{
}",
Keyword("void"),
Identifier("F"),
Method("F"),
Punctuation.OpenParen,
Keyword("ref"),
Keyword("dynamic"),
Identifier("r"),
Parameter("r"),
Punctuation.Comma,
Keyword("out"),
Keyword("dynamic"),
Identifier("o"),
Parameter("o"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Punctuation.CloseCurly);
......@@ -535,14 +535,14 @@ public async Task DynamicInExtensionMethod()
{
}",
Keyword("dynamic"),
Identifier("F"),
ExtensionMethod("F"),
Punctuation.OpenParen,
Keyword("this"),
Keyword("dynamic"),
Identifier("self"),
Parameter("self"),
Punctuation.Comma,
Keyword("dynamic"),
Identifier("p"),
Parameter("p"),
Punctuation.CloseParen,
Punctuation.OpenCurly,
Punctuation.CloseCurly);
......@@ -593,7 +593,7 @@ public async Task DynamicSizeOf()
}",
Keyword("unsafe"),
Keyword("int"),
Identifier("M"),
Method("M"),
Punctuation.OpenParen,
Punctuation.CloseParen,
Punctuation.OpenCurly,
......@@ -626,7 +626,7 @@ public async Task DynamicAsArrayName()
Keyword("int"),
Punctuation.OpenBracket,
Punctuation.CloseBracket,
Identifier("dynamic"),
Field("dynamic"),
Operators.Equals,
Punctuation.OpenCurly,
Number("1"),
......@@ -641,7 +641,7 @@ public async Task DynamicInForeach()
Keyword("foreach"),
Punctuation.OpenParen,
Keyword("dynamic"),
Identifier("dynamic"),
Local("dynamic"),
Keyword("in"),
Identifier("dynamic"));
}
......@@ -653,7 +653,7 @@ public async Task DynamicInUsing()
Keyword("using"),
Punctuation.OpenParen,
Keyword("dynamic"),
Identifier("d"));
Local("d"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -662,7 +662,7 @@ public async Task DynamicAsLocalVariableName()
await TestInMethodAsync(
@"dynamic dynamic;",
Keyword("dynamic"),
Identifier("dynamic"),
Local("dynamic"),
Punctuation.Semicolon);
}
......@@ -721,7 +721,7 @@ public async Task DynamicAsNamespaceAlias()
Identifier("dynamic"),
Operators.Dot,
Identifier("FileInfo"),
Identifier("file"),
Local("file"),
Punctuation.Semicolon);
}
......@@ -734,7 +734,7 @@ public async Task DynamicAsGotoLabel()
Identifier("dynamic"),
Punctuation.Colon,
Keyword("int"),
Identifier("i"),
Local("i"),
Operators.Equals,
Number("0"),
Punctuation.Semicolon,
......@@ -749,7 +749,7 @@ public async Task DynamicAsEnumField()
await TestInMethodAsync(
@"A a = A.dynamic;",
Identifier("A"),
Identifier("a"),
Local("a"),
Operators.Equals,
Identifier("A"),
Operators.Dot,
......@@ -768,7 +768,7 @@ public async Task DynamicAsEnumFieldDefinition()
Keyword("enum"),
Enum("A"),
Punctuation.OpenCurly,
Identifier("dynamic"),
EnumField("dynamic"),
Punctuation.CloseCurly);
}
......@@ -806,7 +806,7 @@ public async Task DynamicAsGenericTypeParameter()
TypeParameter("T"),
Punctuation.OpenCurly,
TypeParameter("dynamic"),
Identifier("d"),
Field("d"),
Punctuation.Semicolon,
Punctuation.CloseCurly);
}
......@@ -816,7 +816,7 @@ public async Task DynamicAsFieldType()
{
await TestInClassAsync(@"dynamic d",
Keyword("dynamic"),
Identifier("d"));
Field("d"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -825,7 +825,7 @@ public async Task DynamicAsStaticFieldType()
await TestInClassAsync(@"static dynamic d",
Keyword("static"),
Keyword("dynamic"),
Identifier("d"));
Field("d"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -833,7 +833,7 @@ public async Task DynamicAsLocalVariableType()
{
await TestInMethodAsync(@"dynamic d",
Keyword("dynamic"),
Identifier("d"));
Local("d"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -843,7 +843,7 @@ public async Task DynamicAsArrayLocalVariableType()
Keyword("dynamic"),
Punctuation.OpenBracket,
Punctuation.CloseBracket,
Identifier("d"));
Local("d"));
}
[Fact, Trait(Traits.Feature, Traits.Features.Classification)]
......@@ -852,7 +852,7 @@ public async Task DynamicAsLambdaParameterType()
await TestInMethodAsync(
@"var q = a.Where((dynamic d) => d == dynamic);",
Keyword("var"),
Identifier("q"),
Local("q"),
Operators.Equals,
Identifier("a"),
Operators.Dot,
......@@ -860,10 +860,10 @@ public async Task DynamicAsLambdaParameterType()
Punctuation.OpenParen,
Punctuation.OpenParen,
Keyword("dynamic"),
Identifier("d"),
Parameter("d"),
Punctuation.CloseParen,
Operators.Text("=>"),
Identifier("d"),
Parameter("d"),
Operators.Text("=="),
Identifier("dynamic"),
Punctuation.CloseParen,
......@@ -876,7 +876,7 @@ public async Task DynamicArray()
await TestInMethodAsync(
@"dynamic d = new dynamic[5];",
Keyword("dynamic"),
Identifier("d"),
Local("d"),
Operators.Equals,
Keyword("new"),
Keyword("dynamic"),
......@@ -892,7 +892,7 @@ public async Task DynamicConstructor()
await TestInMethodAsync(
@"dynamic d = new dynamic();",
Keyword("dynamic"),
Identifier("d"),
Local("d"),
Operators.Equals,
Keyword("new"),
Keyword("dynamic"),
......@@ -933,7 +933,7 @@ public async Task DynamicAsGenericTypeArgument()
Punctuation.OpenAngle,
Keyword("dynamic"),
Punctuation.CloseAngle,
Identifier("l"),
Local("l"),
Operators.Equals,
Keyword("new"),
Identifier("List"),
......@@ -956,7 +956,7 @@ public async Task DynamicAsSecondGenericTypeArgument()
Punctuation.Comma,
Keyword("dynamic"),
Punctuation.CloseAngle,
Identifier("kvp"),
Local("kvp"),
Punctuation.Semicolon);
}
......@@ -1009,7 +1009,7 @@ public async Task DynamicAsUndefinedGenericType()
Punctuation.OpenAngle,
Keyword("int"),
Punctuation.CloseAngle,
Identifier("d"),
Local("d"),
Punctuation.Semicolon);
}
}
......
......@@ -1745,16 +1745,18 @@ internal class EditorFeaturesResources {
return ResourceManager.GetString("User_Types_Structures", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to User Types - Type Parameters.
/// </summary>
internal static string User_Types_Type_Parameters {
get {
internal static string User_Types_Type_Parameters
{
get
{
return ResourceManager.GetString("User_Types_Type_Parameters", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to VB XML Literals - Attribute Name.
/// </summary>
......
......@@ -7,6 +7,7 @@
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Text.Shared.Extensions;
using Microsoft.VisualStudio.Text;
using Microsoft.VisualStudio.Text.Classification;
using Microsoft.VisualStudio.Text.Tagging;
namespace Microsoft.CodeAnalysis.Editor.Implementation.Classification
......@@ -37,9 +38,28 @@ public static void Convert(ClassificationTypeMap typeMap, ITextSnapshot snapshot
{
foreach (var classifiedSpan in list)
{
IClassificationType classificationType;
switch (classifiedSpan.ClassificationType) // filter out unsupported classification types
{
case ClassificationTypeNames.FieldName:
case ClassificationTypeNames.EnumFieldName:
case ClassificationTypeNames.ConstantName:
case ClassificationTypeNames.LocalName:
case ClassificationTypeNames.ParameterName:
case ClassificationTypeNames.MethodName:
case ClassificationTypeNames.ExtensionMethodName:
case ClassificationTypeNames.PropertyName:
case ClassificationTypeNames.EventName:
classificationType = typeMap.GetClassificationType(ClassificationTypeNames.Identifier);
break;
default:
classificationType = typeMap.GetClassificationType(classifiedSpan.ClassificationType);
break;
}
addTag(new TagSpan<IClassificationTag>(
classifiedSpan.TextSpan.ToSnapshotSpan(snapshot),
new ClassificationTag(typeMap.GetClassificationType(classifiedSpan.ClassificationType))));
new ClassificationTag(classificationType)));
}
}
......
......@@ -50,6 +50,60 @@ protected AbstractClassifierTests()
return ClassificationBuilder.TypeParameter(value);
}
[DebuggerStepThrough]
protected Tuple<string, string> Field(string value)
{
return ClassificationBuilder.Field(value);
}
[DebuggerStepThrough]
protected Tuple<string, string> EnumField(string value)
{
return ClassificationBuilder.EnumField(value);
}
[DebuggerStepThrough]
protected Tuple<string, string> Constant(string value)
{
return ClassificationBuilder.Constant(value);
}
[DebuggerStepThrough]
protected Tuple<string, string> Local(string value)
{
return ClassificationBuilder.Local(value);
}
[DebuggerStepThrough]
protected Tuple<string, string> Parameter(string value)
{
return ClassificationBuilder.Parameter(value);
}
[DebuggerStepThrough]
protected Tuple<string, string> Method(string value)
{
return ClassificationBuilder.Method(value);
}
[DebuggerStepThrough]
protected Tuple<string, string> ExtensionMethod(string value)
{
return ClassificationBuilder.ExtensionMethod(value);
}
[DebuggerStepThrough]
protected Tuple<string, string> Property(string value)
{
return ClassificationBuilder.Property(value);
}
[DebuggerStepThrough]
protected Tuple<string, string> Event(string value)
{
return ClassificationBuilder.Event(value);
}
[DebuggerStepThrough]
protected Tuple<string, string> String(string value)
{
......
......@@ -48,6 +48,60 @@ public partial class ClassificationBuilder
return Tuple.Create(value, ClassificationTypeNames.TypeParameterName);
}
[DebuggerStepThrough]
public Tuple<string, string> Field(string value)
{
return Tuple.Create(value, ClassificationTypeNames.FieldName);
}
[DebuggerStepThrough]
public Tuple<string, string> EnumField(string value)
{
return Tuple.Create(value, ClassificationTypeNames.EnumFieldName);
}
[DebuggerStepThrough]
public Tuple<string, string> Constant(string value)
{
return Tuple.Create(value, ClassificationTypeNames.ConstantName);
}
[DebuggerStepThrough]
public Tuple<string, string> Local(string value)
{
return Tuple.Create(value, ClassificationTypeNames.LocalName);
}
[DebuggerStepThrough]
public Tuple<string, string> Parameter(string value)
{
return Tuple.Create(value, ClassificationTypeNames.ParameterName);
}
[DebuggerStepThrough]
public Tuple<string, string> Method(string value)
{
return Tuple.Create(value, ClassificationTypeNames.MethodName);
}
[DebuggerStepThrough]
public Tuple<string, string> ExtensionMethod(string value)
{
return Tuple.Create(value, ClassificationTypeNames.ExtensionMethodName);
}
[DebuggerStepThrough]
public Tuple<string, string> Property(string value)
{
return Tuple.Create(value, ClassificationTypeNames.PropertyName);
}
[DebuggerStepThrough]
public Tuple<string, string> Event(string value)
{
return Tuple.Create(value, ClassificationTypeNames.EventName);
}
[DebuggerStepThrough]
public Tuple<string, string> String(string value)
{
......
......@@ -89,6 +89,16 @@ public void RefreshThemeColors()
UpdateForegroundColor(ClassificationTypeNames.TypeParameterName, sourceFormatMap, targetFormatMap);
UpdateForegroundColor(ClassificationTypeNames.ModuleName, sourceFormatMap, targetFormatMap);
UpdateForegroundColor(ClassificationTypeNames.FieldName, sourceFormatMap, targetFormatMap);
UpdateForegroundColor(ClassificationTypeNames.EnumFieldName, sourceFormatMap, targetFormatMap);
UpdateForegroundColor(ClassificationTypeNames.ConstantName, sourceFormatMap, targetFormatMap);
UpdateForegroundColor(ClassificationTypeNames.LocalName, sourceFormatMap, targetFormatMap);
UpdateForegroundColor(ClassificationTypeNames.ParameterName, sourceFormatMap, targetFormatMap);
UpdateForegroundColor(ClassificationTypeNames.MethodName, sourceFormatMap, targetFormatMap);
UpdateForegroundColor(ClassificationTypeNames.ExtensionMethodName, sourceFormatMap, targetFormatMap);
UpdateForegroundColor(ClassificationTypeNames.PropertyName, sourceFormatMap, targetFormatMap);
UpdateForegroundColor(ClassificationTypeNames.EventName, sourceFormatMap, targetFormatMap);
UpdateForegroundColor(ClassificationTypeNames.VerbatimStringLiteral, sourceFormatMap, targetFormatMap);
UpdateForegroundColor(ClassificationTypeNames.XmlLiteralText, sourceFormatMap, targetFormatMap);
......
......@@ -29,6 +29,9 @@ private partial class ConnectionManager
// indicate whether pool should be used.
private readonly bool _enableConnectionPool;
// indicate whether connection manager has shutdown
private bool _shutdown;
public ConnectionManager(
HubClient hubClient,
HostGroup hostGroup,
......@@ -37,6 +40,8 @@ private partial class ConnectionManager
TimeSpan timeout,
ReferenceCountedDisposable<RemotableDataJsonRpc> remotableDataRpc)
{
_shutdown = false;
_hubClient = hubClient;
_hostGroup = hostGroup;
_timeout = timeout;
......@@ -123,9 +128,10 @@ private void Free(string serviceName, JsonRpcConnection connection)
{
using (_shutdownLock.DisposableRead())
{
if (!_enableConnectionPool)
if (!_enableConnectionPool || _shutdown)
{
// pool is not being used.
// pool is not being used or
// manager is already shutdown
connection.Dispose();
return;
}
......@@ -148,6 +154,8 @@ public void Shutdown()
{
using (_shutdownLock.DisposableWrite())
{
_shutdown = true;
// let ref count this one is holding go
_remotableDataRpc.Dispose();
......
......@@ -118,6 +118,44 @@ private static string GetClassificationForIdentifier(SyntaxToken token)
{
return ClassificationTypeNames.TypeParameterName;
}
else if (token.Parent is MethodDeclarationSyntax methodDeclaration && methodDeclaration.Identifier == token)
{
return IsExtensionMethod(methodDeclaration) ? ClassificationTypeNames.ExtensionMethodName : ClassificationTypeNames.MethodName;
}
else if (token.Parent is PropertyDeclarationSyntax propertyDeclaration && propertyDeclaration.Identifier == token)
{
return ClassificationTypeNames.PropertyName;
}
else if (token.Parent is EnumMemberDeclarationSyntax enumMemberDeclaration && enumMemberDeclaration.Identifier == token)
{
return ClassificationTypeNames.EnumFieldName;
}
else if (token.Parent is VariableDeclaratorSyntax variableDeclarator && variableDeclarator.Identifier == token)
{
var varDecl = variableDeclarator.Parent as VariableDeclarationSyntax;
switch (varDecl.Parent)
{
case FieldDeclarationSyntax fieldDeclaration:
return fieldDeclaration.Modifiers.Any(SyntaxKind.ConstKeyword) ? ClassificationTypeNames.ConstantName : ClassificationTypeNames.FieldName;
case LocalDeclarationStatementSyntax localDeclarationStatement:
return localDeclarationStatement.IsConst ? ClassificationTypeNames.ConstantName : ClassificationTypeNames.LocalName;
case EventFieldDeclarationSyntax aventFieldDeclarationSyntax:
return ClassificationTypeNames.EventName;
}
return ClassificationTypeNames.LocalName;
}
else if (token.Parent is ParameterSyntax parameterSyntax && parameterSyntax.Identifier == token)
{
return ClassificationTypeNames.ParameterName;
}
else if (token.Parent is ForEachStatementSyntax forEachStatementSyntax && forEachStatementSyntax.Identifier == token)
{
return ClassificationTypeNames.LocalName;
}
else if (token.Parent is EventDeclarationSyntax eventDeclarationSyntax && eventDeclarationSyntax.Identifier == token)
{
return ClassificationTypeNames.EventName;
}
else if (IsActualContextualKeyword(token))
{
return ClassificationTypeNames.Keyword;
......@@ -128,6 +166,11 @@ private static string GetClassificationForIdentifier(SyntaxToken token)
}
}
private static bool IsExtensionMethod(MethodDeclarationSyntax methodDeclaration)
{
return methodDeclaration.ParameterList.Parameters.FirstOrDefault()?.Modifiers.Any(SyntaxKind.ThisKeyword) == true;
}
private static string GetClassificationForTypeDeclarationIdentifier(SyntaxToken identifier)
{
switch (identifier.Parent.Kind())
......
......@@ -147,21 +147,61 @@ private static bool IsNamespaceName(NameSyntax name)
}
// Use .Equals since we can't rely on object identity for constructed types.
if (symbol is ITypeSymbol typeSymbol)
SyntaxToken token;
switch (symbol)
{
var classification = GetClassificationForType(typeSymbol);
if (classification != null)
{
var token = name.GetNameToken();
classifiedSpan = new ClassifiedSpan(token.Span, classification);
case ITypeSymbol typeSymbol:
var classification = GetClassificationForType(typeSymbol);
if (classification != null)
{
token = name.GetNameToken();
classifiedSpan = new ClassifiedSpan(token.Span, classification);
return true;
}
break;
case IFieldSymbol fieldSymbol:
token = name.GetNameToken();
classifiedSpan = new ClassifiedSpan(token.Span, GetClassificationForField(fieldSymbol));
return true;
case IMethodSymbol methodSymbol:
token = name.GetNameToken();
classifiedSpan = new ClassifiedSpan(token.Span, methodSymbol.IsExtensionMethod ? ClassificationTypeNames.ExtensionMethodName : ClassificationTypeNames.MethodName);
return true;
case IPropertySymbol propertySymbol:
token = name.GetNameToken();
classifiedSpan = new ClassifiedSpan(token.Span, ClassificationTypeNames.PropertyName);
return true;
case IEventSymbol eventSymbol:
token = name.GetNameToken();
classifiedSpan = new ClassifiedSpan(token.Span, ClassificationTypeNames.EventName);
return true;
case IParameterSymbol parameterSymbol:
if (parameterSymbol.IsImplicitlyDeclared && parameterSymbol.Name == "value")
{
break;
}
token = name.GetNameToken();
classifiedSpan = new ClassifiedSpan(token.Span, ClassificationTypeNames.ParameterName);
return true;
case ILocalSymbol localSymbol:
token = name.GetNameToken();
classifiedSpan = new ClassifiedSpan(token.Span, localSymbol.IsConst ? ClassificationTypeNames.ConstantName : ClassificationTypeNames.LocalName);
return true;
}
}
classifiedSpan = default;
return false;
}
private static string GetClassificationForField(IFieldSymbol fieldSymbol)
{
if (fieldSymbol.IsConst)
{
return fieldSymbol.ContainingType.IsEnumType() ? ClassificationTypeNames.EnumFieldName : ClassificationTypeNames.ConstantName;
}
return ClassificationTypeNames.FieldName;
}
private bool IsInVarContext(NameSyntax name)
{
return
......
......@@ -27,6 +27,16 @@ public static class ClassificationTypeNames
public const string StructName = "struct name";
public const string TypeParameterName = "type parameter name";
public const string FieldName = "field name";
public const string EnumFieldName = "enum field name";
public const string ConstantName = "constant name";
public const string LocalName = "local name";
public const string ParameterName = "parameter name";
public const string MethodName = "method name";
public const string ExtensionMethodName = "extension method name";
public const string PropertyName = "property name";
public const string EventName = "event name";
public const string XmlDocCommentAttributeName = "xml doc comment - attribute name";
public const string XmlDocCommentAttributeQuotes = "xml doc comment - attribute quotes";
public const string XmlDocCommentAttributeValue = "xml doc comment - attribute value";
......
......@@ -150,6 +150,16 @@ private static IEnumerable<SymbolDisplayPart> Space(int count = 1)
return SymbolDisplayPartKind.ModuleName;
case ClassificationTypeNames.VerbatimStringLiteral:
return SymbolDisplayPartKind.StringLiteral;
case ClassificationTypeNames.FieldName:
case ClassificationTypeNames.EnumFieldName:
case ClassificationTypeNames.ConstantName:
case ClassificationTypeNames.LocalName:
case ClassificationTypeNames.ParameterName:
case ClassificationTypeNames.ExtensionMethodName:
case ClassificationTypeNames.MethodName:
case ClassificationTypeNames.PropertyName:
case ClassificationTypeNames.EventName:
return SymbolDisplayPartKind.Text; // TODO: Add more SymbolDisplayPartKinds
}
}
}
......
......@@ -210,6 +210,15 @@ const Microsoft.CodeAnalysis.Classification.ClassificationTypeNames.XmlLiteralEn
const Microsoft.CodeAnalysis.Classification.ClassificationTypeNames.XmlLiteralName = "xml literal - name" -> string
const Microsoft.CodeAnalysis.Classification.ClassificationTypeNames.XmlLiteralProcessingInstruction = "xml literal - processing instruction" -> string
const Microsoft.CodeAnalysis.Classification.ClassificationTypeNames.XmlLiteralText = "xml literal - text" -> string
const Microsoft.CodeAnalysis.Classification.ClassificationTypeNames.FieldName = "field name" -> string
const Microsoft.CodeAnalysis.Classification.ClassificationTypeNames.EnumFieldName = "enum field name" -> string
const Microsoft.CodeAnalysis.Classification.ClassificationTypeNames.ConstantName = "constant name" -> string
const Microsoft.CodeAnalysis.Classification.ClassificationTypeNames.LocalName = "local name" -> string
const Microsoft.CodeAnalysis.Classification.ClassificationTypeNames.ParameterName = "parameter name" -> string
const Microsoft.CodeAnalysis.Classification.ClassificationTypeNames.MethodName = "method name" -> string
const Microsoft.CodeAnalysis.Classification.ClassificationTypeNames.ExtensionMethodName = "extension method name" -> string
const Microsoft.CodeAnalysis.Classification.ClassificationTypeNames.PropertyName = "property name" -> string
const Microsoft.CodeAnalysis.Classification.ClassificationTypeNames.EventName = "event name" -> string
const Microsoft.CodeAnalysis.CodeActions.ConflictAnnotation.Kind = "CodeAction_Conflict" -> string
const Microsoft.CodeAnalysis.CodeActions.RenameAnnotation.Kind = "CodeAction_Rename" -> string
const Microsoft.CodeAnalysis.CodeActions.WarningAnnotation.Kind = "CodeAction_Warning" -> string
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册