From f479e22d4ed407506f33f251aec0c7d9d1557d54 Mon Sep 17 00:00:00 2001 From: filipw Date: Wed, 19 Apr 2017 09:22:33 +0200 Subject: [PATCH 1/5] use temporary project in MetadataHelper --- src/OmniSharp.Roslyn/MetadataHelper.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/OmniSharp.Roslyn/MetadataHelper.cs b/src/OmniSharp.Roslyn/MetadataHelper.cs index 15f8124e57..be6abcdff6 100644 --- a/src/OmniSharp.Roslyn/MetadataHelper.cs +++ b/src/OmniSharp.Roslyn/MetadataHelper.cs @@ -58,7 +58,8 @@ public string GetFilePathForSymbol(Project project, ISymbol symbol) { var filePath = GetFilePathForSymbol(project, symbol); var topLevelSymbol = GetTopLevelContainingNamedType(symbol); - var temporaryDocument = project.AddDocument(filePath, string.Empty); + var temporaryProject = project.Solution.AddProject("metadataTemp", "metadataTemp.dll", LanguageNames.CSharp); + var temporaryDocument = temporaryProject.AddDocument(filePath, string.Empty); var service = _csharpMetadataAsSourceService.CreateInstance(temporaryDocument.Project.LanguageServices); var method = _csharpMetadataAsSourceService.GetMethod(AddSourceToAsync); From 10084d45873684a26692548daa24a4287ef3dbbf Mon Sep 17 00:00:00 2001 From: filipw Date: Wed, 19 Apr 2017 11:00:39 +0200 Subject: [PATCH 2/5] added ability to add CSX projects to test Workspace --- tests/TestUtility/OmniSharpTestHost.cs | 7 ++++++- tests/TestUtility/TestHelpers.cs | 12 +++++++----- tests/TestUtility/TestUtility.csproj | 1 + 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/tests/TestUtility/OmniSharpTestHost.cs b/tests/TestUtility/OmniSharpTestHost.cs index 770cf962bd..9b6348273a 100644 --- a/tests/TestUtility/OmniSharpTestHost.cs +++ b/tests/TestUtility/OmniSharpTestHost.cs @@ -136,7 +136,12 @@ public void AddFilesToWorkspace(params TestFile[] testFiles) this.Workspace, "project.json", new[] { "dnx451", "dnxcore50" }, - testFiles); + testFiles.Where(f => f.FileName.EndsWith(".cs", StringComparison.CurrentCultureIgnoreCase)).ToArray()); + + foreach (var csxFile in testFiles.Where(f => f.FileName.EndsWith(".csx", StringComparison.CurrentCultureIgnoreCase))) + { + TestHelpers.AddCsxProjectToWorkspace(Workspace, csxFile); + } } } } diff --git a/tests/TestUtility/TestHelpers.cs b/tests/TestUtility/TestHelpers.cs index 011b33448e..ad699a74dc 100644 --- a/tests/TestUtility/TestHelpers.cs +++ b/tests/TestUtility/TestHelpers.cs @@ -12,13 +12,16 @@ public static class TestHelpers { public static OmniSharpWorkspace CreateCsxWorkspace(TestFile testFile) { - var versionStamp = VersionStamp.Create(); + var workspace = new OmniSharpWorkspace(new HostServicesAggregator(Enumerable.Empty())); + AddCsxProjectToWorkspace(workspace, testFile); + return workspace; + } + + public static void AddCsxProjectToWorkspace(OmniSharpWorkspace workspace, TestFile testFile) + { var mscorlib = MetadataReference.CreateFromFile(AssemblyHelpers.FromType(typeof(object)).Location); var systemCore = MetadataReference.CreateFromFile(AssemblyHelpers.FromType(typeof(Enumerable)).Location); var references = new[] { mscorlib, systemCore }; - var workspace = new OmniSharpWorkspace( - new HostServicesAggregator( - Enumerable.Empty())); var parseOptions = new CSharpParseOptions( LanguageVersion.Default, @@ -46,7 +49,6 @@ public static OmniSharpWorkspace CreateCsxWorkspace(TestFile testFile) filePath: testFile.FileName); workspace.AddDocument(documentInfo); - return workspace; } public static void AddProjectToWorkspace(OmniSharpWorkspace workspace, string filePath, string[] frameworks, TestFile[] testFiles) diff --git a/tests/TestUtility/TestUtility.csproj b/tests/TestUtility/TestUtility.csproj index 05956f2a48..b1c9dcf144 100644 --- a/tests/TestUtility/TestUtility.csproj +++ b/tests/TestUtility/TestUtility.csproj @@ -19,6 +19,7 @@ + From 998afb04fa8dda6b85527068becc8d2f36fbab3f Mon Sep 17 00:00:00 2001 From: filipw Date: Wed, 19 Apr 2017 15:03:51 +0200 Subject: [PATCH 3/5] added tests for CSX go to metadata --- src/OmniSharp.Roslyn/MetadataHelper.cs | 4 ++- .../GoToDefinitionFacts.cs | 32 ++++++++++++------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/OmniSharp.Roslyn/MetadataHelper.cs b/src/OmniSharp.Roslyn/MetadataHelper.cs index be6abcdff6..1f7ba09c72 100644 --- a/src/OmniSharp.Roslyn/MetadataHelper.cs +++ b/src/OmniSharp.Roslyn/MetadataHelper.cs @@ -58,7 +58,9 @@ public string GetFilePathForSymbol(Project project, ISymbol symbol) { var filePath = GetFilePathForSymbol(project, symbol); var topLevelSymbol = GetTopLevelContainingNamedType(symbol); - var temporaryProject = project.Solution.AddProject("metadataTemp", "metadataTemp.dll", LanguageNames.CSharp); + var temporaryProject = project.Solution.AddProject("metadataTemp", "metadataTemp.dll", LanguageNames.CSharp). + WithCompilationOptions(project.CompilationOptions). + WithMetadataReferences(project.MetadataReferences); var temporaryDocument = temporaryProject.AddDocument(filePath, string.Empty); var service = _csharpMetadataAsSourceService.CreateInstance(temporaryDocument.Project.LanguageServices); diff --git a/tests/OmniSharp.Roslyn.CSharp.Tests/GoToDefinitionFacts.cs b/tests/OmniSharp.Roslyn.CSharp.Tests/GoToDefinitionFacts.cs index ae59d5c842..a369fef21e 100644 --- a/tests/OmniSharp.Roslyn.CSharp.Tests/GoToDefinitionFacts.cs +++ b/tests/OmniSharp.Roslyn.CSharp.Tests/GoToDefinitionFacts.cs @@ -58,10 +58,12 @@ class Bar { await TestGoToSourceAsync(testFile1, testFile2); } - [Fact] - public async Task ReturnsDefinitionInMetadata_WhenSymbolIsStaticMethod() + [Theory] + [InlineData("bar.cs")] + [InlineData("bar.csx")] + public async Task ReturnsDefinitionInMetadata_WhenSymbolIsStaticMethod(string filename) { - var testFile = new TestFile("bar.cs", @" + var testFile = new TestFile(filename, @" using System; class Bar { public void Baz() { @@ -74,10 +76,12 @@ await TestGoToMetadataAsync(testFile, expectedTypeName: "System.Guid"); } - [Fact] - public async Task ReturnsDefinitionInMetadata_WhenSymbolIsInstanceMethod() + [Theory] + [InlineData("bar.cs")] + [InlineData("bar.csx")] + public async Task ReturnsDefinitionInMetadata_WhenSymbolIsInstanceMethod(string filename) { - var testFile = new TestFile("bar.cs", @" + var testFile = new TestFile(filename, @" using System.Collections.Generic; class Bar { public void Baz() { @@ -91,10 +95,12 @@ await TestGoToMetadataAsync(testFile, expectedTypeName: "System.Collections.Generic.List`1"); } - [Fact] - public async Task ReturnsDefinitionInMetadata_WhenSymbolIsGenericType() + [Theory] + [InlineData("bar.cs")] + [InlineData("bar.csx")] + public async Task ReturnsDefinitionInMetadata_WhenSymbolIsGenericType(string filename) { - var testFile = new TestFile("bar.cs", @" + var testFile = new TestFile(filename, @" using System.Collections.Generic; class Bar { public void Baz() { @@ -108,10 +114,12 @@ await TestGoToMetadataAsync(testFile, expectedTypeName: "System.Collections.Generic.List`1"); } - [Fact] - public async Task ReturnsDefinitionInMetadata_WhenSymbolIsType() + [Theory] + [InlineData("bar.cs")] + [InlineData("bar.csx")] + public async Task ReturnsDefinitionInMetadata_WhenSymbolIsType(string filename) { - var testFile = new TestFile("bar.cs", @" + var testFile = new TestFile(filename, @" using System; class Bar { public void Baz() { From a82fa191d3a8a8865e15c5793729313a75bf7b09 Mon Sep 17 00:00:00 2001 From: filipw Date: Wed, 19 Apr 2017 15:58:57 +0200 Subject: [PATCH 4/5] use the new MetadataHelper code path for CSX only --- src/OmniSharp.Roslyn/MetadataHelper.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/OmniSharp.Roslyn/MetadataHelper.cs b/src/OmniSharp.Roslyn/MetadataHelper.cs index 1f7ba09c72..024eb8e7a0 100644 --- a/src/OmniSharp.Roslyn/MetadataHelper.cs +++ b/src/OmniSharp.Roslyn/MetadataHelper.cs @@ -58,11 +58,14 @@ public string GetFilePathForSymbol(Project project, ISymbol symbol) { var filePath = GetFilePathForSymbol(project, symbol); var topLevelSymbol = GetTopLevelContainingNamedType(symbol); - var temporaryProject = project.Solution.AddProject("metadataTemp", "metadataTemp.dll", LanguageNames.CSharp). + + // since submission projects cannot have new documents added to it + // we will use temporary project to hold metadata documents + var metadataProject = project.IsSubmission ? project.Solution.AddProject("metadataTemp", "metadataTemp.dll", LanguageNames.CSharp). WithCompilationOptions(project.CompilationOptions). - WithMetadataReferences(project.MetadataReferences); - var temporaryDocument = temporaryProject.AddDocument(filePath, string.Empty); + WithMetadataReferences(project.MetadataReferences) : project; + var temporaryDocument = metadataProject.AddDocument(filePath, string.Empty); var service = _csharpMetadataAsSourceService.CreateInstance(temporaryDocument.Project.LanguageServices); var method = _csharpMetadataAsSourceService.GetMethod(AddSourceToAsync); From 9cb35defcc07d7ba0d41148cbfb4872ae55e9fd2 Mon Sep 17 00:00:00 2001 From: filipw Date: Wed, 19 Apr 2017 16:28:33 +0200 Subject: [PATCH 5/5] tweaks for Dustin :) --- src/OmniSharp.Roslyn/MetadataHelper.cs | 8 +++++--- tests/TestUtility/OmniSharpTestHost.cs | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/OmniSharp.Roslyn/MetadataHelper.cs b/src/OmniSharp.Roslyn/MetadataHelper.cs index 024eb8e7a0..44f3b1ff20 100644 --- a/src/OmniSharp.Roslyn/MetadataHelper.cs +++ b/src/OmniSharp.Roslyn/MetadataHelper.cs @@ -61,9 +61,11 @@ public string GetFilePathForSymbol(Project project, ISymbol symbol) // since submission projects cannot have new documents added to it // we will use temporary project to hold metadata documents - var metadataProject = project.IsSubmission ? project.Solution.AddProject("metadataTemp", "metadataTemp.dll", LanguageNames.CSharp). - WithCompilationOptions(project.CompilationOptions). - WithMetadataReferences(project.MetadataReferences) : project; + var metadataProject = project.IsSubmission + ? project.Solution.AddProject("metadataTemp", "metadataTemp.dll", LanguageNames.CSharp) + .WithCompilationOptions(project.CompilationOptions) + .WithMetadataReferences(project.MetadataReferences) + : project; var temporaryDocument = metadataProject.AddDocument(filePath, string.Empty); var service = _csharpMetadataAsSourceService.CreateInstance(temporaryDocument.Project.LanguageServices); diff --git a/tests/TestUtility/OmniSharpTestHost.cs b/tests/TestUtility/OmniSharpTestHost.cs index 9b6348273a..c71e0b9da4 100644 --- a/tests/TestUtility/OmniSharpTestHost.cs +++ b/tests/TestUtility/OmniSharpTestHost.cs @@ -136,9 +136,9 @@ public void AddFilesToWorkspace(params TestFile[] testFiles) this.Workspace, "project.json", new[] { "dnx451", "dnxcore50" }, - testFiles.Where(f => f.FileName.EndsWith(".cs", StringComparison.CurrentCultureIgnoreCase)).ToArray()); + testFiles.Where(f => f.FileName.EndsWith(".cs", StringComparison.OrdinalIgnoreCase)).ToArray()); - foreach (var csxFile in testFiles.Where(f => f.FileName.EndsWith(".csx", StringComparison.CurrentCultureIgnoreCase))) + foreach (var csxFile in testFiles.Where(f => f.FileName.EndsWith(".csx", StringComparison.OrdinalIgnoreCase))) { TestHelpers.AddCsxProjectToWorkspace(Workspace, csxFile); }