Exemplo n.º 1
0
        public void BrowseTo()
        {
            try
            {
                if (!VisualStudio.IsDocumentOpen())
                {
                    return;
                }

                var cursorPosition = VisualStudio.GetCursorPositionInLine();
                var line           = VisualStudio.GetCurrentLine();

                int beginIndex;
                var elementName = FortranParseHelper.GetElementName(line, cursorPosition, out beginIndex);

                if (String.IsNullOrEmpty(elementName))
                {
                    return;
                }

                var memberMatches = SyntaxTreeMaintainer.GetSyntaxTrees()
                                    .SelectMany(st => st.GetAllMembers()
                                                .Where(m => Equals(elementName, m.Name))
                                                .Select(m => new SearchResult {
                    SyntaxTree = st, Member = m
                }))
                                    .ToList();

                if (memberMatches.Any())
                {
                    BrowseToCore(memberMatches);
                }
                else
                {
                    BrowseToVariable(elementName);
                }
            }
            catch (Exception e)
            {
                Log.Error("BrowseTo failed", e, GetContext());
            }
        }
Exemplo n.º 2
0
        public void FindUsage()
        {
            try
            {
                if (!VisualStudio.IsDocumentOpen())
                {
                    return;
                }

                var coords         = VisualStudio.GetCaretPositionInScreenCoordinates();
                var cursorPosition = VisualStudio.GetCursorPositionInLine();
                var line           = VisualStudio.GetCurrentLine();

                int beginIndex;
                var memberName = FortranParseHelper.GetElementName(line, cursorPosition, out beginIndex);

                if (String.IsNullOrEmpty(memberName.Trim()))
                {
                    return;
                }

                var asts = SyntaxTreeMaintainer.GetSyntaxTrees().ToList();

                var matchingMember = asts.SelectMany(a => a.GetAllMembers())
                                     .FirstOrDefault(m => String.Equals(m.Name, memberName, StringComparison.InvariantCultureIgnoreCase));

                var searchObj = matchingMember != null ?
                                new MemberOrSearchTerm(matchingMember) :
                                new MemberOrSearchTerm(memberName);

                var usages = new FortranUsageSearcher().FindInFiles(searchObj, asts);

                if (usages.Count == 0)
                {
                    return;
                }
                if (usages.Count == 1)
                {
                    GotoUsage(usages.First());
                    return;
                }

                dialog                  = CreateListFindControl();
                dialog.Location         = coords;
                dialog.MaxResults       = 500;//something big
                dialog.DataSource       = usages.OfType <object>().ToList();
                dialog.AlwaysShowList   = true;
                dialog.HideSearchDialog = true;
                dialog.OnGetIconForItem = o => null;
                dialog.DataMember       = "Name";
                dialog.HintMember       = "Hint";
                dialog.OnGetHintEmphasisRangeForItem = o =>
                {
                    var usageRes = (UsageResult)o;
                    var start    = usageRes.Location.Offset;
                    var end      = start + memberName.Length;
                    return(new Point(start, end));
                };
                dialog.ItemChosen += (chosenUsage, e) => GotoUsage((UsageResult)chosenUsage);
                dialog.Show();
            }
            catch (Exception e)
            {
                Log.Error("FindUsage failed", e, GetContext());
            }
        }