private static async Task FindReferencesAsync(SymbolListItem symbolListItem, Project project, CodeAnalysis.FindUsages.FindUsagesContext context) { var compilation = await project.GetCompilationAsync(context.CancellationToken).ConfigureAwait(false); var symbol = symbolListItem.ResolveSymbol(compilation); if (symbol != null) { await AbstractFindUsagesService.FindSymbolReferencesAsync(context, symbol, project).ConfigureAwait(false); } }
internal IVsNavInfo GetNavInfo(SymbolListItem symbolListItem, bool useExpandedHierarchy) { var project = GetProject(symbolListItem); if (project == null) { return(null); } var compilation = symbolListItem.GetCompilation(this.Workspace); if (compilation == null) { return(null); } var symbol = symbolListItem.ResolveSymbol(compilation); if (symbol == null) { return(null); } if (symbolListItem is MemberListItem) { return(this.LibraryService.NavInfoFactory.CreateForMember(symbol, project, compilation, useExpandedHierarchy)); } else if (symbolListItem is TypeListItem) { return(this.LibraryService.NavInfoFactory.CreateForType((INamedTypeSymbol)symbol, project, compilation, useExpandedHierarchy)); } else if (symbolListItem is NamespaceListItem) { return(this.LibraryService.NavInfoFactory.CreateForNamespace((INamespaceSymbol)symbol, project, compilation, useExpandedHierarchy)); } return(this.LibraryService.NavInfoFactory.CreateForProject(project)); }
internal IVsNavInfo GetNavInfo(SymbolListItem symbolListItem, bool useExpandedHierarchy) { var project = GetProject(symbolListItem); if (project == null) { return(null); } var compilation = symbolListItem.GetCompilation(this.Workspace); if (compilation == null) { return(null); } var symbol = symbolListItem.ResolveSymbol(compilation); if (symbol == null) { return(null); } if (symbolListItem is MemberListItem) { return(GetMemberNavInfo(symbol, project, compilation, useExpandedHierarchy)); } else if (symbolListItem is TypeListItem) { return(GetTypeNavInfo((INamedTypeSymbol)symbol, project, compilation, useExpandedHierarchy)); } else if (symbolListItem is NamespaceListItem) { return(GetNamespaceNavInfo((INamespaceSymbol)symbol, project, compilation, useExpandedHierarchy)); } return(GetProjectNavInfo(project)); }
internal override object GetBrowseObject(SymbolListItem symbolListItem) { var compilation = symbolListItem.GetCompilation(this); if (compilation == null) { return(null); } var symbol = symbolListItem.ResolveSymbol(compilation); var sourceLocation = symbol.Locations.Where(l => l.IsInSource).FirstOrDefault(); if (sourceLocation == null) { return(null); } var projectId = symbolListItem.ProjectId; if (projectId == null) { return(null); } var project = this.CurrentSolution.GetProject(projectId); if (project == null) { return(null); } var codeModelService = project.LanguageServices.GetService <ICodeModelService>(); if (codeModelService == null) { return(null); } var tree = sourceLocation.SourceTree; var document = project.GetDocument(tree); var vsFileCodeModel = this.GetFileCodeModel(document.Id); var fileCodeModel = ComAggregate.GetManagedObject <FileCodeModel>(vsFileCodeModel); if (fileCodeModel != null) { var syntaxNode = tree.GetRoot().FindNode(sourceLocation.SourceSpan); while (syntaxNode != null) { if (!codeModelService.TryGetNodeKey(syntaxNode).IsEmpty) { break; } syntaxNode = syntaxNode.Parent; } if (syntaxNode != null) { var codeElement = fileCodeModel.GetOrCreateCodeElement <EnvDTE.CodeElement>(syntaxNode); if (codeElement != null) { return(codeElement); } } } return(null); }
internal override object?GetBrowseObject(SymbolListItem symbolListItem) { var compilation = symbolListItem.GetCompilation(this); if (compilation == null) { return(null); } var symbol = symbolListItem.ResolveSymbol(compilation); var sourceLocation = symbol.Locations.Where(l => l.IsInSource).FirstOrDefault(); if (sourceLocation == null) { return(null); } var projectId = symbolListItem.ProjectId; if (projectId == null) { return(null); } var project = this.CurrentSolution.GetProject(projectId); if (project == null) { return(null); } var codeModelService = project.LanguageServices.GetService <ICodeModelService>(); if (codeModelService == null) { return(null); } var tree = sourceLocation.SourceTree; Contract.ThrowIfNull(tree, "We have a location that was in source, but doesn't have a SourceTree."); var document = project.GetDocument(tree); Contract.ThrowIfNull(document, "We have a symbol coming from a tree, and that tree isn't in the Project it supposedly came from."); var vsFileCodeModel = this.GetFileCodeModel(document.Id); var fileCodeModel = ComAggregate.GetManagedObject <FileCodeModel>(vsFileCodeModel); if (fileCodeModel != null) { SyntaxNode?syntaxNode = tree.GetRoot().FindNode(sourceLocation.SourceSpan); while (syntaxNode != null) { if (!codeModelService.TryGetNodeKey(syntaxNode).IsEmpty) { break; } syntaxNode = syntaxNode.Parent; } if (syntaxNode != null) { var codeElement = fileCodeModel.GetOrCreateCodeElement <EnvDTE.CodeElement>(syntaxNode); if (codeElement != null) { return(codeElement); } } } return(null); }