Exemplo n.º 1
0
        private async Task UpdateForCaretPositionAsync(SnapshotPoint pointInRoslynSnapshot, CancellationToken cancellationToken)
        {
            try
            {
                await _asyncListener.Delay(TimeSpan.FromMilliseconds(250), cancellationToken).ConfigureAwait(false);

                // If it's not open, don't do anything, since if we are going to show locations in metadata that might
                // be expensive. This doesn't cause a functional issue, since opening the window clears whatever was previously there
                // so the user won't notice we weren't doing anything when it was open.
                if (!await _codeDefinitionWindowService.IsWindowOpenAsync(cancellationToken).ConfigureAwait(false))
                {
                    return;
                }

                var document = pointInRoslynSnapshot.Snapshot.GetOpenDocumentInCurrentContextWithChanges();
                if (document == null)
                {
                    return;
                }

                // Ensure we're off the UI thread for the rest of this since we don't want to be computing locations on the UI thread.
                await TaskScheduler.Default;

                var locations = await GetContextFromPointAsync(document, pointInRoslynSnapshot, cancellationToken).ConfigureAwait(true);

                await _codeDefinitionWindowService.SetContextAsync(locations, cancellationToken).ConfigureAwait(false);
            }
            catch (OperationCanceledException)
            {
            }
            catch (Exception ex) when(FatalError.ReportAndCatch(ex))
            {
            }
        }