Exemplo n.º 1
0
        private static void NavigateToQuickInfoTarget(string navigationTarget, Document document, IStreamingFindUsagesPresenter streamingPresenter)
        {
            var navigateToLinkService = document.Project.Solution.Workspace.Services.GetRequiredService <INavigateToLinkService>();

            if (Uri.TryCreate(navigationTarget, UriKind.Absolute, out var absoluteUri))
            {
                navigateToLinkService.TryNavigateToLinkAsync(absoluteUri, CancellationToken.None);
                return;
            }

            SymbolKeyResolution resolvedSymbolKey;

            try
            {
                resolvedSymbolKey = SymbolKey.ResolveString(navigationTarget, document.Project.GetCompilationAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None), cancellationToken: CancellationToken.None);
            }
            catch
            {
                // Ignore symbol resolution failures. It likely is just a badly formed URI.
                return;
            }

            if (resolvedSymbolKey.GetAnySymbol() is { } symbol)
            {
                GoToDefinitionHelpers.TryGoToDefinition(symbol, document.Project, streamingPresenter, CancellationToken.None);
                return;
            }
        }
Exemplo n.º 2
0
        private static void NavigateToQuickInfoTarget(
            string navigationTarget,
            Workspace workspace,
            DocumentId documentId,
            IThreadingContext threadingContext,
            IStreamingFindUsagesPresenter streamingPresenter)
        {
            var solution = workspace.CurrentSolution;
            SymbolKeyResolution resolvedSymbolKey;

            try
            {
                var project = solution.GetRequiredProject(documentId.ProjectId);
                resolvedSymbolKey = SymbolKey.ResolveString(navigationTarget, project.GetRequiredCompilationAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None), cancellationToken: CancellationToken.None);
            }
            catch
            {
                // Ignore symbol resolution failures. It likely is just a badly formed URI.
                return;
            }

            if (resolvedSymbolKey.GetAnySymbol() is { } symbol)
            {
                GoToDefinitionHelpers.TryGoToDefinition(symbol, solution, threadingContext, streamingPresenter, CancellationToken.None);
                return;
            }
        }
Exemplo n.º 3
0
        public override bool TryGoToDefinition(
            ISymbol symbol,
            Project project,
            CancellationToken cancellationToken
            )
        {
            if (
                !TryResolveSymbol(
                    symbol,
                    project,
                    cancellationToken,
                    out var searchSymbol,
                    out var searchProject
                    )
                )
            {
                return(false);
            }

            return(GoToDefinitionHelpers.TryGoToDefinition(
                       searchSymbol,
                       searchProject.Solution,
                       _threadingContext,
                       _streamingPresenter.Value,
                       cancellationToken
                       ));
        }
 public void Navigate(INavigableRelationship relationship) =>
     _waitIndicator.Wait(
         title: EditorFeaturesResources.Go_to_Definition,
         message: EditorFeaturesResources.Navigating_to_definition,
         allowCancel: true,
         showProgress: false,
         action: context => GoToDefinitionHelpers.TryGoToDefinition(
             _definitions,
             _document.Project.Solution,
             _definitions[0].NameDisplayParts.GetFullText(),
             _threadingContext,
             _presenter));
Exemplo n.º 5
0
 public void Navigate(INavigableRelationship relationship) =>
 _uiThreadOperationExecutor.Execute(
     title: EditorFeaturesResources.Go_to_Definition,
     defaultDescription: EditorFeaturesResources.Navigating_to_definition,
     allowCancellation: true,
     showProgress: false,
     action: context => GoToDefinitionHelpers.TryGoToDefinition(
         _definitions,
         _document.Project.Solution,
         _definitions[0].NameDisplayParts.GetFullText(),
         _threadingContext,
         _presenter,
         context.UserCancellationToken));
        public override bool TryGoToDefinition(ISymbol symbol, Project project, CancellationToken cancellationToken)
        {
            if (!_navigableItemsPresenters.Any())
            {
                return(false);
            }

            ISymbol searchSymbol;
            Project searchProject;

            if (!TryResolveSymbol(symbol, project, cancellationToken, out searchSymbol, out searchProject))
            {
                return(false);
            }

            return(GoToDefinitionHelpers.TryGoToDefinition(
                       searchSymbol, searchProject, _externalDefinitionProviders, _navigableItemsPresenters, cancellationToken: cancellationToken));
        }
Exemplo n.º 7
0
        public override bool TryGoToDefinition(ISymbol symbol, Project project, CancellationToken cancellationToken)
        {
            if (!_navigableItemsPresenters.Any())
            {
                return(false);
            }

            ISymbol searchSymbol;
            Project searchProject;

            if (!TryResolveSymbol(symbol, project, cancellationToken, out searchSymbol, out searchProject))
            {
                return(false);
            }

            return(GoToDefinitionHelpers.TryGoToDefinition(
                       searchSymbol, searchProject, _navigableItemsPresenters,
                       containingTypeSymbol: null, throwOnHiddenDefinition: false, cancellationToken: cancellationToken));
        }
Exemplo n.º 8
0
        public override bool TryGoToDefinition(
            ISymbol symbol, Project project, CancellationToken cancellationToken)
        {
            if (!_navigableItemsPresenters.Any() &&
                !_streamingPresenters.Any())
            {
                return(false);
            }

            if (!TryResolveSymbol(symbol, project, cancellationToken,
                                  out var searchSymbol, out var searchProject))
            {
                return(false);
            }

            return(GoToDefinitionHelpers.TryGoToDefinition(
                       searchSymbol, searchProject,
                       _navigableItemsPresenters, _streamingPresenters, cancellationToken));
        }
 private bool TryGoToImplementations(
     ISymbol symbol, Project project, ImmutableArray <ISymbol> implementations, CancellationToken cancellationToken, out string message)
 {
     if (implementations.Length == 0)
     {
         message = EditorFeaturesResources.The_symbol_has_no_implementations;
         return(false);
     }
     else if (implementations.Length == 1)
     {
         GoToDefinitionHelpers.TryGoToDefinition(
             implementations.Single(), project, _navigableItemPresenters,
             SpecializedCollections.EmptyEnumerable <Lazy <IStreamingFindUsagesPresenter> >(),
             cancellationToken);
         message = null;
         return(true);
     }
     else
     {
         return(TryPresentInNavigableItemsPresenter(symbol, project, implementations, out message));
     }
 }
Exemplo n.º 10
0
        private static void NavigateToQuickInfoTarget(
            string navigationTarget,
            Document document,
            IThreadingContext threadingContext,
            IStreamingFindUsagesPresenter streamingPresenter)
        {
            SymbolKeyResolution resolvedSymbolKey;

            try
            {
                resolvedSymbolKey = SymbolKey.ResolveString(navigationTarget, document.Project.GetCompilationAsync(CancellationToken.None).WaitAndGetResult(CancellationToken.None), cancellationToken: CancellationToken.None);
            }
            catch
            {
                // Ignore symbol resolution failures. It likely is just a badly formed URI.
                return;
            }

            if (resolvedSymbolKey.GetAnySymbol() is { } symbol)
            {
                GoToDefinitionHelpers.TryGoToDefinition(symbol, document.Project.Solution, threadingContext, streamingPresenter, CancellationToken.None);
                return;
            }
        }