Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed GoToMetadata in CSX #829

Merged
merged 6 commits into from
Apr 21, 2017
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion src/OmniSharp.Roslyn/MetadataHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,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);

Expand Down
32 changes: 20 additions & 12 deletions tests/OmniSharp.Roslyn.CSharp.Tests/GoToDefinitionFacts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down
7 changes: 6 additions & 1 deletion tests/TestUtility/OmniSharpTestHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
}
12 changes: 7 additions & 5 deletions tests/TestUtility/TestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<IHostServicesProvider>()));
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<IHostServicesProvider>()));

var parseOptions = new CSharpParseOptions(
LanguageVersion.Default,
Expand Down Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/TestUtility/TestUtility.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Workspaces" Version="2.0.0" />
<PackageReference Include="Microsoft.CodeAnalysis.CSharp.Scripting" Version="2.0.0" />
<PackageReference Include="Microsoft.DotNet.ProjectModel" Version="1.0.0-rc3-1-003177" />
<PackageReference Include="Microsoft.DotNet.ProjectModel.Workspaces" Version="1.0.0-preview2-1-003177" />
<PackageReference Include="xunit" Version="2.2.0" />
Expand Down