public async Task <ImmutableArray <INavigableItem> > FindDefinitionsAsync(
            Document document,
            int position,
            CancellationToken cancellationToken
            )
        {
            var symbolService = document.GetRequiredLanguageService <IGoToDefinitionSymbolService>();

            var(symbol, _) = await symbolService
                             .GetSymbolAndBoundSpanAsync(
                document,
                position,
                includeType : true,
                cancellationToken
                )
                             .ConfigureAwait(false);

            // Try to compute source definitions from symbol.
            return(symbol != null
              ? NavigableItemFactory.GetItemsFromPreferredSourceLocations(
                       document.Project.Solution,
                       symbol,
                       displayTaggedParts : null,
                       cancellationToken : cancellationToken
                       )
              : ImmutableArray <INavigableItem> .Empty);
        }
Exemple #2
0
        public async Task <IEnumerable <INavigableItem> > FindDefinitionsAsync(Document document, int position, CancellationToken cancellationToken)
        {
            var symbol = await FindSymbolAsync(document, position, 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(NavigableItemFactory.GetItemsFromPreferredSourceLocations(document.Project.Solution, symbol).ToList());
        }
        private static IEnumerable <INavigableItem> CreateItemsForImplementation(ISymbol implementation, Solution solution)
        {
            var symbolDisplayService = solution.Workspace.Services.GetLanguageServices(implementation.Language).GetRequiredService <ISymbolDisplayService>();

            return(NavigableItemFactory.GetItemsFromPreferredSourceLocations(
                       solution,
                       implementation,
                       displayString: symbolDisplayService.ToDisplayString(implementation)));
        }
Exemple #4
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, displayTaggedParts : null, cancellationToken : cancellationToken)
                : null;

            // 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());
        }
Exemple #5
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());
        }
Exemple #6
0
        private static async Task <LSP.Location[]> GetSymbolDefinitionLocationsAsync(XamlSymbolDefinition symbolDefinition, RequestContext context, IMetadataAsSourceFileService metadataAsSourceFileService, CancellationToken cancellationToken)
        {
            Contract.ThrowIfNull(symbolDefinition.Symbol);

            using var _ = ArrayBuilder <LSP.Location> .GetInstance(out var locations);

            var symbol = symbolDefinition.Symbol;

            var items = NavigableItemFactory.GetItemsFromPreferredSourceLocations(context.Solution, symbol, displayTaggedParts: null, cancellationToken);

            if (items.Any())
            {
                foreach (var item in items)
                {
                    var location = await ProtocolConversions.TextSpanToLocationAsync(
                        item.Document, item.SourceSpan, item.IsStale, cancellationToken).ConfigureAwait(false);

                    locations.AddIfNotNull(location);
                }
            }
            else
            {
                var metadataLocation = symbol.Locations.Where(loc => loc.IsInMetadata).FirstOrDefault();
                if (metadataLocation != null && metadataAsSourceFileService.IsNavigableMetadataSymbol(symbol))
                {
                    var project = context.Document?.GetCodeProject();
                    if (project != null)
                    {
                        var declarationFile = await metadataAsSourceFileService.GetGeneratedFileAsync(project, symbol, allowDecompilation : false, cancellationToken).ConfigureAwait(false);

                        var linePosSpan = declarationFile.IdentifierLocation.GetLineSpan().Span;
                        locations.Add(new LSP.Location
                        {
                            Uri   = new Uri(declarationFile.FilePath),
                            Range = ProtocolConversions.LinePositionToRange(linePosSpan),
                        });
                    }
                }
            }

            return(locations.ToArray());
        }