diff options
author | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-20 19:07:51 +0300 |
---|---|---|
committer | Lluis Sanchez Gual <lluis@xamarin.com> | 2015-04-20 19:07:51 +0300 |
commit | 95408b1a41b31b645f3a8c3323ab7d3ca4bff26b (patch) | |
tree | f8f137cddcb9a40499d303be95722fd2c6081bce /main/src/addins/NUnit/Services/NUnitProjectTestSuite.cs | |
parent | b70e4e04b4e41b8ec28d7e4b220b401ecf467e7a (diff) | |
parent | de043d330a8bf5855d4d983c804cd36727cb2406 (diff) |
Merge remote-tracking branch 'origin/roslyn' into new-project-model
Diffstat (limited to 'main/src/addins/NUnit/Services/NUnitProjectTestSuite.cs')
-rw-r--r-- | main/src/addins/NUnit/Services/NUnitProjectTestSuite.cs | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/main/src/addins/NUnit/Services/NUnitProjectTestSuite.cs b/main/src/addins/NUnit/Services/NUnitProjectTestSuite.cs index 6a789d36ba..e7381ff1ae 100644 --- a/main/src/addins/NUnit/Services/NUnitProjectTestSuite.cs +++ b/main/src/addins/NUnit/Services/NUnitProjectTestSuite.cs @@ -34,8 +34,9 @@ using System.Collections.Generic; using MonoDevelop.Projects; using MonoDevelop.Ide; using MonoDevelop.Ide.TypeSystem; -using ICSharpCode.NRefactory.TypeSystem; using System; +using Microsoft.CodeAnalysis; +using System.Threading; using ProjectReference = MonoDevelop.Projects.ProjectReference; namespace MonoDevelop.NUnit @@ -82,27 +83,45 @@ namespace MonoDevelop.NUnit { if (string.IsNullOrEmpty (fixtureTypeName) || string.IsNullOrEmpty (fixtureTypeName)) return null; - var ctx = TypeSystemService.GetCompilation (project); - var cls = ctx.MainAssembly.GetTypeDefinition (fixtureTypeNamespace ?? "", fixtureTypeName, 0); + var csc = new CancellationTokenSource (); + var task = TypeSystemService.GetCompilationAsync (project, csc.Token); + task.Wait (2000); + if (!task.IsCompleted) { + csc.Cancel (); + return null; + } + var ctx = task.Result; + var cls = ctx.Assembly.GetTypeByMetadataName (string.IsNullOrEmpty (fixtureTypeNamespace) ? fixtureTypeName : fixtureTypeNamespace + "." + fixtureTypeName); if (cls == null) return null; if (cls.Name != methodName) { - foreach (var met in cls.GetMethods ()) { - if (met.Name == methodName) - return new SourceCodeLocation (met.Region.FileName, met.Region.BeginLine, met.Region.BeginColumn); + foreach (var met in cls.GetMembers ().OfType<IMethodSymbol> ()) { + if (met.Name == methodName) { + var loc = met.Locations.FirstOrDefault (l => l.IsInSource); + return ConvertToSourceCodeLocation (loc); + } } int idx = methodName != null ? methodName.IndexOf ('(') : -1; if (idx > 0) { methodName = methodName.Substring (0, idx); - foreach (var met in cls.GetMethods ()) { - if (met.Name == methodName) - return new SourceCodeLocation (met.Region.FileName, met.Region.BeginLine, met.Region.BeginColumn); + foreach (var met in cls.GetMembers ().OfType<IMethodSymbol> ()) { + if (met.Name == methodName){ + var loc = met.Locations.FirstOrDefault (l => l.IsInSource); + return ConvertToSourceCodeLocation (loc); + } } } } - return new SourceCodeLocation (cls.Region.FileName, cls.Region.BeginLine, cls.Region.BeginColumn); + var classLoc = cls.Locations.FirstOrDefault (l => l.IsInSource); + return ConvertToSourceCodeLocation (classLoc); + } + + SourceCodeLocation ConvertToSourceCodeLocation (Location loc) + { + var lineSpan = loc.GetLineSpan (); + return new SourceCodeLocation (loc.SourceTree.FilePath, lineSpan.StartLinePosition.Line, lineSpan.StartLinePosition.Character); } public override void Dispose () |