Ejemplo n.º 1
0
        // 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);
            }
        }
Ejemplo n.º 2
0
        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);
        }