Skip to content

Commit

Permalink
updated GoToDefinitionFacts and reverted some unneeded changes
Browse files Browse the repository at this point in the history
  • Loading branch information
filipw committed Jun 2, 2017
1 parent d91757a commit bad475b
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,5 @@ public class GotoDefinitionRequest : Request
{
public int Timeout { get; set; } = 2000;
public bool WantMetadata { get; set; }
public string Project { get; set; }
}
}
2 changes: 0 additions & 2 deletions src/OmniSharp.Roslyn.CSharp/Helpers/LocationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ public static QuickFix GetQuickFix(this Location location, OmniSharpWorkspace wo
var path = lineSpan.Path;
var documents = workspace.GetDocuments(path);

if (documents == null || !documents.Any()) return null;

var line = lineSpan.StartLinePosition.Line;
var text = location.SourceTree.GetText().Lines[line].ToString();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public async Task<QuickFixResponse> Handle(FindUsagesRequest request)
var quickFixes = locations.Distinct().Select(l => l.GetQuickFix(_workspace));

response = new QuickFixResponse(quickFixes.Distinct()
.Where(q => q != null)
.OrderBy(q => q.FileName)
.ThenBy(q => q.Line)
.ThenBy(q => q.Column));
Expand Down
26 changes: 20 additions & 6 deletions tests/OmniSharp.Roslyn.CSharp.Tests/GoToDefinitionFacts.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Linq;
using System.Threading.Tasks;
using OmniSharp.Models.GotoDefinition;
using OmniSharp.Roslyn.CSharp.Services.Navigation;
using Microsoft.CodeAnalysis.CSharp;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using TestUtility;
using Xunit;
using Xunit.Abstractions;
using OmniSharp.Models.GotoDefinition;
using OmniSharp.Roslyn.CSharp.Services.Navigation;
using OmniSharp.Models.Metadata;

namespace OmniSharp.Roslyn.CSharp.Tests
Expand Down Expand Up @@ -177,6 +179,7 @@ public void Baz() {
{
var point = testFile.Content.GetPointFromPosition();

// 1. start by asking for definition of "int"
var request = new GotoDefinitionRequest
{
FileName = testFile.FileName,
Expand All @@ -185,10 +188,11 @@ public void Baz() {
Timeout = 60000,
WantMetadata = true
};

var requestHandler = GetRequestHandler(host);
var response = await requestHandler.Handle(request);

// 2. now, based on the response information
// go to the metadata endpoint, and ask for "int" specific metadata
var metadataRequestHandler = host.GetRequestHandler<MetadataService>(OmniSharpEndpoints.Metadata);
var metadataResponse = await metadataRequestHandler.Handle(new MetadataRequest
{
Expand All @@ -198,25 +202,35 @@ public void Baz() {
Language = response.MetadataSource.Language
});

// 3. the metadata response contains SourceName (metadata "file") and SourceText (syntax tree)
// use the source to locate "IComparable" which is an interface implemented by Int32 struct
var metadataTree = CSharpSyntaxTree.ParseText(metadataResponse.Source);
var iComparable = metadataTree.GetCompilationUnitRoot().DescendantNodesAndSelf().OfType<BaseTypeDeclarationSyntax>().
First().BaseList.Types.FirstOrDefault(x => x.Type.ToString() == "IComparable");


// 4. now ask for the definition of "IComparable"
// pass in the SourceName (metadata "file") as FileName - since it's not a regular file in our workspace
var relevantLineSpan = iComparable.GetLocation().GetLineSpan();
var metadataNavigationRequest = new GotoDefinitionRequest
{
FileName = metadataResponse.SourceName,
Line = response.Line,
Column = response.Column + 10,
Line = relevantLineSpan.StartLinePosition.Line,
Column = relevantLineSpan.StartLinePosition.Character,
Timeout = 60000,
WantMetadata = true
};

var metadataNavigationResponse = await requestHandler.Handle(metadataNavigationRequest);

// 5. validate the response to be matching the expected IComparable meta info
Assert.NotNull(metadataNavigationResponse.MetadataSource);
Assert.Equal(AssemblyHelpers.CorLibName, metadataNavigationResponse.MetadataSource.AssemblyName);
Assert.Equal("System.IComparable", metadataNavigationResponse.MetadataSource.TypeName);

Assert.NotEqual(0, metadataNavigationResponse.Line);
Assert.NotEqual(0, metadataNavigationResponse.Column);
}

}

private async Task TestGoToSourceAsync(params TestFile[] testFiles)
Expand Down
4 changes: 2 additions & 2 deletions tests/TestUtility/OmniSharpTestHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ public static OmniSharpTestHost Create(string path = null, ITestOutputHelper tes
dotNetPath = Path.ChangeExtension(dotNetPath, ".exe");
}

/*if (!File.Exists(dotNetPath))
if (!File.Exists(dotNetPath))
{
throw new InvalidOperationException($"Local .NET CLI path does not exist. Did you run build.(ps1|sh) from the command line?");
}*/
}

var builder = new ConfigurationBuilder();
builder.AddInMemoryCollection(configurationData);
Expand Down

0 comments on commit bad475b

Please sign in to comment.