public async Task GetSymbolsAsync(GoToSymbolContext context)
        {
            var document          = context.Document;
            var position          = context.Position;
            var cancellationToken = context.CancellationToken;
            var service           = document.GetRequiredLanguageService <IGoToDefinitionSymbolService>();

            // [includeType: false]
            // Enable Ctrl+Click on tokens with aliased, referenced or declared symbol.
            // If the token has none of those but does have a type (mostly literals), we're not interested
            var(symbol, span) = await service.GetSymbolAndBoundSpanAsync(document, position, includeType : false, cancellationToken).ConfigureAwait(false);

            if (symbol == null)
            {
                return;
            }

            var solution    = document.Project.Solution;
            var definitions = await GoToDefinitionHelpers.GetDefinitionsAsync(symbol, solution, thirdPartyNavigationAllowed : true, cancellationToken).ConfigureAwait(false);

            foreach (var definition in definitions)
            {
                if (await definition.CanNavigateToAsync(solution.Workspace, cancellationToken).ConfigureAwait(false))
                {
                    context.AddItem(WellKnownSymbolTypes.Definition, definition);
                }
            }

            context.Span = span;
        }
Example #2
0
        public async Task GetSymbolsAsync(GoToSymbolContext context)
        {
            var document          = context.Document;
            var position          = context.Position;
            var cancellationToken = context.CancellationToken;
            var service           = document.GetLanguageService <IGoToDefinitionSymbolService>();

            // [includeType: false]
            // Enable Ctrl+Click on tokens with aliased, referenced or declared symbol.
            // If the token has none of those but does have a type (mostly literals), we're not interested
            var(symbol, span) = await service.GetSymbolAndBoundSpanAsync(document, position, includeType : false, cancellationToken).ConfigureAwait(false);

            if (symbol == null)
            {
                return;
            }

            // We want ctrl-click GTD to be as close to regular GTD as possible.
            // This means we have to query for "third party navigation", from
            // XAML, etc. That call has to be done on the UI thread.
            await ThreadingContext.JoinableTaskFactory.SwitchToMainThreadAsync(alwaysYield : true, cancellationToken);

            var solution    = document.Project.Solution;
            var definitions = GoToDefinitionHelpers.GetDefinitions(symbol, solution, thirdPartyNavigationAllowed: true, cancellationToken)
                              .WhereAsArray(d => d.CanNavigateTo(solution.Workspace));

            await TaskScheduler.Default;

            foreach (var definition in definitions)
            {
                context.AddItem(WellKnownSymbolTypes.Definition, definition);
            }

            context.Span = span;
        }
Example #3
0
        public async Task GetSymbolsAsync(GoToSymbolContext context)
        {
            var document          = context.Document;
            var position          = context.Position;
            var cancellationToken = context.CancellationToken;

            var service = document.GetLanguageService <IGoToDefinitionSymbolService>();

            var(symbol, span) = await service.GetSymbolAndBoundSpanAsync(document, position, cancellationToken).ConfigureAwait(false);

            if (symbol == null)
            {
                return;
            }

            // We want ctrl-click GTD to be as close to regular GTD as possible.
            // This means we have to query for "third party navigation", from
            // XAML, etc. That call has to be done on the UI thread.
            var definitions = await Task.Factory.StartNew(() =>
                                                          GoToDefinitionHelpers.GetDefinitions(symbol, document.Project, thirdPartyNavigationAllowed : true, cancellationToken : cancellationToken)
                                                          .WhereAsArray(d => d.CanNavigateTo(document.Project.Solution.Workspace)),
                                                          cancellationToken,
                                                          TaskCreationOptions.None,
                                                          ForegroundTaskScheduler).ConfigureAwait(false);

            foreach (var definition in definitions)
            {
                context.AddItem(WellKnownSymbolTypes.Definition, definition);
            }

            context.Span = span;
        }