/
githubmirror
/
roslyn
Обзор
Документация
Войти
/
githubmirror
/
roslyn
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/EditorFeatures/Core/NavigateTo/NavigateToHelpers.cs
59 строк
3 KB
Tomáš Matoušek
More improvements to source packages (#78587)
16 май 2025, 01:46
Не верифицирован
16 май 2025, 01:46
015a854
Код
Авторство
О чём код?
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. // See the LICENSE file in the project root for more information. using System.Threading.Tasks; using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.ErrorReporting; using Microsoft.CodeAnalysis.NavigateTo; using Microsoft.CodeAnalysis.Navigation; using Microsoft.CodeAnalysis.Shared.TestHooks; using Microsoft.VisualStudio.Utilities; namespace Microsoft.CodeAnalysis.Editor.NavigateTo; internal static class NavigateToHelpers { public static void NavigateTo( INavigateToSearchResult searchResult, IThreadingContext threadingContext, IUIThreadOperationExecutor threadOperationExecutor, IAsynchronousOperationListener asyncListener) { var token = asyncListener.BeginAsyncOperation(nameof(NavigateTo)); NavigateToAsync(searchResult, threadingContext, threadOperationExecutor) .ReportNonFatalErrorAsync() .CompletesAsyncOperation(token); } private static async Task NavigateToAsync( INavigateToSearchResult searchResult, IThreadingContext threadingContext, IUIThreadOperationExecutor threadOperationExecutor) { var document = searchResult.NavigableItem.Document; if (document == null) return; var workspace = document.Workspace; Contract.ThrowIfNull(workspace, "Workspace is null, which should only happen in OOP where navigation is not possible anyway."); var navigationService = workspace.Services.GetRequiredService<IDocumentNavigationService>(); // Document tabs opened by NavigateTo are carefully created as preview or regular tabs // by them; trying to specifically open them in a particular kind of tab here has no // effect. // // In the case of a stale item, don't require that the span be in bounds of the document // as it exists right now. using var context = threadOperationExecutor.BeginExecute( EditorFeaturesResources.Navigating_to_definition, EditorFeaturesResources.Navigating_to_definition, allowCancellation: true, showProgress: false); await navigationService.TryNavigateToSpanAsync( threadingContext, workspace, document.Id, searchResult.NavigableItem.SourceSpan, NavigationOptions.Default, allowInvalidSpan: searchResult.NavigableItem.IsStale, context.UserCancellationToken).ConfigureAwait(false); } }