private static async Task FindImplementationsInCurrentProcessAsync( ISymbol symbol, Project project, IFindUsagesContext context) { var cancellationToken = context.CancellationToken; var solution = project.Solution; var(implementations, message) = await FindSourceImplementationsAsync( solution, symbol, cancellationToken).ConfigureAwait(false); if (message != null) { await context.ReportMessageAsync(message).ConfigureAwait(false); return; } await context.SetSearchTitleAsync( string.Format(EditorFeaturesResources._0_implementations, FindUsagesHelpers.GetDisplayName(symbol))).ConfigureAwait(false); foreach (var implementation in implementations) { var definitionItem = await implementation.ToClassifiedDefinitionItemAsync( solution, isPrimary : true, includeHiddenLocations : false, FindReferencesSearchOptions.Default, cancellationToken).ConfigureAwait(false); await context.OnDefinitionFoundAsync(definitionItem).ConfigureAwait(false); } }
public async Task FindBasesAsync(Document document, int position, IFindUsagesContext context) { var cancellationToken = context.CancellationToken; var symbolAndProjectOpt = await FindUsagesHelpers.GetRelevantSymbolAndProjectAtPositionAsync( document, position, cancellationToken).ConfigureAwait(false); if (symbolAndProjectOpt == null) { await context.ReportMessageAsync( EditorFeaturesResources.Cannot_navigate_to_the_symbol_under_the_caret).ConfigureAwait(false); return; } var(symbol, project) = symbolAndProjectOpt.Value; var bases = FindBaseHelpers.FindBases( symbol, project, cancellationToken); await context.SetSearchTitleAsync( string.Format(EditorFeaturesResources._0_bases, FindUsagesHelpers.GetDisplayName(symbol))).ConfigureAwait(false); var found = false; // For each potential base, try to find its definition in sources. // If found, add it's definitionItem to the context. // If not found but the symbol is from metadata, create it's definition item from metadata and add to the context. foreach (var baseSymbol in bases) { var sourceDefinition = await SymbolFinder.FindSourceDefinitionAsync( SymbolAndProjectId.Create(baseSymbol, project.Id), project.Solution, cancellationToken).ConfigureAwait(false); if (sourceDefinition.Symbol != null) { var definitionItem = await sourceDefinition.Symbol.ToClassifiedDefinitionItemAsync( project.Solution.GetProject(sourceDefinition.ProjectId), includeHiddenLocations : false, FindReferencesSearchOptions.Default, cancellationToken : cancellationToken) .ConfigureAwait(false); await context.OnDefinitionFoundAsync(definitionItem).ConfigureAwait(false); found = true; } else if (baseSymbol.Locations.Any(l => l.IsInMetadata)) { var definitionItem = baseSymbol.ToNonClassifiedDefinitionItem( project, includeHiddenLocations: true); await context.OnDefinitionFoundAsync(definitionItem).ConfigureAwait(false); found = true; } } if (!found) { await context.ReportMessageAsync(EditorFeaturesResources.The_symbol_has_no_base) .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) { await context.SetSearchTitleAsync(string.Format(EditorFeaturesResources._0_references, FindUsagesHelpers.GetDisplayName(symbol))).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).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(EditorFeaturesResources._0_references, FindUsagesHelpers.GetDisplayName(symbol))).ConfigureAwait(false); var progressAdapter = new FindReferencesProgressAdapter(project.Solution, context); // 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 SymbolFinder.FindReferencesAsync( SymbolAndProjectId.Create(symbol, project.Id), project.Solution, progressAdapter, documents : null, cancellationToken : cancellationToken).ConfigureAwait(false); }
public async Task FindImplementationsAsync( Document document, int position, IFindUsagesContext context) { var cancellationToken = context.CancellationToken; var tuple = await FindUsagesHelpers.FindImplementationsAsync( document, position, cancellationToken).ConfigureAwait(false); if (tuple == null) { await context.ReportMessageAsync( EditorFeaturesResources.Cannot_navigate_to_the_symbol_under_the_caret).ConfigureAwait(false); return; } var message = tuple.Value.message; if (message != null) { await context.ReportMessageAsync(message).ConfigureAwait(false); return; } await context.SetSearchTitleAsync( string.Format(EditorFeaturesResources._0_implementations, FindUsagesHelpers.GetDisplayName(tuple.Value.symbol))).ConfigureAwait(false); var project = tuple.Value.project; foreach (var implementation in tuple.Value.implementations) { var definitionItem = await implementation.ToClassifiedDefinitionItemAsync( project, includeHiddenLocations : false, FindReferencesSearchOptions.Default, cancellationToken : cancellationToken).ConfigureAwait(false); await context.OnDefinitionFoundAsync(definitionItem).ConfigureAwait(false); } }
public static async Task FindSymbolReferencesAsync( IFindUsagesContext context, ISymbol symbol, Project project) { var solution = project.Solution; var monikerUsagesService = solution.Workspace.Services.GetRequiredService <IFindSymbolMonikerUsagesService>(); await context.SetSearchTitleAsync(string.Format(EditorFeaturesResources._0_references, FindUsagesHelpers.GetDisplayName(symbol))).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. // // Kick off work to search the online code index system in parallel. // // Do both in parallel so we can get all the results as soon as possible. await Task.WhenAll( FindReferencesAsync(context, symbol, project, options), FindSymbolMonikerReferencesAsync(monikerUsagesService, symbol, context)).ConfigureAwait(false); }
private async Task <bool> TryFindLiteralReferencesAsync( Document document, int position, IFindUsagesContext context) { var cancellationToken = context.CancellationToken; cancellationToken.ThrowIfCancellationRequested(); var syntaxTree = await document.GetRequiredSyntaxTreeAsync(cancellationToken).ConfigureAwait(false); var syntaxFacts = document.GetRequiredLanguageService <ISyntaxFactsService>(); // Currently we only support FAR for numbers, strings and characters. We don't // bother with true/false/null as those are likely to have way too many results // to be useful. var token = await syntaxTree.GetTouchingTokenAsync( position, t => syntaxFacts.IsNumericLiteral(t) || syntaxFacts.IsCharacterLiteral(t) || syntaxFacts.IsStringLiteral(t), cancellationToken).ConfigureAwait(false); if (token.RawKind == 0) { return(false); } // Searching for decimals not supported currently. Our index can only store 64bits // for numeric values, and a decimal won't fit within that. var tokenValue = token.Value; if (tokenValue == null || tokenValue is decimal) { return(false); } if (token.Parent is null) { return(false); } var semanticModel = await document.GetRequiredSemanticModelAsync(cancellationToken).ConfigureAwait(false); var symbol = semanticModel.GetSymbolInfo(token.Parent).Symbol ?? semanticModel.GetDeclaredSymbol(token.Parent); // Numeric labels are available in VB. In that case we want the normal FAR engine to // do the searching. For these literals we want to find symbolic results and not // numeric matches. if (symbol is ILabelSymbol) { return(false); } // Use the literal to make the title. Trim literal if it's too long. var title = syntaxFacts.ConvertToSingleLine(token.Parent).ToString(); if (title.Length >= 10) { title = title.Substring(0, 10) + "..."; } var searchTitle = string.Format(EditorFeaturesResources._0_references, title); await context.SetSearchTitleAsync(searchTitle).ConfigureAwait(false); var solution = document.Project.Solution; // There will only be one 'definition' that all matching literal reference. // So just create it now and report to the context what it is. var definition = DefinitionItem.CreateNonNavigableItem( ImmutableArray.Create(TextTags.StringLiteral), ImmutableArray.Create(new TaggedText(TextTags.Text, searchTitle))); await context.OnDefinitionFoundAsync(definition).ConfigureAwait(false); var progressAdapter = new FindLiteralsProgressAdapter(context, definition); // 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 // FindUsagesContext instance we were given. await SymbolFinder.FindLiteralReferencesAsync( tokenValue, Type.GetTypeCode(tokenValue.GetType()), solution, progressAdapter, cancellationToken).ConfigureAwait(false); return(true); }
public Task SetSearchTitleAsync(string title) => _context.SetSearchTitleAsync(title).AsTask();
public ValueTask SetSearchTitleAsync(string title, CancellationToken cancellationToken) => _context.SetSearchTitleAsync(title, cancellationToken);
public Task SetSearchTitleAsync(string title) { return(_context.SetSearchTitleAsync(title)); }
public Task SetSearchTitleAsync(string title) => _underlyingContext.SetSearchTitleAsync(title);
public Task SetSearchTitleAsync(string title) { return(_context.SetSearchTitleAsync(title, _cancellationToken).AsTask()); }