提交 64133226 编写于 作者: J Jason Malinowski 提交者: GitHub

Merge pull request #17146 from dotnet/master

Merge master into dev15.1.x
......@@ -121,6 +121,16 @@ protected static void VerifyModelForDeclarationPatternDuplicateInSameScope(Seman
}
}
protected static void VerifyNotAPatternField(SemanticModel model, IdentifierNameSyntax reference)
{
var symbol = model.GetSymbolInfo(reference).Symbol;
Assert.NotEqual(SymbolKind.Field, symbol.Kind);
Assert.Same(symbol, model.LookupSymbols(reference.SpanStart, name: reference.Identifier.ValueText).Single());
Assert.True(model.LookupNames(reference.SpanStart).Contains(reference.Identifier.ValueText));
}
protected static void VerifyNotAPatternLocal(SemanticModel model, IdentifierNameSyntax reference)
{
var symbol = model.GetSymbolInfo(reference).Symbol;
......@@ -301,6 +311,11 @@ protected static void VerifyModelNotSupported(SemanticModel model, params Identi
}
}
protected static void AssertNoGlobalStatements(SyntaxTree tree)
{
Assert.Empty(tree.GetRoot().DescendantNodes().OfType<GlobalStatementSyntax>());
}
#endregion helpers
}
}
......@@ -795,6 +795,13 @@ static bool Dummy(int x)
var compilation = CreateCompilationWithMscorlib45(source, options: TestOptions.DebugExe);
CompileAndVerify(compilation, expectedOutput: @"1
True");
var tree = compilation.SyntaxTrees.Single();
var model = compilation.GetSemanticModel(tree);
var x1Decl = GetPatternDeclaration(tree, "x1");
var x1Ref = GetReferences(tree, "x1").Single();
VerifyModelForDeclarationPattern(model, x1Decl, x1Ref);
}
[Fact]
......@@ -902,6 +909,49 @@ static bool Print(object x)
}
}
[Fact]
public void Query_02()
{
var source =
@"
using System.Linq;
public class X
{
public static void Main()
{
Test1();
}
static void Test1()
{
var res = from x1 in new[] { 1 is var y1 && Print(y1) ? 2 : 0}
select Print(x1);
res.ToArray();
}
static bool Print(object x)
{
System.Console.WriteLine(x);
return true;
}
}
";
var compilation = CreateCompilationWithMscorlib45(source, new[] { SystemCoreRef }, options: TestOptions.DebugExe, parseOptions: TestOptions.Regular);
CompileAndVerify(compilation, expectedOutput:
@"1
2");
var tree = compilation.SyntaxTrees.Single();
var model = compilation.GetSemanticModel(tree);
var yDecl = GetPatternDeclaration(tree, "y1");
var yRef = GetReferences(tree, "y1").Single();
VerifyModelForDeclarationPattern(model, yDecl, yRef);
}
[Fact]
public void ExpressionBodiedFunctions_01()
{
......@@ -2359,6 +2409,14 @@ static System.Collections.IEnumerable Dummy(object y, object z)
CompileAndVerify(compilation, expectedOutput:
@"3
3");
var tree = compilation.SyntaxTrees.Single();
var model = compilation.GetSemanticModel(tree);
var x1Decl = GetPatternDeclaration(tree, "x1");
var x1Ref = GetReferences(tree, "x1").ToArray();
Assert.Equal(2, x1Ref.Length);
VerifyModelForDeclarationPattern(model, x1Decl, x1Ref);
}
[Fact]
......@@ -2775,6 +2833,14 @@ static bool Dummy(object y, object z)
CompileAndVerify(compilation, expectedOutput:
@"System.InvalidOperationException
System.InvalidOperationException");
var tree = compilation.SyntaxTrees.Single();
var model = compilation.GetSemanticModel(tree);
var x1Decl = GetPatternDeclaration(tree, "x1");
var x1Ref = GetReferences(tree, "x1").ToArray();
Assert.Equal(2, x1Ref.Length);
VerifyModelForDeclarationPattern(model, x1Decl, x1Ref);
}
[Fact]
......
......@@ -242,7 +242,10 @@ public async Task MergeAsync(ActiveFileState state, Document document)
var semantic = state.GetAnalysisData(AnalysisKind.Semantic);
var project = document.Project;
var fullAnalysis = ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(project);
// if project didn't successfully loaded, then it is same as FSA off
var fullAnalysis = ServiceFeatureOnOffOptions.IsClosedFileDiagnosticsEnabled(project) &&
await project.HasSuccessfullyLoadedAsync(CancellationToken.None).ConfigureAwait(false);
// keep from build flag if full analysis is off
var fromBuild = fullAnalysis ? false : lastResult.FromBuild;
......
......@@ -24,6 +24,7 @@ public static int Main(string[] args)
string submissionType = null;
string traceDestination = @"\\mlangfs1\public\basoundr\PerfTraces";
string branch = null;
string searchDirectory = AppDomain.CurrentDomain.BaseDirectory;
var parameterOptions = new OptionSet()
{
......@@ -33,8 +34,10 @@ public static int Main(string[] args)
{"branch=", "name of the branch you are measuring on", name => { branch = name; } },
{"ci-test", "mention that we are running in the continuous integration lab", _ => isCiTest = true},
{"no-trace-upload", "disable the uploading of traces", _ => shouldUploadTrace = false},
{"trace-upload_destination", "set the trace uploading destination", loc => { traceDestination = loc; }}
{"trace-upload_destination=", "set the trace uploading destination", loc => { traceDestination = loc; } },
{"search-directory=", "the directory to recursively search for tests", dir => { searchDirectory = dir; } }
};
parameterOptions.Parse(args);
if (shouldReportBenchview)
......@@ -48,7 +51,7 @@ public static int Main(string[] args)
}
Cleanup();
AsyncMain(isCiTest).GetAwaiter().GetResult();
AsyncMain(isCiTest, searchDirectory).GetAwaiter().GetResult();
if (isCiTest)
{
......@@ -139,12 +142,10 @@ private static void Cleanup()
}
}
private static async Task AsyncMain(bool isRunningUnderCI)
private static async Task AsyncMain(bool isRunningUnderCI, string searchDirectory)
{
RuntimeSettings.IsRunnerAttached = true;
var testDirectory = AppDomain.CurrentDomain.BaseDirectory;
// Print message at startup
Log("Starting Performance Test Run");
Log("hash: " + FirstLine(StdoutFromOrDefault("git", "show --format=\"%h\" HEAD --", "git missing")));
......@@ -153,7 +154,7 @@ private static async Task AsyncMain(bool isRunningUnderCI)
var testInstances = new List<PerfTest>();
// Find all the tests from inside of the csx files.
foreach (var script in GetAllCsxRecursive(testDirectory))
foreach (var script in GetAllCsxRecursive(searchDirectory))
{
var scriptName = Path.GetFileNameWithoutExtension(script);
Log($"Collecting tests from {scriptName}");
......
......@@ -5,6 +5,7 @@
using System.Collections.Immutable;
using System.ComponentModel.Composition;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Microsoft.CodeAnalysis.Host;
using Microsoft.VisualStudio.LanguageServices.Implementation.TaskList;
using Microsoft.VisualStudio.LanguageServices.ProjectSystem;
......@@ -16,7 +17,7 @@
namespace Microsoft.VisualStudio.LanguageServices.Implementation.ProjectSystem.CPS
{
[Export(typeof(IWorkspaceProjectContextFactory))]
internal partial class CPSProjectFactory : IWorkspaceProjectContextFactory
internal partial class CPSProjectFactory : ForegroundThreadAffinitizedObject, IWorkspaceProjectContextFactory
{
private readonly IServiceProvider _serviceProvider;
private readonly VisualStudioWorkspaceImpl _visualStudioWorkspace;
......@@ -33,7 +34,8 @@ internal partial class CPSProjectFactory : IWorkspaceProjectContextFactory
public CPSProjectFactory(
SVsServiceProvider serviceProvider,
VisualStudioWorkspaceImpl visualStudioWorkspace,
HostDiagnosticUpdateSource hostDiagnosticUpdateSource)
HostDiagnosticUpdateSource hostDiagnosticUpdateSource) :
base(assertIsForeground: false)
{
_serviceProvider = serviceProvider;
_visualStudioWorkspace = visualStudioWorkspace;
......@@ -43,6 +45,7 @@ internal partial class CPSProjectFactory : IWorkspaceProjectContextFactory
// internal for testing purposes only.
internal static CPSProject CreateCPSProject(VisualStudioProjectTracker projectTracker, IServiceProvider serviceProvider, IVsHierarchy hierarchy, string projectDisplayName, string projectFilePath, Guid projectGuid, string language, ICommandLineParserService commandLineParserService, string binOutputPath)
{
// this only runs under unit test
return new CPSProject(projectTracker, reportExternalErrorCreatorOpt: null, hierarchy: hierarchy, language: language,
serviceProvider: serviceProvider, visualStudioWorkspaceOpt: null, hostDiagnosticUpdateSourceOpt: null,
projectDisplayName: projectDisplayName, projectFilePath: projectFilePath, projectGuid: projectGuid,
......@@ -57,6 +60,10 @@ internal static CPSProject CreateCPSProject(VisualStudioProjectTracker projectTr
object hierarchy,
string binOutputPath)
{
AssertIsForeground();
EnsurePackageLoaded(languageName);
// NOTE: It is acceptable for hierarchy to be null in Deferred Project Load scenarios.
var vsHierarchy = hierarchy as IVsHierarchy;
......@@ -76,6 +83,10 @@ internal static CPSProject CreateCPSProject(VisualStudioProjectTracker projectTr
string binOutputPath,
ProjectExternalErrorReporter errorReporter)
{
AssertIsForeground();
EnsurePackageLoaded(languageName);
// NOTE: It is acceptable for hierarchy to be null in Deferred Project Load scenarios.
var vsHierarchy = hierarchy as IVsHierarchy;
......@@ -94,5 +105,33 @@ private IVsReportExternalErrors GetExternalErrorReporter(ProjectId projectId, st
return new ProjectExternalErrorReporter(projectId, errorCodePrefix, _serviceProvider);
}
private void EnsurePackageLoaded(string language)
{
// we need to make sure we load required packages which initialize VS related services
// such as OB, FAR, Error list, Msic workspace, solution crawler before actually
// set roslyn CPS up.
var shell = (IVsShell)_serviceProvider.GetService(typeof(SVsShell));
if (shell == null)
{
// no shell. can happen in unit test
return;
}
IVsPackage unused;
switch (language)
{
case LanguageNames.CSharp:
shell.LoadPackage(Guids.CSharpPackageId, out unused);
break;
case LanguageNames.VisualBasic:
shell.LoadPackage(Guids.VisualBasicPackageId, out unused);
break;
default:
// by default, load roslyn package for things like typescript and etc
shell.LoadPackage(Guids.RoslynPackageId, out unused);
break;
}
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册