Example #1
0
 public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
 {
     if (session.RelationshipName == RotPeekRelationship.SName)
     {
         peekableItems.Add(new RotPeekableItem(ExpandTactic(ActiveTextView)));
     }
 }
Example #2
0
        public void AugmentPeekSession(IPeekSession session, IList<IPeekableItem> peekableItems)
        {
            var triggerPoint = session.GetTriggerPoint(_textBuffer.CurrentSnapshot);
            if (!triggerPoint.HasValue)
            {
                return;
            }

            var document = triggerPoint.Value.Snapshot.GetOpenDocumentInCurrentContextWithChanges();
            if (document == null)
            {
                return;
            }

            _waitIndicator.Wait(EditorFeaturesResources.Peek, EditorFeaturesResources.LoadingPeekInformation, allowCancel: true, action: context =>
            {
                var cancellationToken = context.CancellationToken;

                IEnumerable<IPeekableItem> results;

                if (!document.SupportsSemanticModel)
                {
                    // For documents without semantic models, just try to use the goto-def service
                    // as a reasonable place to peek at.
                    var goToDefinitionService = document.GetLanguageService<IGoToDefinitionService>();
                    var navigableItems = goToDefinitionService.FindDefinitionsAsync(document, triggerPoint.Value.Position, cancellationToken)
                                                              .WaitAndGetResult(cancellationToken);

                    results = GetPeekableItemsForNavigableItems(navigableItems, document.Project, _peekResultFactory, cancellationToken);
                }
                else
                {
                    var semanticModel = document.GetSemanticModelAsync(cancellationToken).WaitAndGetResult(cancellationToken);
                    var symbol = SymbolFinder.FindSymbolAtPosition(semanticModel,
                                                                   triggerPoint.Value.Position,
                                                                   document.Project.Solution.Workspace,
                                                                   bindLiteralsToUnderlyingType: true,
                                                                   cancellationToken: cancellationToken);

                    if (symbol == null)
                    {
                        return;
                    }

                    symbol = symbol.GetOriginalUnreducedDefinition();

                    // Get the symbol back from the originating workspace
                    var symbolMappingService = document.Project.Solution.Workspace.Services.GetService<ISymbolMappingService>();
                    var mappingResult = symbolMappingService.MapSymbolAsync(document, symbol, cancellationToken)
                                                            .WaitAndGetResult(cancellationToken);

                    mappingResult = mappingResult ?? new SymbolMappingResult(document.Project, symbol);

                    results = _peekableItemFactory.GetPeekableItemsAsync(mappingResult.Symbol, mappingResult.Project, _peekResultFactory, cancellationToken)
                                                 .WaitAndGetResult(cancellationToken);
                }

                peekableItems.AddRange(results);
            });
        }
Example #3
0
        public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
        {
            var triggerPoint = session.GetTriggerPoint(_textBuffer.CurrentSnapshot);

            if (!triggerPoint.HasValue)
            {
                return;
            }

            var itemName = session.TextView.GetIdentifierUnderCaret(out Span span);

            if (!string.IsNullOrEmpty(itemName))
            {
                var textDocument   = _textBuffer.GetTextDocument();
                var document       = _textBuffer.GetEditorDocument <IREditorDocument>();
                var definitionNode = document?.EditorTree.AstRoot.FindItemDefinition(triggerPoint.Value, itemName);
                if (definitionNode != null)
                {
                    peekableItems.Add(new UserDefinedPeekItem(textDocument.FilePath, definitionNode, itemName, _peekResultFactory, _services));
                }
                else
                {
                    // Not found. Try internal functions
                    var item = new InternalFunctionPeekItem(textDocument.FilePath, span, itemName, _peekResultFactory, _services);
                    peekableItems.Add(item);
                }
            }
        }
Example #4
0
 public void AugmentPeekSession(IPeekSession session, IList<IPeekableItem> peekableItems)
 {
   if (session.RelationshipName != RotPeekRelationship.SName) return;
   var s = DafnyClassifier.DafnyMenuPackage.TacnyMenuProxy.GetExpandedForPeekSession(session);
   if (s == null) return;
   peekableItems.Add(new RotPeekableItem(s));
 }
        public UIElement Create(IPeekSession session, IPeekResultScrollState scrollState)
        {
            var view = new InlineCommentPeekView();

            view.DataContext = viewModel;
            return(view);
        }
Example #6
0
        public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
        {
            if (!string.Equals(session.RelationshipName, PredefinedPeekRelationships.Definitions.Name, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var triggerPoint = session.GetTriggerPoint(_textBuffer.CurrentSnapshot);

            if (!triggerPoint.HasValue)
            {
                return;
            }

            var document = triggerPoint.Value.Snapshot.GetOpenDocumentInCurrentContextWithChanges();

            if (document == null)
            {
                return;
            }

            _uiThreadOperationExecutor.Execute(EditorFeaturesResources.Peek, EditorFeaturesResources.Loading_Peek_information, allowCancellation: true, showProgress: false, action: context =>
            {
                _threadingContext.JoinableTaskFactory.Run(() => AugumentPeekSessionAsync(peekableItems, context, triggerPoint.Value, document));
            });
        }
Example #7
0
        public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
        {
            var triggerPoint = session.GetTriggerPoint(_textBuffer.CurrentSnapshot);

            if (!triggerPoint.HasValue)
            {
                return;
            }

            Span   span;
            string itemName = session.TextView.GetIdentifierUnderCaret(out span);

            if (!string.IsNullOrEmpty(itemName))
            {
                var document       = REditorDocument.FromTextBuffer(_textBuffer);
                var definitionNode = document.EditorTree.AstRoot.FindItemDefinition(triggerPoint.Value, itemName);
                if (definitionNode != null)
                {
                    ITextDocument textDocument = _textBuffer.GetTextDocument();
                    if (textDocument != null)
                    {
                        peekableItems.Add(new PeekItem(textDocument.FilePath, definitionNode, itemName, _peekResultFactory));
                    }
                }
            }
        }
Example #8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InlineCommentPeekViewModel"/> class.
        /// </summary>
        public InlineCommentPeekViewModel(
            IInlineCommentPeekService peekService,
            IPeekSession peekSession,
            IPullRequestSessionManager sessionManager,
            INextInlineCommentCommand nextCommentCommand,
            IPreviousInlineCommentCommand previousCommentCommand)
        {
            Guard.ArgumentNotNull(peekService, nameof(peekService));
            Guard.ArgumentNotNull(peekSession, nameof(peekSession));
            Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));
            Guard.ArgumentNotNull(nextCommentCommand, nameof(nextCommentCommand));
            Guard.ArgumentNotNull(previousCommentCommand, nameof(previousCommentCommand));

            this.peekService    = peekService;
            this.peekSession    = peekSession;
            this.sessionManager = sessionManager;
            triggerPoint        = peekSession.GetTriggerPoint(peekSession.TextView.TextBuffer);

            peekSession.Dismissed += (s, e) => Dispose();

            NextComment = ReactiveCommand.CreateAsyncTask(
                Observable.Return(nextCommentCommand.Enabled),
                _ => nextCommentCommand.Execute(new InlineCommentNavigationParams
            {
                FromLine = peekService.GetLineNumber(peekSession, triggerPoint).Item1,
            }));

            PreviousComment = ReactiveCommand.CreateAsyncTask(
                Observable.Return(previousCommentCommand.Enabled),
                _ => previousCommentCommand.Execute(new InlineCommentNavigationParams
            {
                FromLine = peekService.GetLineNumber(peekSession, triggerPoint).Item1,
            }));
        }
Example #9
0
        public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
        {
            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }

            if (peekableItems == null)
            {
                throw new ArgumentNullException(nameof(peekableItems));
            }

            if (!string.Equals(session.RelationshipName, PredefinedPeekRelationships.Definitions.Name, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var triggerPoint = session.GetTriggerPoint(_textBuffer.CurrentSnapshot);

            if (!triggerPoint.HasValue)
            {
                return;
            }

            ThreadHelper.JoinableTaskFactory.Run(async() => {
                var item = await GetPeekableItemAsync(_peekResultFactory, _textBuffer, triggerPoint.Value);
                if (item != null)
                {
                    peekableItems.Add(item);
                }
            });
        }
Example #10
0
        public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
        {
            if (session == null)
            {
                throw new ArgumentNullException(nameof(session));
            }

            if (peekableItems == null)
            {
                throw new ArgumentNullException(nameof(peekableItems));
            }

            if (!string.Equals(session.RelationshipName, PredefinedPeekRelationships.Definitions.Name, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var triggerPoint = session.GetTriggerPoint(_textBuffer.CurrentSnapshot);

            if (!triggerPoint.HasValue)
            {
                return;
            }

            var tokensResult = ThreadHelper.JoinableTaskFactory.Run(
                () => _navigationTokenService.GetNavigationsAsync(triggerPoint.Value));

            if (tokensResult == null || tokensResult.Values.Count != 1)
            {
                return;
            }
            peekableItems.Add(new PeekableItem(_peekResultFactory, tokensResult.Values[0]));
        }
Example #11
0
        public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
        {
            if (session == null)
            {
                throw new ArgumentNullException("session");
            }
            if (peekableItems == null)
            {
                throw new ArgumentNullException("peekableItems");
            }
            if (session.RelationshipName == PredefinedPeekRelationships.Definitions.Name)
            {
                ITextDocument document;
                SnapshotPoint?triggerPoint = session.GetTriggerPoint(this._buffer.CurrentSnapshot);
                if (triggerPoint.HasValue && this.TryGetTextDocument(_buffer, out document))
                {
                    if (!session.TextView.TextBuffer.Properties.ContainsProperty(typeof(ITextDocument)))
                    {
                        session.TextView.TextBuffer.Properties.AddProperty(typeof(ITextDocument), document);
                    }

                    peekableItems.Add(new PeekableItem(EditFilter.GetLocations(session.TextView, EditFilter.GetLocationOptions.Definitions), _factory));
                }
            }
        }
Example #12
0
 /// <summary>
 /// Called by a <see cref="IPeekBroker"/> to add <see cref="IPeekableItem"/>s to a current
 /// <see cref="IPeekSession"/>.
 /// </summary>
 /// <remarks>
 /// The <see cref="IPeekBroker"/> does not know if the <see cref="IPeekableItemSource"/>
 /// supports the relationship in <see cref="IPeekSession"/>, so you should always check to
 /// see if the relationship actually applies to this class.
 /// </remarks>
 /// <param name="session">The running <see cref="IPeekSession"/>.</param>
 /// <param name="peekableItems">A list of <see cref="IPeekableItem"/>s to append to.</param>
 public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
 {
     // Only add a new CommentPeekPeekableItem if the relationship is a CommentPeek
     if (session.RelationshipName.Equals(CommentPeek.RelationshipName, StringComparison.OrdinalIgnoreCase))
     {
         peekableItems.Add(new CommentPeekPeekableItem(textBuffer));
     }
 }
Example #13
0
        public void AddUpdaterForRot(IPeekSession session, Action <string> recalculate)
        {
            string file;
            var    fileLoaded = RefactoringUtil.LoadAndCheckDocument(session.TextView.TextBuffer, out file);

            if (fileLoaded && _activePeekSession != null && _activePeekSession.ContainsKey(file))
            {
                _activePeekSession[file].Updater = recalculate;
            }
        }
Example #14
0
        public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
        {
            var triggerPoint = session.GetTriggerPoint(buffer.CurrentSnapshot);

            if (triggerPoint == null)
            {
                return;
            }

            peekableItems.Add(new MyPeekItem(peekResultFactory));
        }
Example #15
0
 public UIElement Create(IPeekSession session, IPeekResultScrollState scrollState) {
   _tb = new TextBox {
     Text = _expandedTactic,
     Background = Brushes.AliceBlue,
     IsReadOnly = true,
     FontFamily = new FontFamily("Consolas"),
     FontSize = ExpectedFontSize,
     MinHeight = TextHeight
   };
   return _tb;
 }
Example #16
0
        public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
        {
            var triggerPoint = session.GetTriggerPoint(_textBuffer.CurrentSnapshot);

            if (!triggerPoint.HasValue)
            {
                return;
            }

            peekableItems.Add(new ClassDefinitionPeekItem(serviceProvider, "comment", _peekResultFactory, _textBuffer));
        }
Example #17
0
 public UIElement Create(IPeekSession session, IPeekResultScrollState scrollState)
 {
     _tb = new TextBox {
         Text       = _expandedTactic,
         Background = Brushes.AliceBlue,
         IsReadOnly = true,
         FontFamily = new FontFamily("Consolas"),
         FontSize   = ExpectedFontSize,
         MinHeight  = TextHeight
     };
     return(_tb);
 }
        public void AugmentPeekSession(IPeekSession session, IList<IPeekableItem> peekableItems)
        {
            var triggerPoint = session.GetTriggerPoint(_textBuffer.CurrentSnapshot);
            if (!triggerPoint.HasValue)
                return;

            string className = HtmlHelpers.GetSinglePropertyValue(_textBuffer, triggerPoint.Value.Position, "class");
            if (string.IsNullOrEmpty(className))
                return;


            peekableItems.Add(new ClassDefinitionPeekItem(className, _peekResultFactory, _textBuffer));
        }
Example #19
0
 public UIElement Create(IPeekSession session, IPeekResultScrollState scrollState) {
   _session = session;
   DafnyClassifier.DafnyMenuPackage.TacnyMenuProxy.AddUpdaterForRot(_session, Recalculate);
   _tb = new TextBox {
     Text = _expandedTactic,
     Background = Brushes.AliceBlue,
     IsReadOnly = true,
     FontFamily = new FontFamily("Consolas"),
     FontSize = ExpectedFontSize,
     MinHeight = TextHeight
   };
   return _tb;
 }
Example #20
0
        public Tuple <string, string> GetExpandedForPeekSession(IPeekSession session)
        {
            string file;
            var    status = RefactoringUtil.LoadAndCheckDocument(session.TextView.TextBuffer, out file);

            if (!status)
            {
                return(null);
            }
            var storedSessionData = _activePeekSession[file];

            return(new Tuple <string, string>(storedSessionData.ExpandedTactic, storedSessionData.ActiveTactic));
        }
Example #21
0
        public UIElement Create(IPeekSession session, IPeekResultScrollState scrollState)
        {
            view             = new InlineCommentPeekView();
            view.DataContext = viewModel;

            // Report the desired size back to the peek view. Unfortunately the peek view
            // helpfully assigns this desired size to the control that also contains the tab at
            // the top of the peek view, so we need to put in a fudge factor. Using a const
            // value for the moment, as there's no easy way to get the size of the control.
            view.DesiredHeight.Subscribe(x => DesiredHeight = x + PeekBorders);

            return(view);
        }
Example #22
0
 public UIElement Create(IPeekSession session, IPeekResultScrollState scrollState)
 {
     _session = session;
     DafnyClassifier.DafnyMenuPackage.TacnyMenuProxy.AddUpdaterForRot(_session, Recalculate);
     _tb = new TextBox {
         Text       = _expandedTactic,
         Background = Brushes.AliceBlue,
         IsReadOnly = true,
         FontFamily = new FontFamily("Consolas"),
         FontSize   = ExpectedFontSize,
         MinHeight  = TextHeight
     };
     return(_tb);
 }
Example #23
0
        public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
        {
            if (session.RelationshipName != RotPeekRelationship.SName)
            {
                return;
            }
            var s = DafnyClassifier.DafnyMenuPackage.TacnyMenuProxy.GetExpandedForPeekSession(session);

            if (s == null)
            {
                return;
            }
            peekableItems.Add(new RotPeekableItem(s));
        }
 public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
 {
     if (session.RelationshipName == InlineCommentPeekRelationship.Instance.Name)
     {
         var viewModel = new InlineCommentPeekViewModel(
             peekService,
             session,
             sessionManager,
             nextCommentCommand,
             previousCommentCommand);
         viewModel.Initialize().Forget();
         peekableItems.Add(new InlineCommentPeekableItem(viewModel));
     }
 }
        public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
        {
            try
            {
                XSharpModel.ModelWalker.Suspend();
                if (!string.Equals(session.RelationshipName, PredefinedPeekRelationships.Definitions.Name, StringComparison.OrdinalIgnoreCase))
                {
                    return;
                }
                //
                var tp = session.GetTriggerPoint(_textBuffer.CurrentSnapshot);
                if (!tp.HasValue)
                {
                    return;
                }
                //
                var    triggerPoint = tp.Value;
                IToken stopToken;
                //
                // Check if we can get the member where we are
                XSharpModel.XTypeMember member           = XSharpLanguage.XSharpTokenTools.FindMember(triggerPoint.GetContainingLine().LineNumber, _file);
                XSharpModel.XType       currentNamespace = XSharpLanguage.XSharpTokenTools.FindNamespace(triggerPoint.Position, _file);

                var           lineNumber = triggerPoint.GetContainingLine().LineNumber;
                var           snapshot   = _textBuffer.CurrentSnapshot;
                List <String> tokenList  = XSharpTokenTools.GetTokenList(triggerPoint.Position, lineNumber, snapshot, out stopToken, false, _file, false, member);
                // LookUp for the BaseType, reading the TokenList (From left to right)
                CompletionElement gotoElement;
                String            currentNS = "";
                if (currentNamespace != null)
                {
                    currentNS = currentNamespace.Name;
                }
                XSharpModel.CompletionType cType = XSharpLanguage.XSharpTokenTools.RetrieveType(_file, tokenList, member, currentNS, stopToken, out gotoElement, snapshot, lineNumber, _file.Project.Dialect);
                //
                if ((gotoElement != null) && (gotoElement.XSharpElement != null))
                {
                    peekableItems.Add(new XSharpDefinitionPeekItem(gotoElement.XSharpElement, _peekResultFactory));
                }
            }
            catch (Exception ex)
            {
                XSharpProjectPackage.Instance.DisplayOutPutMessage("XSharpPeekItemSource.AugmentPeekSession failed : ");
                XSharpProjectPackage.Instance.DisplayException(ex);
            }
            finally
            {
                XSharpModel.ModelWalker.Resume();
            }
        }
Example #26
0
        public void AugmentPeekSession(IPeekSession session, IList<IPeekableItem> peekableItems)
        {
            if (session.RelationshipName == PeekHelpRelationship.Instance.Name)
            {
                DTE dte = ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE;
                var attributes = new Dictionary<string, string[]>(StringComparer.CurrentCultureIgnoreCase);
                ExtractAttributes(dte.ActiveWindow.ContextAttributes, attributes);
                ExtractAttributes(dte.ContextAttributes, attributes);

                string helpUrl = HelpUrlBuilder.Build(attributes);
                if (!string.IsNullOrWhiteSpace(helpUrl))
                {
                    peekableItems.Add(new F1PeekableItem(helpUrl));
                }
            }
        }
Example #27
0
        public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
        {
            if (session.RelationshipName == PeekHelpRelationship.Instance.Name)
            {
                DTE dte        = ServiceProvider.GlobalProvider.GetService(typeof(DTE)) as DTE;
                var attributes = new Dictionary <string, string[]>(StringComparer.CurrentCultureIgnoreCase);
                ExtractAttributes(dte.ActiveWindow.ContextAttributes, attributes);
                ExtractAttributes(dte.ContextAttributes, attributes);

                string helpUrl = HelpUrlBuilder.Build(attributes);
                if (!string.IsNullOrWhiteSpace(helpUrl))
                {
                    peekableItems.Add(new F1PeekableItem(helpUrl));
                }
            }
        }
        public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
        {
            SnapshotPoint?triggerPoint = session.GetTriggerPoint(_textBuffer.CurrentSnapshot);

            if (!triggerPoint.HasValue)
            {
                return;
            }

            string id = HtmlHelpers.GetSinglePropertyValue(_textBuffer, triggerPoint.Value.Position, "id");

            if (string.IsNullOrEmpty(id))
            {
                return;
            }

            peekableItems.Add(new IdDefinitionPeekItem(id, _peekResultFactory, _textBuffer));
        }
        public System.Windows.UIElement Create(IPeekSession session, IPeekResultScrollState state)
        {
            _textView = (IWpfTextView)session.TextView;
            _textView.BackgroundBrushChanged += OnTextViewBackgroundBrushChanged;

            _textView.LayoutChanged += ContainingTextView_LayoutChanged;

            _control             = new UrlPeekPresentationControl();
            _control.DataContext = this;

            _browser     = new System.Windows.Forms.WebBrowser();
            _browser.Url = _helpUri;
            _control.WinFormsHost.Child = _browser;

            _browser.DocumentCompleted += Browser_DocumentCompleted;
            _browser.Navigating        += Browser_Navigating;

            return(_control);
        }
        public System.Windows.UIElement Create(IPeekSession session, IPeekResultScrollState state)
        {
            _textView = (IWpfTextView)session.TextView;
            _textView.BackgroundBrushChanged += OnTextViewBackgroundBrushChanged;

            _textView.LayoutChanged += ContainingTextView_LayoutChanged;

            _control = new F1PeekPresentationControl();
            _control.DataContext = this;

            _browser = new System.Windows.Forms.WebBrowser();
            _browser.Url = _helpUri;
            _control.WinFormsHost.Child = _browser;

            _browser.DocumentCompleted += Browser_DocumentCompleted;
            _browser.Navigating += Browser_Navigating;

            return _control;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="InlineCommentPeekViewModel"/> class.
        /// </summary>
        public InlineCommentPeekViewModel(IInlineCommentPeekService peekService,
                                          IPeekSession peekSession,
                                          IPullRequestSessionManager sessionManager,
                                          INextInlineCommentCommand nextCommentCommand,
                                          IPreviousInlineCommentCommand previousCommentCommand,
                                          IViewViewModelFactory factory)
        {
            Guard.ArgumentNotNull(peekService, nameof(peekService));
            Guard.ArgumentNotNull(peekSession, nameof(peekSession));
            Guard.ArgumentNotNull(sessionManager, nameof(sessionManager));
            Guard.ArgumentNotNull(nextCommentCommand, nameof(nextCommentCommand));
            Guard.ArgumentNotNull(previousCommentCommand, nameof(previousCommentCommand));
            Guard.ArgumentNotNull(factory, nameof(factory));

            this.peekService    = peekService;
            this.peekSession    = peekSession;
            this.sessionManager = sessionManager;
            this.factory        = factory;
            triggerPoint        = peekSession.GetTriggerPoint(peekSession.TextView.TextBuffer);

            peekSession.Dismissed += (s, e) => Dispose();

            Close = this.WhenAnyValue(x => x.Thread)
                    .Where(x => x != null)
                    .SelectMany(x => x.IsNewThread
                    ? x.Comments.Single().CancelEdit.SelectUnit()
                    : Observable.Never <Unit>());

            NextComment = ReactiveCommand.CreateFromTask(
                () => nextCommentCommand.Execute(new InlineCommentNavigationParams
            {
                FromLine = peekService.GetLineNumber(peekSession, triggerPoint).Item1,
            }),
                Observable.Return(nextCommentCommand.Enabled));

            PreviousComment = ReactiveCommand.CreateFromTask(
                () => previousCommentCommand.Execute(new InlineCommentNavigationParams
            {
                FromLine = peekService.GetLineNumber(peekSession, triggerPoint).Item1,
            }),
                Observable.Return(previousCommentCommand.Enabled));
        }
        /// <inheritdoc/>
        public Tuple <int, bool> GetLineNumber(IPeekSession session, ITrackingPoint point)
        {
            var diffModel          = (session.TextView as IWpfTextView)?.TextViewModel as IDifferenceTextViewModel;
            var leftBuffer         = false;
            ITextSnapshotLine line = null;

            if (diffModel != null)
            {
                if (diffModel.ViewType == DifferenceViewType.InlineView)
                {
                    // If we're displaying a diff in inline mode, then we need to map the point down
                    // to the left or right buffer.
                    var snapshotPoint = point.GetPoint(point.TextBuffer.CurrentSnapshot);
                    var mappedPoint   = session.TextView.BufferGraph.MapDownToFirstMatch(
                        snapshotPoint,
                        PointTrackingMode.Negative,
                        x => !(x is IProjectionSnapshot),
                        PositionAffinity.Successor);

                    if (mappedPoint != null)
                    {
                        leftBuffer = mappedPoint.Value.Snapshot == diffModel.Viewer.DifferenceBuffer.LeftBuffer.CurrentSnapshot;
                        line       = mappedPoint.Value.GetContainingLine();
                    }
                }
                else
                {
                    // If we're displaying a diff in any other mode than inline, then we're in the
                    // left buffer if the session's text view is the diff's left view.
                    leftBuffer = session.TextView == diffModel.Viewer.LeftView;
                }
            }

            if (line == null)
            {
                line = point.GetPoint(point.TextBuffer.CurrentSnapshot).GetContainingLine();
            }

            return(Tuple.Create(line.LineNumber, leftBuffer));
        }
Example #33
0
        public void AugmentPeekSession(IPeekSession session, IList<IPeekableItem> peekableItems) {
            var triggerPoint = session.GetTriggerPoint(_textBuffer.CurrentSnapshot);
            if (!triggerPoint.HasValue)
                return;

            Span span;
            string itemName = session.TextView.GetIdentifierUnderCaret(out span);
            if (!string.IsNullOrEmpty(itemName)) {
                ITextDocument textDocument = _textBuffer.GetTextDocument();
                var document = REditorDocument.TryFromTextBuffer(_textBuffer);
                var definitionNode = document?.EditorTree.AstRoot.FindItemDefinition(triggerPoint.Value, itemName);
                if (definitionNode != null) {
                    peekableItems.Add(new UserDefinedPeekItem(textDocument.FilePath, definitionNode, itemName, _peekResultFactory, _shell));
                } else {
                    // Not found. Try internal functions
                    IPeekableItem item = new InternalFunctionPeekItem(textDocument.FilePath, span, itemName, _peekResultFactory, _shell);
                    if (item != null) {
                        peekableItems.Add(item);
                    }
                }
            }
        }
Example #34
0
        private void HandlePeekHelp()
        {
            PeekSessionCreationOptions options = new PeekSessionCreationOptions(_textView, PeekHelpRelationship.Instance.Name);

            if (_textView.Roles.Contains(PredefinedTextViewRoles.EmbeddedPeekTextView))
            {
                ITextView containingTextView;
                if (_textView.Properties.TryGetProperty("PeekContainingTextView", out containingTextView) && containingTextView != null)
                {
                    IPeekSession session = _peekBroker.GetPeekSession(containingTextView);
                    if (session != null)
                    {
                        _peekBroker.TriggerNestedPeekSession(options, session);
                    }
                }
            }
            else
            {
                _peekBroker.TriggerPeekSession(options);
            }

            _telemetrySession.PostEvent("VS/PPT-PeekHelp/PeekF1CommandInvoked");
        }
Example #35
0
 public void AddUpdaterForRot(IPeekSession session, Action<string> recalculate)
 {
   string file;
   var fileLoaded = RefactoringUtil.LoadAndCheckDocument(session.TextView.TextBuffer, out file);
   if (fileLoaded && _activePeekSession!=null && _activePeekSession.ContainsKey(file))
     _activePeekSession[file].Updater = recalculate;
 }
Example #36
0
 public void AugmentPeekSession(IPeekSession session, IList<IPeekableItem> peekableItems) {
   if(session.RelationshipName == RotPeekRelationship.SName) peekableItems.Add(new RotPeekableItem(ExpandTactic(ActiveTextView)));
 }
Example #37
0
        public bool ClearPeekSession(IPeekSession session)
        {
            string file;

            return(RefactoringUtil.LoadAndCheckDocument(session.TextView.TextBuffer, out file) && _activePeekSession.Remove(file));
        }
Example #38
0
        public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
        {
            if (!string.Equals(session.RelationshipName, PredefinedPeekRelationships.Definitions.Name, StringComparison.OrdinalIgnoreCase))
            {
                return;
            }

            var triggerPoint = session.GetTriggerPoint(_textBuffer.CurrentSnapshot);

            if (!triggerPoint.HasValue)
            {
                return;
            }

            var document = triggerPoint.Value.Snapshot.GetOpenDocumentInCurrentContextWithChanges();

            if (document == null)
            {
                return;
            }

            _waitIndicator.Wait(EditorFeaturesResources.Peek, EditorFeaturesResources.Loading_Peek_information, allowCancel: true, action: context =>
            {
                var cancellationToken = context.CancellationToken;

                IEnumerable <IPeekableItem> results;

                if (!document.SupportsSemanticModel)
                {
                    // For documents without semantic models, just try to use the goto-def service
                    // as a reasonable place to peek at.
                    var goToDefinitionService = document.GetLanguageService <IGoToDefinitionService>();
                    var navigableItems        = goToDefinitionService.FindDefinitionsAsync(document, triggerPoint.Value.Position, cancellationToken)
                                                .WaitAndGetResult(cancellationToken);

                    results = GetPeekableItemsForNavigableItems(navigableItems, document.Project, _peekResultFactory, cancellationToken);
                }
                else
                {
                    var semanticModel = document.GetSemanticModelAsync(cancellationToken).WaitAndGetResult(cancellationToken);
                    var symbol        = SymbolFinder.FindSymbolAtPositionAsync(semanticModel,
                                                                               triggerPoint.Value.Position,
                                                                               document.Project.Solution.Workspace,
                                                                               bindLiteralsToUnderlyingType: true,
                                                                               cancellationToken: cancellationToken).WaitAndGetResult(cancellationToken);

                    if (symbol == null)
                    {
                        return;
                    }

                    symbol = symbol.GetOriginalUnreducedDefinition();

                    // Get the symbol back from the originating workspace
                    var symbolMappingService = document.Project.Solution.Workspace.Services.GetService <ISymbolMappingService>();
                    var mappingResult        = symbolMappingService.MapSymbolAsync(document, symbol, cancellationToken)
                                               .WaitAndGetResult(cancellationToken);

                    mappingResult = mappingResult ?? new SymbolMappingResult(document.Project, symbol);

                    results = _peekableItemFactory.GetPeekableItemsAsync(mappingResult.Symbol, mappingResult.Project, _peekResultFactory, cancellationToken)
                              .WaitAndGetResult(cancellationToken);
                }

                peekableItems.AddRange(results);
            });
        }
        public void AugmentPeekSession(IPeekSession session, IList<IPeekableItem> peekableItems)
        {
            var triggerPoint = session.GetTriggerPoint(buffer.CurrentSnapshot);
            if (triggerPoint == null)
                return;

            peekableItems.Add(new MyPeekItem(peekResultFactory));
        }
Example #40
0
 public bool ClearPeekSession(IPeekSession session)
 {
   string file;
   return RefactoringUtil.LoadAndCheckDocument(session.TextView.TextBuffer, out file) && _activePeekSession.Remove(file);
 }
Example #41
0
 public Tuple<string, string> GetExpandedForPeekSession(IPeekSession session)
 {
   string file;
   var status = RefactoringUtil.LoadAndCheckDocument(session.TextView.TextBuffer, out file);
   if(!status) return null;
   var storedSessionData = _activePeekSession[file];
   return new Tuple<string, string>(storedSessionData.ExpandedTactic, storedSessionData.ActiveTactic);
 }
Example #42
0
 public void TriggerNestedPeekSession(ITextView textView, ITrackingPoint triggerPoint, string relationshipName, IPeekSession containingSession)
 {
     throw new NotImplementedException();
 }
Example #43
0
 public void TriggerNestedPeekSession(PeekSessionCreationOptions options, IPeekSession containingSession)
 {
     throw new NotImplementedException();
 }