Esempio n. 1
0
        private static async Task FindImplementationsInCurrentProcessAsync(
            ISymbol symbol, Project project, IFindUsagesContext context, CancellationToken cancellationToken)
        {
            await context.SetSearchTitleAsync(
                string.Format(FeaturesResources._0_implementations,
                              FindUsagesHelpers.GetDisplayName(symbol)),
                cancellationToken).ConfigureAwait(false);

            var solution        = project.Solution;
            var implementations = await FindSourceImplementationsAsync(solution, symbol, cancellationToken).ConfigureAwait(false);

            if (implementations.IsEmpty)
            {
                await context.ReportMessageAsync(FeaturesResources.The_symbol_has_no_implementations, cancellationToken).ConfigureAwait(false);

                return;
            }

            foreach (var implementation in implementations)
            {
                var definitionItem = await implementation.ToClassifiedDefinitionItemAsync(
                    context, solution, FindReferencesSearchOptions.Default, isPrimary : true, includeHiddenLocations : false, cancellationToken).ConfigureAwait(false);

                await context.OnDefinitionFoundAsync(definitionItem, cancellationToken).ConfigureAwait(false);
            }
        }
        /// <summary>
        /// Public helper that we use from features like ObjectBrowser which start with a symbol
        /// and want to push all the references to it into the Streaming-Find-References window.
        /// </summary>
        public static async Task FindSymbolReferencesAsync(
            IFindUsagesContext context, ISymbol symbol, Project project, CancellationToken cancellationToken)
        {
            await context.SetSearchTitleAsync(
                string.Format(FeaturesResources._0_references,
                              FindUsagesHelpers.GetDisplayName(symbol)),
                cancellationToken).ConfigureAwait(false);

            var options = FindReferencesSearchOptions.GetFeatureOptionsForStartingSymbol(symbol);

            // Now call into the underlying FAR engine to find reference.  The FAR
            // engine will push results into the 'progress' instance passed into it.
            // We'll take those results, massage them, and forward them along to the
            // FindReferencesContext instance we were given.
            await FindReferencesAsync(context, symbol, project, options, cancellationToken).ConfigureAwait(false);
        }
        private static async Task FindSymbolReferencesAsync(
            IFindUsagesContext context, Document document, int position, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            // If this is a symbol from a metadata-as-source project, then map that symbol back to a symbol in the primary workspace.
            var symbolAndProjectOpt = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(
                document, position, cancellationToken).ConfigureAwait(false);

            if (symbolAndProjectOpt == null)
            {
                return;
            }

            var(symbol, project) = symbolAndProjectOpt.Value;

            await FindSymbolReferencesAsync(
                context, symbol, project, cancellationToken).ConfigureAwait(false);
        }
Esempio n. 4
0
        public async Task FindImplementationsAsync(
            IFindUsagesContext context, Document document, int position, CancellationToken cancellationToken)
        {
            // If this is a symbol from a metadata-as-source project, then map that symbol back to a symbol in the primary workspace.
            var symbolAndProjectOpt = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync(
                document, position, cancellationToken).ConfigureAwait(false);

            if (symbolAndProjectOpt == null)
            {
                await context.ReportMessageAsync(
                    FeaturesResources.Cannot_navigate_to_the_symbol_under_the_caret, cancellationToken).ConfigureAwait(false);

                return;
            }

            var symbolAndProject = symbolAndProjectOpt.Value;

            await FindImplementationsAsync(
                context, symbolAndProject.symbol, symbolAndProject.project, cancellationToken).ConfigureAwait(false);
        }