提交 9d9008d0 编写于 作者: C CyrusNajmabadi

Merge remote-tracking branch 'upstream/master'

......@@ -19,4 +19,4 @@ Invoke-WebRequest -Uri http://dotnetci.blob.core.windows.net/roslyn-perf/cpc.zip
# Preview 4 specific
[Environment]::SetEnvironmentVariable("VS150COMNTOOLS", "C:\\Program Files (x86)\\Microsoft Visual Studio\\VS15Preview\\Common7\\Tools", "Process")
./cibuild.cmd /testPerfRun
./cibuild.cmd /testPerfRun /release
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Roslyn.Utilities;
using System;
using System.Collections.Immutable;
using System.Diagnostics;
......@@ -107,6 +108,14 @@ public override BoundNode VisitLocalFunctionStatement(BoundLocalFunctionStatemen
if (!localFunc.WasCompilerGenerated) EnterParameters(localFunc.Symbol.Parameters);
var oldPending2 = SavePending();
// If this is an iterator, there's an implicit branch before the first statement
// of the function where the enumerable is returned.
if (localFunc.Symbol.IsIterator)
{
PendingBranches.Add(new PendingBranch(null, this.State));
}
VisitAlways(localFunc.Body);
RestorePending(oldPending2); // process any forward branches within the lambda body
ImmutableArray<PendingBranch> pendingReturns = RemoveReturns();
......@@ -126,17 +135,10 @@ public override BoundNode VisitLocalFunctionStatement(BoundLocalFunctionStatemen
{
this.State = pending.State;
BoundNode branch = pending.Branch;
if (branch.Kind == BoundKind.ReturnStatement)
{
// ensure out parameters are definitely assigned at each return
LeaveParameters(localFunc.Symbol.Parameters, branch.Syntax,
branch.WasCompilerGenerated ? location : null);
IntersectWith(ref stateAtReturn, ref this.State);
}
else
{
// other ways of branching out of a lambda are errors, previously reported in control-flow analysis
}
LeaveParameters(localFunc.Symbol.Parameters, branch?.Syntax,
branch?.WasCompilerGenerated == true
? location : null);
IntersectWith(ref stateAtReturn, ref this.State);
}
// Check for changes to the read and write sets
......
......@@ -7191,7 +7191,7 @@ public override string ToString()
Assert.Equal(Conversion.NoConversion, model.GetConversion(node));
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/11289")]
[Fact]
[WorkItem(11289, "https://github.com/dotnet/roslyn/issues/11289")]
public void TupleConvertedTypeUDC04()
{
......@@ -7265,7 +7265,7 @@ public override string ToString()
CompileAndVerify(comp, expectedOutput: "{1, qq}");
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/11289")]
[Fact]
[WorkItem(11289, "https://github.com/dotnet/roslyn/issues/11289")]
public void TupleConvertedTypeUDC05()
{
......@@ -7348,7 +7348,7 @@ public override string ToString()
{1, qq}");
}
[Fact(Skip = "https://github.com/dotnet/roslyn/issues/11289")]
[Fact]
[WorkItem(11289, "https://github.com/dotnet/roslyn/issues/11289")]
public void TupleConvertedTypeUDC06()
{
......
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Xunit;
namespace Microsoft.CodeAnalysis.CSharp.UnitTests
......@@ -6,6 +7,135 @@ namespace Microsoft.CodeAnalysis.CSharp.UnitTests
[CompilerTrait(CompilerFeature.LocalFunctions)]
public class LocalFunctions : FlowTestBase
{
[Fact]
public void InvalidBranchOutOfLocalFunc()
{
var comp = CreateCompilationWithMscorlib(@"
class C
{
public static void M()
{
label1:
L();
L2();
L3();
void L()
{
goto label1;
}
void L2()
{
break;
}
void L3()
{
continue;
}
}
}");
comp.VerifyDiagnostics(
// (14,13): error CS0159: No such label 'label1' within the scope of the goto statement
// goto label1;
Diagnostic(ErrorCode.ERR_LabelNotFound, "goto").WithArguments("label1").WithLocation(14, 13),
// (19,13): error CS0139: No enclosing loop out of which to break or continue
// break;
Diagnostic(ErrorCode.ERR_NoBreakOrCont, "break;").WithLocation(19, 13),
// (24,13): error CS0139: No enclosing loop out of which to break or continue
// continue;
Diagnostic(ErrorCode.ERR_NoBreakOrCont, "continue;").WithLocation(24, 13),
// (6,9): warning CS0164: This label has not been referenced
// label1:
Diagnostic(ErrorCode.WRN_UnreferencedLabel, "label1").WithLocation(6, 9));
}
[Fact]
[WorkItem(13762, "https://github.com/dotnet/roslyn/issues/13762")]
public void AssignsInAsync()
{
var comp = CreateCompilationWithMscorlib46(@"
using System.Threading.Tasks;
class C
{
public static void M2()
{
int a=0, x, y, z;
L1();
a++;
x++;
y++;
z++;
async void L1()
{
x = 0;
await Task.Delay(0);
y = 0;
}
}
}");
comp.VerifyDiagnostics(
// (12,9): error CS0165: Use of unassigned local variable 'y'
// y++;
Diagnostic(ErrorCode.ERR_UseDefViolation, "y").WithArguments("y").WithLocation(12, 9),
// (13,9): error CS0165: Use of unassigned local variable 'z'
// z++;
Diagnostic(ErrorCode.ERR_UseDefViolation, "z").WithArguments("z").WithLocation(13, 9));
}
[Fact]
[WorkItem(13762, "https://github.com/dotnet/roslyn/issues/13762")]
public void AssignsInIterator()
{
var comp = CreateCompilationWithMscorlib46(@"
using System.Collections.Generic;
class C
{
public static void M2()
{
int a=0, w, x, y, z;
L1();
a++;
w++;
x++;
y++;
z++;
IEnumerable<bool> L1()
{
w = 0;
yield return false;
x = 0;
yield break;
y = 0;
}
}
}");
comp.VerifyDiagnostics(
// (24,13): warning CS0162: Unreachable code detected
// y = 0;
Diagnostic(ErrorCode.WRN_UnreachableCode, "y").WithLocation(24, 13),
// (13,9): error CS0165: Use of unassigned local variable 'w'
// w++;
Diagnostic(ErrorCode.ERR_UseDefViolation, "w").WithArguments("w").WithLocation(13, 9),
// (14,9): error CS0165: Use of unassigned local variable 'x'
// x++;
Diagnostic(ErrorCode.ERR_UseDefViolation, "x").WithArguments("x").WithLocation(14, 9),
// (15,9): error CS0165: Use of unassigned local variable 'y'
// y++;
Diagnostic(ErrorCode.ERR_UseDefViolation, "y").WithArguments("y").WithLocation(15, 9),
// (16,9): error CS0165: Use of unassigned local variable 'z'
// z++;
Diagnostic(ErrorCode.ERR_UseDefViolation, "z").WithArguments("z").WithLocation(16, 9));
}
[Fact]
public void SimpleForwardCall()
{
......
......@@ -26590,7 +26590,7 @@ public static void TakeOutParam(out int x, long y)
";
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.ReleaseExe.WithScriptClassName("Script"), parseOptions: TestOptions.Script);
compilation.VerifyDiagnostics(
compilation.GetDeclarationDiagnostics().Verify(
// (3,24): error CS7019: Type of 'x1' cannot be inferred since its initializer directly or indirectly refers to the definition.
// H.TakeOutParam(out var x1, x1);
Diagnostic(ErrorCode.ERR_RecursivelyTypedVariable, "x1").WithArguments("x1").WithLocation(3, 24)
......@@ -19,14 +19,7 @@ public static IList<string> ParseFeatureFromMSBuild(string features)
return SpecializedCollections.EmptyList<string>();
}
var all = features.Split(new[] { ';', ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
var list = new List<string>(capacity: all.Length);
foreach (var feature in all)
{
list.Add(feature);
}
return list;
return features.Split(new[] { ';', ',', ' ' }, StringSplitOptions.RemoveEmptyEntries);
}
public static ImmutableDictionary<string, string> ParseFeatures(List<string> values)
......
......@@ -8,7 +8,7 @@
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.AppContext.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Console.dll")]
[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\System.Diagnostics.FileVersionInfo.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Diagnostics.FileVersionInfo.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Diagnostics.Process.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.IO.Compression.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.IO.FileSystem.dll")]
......@@ -19,11 +19,12 @@
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Security.AccessControl.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Security.Claims.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Security.Cryptography.Algorithms.dll")]
[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\System.Security.Cryptography.Encoding.dll")]
[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\System.Security.Cryptography.Primitives.dll")]
[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\System.Security.Cryptography.X509Certificates.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Security.Cryptography.Encoding.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Security.Cryptography.Primitives.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Security.Cryptography.X509Certificates.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Security.Principal.Windows.dll")]
[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\System.Text.Encoding.CodePages.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Text.Encoding.CodePages.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Threading.Thread.dll")]
[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\System.Xml.XmlDocument.dll")]
[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\System.Xml.XPath.XDocument.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Xml.XmlDocument.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Xml.XPath.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Xml.XPath.XDocument.dll")]
......@@ -47,7 +47,6 @@
<ItemGroup>
<NuGetPackageToIncludeInVsix Include="Microsoft.DiaSymReader.Native" />
<NuGetPackageToIncludeInVsix Include="Microsoft.Win32.Primitives" />
<!-- Even though the VS process includes both of these, we need to also include them in the VSIX for the compiler processes -->
<NuGetPackageToIncludeInVsix Include="System.AppContext" />
<NuGetPackageToIncludeInVsix Include="System.Collections" />
<NuGetPackageToIncludeInVsix Include="System.Collections.Concurrent" />
......
......@@ -365,6 +365,10 @@ Friend Class MockNamedTypeSymbol
Friend Overrides Sub GenerateDeclarationErrors(cancellationToken As CancellationToken)
Throw New InvalidOperationException()
End Sub
Friend NotOverridable Overrides Function GetSynthesizedWithEventsOverrides() As IEnumerable(Of PropertySymbol)
Return SpecializedCollections.EmptyEnumerable(Of PropertySymbol)()
End Function
End Class
Friend Class MockMethodSymbol
......
......@@ -1595,6 +1595,9 @@ DoneWithDiagnostics:
If targetType.IsTupleType Then
Dim destTupleType = DirectCast(targetType, TupleTypeSymbol)
TupleTypeSymbol.ReportNamesMismatchesIfAny(targetType, sourceTuple, diagnostics)
' do not lose the original element names in the literal if different from names in the target
' Come back to this, what about locations? (https:'github.com/dotnet/roslyn/issues/11013)
targetType = destTupleType.WithElementNames(sourceTuple.ArgumentNamesOpt)
......
......@@ -1766,8 +1766,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
WRN_ConstraintsFailedForInferredArgs2 = 41006
WRN_ConditionalNotValidOnFunction = 41007
WRN_UseSwitchInsteadOfAttribute = 41008
WRN_TupleLiteralNameMismatch = 41009
'// AVAILABLE 41009 - 41199
'// AVAILABLE 41010 - 41199
WRN_ReferencedAssemblyDoesNotHaveStrongName = 41997
WRN_RecursiveAddHandlerCall = 41998
WRN_ImplicitConversionCopyBack = 41999
......
......@@ -295,7 +295,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
Friend Overrides Sub AddSynthesizedAttributes(compilationState as ModuleCompilationState, ByRef attributes As ArrayBuilder(Of SynthesizedAttributeData))
Friend Overrides Sub AddSynthesizedAttributes(compilationState As ModuleCompilationState, ByRef attributes As ArrayBuilder(Of SynthesizedAttributeData))
MyBase.AddSynthesizedAttributes(compilationState, attributes)
Dim compilation = Me.DeclaringCompilation
......@@ -308,5 +308,8 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
WellKnownMember.System_Runtime_CompilerServices_CompilerGeneratedAttribute__ctor))
End Sub
Friend NotOverridable Overrides Function GetSynthesizedWithEventsOverrides() As IEnumerable(Of PropertySymbol)
Return SpecializedCollections.EmptyEnumerable(Of PropertySymbol)()
End Function
End Class
End Namespace
......@@ -300,6 +300,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Throw ExceptionUtilities.Unreachable
End Function
Friend NotOverridable Overrides Function GetSynthesizedWithEventsOverrides() As IEnumerable(Of PropertySymbol)
Return SpecializedCollections.EmptyEnumerable(Of PropertySymbol)()
End Function
End Class
End Class
......
......@@ -355,6 +355,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Throw ExceptionUtilities.Unreachable
End Sub
Friend NotOverridable Overrides Function GetSynthesizedWithEventsOverrides() As IEnumerable(Of PropertySymbol)
Return SpecializedCollections.EmptyEnumerable(Of PropertySymbol)()
End Function
End Class
End Class
......
......@@ -396,6 +396,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Throw ExceptionUtilities.Unreachable
End Sub
Friend NotOverridable Overrides Function GetSynthesizedWithEventsOverrides() As IEnumerable(Of PropertySymbol)
Return SpecializedCollections.EmptyEnumerable(Of PropertySymbol)()
End Function
#Region "IErrorTypeSymbol members"
Public ReadOnly Property IErrorTypeSymbol_CandidateSymbols As ImmutableArray(Of ISymbol) Implements IErrorTypeSymbol.CandidateSymbols
......
......@@ -1475,6 +1475,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Metadata.PE
Next
End Function
Friend NotOverridable Overrides Function GetSynthesizedWithEventsOverrides() As IEnumerable(Of PropertySymbol)
Return SpecializedCollections.EmptyEnumerable(Of PropertySymbol)()
End Function
End Class
End Namespace
......@@ -1080,6 +1080,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
''' <returns>True if this Is an interface type.</returns>
Friend MustOverride ReadOnly Property IsInterface As Boolean
''' <summary>
''' Get synthesized WithEvents overrides that aren't returned by <see cref="GetMembers"/>
''' </summary>
Friend MustOverride Function GetSynthesizedWithEventsOverrides() As IEnumerable(Of PropertySymbol)
#Region "INamedTypeSymbol"
Private ReadOnly Property INamedTypeSymbol_Arity As Integer Implements INamedTypeSymbol.Arity
......
......@@ -522,5 +522,11 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols.Retargeting
Public Overrides Function GetDocumentationCommentXml(Optional preferredCulture As CultureInfo = Nothing, Optional expandIncludes As Boolean = False, Optional cancellationToken As CancellationToken = Nothing) As String
Return _underlyingType.GetDocumentationCommentXml(preferredCulture, expandIncludes, cancellationToken)
End Function
Friend Overrides Iterator Function GetSynthesizedWithEventsOverrides() As IEnumerable(Of PropertySymbol)
For Each underlying As PropertySymbol In _underlyingType.GetSynthesizedWithEventsOverrides()
Yield RetargetingTranslator.Retarget(underlying)
Next
End Function
End Class
End Namespace
......@@ -191,5 +191,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Next
End Sub
Friend Overrides Function GetSynthesizedWithEventsOverrides() As IEnumerable(Of PropertySymbol)
' All infrastructure for proper WithEvents handling is in SourceNamedTypeSymbol,
' but this type derives directly from SourceMemberContainerTypeSymbol, which is a base class of
' SourceNamedTypeSymbol.
' Tracked by https://github.com/dotnet/roslyn/issues/14073.
Return SpecializedCollections.EmptyEnumerable(Of PropertySymbol)()
End Function
End Class
End Namespace
......@@ -697,54 +697,22 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Dim overriddenInThisType As ArrayBuilder(Of TSymbol) = ArrayBuilder(Of TSymbol).GetInstance()
For Each sym In currType.GetMembers(overridingSym.Name)
' Use original definition for accessibility check, because substitutions can cause
' reductions in accessibility that aren't appropriate (see bug #12038 for example).
Dim accessible = AccessCheck.IsSymbolAccessible(sym.OriginalDefinition, overridingContainingType.OriginalDefinition, Nothing, useSiteDiagnostics:=Nothing)
If sym.Kind = overridingSym.Kind AndAlso
CanOverrideOrHide(sym) Then
Dim member As TSymbol = DirectCast(sym, TSymbol)
Dim exactMatch As Boolean = True ' considered to be True for all runtime signature comparisons
Dim exactMatchIgnoringCustomModifiers As Boolean = True ' considered to be True for all runtime signature comparisons
If If(overridingIsFromSomeCompilation,
sym.IsWithEventsProperty = overridingSym.IsWithEventsProperty AndAlso
SignaturesMatch(overridingSym, member, exactMatch, exactMatchIgnoringCustomModifiers),
s_runtimeSignatureComparer.Equals(overridingSym, member)) Then
If accessible Then
If exactMatchIgnoringCustomModifiers Then
If exactMatch Then
If Not haveExactMatch Then
haveExactMatch = True
stopLookup = True
overriddenInThisType.Clear()
End If
overriddenInThisType.Add(member)
ElseIf Not haveExactMatch Then
overriddenInThisType.Add(member)
End If
Else
' Add only if not hidden by signature
AddMemberToABuilder(member, inexactOverriddenMembers)
End If
Else
If exactMatchIgnoringCustomModifiers Then
' only exact matched methods are to be added
inaccessibleBuilder.Add(member)
End If
ProcessMemberWithMatchingName(sym, overridingSym, overridingIsFromSomeCompilation, overridingContainingType, inexactOverriddenMembers,
inaccessibleBuilder, overriddenInThisType, stopLookup, haveExactMatch)
Next
If overridingSym.Kind = SymbolKind.Property Then
Dim prop = DirectCast(DirectCast(overridingSym, Object), PropertySymbol)
If prop.IsImplicitlyDeclared AndAlso prop.IsWithEvents Then
For Each sym In currType.GetSynthesizedWithEventsOverrides()
If sym.Name.Equals(prop.Name) Then
ProcessMemberWithMatchingName(sym, overridingSym, overridingIsFromSomeCompilation, overridingContainingType, inexactOverriddenMembers,
inaccessibleBuilder, overriddenInThisType, stopLookup, haveExactMatch)
End If
ElseIf Not member.IsOverloads() AndAlso accessible Then
' hiding symbol by name
stopLookup = True
End If
ElseIf accessible Then
' Any accessible symbol of different kind stops further lookup
stopLookup = True
Next
End If
Next
End If
If overriddenInThisType.Count > 1 Then
RemoveMembersWithConflictingAccessibility(overriddenInThisType)
......@@ -765,6 +733,66 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Return stopLookup
End Function
Private Shared Sub ProcessMemberWithMatchingName(
sym As Symbol,
overridingSym As TSymbol,
overridingIsFromSomeCompilation As Boolean,
overridingContainingType As NamedTypeSymbol,
inexactOverriddenMembers As ArrayBuilder(Of TSymbol),
inaccessibleBuilder As ArrayBuilder(Of TSymbol),
overriddenInThisType As ArrayBuilder(Of TSymbol),
ByRef stopLookup As Boolean,
ByRef haveExactMatch As Boolean
)
' Use original definition for accessibility check, because substitutions can cause
' reductions in accessibility that aren't appropriate (see bug #12038 for example).
Dim accessible = AccessCheck.IsSymbolAccessible(sym.OriginalDefinition, overridingContainingType.OriginalDefinition, Nothing, useSiteDiagnostics:=Nothing)
If sym.Kind = overridingSym.Kind AndAlso
CanOverrideOrHide(sym) Then
Dim member As TSymbol = DirectCast(sym, TSymbol)
Dim exactMatch As Boolean = True ' considered to be True for all runtime signature comparisons
Dim exactMatchIgnoringCustomModifiers As Boolean = True ' considered to be True for all runtime signature comparisons
If If(overridingIsFromSomeCompilation,
sym.IsWithEventsProperty = overridingSym.IsWithEventsProperty AndAlso
SignaturesMatch(overridingSym, member, exactMatch, exactMatchIgnoringCustomModifiers),
s_runtimeSignatureComparer.Equals(overridingSym, member)) Then
If accessible Then
If exactMatchIgnoringCustomModifiers Then
If exactMatch Then
If Not haveExactMatch Then
haveExactMatch = True
stopLookup = True
overriddenInThisType.Clear()
End If
overriddenInThisType.Add(member)
ElseIf Not haveExactMatch Then
overriddenInThisType.Add(member)
End If
Else
' Add only if not hidden by signature
AddMemberToABuilder(member, inexactOverriddenMembers)
End If
Else
If exactMatchIgnoringCustomModifiers Then
' only exact matched methods are to be added
inaccessibleBuilder.Add(member)
End If
End If
ElseIf Not member.IsOverloads() AndAlso accessible Then
' hiding symbol by name
stopLookup = True
End If
ElseIf accessible Then
' Any accessible symbol of different kind stops further lookup
stopLookup = True
End If
End Sub
Private Shared Sub AddMemberToABuilder(member As TSymbol,
builder As ArrayBuilder(Of TSymbol))
......
......@@ -35,6 +35,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
' Overriding properties are created when a methods "Handles" is bound and can happen concurrently.
' We need this table to ensure that we create each override just once.
Private _lazyWithEventsOverrides As ConcurrentDictionary(Of PropertySymbol, SynthesizedOverridingWithEventsProperty)
Private _withEventsOverridesAreFrozen As Boolean
' method flags for the synthesized delegate methods
Friend Const DelegateConstructorMethodFlags As SourceMemberFlags = SourceMemberFlags.MethodKindConstructor
......@@ -99,7 +100,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
#Region "Completion"
Protected Overrides Sub GenerateAllDeclarationErrorsImpl(cancellationToken As CancellationToken)
#If DEBUG Then
EnsureAllHandlesAreBound()
#End If
MyBase.GenerateAllDeclarationErrorsImpl(cancellationToken)
_withEventsOverridesAreFrozen = True
cancellationToken.ThrowIfCancellationRequested()
PerformComClassAnalysis()
......@@ -144,7 +150,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
' for cases where constraint checking may result in a recursive binding attempt.
Private Function CreateLocationSpecificBinderForType(tree As SyntaxTree, location As BindingLocation) As Binder
Debug.Assert(location <> BindingLocation.None)
Dim binder As binder = BinderBuilder.CreateBinderForType(ContainingSourceModule, tree, Me)
Dim binder As Binder = BinderBuilder.CreateBinderForType(ContainingSourceModule, tree, Me)
Return New LocationSpecificBinder(location, binder)
End Function
#End Region
......@@ -164,7 +170,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Dim node = syntaxRef.GetVisualBasicSyntax()
' Set up a binder for this part of the type.
Dim binder As binder = BinderBuilder.CreateBinderForType(ContainingSourceModule, syntaxRef.SyntaxTree, Me)
Dim binder As Binder = BinderBuilder.CreateBinderForType(ContainingSourceModule, syntaxRef.SyntaxTree, Me)
' Script and implicit classes are syntactically represented by CompilationUnitSyntax or NamespaceBlockSyntax nodes.
Dim staticInitializers As ArrayBuilder(Of FieldOrPropertyInitializer) = Nothing
......@@ -2472,10 +2478,36 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Else
' we need to create a lambda here since we need to close over baseProperty
' we will however create a lambda only on a cache miss, hopefully not very often.
Return overridesDict.GetOrAdd(baseProperty, Function() New SynthesizedOverridingWithEventsProperty(baseProperty, Me))
Return overridesDict.GetOrAdd(baseProperty, Function()
Debug.Assert(Not _withEventsOverridesAreFrozen)
Return New SynthesizedOverridingWithEventsProperty(baseProperty, Me)
End Function)
End If
End Function
Friend NotOverridable Overrides Function GetSynthesizedWithEventsOverrides() As IEnumerable(Of PropertySymbol)
EnsureAllHandlesAreBound()
Dim overridesDict = Me._lazyWithEventsOverrides
If overridesDict IsNot Nothing Then
Return overridesDict.Values
End If
Return SpecializedCollections.EmptyEnumerable(Of PropertySymbol)()
End Function
Private Sub EnsureAllHandlesAreBound()
If Not _withEventsOverridesAreFrozen Then
For Each member In Me.GetMembersUnordered()
If member.Kind = SymbolKind.Method Then
Dim notUsed = DirectCast(member, MethodSymbol).HandledEvents
End If
Next
_withEventsOverridesAreFrozen = True
End If
End Sub
Protected Overrides Sub AddEntryPointIfNeeded(membersBuilder As MembersAndInitializersBuilder)
If Me.TypeKind = TypeKind.Class AndAlso Not Me.IsGenericType Then
Dim mainTypeName As String = DeclaringCompilation.Options.MainTypeName
......
......@@ -1009,6 +1009,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Friend Overrides Function GetUnificationUseSiteDiagnosticRecursive(owner As Symbol, ByRef checkedTypes As HashSet(Of TypeSymbol)) As DiagnosticInfo
Return Nothing
End Function
Friend NotOverridable Overrides Function GetSynthesizedWithEventsOverrides() As IEnumerable(Of PropertySymbol)
Return SpecializedCollections.EmptyEnumerable(Of PropertySymbol)()
End Function
End Class
Private Class SynthesizedComMethod
......
......@@ -536,6 +536,12 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Return OriginalDefinition.GetDocumentationCommentXml(preferredCulture, expandIncludes, cancellationToken)
End Function
Friend NotOverridable Overrides Iterator Function GetSynthesizedWithEventsOverrides() As IEnumerable(Of PropertySymbol)
For Each definition In OriginalDefinition.GetSynthesizedWithEventsOverrides()
Yield SubstituteTypeParametersForMemberProperty(definition)
Next
End Function
''' <summary>
''' Base class for symbols representing non-generic or open generic types contained within constructed generic type.
''' For example: A(Of Integer).B, A(Of Integer).B.C or A(Of Integer).B.C(Of ).
......
......@@ -431,6 +431,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Return Nothing
End Get
End Property
Friend Overrides Function GetSynthesizedWithEventsOverrides() As IEnumerable(Of PropertySymbol)
Return SpecializedCollections.EmptyEnumerable(Of PropertySymbol)()
End Function
End Class
End Namespace
......@@ -999,5 +999,32 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Friend Overrides Sub GenerateDeclarationErrors(cancellationToken As CancellationToken)
Me._underlyingType.GenerateDeclarationErrors(cancellationToken)
End Sub
Friend Overrides Function GetSynthesizedWithEventsOverrides() As IEnumerable(Of PropertySymbol)
' We might need to have a real implementation here, depending on the resolution
' of https://github.com/dotnet/roslyn/issues/14104
Return SpecializedCollections.EmptyEnumerable(Of PropertySymbol)()
End Function
Friend Shared Sub ReportNamesMismatchesIfAny(destination As TypeSymbol, literal As BoundTupleLiteral, diagnostics As DiagnosticBag)
Dim sourceNames = literal.ArgumentNamesOpt
If sourceNames.IsDefault Then
Return
End If
Dim destinationNames As ImmutableArray(Of String) = destination.TupleElementNames
Dim sourceLength As Integer = sourceNames.Length
Dim allMissing As Boolean = destinationNames.IsDefault
Debug.Assert(allMissing OrElse destinationNames.Length = sourceLength)
For i = 0 To sourceLength - 1
Dim sourceName = sourceNames(i)
If sourceName IsNot Nothing AndAlso (allMissing OrElse String.CompareOrdinal(destinationNames(i), sourceName) <> 0) Then
diagnostics.Add(ERRID.WRN_TupleLiteralNameMismatch, literal.Arguments(i).Syntax.Parent.Location, sourceName, destination)
End If
Next
End Sub
End Class
End Namespace
......@@ -317,6 +317,10 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.Symbols
Throw ExceptionUtilities.Unreachable
End Function
Friend NotOverridable Overrides Function GetSynthesizedWithEventsOverrides() As IEnumerable(Of PropertySymbol)
Return SpecializedCollections.EmptyEnumerable(Of PropertySymbol)()
End Function
Private NotInheritable Class ConstructedSymbol
Inherits UnboundGenericType
......
......@@ -14574,6 +14574,24 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
'''<summary>
''' Looks up a localized string similar to The tuple element name &apos;{0}&apos; is ignored because a different name is specified by the target type &apos;{1}&apos;..
'''</summary>
Friend ReadOnly Property WRN_TupleLiteralNameMismatch() As String
Get
Return ResourceManager.GetString("WRN_TupleLiteralNameMismatch", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to The tuple element name is ignored because a different name is specified by the assignment target..
'''</summary>
Friend ReadOnly Property WRN_TupleLiteralNameMismatch_Title() As String
Get
Return ResourceManager.GetString("WRN_TupleLiteralNameMismatch_Title", resourceCulture)
End Get
End Property
'''<summary>
''' Looks up a localized string similar to {0} &apos;{1}&apos; and partial {2} &apos;{3}&apos; conflict in {4} &apos;{5}&apos;, but are being merged because one of them is declared partial..
'''</summary>
......
......@@ -5382,6 +5382,12 @@
<data name="ERR_TupleDuplicateElementName" xml:space="preserve">
<value>Tuple element names must be unique.</value>
</data>
<data name="WRN_TupleLiteralNameMismatch" xml:space="preserve">
<value>The tuple element name '{0}' is ignored because a different name is specified by the target type '{1}'.</value>
</data>
<data name="WRN_TupleLiteralNameMismatch_Title" xml:space="preserve">
<value>The tuple element name is ignored because a different name is specified by the assignment target.</value>
</data>
<data name="ERR_TupleReservedElementName" xml:space="preserve">
<value>Tuple element name '{0}' is only allowed at position {1}.</value>
</data>
......
......@@ -54,7 +54,7 @@ class Class2 { }";
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)]
[WorkItem(14008, "https://github.com/dotnet/roslyn/issues/14008")]
public async Task TestFolders()
public async Task TestMoveToNewFileWithFolders()
{
var code =
@"
......
......@@ -33,6 +33,28 @@ class Inner { }
await TestRenameFileToMatchTypeAsync(code, expectedDocumentName);
}
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)]
public async Task TestRenameFileWithFolders()
{
var code =
@"
<Workspace>
<Project Language=""C#"" AssemblyName=""Assembly1"" CommonReferences=""true"">
<Document Folders=""A\B"">
[||]class Class1
{
class Inner { }
}
</Document>
</Project>
</Workspace>";
var expectedDocumentName = "Class1.cs";
await TestRenameFileToMatchTypeAsync(code, expectedDocumentName,
destinationDocumentContainers: new[] { "A", "B" });
}
[WpfFact, Trait(Traits.Feature, Traits.Features.CodeActionsMoveType)]
public async Task TestMissing_TypeNameMatchesFileName_RenameFile()
{
......
......@@ -68,6 +68,12 @@ public Task OnDefinitionFoundAsync(SymbolAndProjectId definition)
public async Task OnReferenceFoundAsync(SymbolAndProjectId definition, ReferenceLocation location)
{
// Ignore duplicate locations. We don't want to clutter the UI with them.
if (location.IsDuplicateReferenceLocation)
{
return;
}
var referenceItem = location.TryCreateSourceReferenceItem(
GetDefinitionItem(definition));
......
......@@ -73,7 +73,8 @@ protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspa
string originalCode,
string expectedDocumentName = null,
bool expectedCodeAction = true,
bool compareTokens = true)
bool compareTokens = true,
IList<string> destinationDocumentContainers = null)
{
using (var workspace = await CreateWorkspaceFromFileAsync(originalCode, parseOptions: null, compilationOptions: null))
{
......@@ -82,10 +83,8 @@ protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspa
Assert.True(expectedDocumentName != null, $"{nameof(expectedDocumentName)} should be present if {nameof(expectedCodeAction)} is true.");
var oldDocumentId = workspace.Documents[0].Id;
string expectedText;
IList<TextSpan> spans;
MarkupTestFile.GetSpans(originalCode, out expectedText, out spans);
var expectedText = workspace.Documents[0].TextBuffer.CurrentSnapshot.GetText();
var spans = workspace.Documents[0].SelectedSpans;
var codeActionTitle = string.Format(RenameFileCodeActionTitle, expectedDocumentName);
......@@ -96,6 +95,12 @@ protected override CodeRefactoringProvider CreateCodeRefactoringProvider(Workspa
// the original source document does not exist in the new solution.
var newSolution = oldSolutionAndNewSolution.Item2;
Assert.Null(newSolution.GetDocument(oldDocumentId));
if (destinationDocumentContainers != null)
{
var newDocument = newSolution.Projects.First().Documents.First();
Assert.Equal(destinationDocumentContainers, newDocument.Folders);
}
}
else
{
......
......@@ -356,6 +356,9 @@ Namespace Microsoft.CodeAnalysis.VisualBasic.ExpressionEvaluator
Next
End Sub
Friend Overrides Function GetSynthesizedWithEventsOverrides() As IEnumerable(Of PropertySymbol)
Return SpecializedCollections.EmptyEnumerable(Of PropertySymbol)()
End Function
End Class
End Namespace
\ No newline at end of file
......@@ -26,16 +26,17 @@ internal override Task<IEnumerable<CodeActionOperation>> GetOperationsAsync()
/// </summary>
private IEnumerable<CodeActionOperation> RenameFileToMatchTypeName()
{
var solution = SemanticDocument.Document.Project.Solution;
var oldDocument = SemanticDocument.Document;
var solution = oldDocument.Project.Solution;
var text = SemanticDocument.Text;
var oldDocumentId = SemanticDocument.Document.Id;
var newDocumentId = DocumentId.CreateNewId(SemanticDocument.Document.Project.Id, FileName);
var oldDocumentId = oldDocument.Id;
var newDocumentId = DocumentId.CreateNewId(oldDocument.Project.Id, FileName);
// currently, document rename is accomplished by a remove followed by an add.
// the workspace takes care of resolving conflicts if the document name is not unique in the project
// by adding numeric suffixes to the new document being added.
var newSolution = solution.RemoveDocument(oldDocumentId);
newSolution = newSolution.AddDocument(newDocumentId, FileName, text);
newSolution = newSolution.AddDocument(newDocumentId, FileName, text, oldDocument.Folders);
return new CodeActionOperation[]
{
......
......@@ -106,19 +106,27 @@ Public Class BuildDevDivInsertionFiles
"Microsoft.DiaSymReader.Native.x86.dll",
"System.AppContext.dll",
"System.Console.dll",
"System.Diagnostics.FileVersionInfo.dll",
"System.Diagnostics.Process.dll",
"System.Diagnostics.StackTrace.dll",
"System.IO.Pipes.dll",
"System.IO.Compression.dll",
"System.IO.FileSystem.dll",
"System.IO.FileSystem.DriveInfo.dll",
"System.IO.FileSystem.Primitives.dll",
"System.IO.Pipes.dll",
"System.Runtime.InteropServices.RuntimeInformation.dll",
"System.Security.AccessControl.dll",
"System.Security.Claims.dll",
"System.Security.Cryptography.Algorithms.dll",
"System.Security.Cryptography.Encoding.dll",
"System.Security.Cryptography.Primitives.dll",
"System.Security.Cryptography.X509Certificates.dll",
"System.Security.Principal.Windows.dll",
"System.Text.Encoding.CodePages.dll",
"System.Threading.Thread.dll",
"System.Xml.XmlDocument.dll",
"System.Xml.XPath.dll",
"System.Xml.XPath.XDocument.dll",
"csc.exe",
"csc.exe.config",
"csc.rsp",
......
......@@ -8,9 +8,33 @@
"ManagedEsent": "1.9.4",
"System.AppContext": "4.1.0",
"System.Console": "4.0.0",
"System.Collections": "4.0.11",
"System.Collections.Concurrent": "4.0.12",
"System.Diagnostics.Process": "4.1.0",
"System.Diagnostics.Tools": "4.0.1",
"System.Diagnostics.FileVersionInfo": "4.0.0",
"System.Diagnostics.StackTrace": "4.0.1",
"System.IO": "4.1.0",
"System.IO.Compression": "4.1.0",
"System.IO.FileSystem": "4.0.1",
"System.IO.FileSystem.Primitives": "4.0.1",
"System.IO.Pipes": "4.0.0",
"System.Runtime.InteropServices.RuntimeInformation": "4.0.0",
"System.Runtime.Numerics": "4.0.1",
"System.Security.AccessControl": "4.0.0",
"System.Security.Cryptography.Algorithms": "4.2.0",
"System.Security.Cryptography.Encoding": "4.0.0",
"System.Security.Cryptography.X509Certificates": "4.1.0",
"System.Security.Principal.Windows": "4.0.0",
"System.Text.Encoding": "4.0.11",
"System.Text.Encoding.CodePages": "4.0.1",
"System.Text.Encoding.Extensions": "4.0.11",
"System.Text.RegularExpressions": "4.1.0",
"System.Threading.Thread": "4.0.0",
"System.Xml.ReaderWriter": "4.0.11",
"System.Xml.XDocument": "4.0.11",
"System.Xml.XmlDocument": "4.0.1",
"System.Xml.XPath.XDocument": "4.0.1"
},
"frameworks": {
"net46": {}
......
......@@ -34,19 +34,27 @@ folder InstallDir:\MSBuild\15.0\Bin
file source=$(OutputPath)\System.AppContext.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Console.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Diagnostics.FileVersionInfo.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Diagnostics.Process.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Diagnostics.StackTrace.dll vs.file.ngen=yes
file source=$(OutputPath)\System.IO.Pipes.dll vs.file.ngen=yes
file source=$(OutputPath)\System.IO.Compression.dll vs.file.ngen=yes
file source=$(OutputPath)\System.IO.FileSystem.dll vs.file.ngen=yes
file source=$(OutputPath)\System.IO.FileSystem.DriveInfo.dll vs.file.ngen=yes
file source=$(OutputPath)\System.IO.FileSystem.Primitives.dll vs.file.ngen=yes
file source=$(OutputPath)\System.IO.Pipes.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Runtime.InteropServices.RuntimeInformation.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Security.AccessControl.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Security.Claims.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Security.Cryptography.Algorithms.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Security.Cryptography.Encoding.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Security.Cryptography.Primitives.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Security.Cryptography.X509Certificates.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Security.Principal.Windows.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Text.Encoding.CodePages.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Threading.Thread.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Xml.XmlDocument.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Xml.XPath.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Xml.XPath.XDocument.dll vs.file.ngen=yes
folder InstallDir:\MSBuild\15.0\Bin\amd64
file source=$(OutputPath)\VBCSCompiler.exe vs.file.ngen=yes
......@@ -79,16 +87,24 @@ folder InstallDir:\MSBuild\15.0\Bin\amd64
file source=$(OutputPath)\System.AppContext.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Console.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Diagnostics.FileVersionInfo.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Diagnostics.Process.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Diagnostics.StackTrace.dll vs.file.ngen=yes
file source=$(OutputPath)\System.IO.Pipes.dll vs.file.ngen=yes
file source=$(OutputPath)\System.IO.Compression.dll vs.file.ngen=yes
file source=$(OutputPath)\System.IO.FileSystem.dll vs.file.ngen=yes
file source=$(OutputPath)\System.IO.FileSystem.DriveInfo.dll vs.file.ngen=yes
file source=$(OutputPath)\System.IO.FileSystem.Primitives.dll vs.file.ngen=yes
file source=$(OutputPath)\System.IO.Pipes.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Runtime.InteropServices.RuntimeInformation.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Security.AccessControl.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Security.Claims.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Security.Cryptography.Algorithms.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Security.Cryptography.Encoding.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Security.Cryptography.Primitives.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Security.Cryptography.X509Certificates.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Security.Principal.Windows.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Text.Encoding.CodePages.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Threading.Thread.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Xml.XmlDocument.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Xml.XPath.dll vs.file.ngen=yes
file source=$(OutputPath)\System.Xml.XPath.XDocument.dll vs.file.ngen=yes
use vs
package name=PortableFacades
version=1.1.0.0
version=1.2.0.0
folder InstallDir:\Common7\IDE\PrivateAssemblies
file source="$(NuGetPackageRoot)\System.AppContext\4.1.0\lib\net46\System.AppContext.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.Console\4.0.0\lib\net46\System.Console.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.Diagnostics.FileVersionInfo\4.0.0\runtimes\win\lib\net46\System.Diagnostics.FileVersionInfo.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.Diagnostics.Process\4.1.0\runtimes\win\lib\net46\System.Diagnostics.Process.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.Diagnostics.StackTrace\4.0.1\lib\net46\System.Diagnostics.StackTrace.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.IO.Compression\4.1.0\runtimes\win\lib\net46\System.IO.Compression.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.IO.FileSystem\4.0.1\lib\net46\System.IO.FileSystem.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.IO.FileSystem.Primitives\4.0.1\lib\net46\System.IO.FileSystem.Primitives.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.IO.Pipes\4.0.0\runtimes\win\lib\net46\System.IO.Pipes.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.Net.Security\4.0.0\runtimes\win\lib\net46\System.Net.Security.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.Net.Sockets\4.1.0\lib\net46\System.Net.Sockets.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.Reflection.TypeExtensions\4.1.0\lib\net46\System.Reflection.TypeExtensions.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.Security.AccessControl\4.0.0\runtimes\win\lib\net46\System.Security.AccessControl.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.Security.Claims\4.0.1\lib\net46\System.Security.Claims.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.Security.Cryptography.Algorithms\4.2.0\runtimes\win\lib\net46\System.Security.Cryptography.Algorithms.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.Security.Cryptography.Encoding\4.0.0\runtimes\win\lib\net46\System.Security.Cryptography.Encoding.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.Security.Cryptography.Primitives\4.0.0\lib\net46\System.Security.Cryptography.Primitives.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.Security.Cryptography.X509Certificates\4.1.0\runtimes\win\lib\net46\System.Security.Cryptography.X509Certificates.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.Security.Principal.Windows\4.0.0\runtimes\win\lib\net46\System.Security.Principal.Windows.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.Threading.Thread\4.0.0\lib\net46\System.Threading.Thread.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.Xml.XmlDocument\4.0.1\lib\net46\System.Xml.XmlDocument.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.Xml.XPath\4.0.1\lib\net46\System.Xml.XPath.dll" vs.file.ngen=yes
file source="$(NuGetPackageRoot)\System.Xml.XPath.XDocument\4.0.1\lib\net46\System.Xml.XPath.XDocument.dll" vs.file.ngen=yes
......@@ -259,7 +259,10 @@ private bool DynamicAnalysisEnabled()
private bool CodeLenEnabled()
{
#if false
return _globalEditorOptions.GetOptionValue(CodeLensOptions.IsCodeLensEnabledOptionKey);
#endif
return false;
}
}
}
......
......@@ -150,8 +150,8 @@ private async Task CreateNoResultsFoundEntryIfNecessaryAsync()
{
// Create a fake definition/reference called "search found no results"
await OnEntryFoundAsync(NoResultsDefinitionItem,
(db, c) => SimpleMessageEntry.CreateAsync(
db, ServicesVisualStudioNextResources.Search_found_no_results)).ConfigureAwait(false);
bucket => SimpleMessageEntry.CreateAsync(
bucket, ServicesVisualStudioNextResources.Search_found_no_results)).ConfigureAwait(false);
}
}
......@@ -173,8 +173,8 @@ private async Task CreateMissingReferenceEntriesIfNecessaryAsync()
// Create a fake reference to this definition that says
// "no references found to <symbolname>".
await OnEntryFoundAsync(definition,
(db, c) => SimpleMessageEntry.CreateAsync(
db, GetMessage(db.DefinitionItem))).ConfigureAwait(false);
bucket => SimpleMessageEntry.CreateAsync(
bucket, GetMessage(bucket.DefinitionItem))).ConfigureAwait(false);
}
}
......@@ -230,27 +230,74 @@ public override async Task OnDefinitionFoundAsync(DefinitionItem definition)
_definitions.Add(definition);
}
foreach (var location in definition.SourceSpans)
// If this is a definition we always want to show, then create entries
// for all the definition locations immediately.
if (definition.DisplayIfNoReferences)
{
await OnEntryFoundAsync(definition,
(db, c) => CreateDocumentLocationEntryAsync(
db, location, isDefinitionLocation: true, cancellationToken: c)).ConfigureAwait(false);
await AddDefinitionEntriesAsync(definition).ConfigureAwait(false);
}
}
private async Task AddDefinitionEntriesAsync(DefinitionItem definition)
{
CancellationToken.ThrowIfCancellationRequested();
// Don't do anything if we already have entries for this definition
// (i.e. another thread beat us to this).
if (HasEntriesForDefinition(definition))
{
return;
}
// First find the bucket corresponding to our definition. If we can't find/create
// one, then don't do anything for this reference.
var definitionBucket = GetOrCreateDefinitionBucket(definition);
if (definitionBucket == null)
{
return;
}
// We could do this inside the lock. but that would mean async activity in a
// lock, and i'd like to avoid that. That does mean that we might do extra
// work if multiple threads end up down htis path. But only one of them will
// win when we access the lock below.
var builder = ImmutableArray.CreateBuilder<Entry>();
foreach (var definitionLocation in definition.SourceSpans)
{
var definitionEntry = await CreateDocumentLocationEntryAsync(
definitionBucket, definitionLocation, isDefinitionLocation: true).ConfigureAwait(false);
if (definitionEntry != null)
{
builder.Add(definitionEntry);
}
}
lock (_gate)
{
// Do one final check to ensure that no other thread beat us here.
if (!HasEntriesForDefinition(definition))
{
_entries = _entries.AddRange(builder);
CurrentVersionNumber++;
}
}
// Let all our subscriptions know that we've updated.
_tableDataSink.FactorySnapshotChanged(this);
}
public override Task OnReferenceFoundAsync(SourceReferenceItem reference)
{
return OnEntryFoundAsync(reference.Definition,
(db, c) => CreateDocumentLocationEntryAsync(
db, reference.SourceSpan, isDefinitionLocation: false, cancellationToken: c));
bucket => CreateDocumentLocationEntryAsync(
bucket, reference.SourceSpan, isDefinitionLocation: false));
}
private async Task OnEntryFoundAsync(
DefinitionItem definition,
Func<RoslynDefinitionBucket, CancellationToken, Task<Entry>> createEntryAsync)
DefinitionItem definition,
Func<RoslynDefinitionBucket, Task<Entry>> createEntryAsync)
{
var cancellationToken = _cancellationTokenSource.Token;
cancellationToken.ThrowIfCancellationRequested();
CancellationToken.ThrowIfCancellationRequested();
// First find the bucket corresponding to our definition. If we can't find/create
// one, then don't do anything for this reference.
......@@ -260,13 +307,19 @@ public override Task OnReferenceFoundAsync(SourceReferenceItem reference)
return;
}
var entry = await createEntryAsync(
definitionBucket, cancellationToken).ConfigureAwait(false);
var entry = await createEntryAsync(definitionBucket).ConfigureAwait(false);
if (entry == null)
{
return;
}
// Ok, we got a *reference* to some definition item. This may have been
// a reference for some definition that we haven't created any definition
// entries for (i.e. becuase it had DisplayIfNoReferences = false). Because
// we've now found a reference, we want to make sure all tis definition
// entries are added.
await AddDefinitionEntriesAsync(definition).ConfigureAwait(false);
lock (_gate)
{
// Once we can make the new entry, add it to our list.
......@@ -278,11 +331,18 @@ public override Task OnReferenceFoundAsync(SourceReferenceItem reference)
_tableDataSink.FactorySnapshotChanged(this);
}
private bool HasEntriesForDefinition(DefinitionItem definition)
{
lock (_gate)
{
return _entries.Any(e => e.DefinitionBucket.DefinitionItem == definition);
}
}
private async Task<Entry> CreateDocumentLocationEntryAsync(
RoslynDefinitionBucket definitionBucket,
DocumentSpan documentSpan,
bool isDefinitionLocation,
CancellationToken cancellationToken)
bool isDefinitionLocation)
{
var document = documentSpan.Document;
......@@ -300,12 +360,12 @@ public override Task OnReferenceFoundAsync(SourceReferenceItem reference)
return null;
}
var sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
var sourceText = await document.GetTextAsync(CancellationToken).ConfigureAwait(false);
var referenceSpan = documentSpan.SourceSpan;
var lineSpan = GetLineSpanForReference(sourceText, referenceSpan);
var taggedLineParts = await GetTaggedTextForReferenceAsync(document, referenceSpan, lineSpan, cancellationToken).ConfigureAwait(false);
var taggedLineParts = await GetTaggedTextForReferenceAsync(document, referenceSpan, lineSpan).ConfigureAwait(false);
return new DocumentSpanEntry(
this, workspace, definitionBucket, documentSpan,
......@@ -334,7 +394,7 @@ private TextSpan GetRegionSpanForReference(SourceText sourceText, TextSpan refer
}
private async Task<ClassifiedSpansAndHighlightSpan> GetTaggedTextForReferenceAsync(
Document document, TextSpan referenceSpan, TextSpan widenedSpan, CancellationToken cancellationToken)
Document document, TextSpan referenceSpan, TextSpan widenedSpan)
{
var classificationService = document.GetLanguageService<IEditorClassificationService>();
if (classificationService == null)
......@@ -352,12 +412,12 @@ private TextSpan GetRegionSpanForReference(SourceText sourceText, TextSpan refer
var syntaxSpans = new List<ClassifiedSpan>();
var semanticSpans = new List<ClassifiedSpan>();
var sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
var sourceText = await document.GetTextAsync(CancellationToken).ConfigureAwait(false);
await classificationService.AddSyntacticClassificationsAsync(
document, widenedSpan, syntaxSpans, cancellationToken).ConfigureAwait(false);
document, widenedSpan, syntaxSpans, CancellationToken).ConfigureAwait(false);
await classificationService.AddSemanticClassificationsAsync(
document, widenedSpan, semanticSpans, cancellationToken).ConfigureAwait(false);
document, widenedSpan, semanticSpans, CancellationToken).ConfigureAwait(false);
var classifiedSpans = MergeClassifiedSpans(
syntaxSpans, semanticSpans, widenedSpan, sourceText);
......
......@@ -19,13 +19,14 @@ namespace Microsoft.VisualStudio.LanguageServices.ProjectSystem
[ExportWorkspaceService(typeof(IDeferredProjectWorkspaceService)), Shared]
internal class DeferredProjectWorkspaceService : IDeferredProjectWorkspaceService
{
private readonly IVsSolutionWorkspaceService _solutionWorkspaceService;
private readonly Lazy<IVsSolutionWorkspaceService> _solutionWorkspaceService;
private readonly IVsSolution7 _solution7;
[ImportingConstructor]
public DeferredProjectWorkspaceService(SVsServiceProvider serviceProvider)
{
_solutionWorkspaceService = serviceProvider.GetService(typeof(SVsSolutionWorkspaceService)) as IVsSolutionWorkspaceService;
_solutionWorkspaceService = new Lazy<IVsSolutionWorkspaceService>(
() => (IVsSolutionWorkspaceService)serviceProvider.GetService(typeof(SVsSolutionWorkspaceService)));
_solution7 = serviceProvider.GetService(typeof(SVsSolution)) as IVsSolution7;
}
......@@ -35,7 +36,7 @@ public DeferredProjectWorkspaceService(SVsServiceProvider serviceProvider)
string solutionConfiguration,
CancellationToken cancellationToken)
{
var commandLineInfos = await _solutionWorkspaceService.GetManagedCommandLineInfoAsync(
var commandLineInfos = await _solutionWorkspaceService.Value.GetManagedCommandLineInfoAsync(
solutionConfiguration, cancellationToken).ConfigureAwait(false);
// NOTE: Anycode gives us the project references as if they were command line arguments with
......
......@@ -36,7 +36,7 @@
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.AppContext.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Console.dll")]
[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\System.Diagnostics.FileVersionInfo.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Diagnostics.FileVersionInfo.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Diagnostics.Process.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.IO.Compression.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.IO.FileSystem.dll")]
......@@ -47,11 +47,12 @@
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Security.AccessControl.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Security.Claims.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Security.Cryptography.Algorithms.dll")]
[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\System.Security.Cryptography.Encoding.dll")]
[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\System.Security.Cryptography.Primitives.dll")]
[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\System.Security.Cryptography.X509Certificates.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Security.Cryptography.Encoding.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Security.Cryptography.Primitives.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Security.Cryptography.X509Certificates.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Security.Principal.Windows.dll")]
[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\System.Text.Encoding.CodePages.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Text.Encoding.CodePages.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Threading.Thread.dll")]
[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\System.Xml.XmlDocument.dll")]
[assembly: ProvideCodeBase(CodeBase = @"$PackageFolder$\System.Xml.XPath.XDocument.dll")]
\ No newline at end of file
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Xml.XmlDocument.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Xml.XPath.dll")]
[assembly: ProvideCodeBase(CodeBase = "$PackageFolder$\\System.Xml.XPath.XDocument.dll")]
\ No newline at end of file
......@@ -14,6 +14,12 @@ namespace Microsoft.CodeAnalysis.FindSymbols.Finders
{
internal class ConstructorSymbolReferenceFinder : AbstractReferenceFinder<IMethodSymbol>
{
public static readonly ConstructorSymbolReferenceFinder Instance = new ConstructorSymbolReferenceFinder();
private ConstructorSymbolReferenceFinder()
{
}
protected override bool CanFind(IMethodSymbol symbol)
{
return symbol.MethodKind == MethodKind.Constructor;
......@@ -52,7 +58,15 @@ protected override bool CanFind(IMethodSymbol symbol)
predefinedType == actualType;
}
protected override async Task<ImmutableArray<ReferenceLocation>> FindReferencesInDocumentAsync(
protected override Task<ImmutableArray<ReferenceLocation>> FindReferencesInDocumentAsync(
IMethodSymbol methodSymbol,
Document document,
CancellationToken cancellationToken)
{
return FindAllReferencesInDocumentAsync(methodSymbol, document, cancellationToken);
}
internal async Task<ImmutableArray<ReferenceLocation>> FindAllReferencesInDocumentAsync(
IMethodSymbol methodSymbol,
Document document,
CancellationToken cancellationToken)
......
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic;
using System;
using System.Collections.Immutable;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.LanguageServices;
using Microsoft.CodeAnalysis.Shared.Extensions;
using Roslyn.Utilities;
......@@ -85,6 +84,64 @@ protected override bool CanFind(INamedTypeSymbol symbol)
INamedTypeSymbol namedType,
Document document,
CancellationToken cancellationToken)
{
var namedTypereferences = await FindReferencesInDocumentWorker(
namedType, document, cancellationToken).ConfigureAwait(false);
// Mark any references that are also Constructor references. Some callers
// will want to know about these so they won't display duplicates.
return await MarkConstructorReferences(
namedType, document, namedTypereferences, cancellationToken).ConfigureAwait(false);
}
private async Task<ImmutableArray<ReferenceLocation>> MarkConstructorReferences(
INamedTypeSymbol namedType, Document document,
ImmutableArray<ReferenceLocation> namedTypereferences,
CancellationToken cancellationToken)
{
var constructorReferences = ArrayBuilder<ReferenceLocation>.GetInstance();
foreach (var constructor in namedType.Constructors)
{
var references = await ConstructorSymbolReferenceFinder.Instance.FindAllReferencesInDocumentAsync(
constructor, document, cancellationToken).ConfigureAwait(false);
constructorReferences.AddRange(references);
}
var result = ArrayBuilder<ReferenceLocation>.GetInstance();
foreach (var reference in namedTypereferences)
{
if (Contains(constructorReferences, reference))
{
var localReference = reference;
localReference.IsDuplicateReferenceLocation = true;
result.Add(localReference);
}
else
{
result.Add(reference);
}
}
return result.ToImmutableAndFree();
}
private bool Contains(
ArrayBuilder<ReferenceLocation> constructorReferences,
ReferenceLocation reference)
{
foreach (var constructorRef in constructorReferences)
{
if (reference.Location == constructorRef.Location)
{
return true;
}
}
return false;
}
private static async Task<ImmutableArray<ReferenceLocation>> FindReferencesInDocumentWorker(
INamedTypeSymbol namedType, Document document, CancellationToken cancellationToken)
{
var nonAliasReferences = await FindNonAliasReferencesAsync(namedType, document, cancellationToken).ConfigureAwait(false);
var symbolsMatch = GetStandardSymbolsMatchFunction(namedType, null, document.Project.Solution, cancellationToken);
......
......@@ -6,7 +6,7 @@ namespace Microsoft.CodeAnalysis.FindSymbols.Finders
{
internal static class ReferenceFinders
{
public static readonly IReferenceFinder Constructor = new ConstructorSymbolReferenceFinder();
public static readonly IReferenceFinder Constructor = ConstructorSymbolReferenceFinder.Instance;
public static readonly IReferenceFinder ConstructorInitializer = new ConstructorInitializerSymbolReferenceFinder();
public static readonly IReferenceFinder Destructor = new DestructorSymbolReferenceFinder();
public static readonly IReferenceFinder ExplicitInterfaceMethod = new ExplicitInterfaceMethodReferenceFinder();
......
......@@ -41,6 +41,13 @@ public struct ReferenceLocation : IComparable<ReferenceLocation>, IEquatable<Ref
/// </summary>
internal bool IsWrittenTo { get; }
/// <summary>
/// Indicates if this location is a duplicate of some another ReferenceLocation.
/// In this case, it's acceptable for a presenter to not show this location and
/// intead prefer the latter.
/// </summary>
internal bool IsDuplicateReferenceLocation;
public CandidateReason CandidateReason { get; }
internal ReferenceLocation(Document document, IAliasSymbol alias, Location location, bool isImplicit, bool isWrittenTo, CandidateReason candidateReason)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册