Ejemplo n.º 1
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));
                }
            }
        }
Ejemplo n.º 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);
            });
        }
Ejemplo n.º 3
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));
                    }
                }
            }
        }
Ejemplo n.º 4
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);
                }
            });
        }
Ejemplo n.º 5
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,
            }));
        }
Ejemplo n.º 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));
            });
        }
Ejemplo n.º 7
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]));
        }
Ejemplo n.º 8
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);
                }
            }
        }
Ejemplo n.º 9
0
        public void AugmentPeekSession(IPeekSession session, IList <IPeekableItem> peekableItems)
        {
            var triggerPoint = session.GetTriggerPoint(buffer.CurrentSnapshot);

            if (triggerPoint == null)
            {
                return;
            }

            peekableItems.Add(new MyPeekItem(peekResultFactory));
        }
Ejemplo n.º 10
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));
        }
        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));
        }
Ejemplo n.º 12
0
        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();
            }
        }
Ejemplo n.º 13
0
        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));
        }
        /// <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));
        }
Ejemplo n.º 15
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);
                    }
                }
            }
        }
Ejemplo n.º 16
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)
        {
            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;

                // LookUp for the BaseType, reading the TokenList (From left to right)
                var location = _textBuffer.FindLocation(triggerPoint);
                if (location == null)
                {
                    return;
                }

                CompletionState state;
                var             tokenList = XSharpTokenTools.GetTokensUnderCursor(location, out state);
                var             result    = new List <IXSymbol>();
                result.AddRange(XSharpLookup.RetrieveElement(location, tokenList, state, out var notProcessed, true));
                //
                if (result.Count > 0)
                {
                    if (result[0] is XSourceSymbol symbol)
                    {
                        peekableItems.Add(new XSharpDefinitionPeekItem(symbol, _peekResultFactory));
                    }
                    else if (result[0] is XPESymbol pesymbol)
                    {
                        XPETypeSymbol petype;
                        if (pesymbol is XPETypeSymbol)
                        {
                            petype = (XPETypeSymbol)pesymbol;
                        }
                        else if (pesymbol is XPEMemberSymbol member)
                        {
                            petype = (XPETypeSymbol)member.Parent;
                        }
                        else
                        {
                            return;
                        }
                        var file   = XSharpGotoDefinition.CreateFileForSystemType(petype, pesymbol);
                        var entity = XSharpGotoDefinition.FindElementInFile(file, petype, pesymbol);
                        if (entity != null)
                        {
                            peekableItems.Add(new XSharpDefinitionPeekItem(entity, _peekResultFactory));
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                XSettings.LogException(ex, "XSharpPeekItemSource.AugmentPeekSession failed : ");
            }
            finally
            {
                ModelWalker.Resume();
            }
        }
Ejemplo n.º 18
0
        public void AugmentPeekSession(IPeekSession session, IList<IPeekableItem> peekableItems)
        {
            var triggerPoint = session.GetTriggerPoint(buffer.CurrentSnapshot);
            if (triggerPoint == null)
                return;

            peekableItems.Add(new MyPeekItem(peekResultFactory));
        }