Example #1
0
        public bool TryGoToDefinition(Document document, int position, CancellationToken cancellationToken)
        {
            var symbol = FindSymbolAsync(document, position, cancellationToken).WaitAndGetResult(cancellationToken);

            if (symbol != null)
            {
                var containingTypeSymbol = GetContainingTypeSymbol(position, document, cancellationToken);

                if (GoToDefinitionHelpers.TryGoToDefinition(symbol, document.Project, _presenters, containingTypeSymbol, throwOnHiddenDefinition: true, cancellationToken: cancellationToken))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #2
0
        public async Task <IEnumerable <INavigableItem> > FindDefinitionsAsync(Document document, int position, CancellationToken cancellationToken)
        {
            var symbol = await FindSymbolAsync(document, position, cancellationToken).ConfigureAwait(false);

            // Try to compute source definitions from symbol.
            var items = symbol != null?NavigableItemFactory.GetItemsFromPreferredSourceLocations(document.Project.Solution, symbol) : null;

            if (items == null || items.IsEmpty())
            {
                // Fallback to asking the navigation definition providers for navigable definition locations.
                items = await GoToDefinitionHelpers.FindExternalDefinitionsAsync(document, position, _externalDefinitionProviders, cancellationToken).ConfigureAwait(false);
            }

            // realize the list here so that the consumer await'ing the result doesn't lazily cause
            // them to be created on an inappropriate thread.
            return(items?.ToList());
        }
Example #3
0
        public bool TryGoToDefinition(Document document, int position, CancellationToken cancellationToken)
        {
            // First try to compute the referenced symbol and attempt to go to definition for the symbol.
            var symbol = FindSymbolAsync(document, position, cancellationToken).WaitAndGetResult(cancellationToken);

            if (symbol == null)
            {
                return(false);
            }

            var isThirdPartyNavigationAllowed = IsThirdPartyNavigationAllowed(symbol, position, document, cancellationToken);

            return(GoToDefinitionHelpers.TryGoToDefinition(symbol,
                                                           document.Project,
                                                           _presenters,
                                                           _streamingPresenters,
                                                           thirdPartyNavigationAllowed: isThirdPartyNavigationAllowed,
                                                           throwOnHiddenDefinition: true,
                                                           cancellationToken: cancellationToken));
        }
Example #4
0
        public bool TryGoToDefinition(Document document, int position, CancellationToken cancellationToken)
        {
            var symbol = FindSymbolAsync(document, position, cancellationToken).WaitAndGetResult(cancellationToken);

            if (symbol != null)
            {
                var isThirdPartyNavigationAllowed = IsThirdPartyNavigationAllowed(symbol, position, document, cancellationToken);

                if (GoToDefinitionHelpers.TryGoToDefinition(symbol,
                                                            document.Project,
                                                            _presenters,
                                                            thirdPartyNavigationAllowed: isThirdPartyNavigationAllowed,
                                                            throwOnHiddenDefinition: true,
                                                            cancellationToken: cancellationToken))
                {
                    return(true);
                }
            }

            return(false);
        }
Example #5
0
        public bool TryGoToDefinition(Document document, int position, CancellationToken cancellationToken)
        {
            // First try to compute the referenced symbol and attempt to go to definition for the symbol.
            var symbol = FindSymbolAsync(document, position, cancellationToken).WaitAndGetResult(cancellationToken);

            if (symbol != null)
            {
                var isThirdPartyNavigationAllowed = IsThirdPartyNavigationAllowed(symbol, position, document, cancellationToken);

                return(GoToDefinitionHelpers.TryGoToDefinition(symbol,
                                                               document.Project,
                                                               _externalDefinitionProviders,
                                                               _presenters,
                                                               thirdPartyNavigationAllowed: isThirdPartyNavigationAllowed,
                                                               throwOnHiddenDefinition: true,
                                                               cancellationToken: cancellationToken));
            }

            // Otherwise, fallback to the external navigation definition providers.
            return(GoToDefinitionHelpers.TryExternalGoToDefinition(document, position, _externalDefinitionProviders, _presenters, cancellationToken));
        }