Exemple #1
0
        public static DeclarationSymbol SpanToSymbol(IList <object> quickInfoContent, NSpan span, IAst ast, out bool foundSomething)
        {
            var cts = new CancellationTokenSource();
            DeclarationSymbol symbol = null;
            var visitor = new CollectSymbolsAndRefsInSpanAstVisitor(cts.Token, span);

            visitor.Visit(ast);

            foreach (var rf in visitor.Refs)
            {
                if (rf.IsAmbiguous)
                {
                    var foundHint = false;
                    foreach (var ambiguity in rf.Ambiguities)
                    {
                        var hint = SymbolToHint(ambiguity);
                        if (hint != null)
                        {
                            quickInfoContent.Add(hint);
                            symbol    = ambiguity;
                            foundHint = true;
                            break;
                        }
                    }

                    if (foundHint)
                    {
                        break;
                    }
                }
                else if (rf.IsSymbolEvaluated)
                {
                    var hint = SymbolToHint(rf.Symbol);
                    if (hint != null)
                    {
                        quickInfoContent.Add(hint);
                        symbol = rf.Symbol;
                        break;
                    }
                }
            }

            foundSomething = visitor.Refs.Count > 0 || visitor.Names.Count > 0;

            return(symbol);
        }
            public void Execute(IDataContext context, DelegateExecute nextExecute)
            {
                var callNext = true;

                try
                {
                    var solution = context.GetData(JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION);
                    if (solution != null)
                    {
                        var documentOffset = context.GetData(JetBrains.DocumentModel.DataConstants.DOCUMENT_OFFSET);
                        if (documentOffset == null)
                        {
                            return;
                        }

                        //var psiServices = solution.GetPsiServices();
                        var psiFile = documentOffset.Document.GetPsiSourceFile(solution);
                        if (psiFile == null)
                        {
                            return;
                        }
                        var projectFile = psiFile.ToProjectFile();
                        if (projectFile == null)
                        {
                            return;
                        }
                        var project = projectFile.GetProject();
                        if (project == null)
                        {
                            return;
                        }
                        var nitraProject = _nitraSolution.GetProject(project);
                        if (nitraProject == null)
                        {
                            return;
                        }
                        var nitraFile = nitraProject.TryGetFile(projectFile);
                        if (nitraFile == null)
                        {
                            return;
                        }

                        var pos     = documentOffset.Value;
                        var visitor = new CollectSymbolsAndRefsInSpanAstVisitor(new NSpan(pos));
                        nitraFile.Ast.Accept(visitor);

                        var popupWindowContext = context.GetData(JetBrains.UI.DataConstants.PopupWindowContextSource);
                        if (popupWindowContext == null)
                        {
                            return;
                        }

                        var decls = visitor.Refs.Where(r => r.IsSymbolEvaluated).SelectMany(r => r.Symbol.Declarations).Where(d => !d.File.IsFake).ToArray();

                        if (decls.Length == 0)
                        {
                            if (visitor.Names.Count == 0)
                            {
                                return;
                            }

                            decls = visitor.Names.Where(n => n.IsSymbolEvaluated).SelectMany(n => n.Symbol.Declarations).Where(d => !d.File.IsFake).ToArray();
                        }

                        if (decls.Length == 0)
                        {
                            return;
                        }
                        if (decls.Length == 1)
                        {
                            Navigate(decls[0], solution, project, popupWindowContext);
                        }
                        else
                        {
                            callNext = false;
                            var jetPopupMenus = _nitraSolution._jetPopupMenus;
                            jetPopupMenus.Show(_lifetime, JetPopupMenu.ShowWhen.NoItemsBannerIfNoItems, (lifetime, menu) =>
                            {
                                menu.ItemKeys.AddRange(Sorter(decls));
                                menu.PopupWindowContext = popupWindowContext.Create(lifetime);
                                menu.Caption.Value      = WindowlessControl.Create("Declaration of " + string.Join(", ", decls.Select(d => d.Name.Text)));
                                menu.NoItemsBanner      = WindowlessControl.Create("There are no declarations.");
                                menu.DescribeItem.Advise(lifetime, args =>
                                {
                                    var decl = (Declaration)args.Key;
                                    var loc  = decl.Name.ToLocation();

                                    //args.Descriptor.Style |= MenuItemStyle.Enabled;
                                    args.Descriptor.Style  |= visitor.Names.Contains(decl.Name) ? MenuItemStyle.None : args.Descriptor.Style = MenuItemStyle.Enabled;
                                    args.Descriptor.Text    = new RichText(Path.GetFileName(decl.File.FullName)).Append(" ").Append("(" + loc.EndLineColumn + ")", TextStyle.FromForeColor(Color.RoyalBlue));
                                    args.Descriptor.Tooltip =
                                        new RichText(decl.Symbol.Kind, TextStyle.FromForeColor(Color.Blue))
                                        .Append(" ")
                                        .Append(decl.Name.Text, new TextStyle(FontStyle.Bold));
                                    //args.Descriptor.ShortcutText = XamlToRichText(decl.ToXaml());
                                    //args.Descriptor.Icon = ;
                                });
                                menu.ItemClicked.Advise(lifetime, arg => _shellLocks.ExecuteOrQueueReadLock("Nitra GoTo Declaration", () =>
                                {
                                    var decl = (Declaration)arg;
                                    Navigate(decl, solution, project, popupWindowContext);
                                }));
                            });
                        }
                    }
                }
                finally
                {
                    if (callNext)
                    {
                        nextExecute();
                    }
                }
            }
      public void Execute(IDataContext context, DelegateExecute nextExecute)
      {
        var callNext = true;
        try
        {
          var solution = context.GetData(JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION);
          if (solution != null)
          {
            var documentOffset = context.GetData(JetBrains.DocumentModel.DataConstants.DOCUMENT_OFFSET);
            if (documentOffset == null)
              return;

            //var psiServices = solution.GetPsiServices();
            var psiFile = documentOffset.Document.GetPsiSourceFile(solution);
            if (psiFile == null)
              return;
            var projectFile = psiFile.ToProjectFile();
            if (projectFile == null)
              return;
            var project = projectFile.GetProject();
            if (project == null)
              return;
            var nitraProject = _nitraSolution.GetProject(project);
            if (nitraProject == null)
              return;
            var nitraFile = nitraProject.TryGetFile(projectFile);
            if (nitraFile == null)
              return;

            var pos = documentOffset.Value;
            var visitor = new CollectSymbolsAndRefsInSpanAstVisitor(new NSpan(pos));
            nitraFile.Ast.Accept(visitor);

            var popupWindowContext = context.GetData(JetBrains.UI.DataConstants.PopupWindowContextSource);
            if (popupWindowContext == null)
              return;

            var decls = visitor.Refs.Where(r => r.IsSymbolEvaluated).SelectMany(r => r.Symbol.Declarations).Where(d => !d.File.IsFake).ToArray();

            if (decls.Length == 0)
            {
              if (visitor.Names.Count == 0)
                return;

              decls = visitor.Names.Where(n => n.IsSymbolEvaluated).SelectMany(n => n.Symbol.Declarations).Where(d => !d.File.IsFake).ToArray();
            }

            if (decls.Length == 0)
              return;
            if (decls.Length == 1)
              Navigate(decls[0], solution, project, popupWindowContext);
            else
            {
              callNext = false;
              var jetPopupMenus = _nitraSolution._jetPopupMenus;
              jetPopupMenus.Show(_lifetime, JetPopupMenu.ShowWhen.NoItemsBannerIfNoItems, (lifetime, menu) =>
              {
                menu.ItemKeys.AddRange(Sorter(decls));
                menu.PopupWindowContext = popupWindowContext.Create(lifetime);
                menu.Caption.Value = WindowlessControl.Create("Declaration of " + string.Join(", ", decls.Select(d => d.Name.Text)));
                menu.NoItemsBanner = WindowlessControl.Create("There are no declarations.");
                menu.DescribeItem.Advise(lifetime, args =>
                {
                  var decl = (Declaration)args.Key;
                  var loc = decl.Name.ToLocation();

                  //args.Descriptor.Style |= MenuItemStyle.Enabled;
                  args.Descriptor.Style |= visitor.Names.Contains(decl.Name) ? MenuItemStyle.None : args.Descriptor.Style = MenuItemStyle.Enabled;
                  args.Descriptor.Text = new RichText(Path.GetFileName(decl.File.FullName)).Append(" ").Append("(" + loc.EndLineColumn + ")", TextStyle.FromForeColor(Color.RoyalBlue));
                  args.Descriptor.Tooltip =
                    new RichText(decl.Symbol.Kind, TextStyle.FromForeColor(Color.Blue))
                    .Append(" ")
                    .Append(decl.Name.Text, new TextStyle(FontStyle.Bold));
                  //args.Descriptor.ShortcutText = XamlToRichText(decl.ToXaml());
                  //args.Descriptor.Icon = ;
                });
                menu.ItemClicked.Advise(lifetime, arg => _shellLocks.ExecuteOrQueueReadLock("Nitra GoTo Declaration", () =>
                {
                  var decl = (Declaration)arg;
                  Navigate(decl, solution, project, popupWindowContext);
                }));
              });
            }
          }
        }
        finally
        {
          if (callNext)
            nextExecute();
        }
      }
Exemple #4
0
      public void Execute(IDataContext context, DelegateExecute nextExecute)
      {
        var solution = context.GetData(JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION);
        if (solution != null)
        {
          var documentOffset = context.GetData(JetBrains.DocumentModel.DataConstants.DOCUMENT_OFFSET);
          if (documentOffset == null)
            return;

          //var psiServices = solution.GetPsiServices();
          var psiFile = documentOffset.Document.GetPsiSourceFile(solution);
          if (psiFile == null)
            return;
          var projectFile = psiFile.ToProjectFile();
          if (projectFile == null)
            return;
          var project = projectFile.GetProject();
          if (project == null)
            return;
          var nitraProject = _nitraSolution.GetProject(project);
          if (nitraProject == null)
            return;
          var nitraFile = nitraProject.TryGetFile(projectFile);
          if (nitraFile == null)
            return;

          var pos = documentOffset.Value;
          var symbolCollector = new CollectSymbolsAndRefsInSpanAstVisitor(new NSpan(pos));
          nitraFile.Ast.Accept(symbolCollector);


          var popupWindowContext = context.GetData(JetBrains.UI.DataConstants.PopupWindowContextSource);
          if (popupWindowContext == null)
            return;

          var symbols = symbolCollector.Refs.Where(r => r.IsSymbolEvaluated).Select(r => r.Symbol).ToArray();

          if (symbols.Length == 0)
          {
            if (symbolCollector.Names.Count == 0)
              return;

            symbols = symbolCollector.Names.Where(n => n.IsSymbolEvaluated).Select(n => n.Symbol).ToArray();
          }

          List<IOccurence> items = new List<IOccurence>();
          var s = nitraFile.Project.Solution;

          foreach (var p in s.Projects)
          {
            foreach (var file in p.Files)
            {

              foreach (var symbol in symbols)
              {
                var collectRefs = new CollectSymbolRefsAstVisitor(symbol);
                file.Ast.Accept(collectRefs);

                foreach (var r in collectRefs.FoundSymbols)
                {
                  var refNitraFile = r.File as XXLanguageXXFile; // TODO: add INitraReSharperFile
                  if (refNitraFile == null)
                    continue;
                  items.Add(new RangeOccurence(refNitraFile.PsiSourceFile, new DocumentRange(refNitraFile.Document, new TextRange(r.Span.StartPos, r.Span.EndPos))));
                }
              }
            }
          }

          var descriptor = new NitraOccurenceBrowserDescriptor(solution, items);
          FindResultsBrowser.ShowResults(descriptor);
        }
        nextExecute();
      }
Exemple #5
0
            public void Execute(IDataContext context, DelegateExecute nextExecute)
            {
                var solution = context.GetData(JetBrains.ProjectModel.DataContext.DataConstants.SOLUTION);

                if (solution != null)
                {
                    var documentOffset = context.GetData(JetBrains.DocumentModel.DataConstants.DOCUMENT_OFFSET);
                    if (documentOffset == null)
                    {
                        return;
                    }

                    //var psiServices = solution.GetPsiServices();
                    var psiFile = documentOffset.Document.GetPsiSourceFile(solution);
                    if (psiFile == null)
                    {
                        return;
                    }
                    var projectFile = psiFile.ToProjectFile();
                    if (projectFile == null)
                    {
                        return;
                    }
                    var project = projectFile.GetProject();
                    if (project == null)
                    {
                        return;
                    }
                    var nitraProject = _nitraSolution.GetProject(project);
                    if (nitraProject == null)
                    {
                        return;
                    }
                    var nitraFile = nitraProject.TryGetFile(projectFile);
                    if (nitraFile == null)
                    {
                        return;
                    }

                    var pos             = documentOffset.Value;
                    var symbolCollector = new CollectSymbolsAndRefsInSpanAstVisitor(new NSpan(pos));
                    nitraFile.Ast.Accept(symbolCollector);


                    var popupWindowContext = context.GetData(JetBrains.UI.DataConstants.PopupWindowContextSource);
                    if (popupWindowContext == null)
                    {
                        return;
                    }

                    var symbols = symbolCollector.Refs.Where(r => r.IsSymbolEvaluated).Select(r => r.Symbol).ToArray();

                    if (symbols.Length == 0)
                    {
                        if (symbolCollector.Names.Count == 0)
                        {
                            return;
                        }

                        symbols = symbolCollector.Names.Where(n => n.IsSymbolEvaluated).Select(n => n.Symbol).ToArray();
                    }

                    List <IOccurence> items = new List <IOccurence>();
                    var s = nitraFile.Project.Solution;

                    foreach (var p in s.Projects)
                    {
                        foreach (var file in p.Files)
                        {
                            foreach (var symbol in symbols)
                            {
                                var collectRefs = new CollectSymbolRefsAstVisitor(symbol);
                                file.Ast.Accept(collectRefs);

                                foreach (var r in collectRefs.FoundSymbols)
                                {
                                    var refNitraFile = r.File as XXLanguageXXFile; // TODO: add INitraReSharperFile
                                    if (refNitraFile == null)
                                    {
                                        continue;
                                    }
                                    items.Add(new RangeOccurence(refNitraFile.PsiSourceFile, new DocumentRange(refNitraFile.Document, new TextRange(r.Span.StartPos, r.Span.EndPos))));
                                }
                            }
                        }
                    }

                    var descriptor = new NitraOccurenceBrowserDescriptor(solution, items);
                    FindResultsBrowser.ShowResults(descriptor);
                }
                nextExecute();
            }