// Consider removing this function, and thus a dependency on Microsoft.CodeAnalysis internal static async Task <Tuple <SyntaxNode, Document> > GetSelectedSyntaxNode() { int startPosition, endPosition; string filePath; if (TextManager.TryFindDocumentAndPosition(out filePath, out startPosition, out endPosition)) { Document document; try { document = WorkspaceHelpers.GetDocument(filePath); } catch (NullReferenceException) { StatusBar.ShowStatus($"Error accessing the document. Try building the solution."); return(null); } var root = await document.GetSyntaxRootAsync(); var element = root.FindNode(new Microsoft.CodeAnalysis.Text.TextSpan(startPosition, endPosition - startPosition)); return(Tuple.Create(element, document)); } else { StatusBar.ShowStatus("To use Roslyn Search, please navigate to C# code."); return(null); } }
internal static Document GetCurrentDocument() { int startPosition, endPosition; string filePath; if (TextManager.TryFindDocumentAndPosition(out filePath, out startPosition, out endPosition)) { try { return(WorkspaceHelpers.GetDocument(filePath)); } catch (NullReferenceException) { StatusBar.ShowStatus($"Error accessing the document. Try building the solution."); } } return(null); }