diff --git a/src/OmniSharp.Roslyn/MetadataHelper.cs b/src/OmniSharp.Roslyn/MetadataHelper.cs index 833a5cb127..02a5979be0 100644 --- a/src/OmniSharp.Roslyn/MetadataHelper.cs +++ b/src/OmniSharp.Roslyn/MetadataHelper.cs @@ -59,8 +59,16 @@ public string GetFilePathForSymbol(Project project, ISymbol symbol) { var filePath = GetFilePathForSymbol(project, symbol); var topLevelSymbol = GetTopLevelContainingNamedType(symbol); - var temporaryDocument = project.AddDocument(filePath, string.Empty); + // 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 temporaryDocument = metadataProject.AddDocument(filePath, string.Empty); var service = _csharpMetadataAsSourceService.CreateInstance(temporaryDocument.Project.LanguageServices); var method = _csharpMetadataAsSourceService.GetMethod(AddSourceToAsync); 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() { diff --git a/tests/TestUtility/OmniSharpTestHost.cs b/tests/TestUtility/OmniSharpTestHost.cs index 770cf962bd..c71e0b9da4 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.OrdinalIgnoreCase)).ToArray()); + + foreach (var csxFile in testFiles.Where(f => f.FileName.EndsWith(".csx", StringComparison.OrdinalIgnoreCase))) + { + 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 @@ +