public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback) { if (relationshipName != PredefinedPeekRelationships.Definitions.Name) { return; } // If task is still running, wait a bit, but not too long. LookupTask.Wait(_shell.IsUnitTestEnvironment ? 50000 : 2000); if (_exception != null) { callback.ReportFailure(_exception); } else if (LookupTask.IsCompleted && LookupTask.Result != null) { resultCollection.Add(LookupTask.Result); } }
public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback) { if (relationshipName != PredefinedPeekRelationships.Definitions.Name) { return; } // Note: this is called on a background thread, but we must block the thread since the API doesn't support proper asynchrony. var workspace = _peekableItem._workspace; var solution = workspace.CurrentSolution; var project = solution.GetProject(_peekableItem._projectId); var compilation = project.GetCompilationAsync(cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken); var symbol = _peekableItem._symbolKey.Resolve(compilation, ignoreAssemblyKey: true, cancellationToken: cancellationToken).Symbol; if (symbol == null) { callback.ReportFailure(new Exception(EditorFeaturesResources.No_information_found)); return; } var sourceLocations = symbol.Locations.Where(l => l.IsInSource).ToList(); if (!sourceLocations.Any()) { // It's a symbol from metadata, so we want to go produce it from metadata var options = _peekableItem._globalOptions.GetMetadataAsSourceOptions(); var declarationFile = _peekableItem._metadataAsSourceFileService.GetGeneratedFileAsync(project, symbol, signaturesOnly: true, options, cancellationToken).WaitAndGetResult_CanCallOnBackground(cancellationToken); var peekDisplayInfo = new PeekResultDisplayInfo(declarationFile.DocumentTitle, declarationFile.DocumentTitle, declarationFile.DocumentTitle, declarationFile.DocumentTitle); var identifierSpan = declarationFile.IdentifierLocation.GetLineSpan().Span; var entityOfInterestSpan = PeekHelpers.GetEntityOfInterestSpan(symbol, workspace, declarationFile.IdentifierLocation, cancellationToken); resultCollection.Add(PeekHelpers.CreateDocumentPeekResult(declarationFile.FilePath, identifierSpan, entityOfInterestSpan, peekDisplayInfo, _peekableItem.PeekResultFactory, isReadOnly: true)); } var processedSourceLocations = 0; foreach (var declaration in sourceLocations) { var declarationLocation = declaration.GetMappedLineSpan(); var entityOfInterestSpan = PeekHelpers.GetEntityOfInterestSpan(symbol, workspace, declaration, cancellationToken); resultCollection.Add(PeekHelpers.CreateDocumentPeekResult(declarationLocation.Path, declarationLocation.Span, entityOfInterestSpan, _peekableItem.PeekResultFactory)); callback.ReportProgress(100 * ++processedSourceLocations / sourceLocations.Count); } }
public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback) { if (relationshipName != PredefinedPeekRelationships.Definitions.Name) { return; } // Note: this is called on a background thread, but we must block the thread since the API doesn't support proper asynchrony. var workspace = _peekableItem._workspace; var solution = workspace.CurrentSolution; var project = solution.GetProject(_peekableItem._projectId); var compilation = project.GetCompilationAsync(cancellationToken).WaitAndGetResult(cancellationToken); var symbol = _peekableItem._symbolKey.Resolve(compilation, ignoreAssemblyKey: true, cancellationToken: cancellationToken).Symbol; if (symbol == null) { callback.ReportFailure(new Exception(EditorFeaturesResources.No_information_found)); return; } var sourceLocations = symbol.Locations.Where(l => l.IsInSource).ToList(); if (!sourceLocations.Any()) { // It's a symbol from metadata, so we want to go produce it from metadata var declarationFile = _peekableItem._metadataAsSourceFileService.GetGeneratedFileAsync(project, symbol, cancellationToken).WaitAndGetResult(cancellationToken); var peekDisplayInfo = new PeekResultDisplayInfo(declarationFile.DocumentTitle, declarationFile.DocumentTitle, declarationFile.DocumentTitle, declarationFile.DocumentTitle); var identifierSpan = declarationFile.IdentifierLocation.GetLineSpan().Span; var entityOfInterestSpan = PeekHelpers.GetEntityOfInterestSpan(symbol, workspace, declarationFile.IdentifierLocation, cancellationToken); resultCollection.Add(PeekHelpers.CreateDocumentPeekResult(declarationFile.FilePath, identifierSpan, entityOfInterestSpan, peekDisplayInfo, _peekableItem.PeekResultFactory, isReadOnly: true)); } int processedSourceLocations = 0; foreach (var declaration in sourceLocations) { var declarationLocation = declaration.GetLineSpan(); var entityOfInterestSpan = PeekHelpers.GetEntityOfInterestSpan(symbol, workspace, declaration, cancellationToken); resultCollection.Add(PeekHelpers.CreateDocumentPeekResult(declarationLocation.Path, declarationLocation.Span, entityOfInterestSpan, _peekableItem.PeekResultFactory)); callback.ReportProgress(100 * ++processedSourceLocations / sourceLocations.Count); } }
public void FindResults(string relationshipName, IPeekResultCollection resultCollection, CancellationToken cancellationToken, IFindPeekResultsCallback callback) { if (relationshipName != PredefinedPeekRelationships.Definitions.Name) { return; } // If task is still running, wait a bit, but not too long. LookupTask.Wait(TestEnvironment.Current != null ? 50000 : 2000); if (_exception != null) { callback.ReportFailure(_exception); } else if (LookupTask.IsCompleted && LookupTask.Result != null) { resultCollection.Add(LookupTask.Result); } }