public async Task <CodeLensDataPointDescriptor?> GetDataAsync(CodeLensDescriptorContext descriptorContext, CancellationToken cancellationToken) { var codeElementKind = GetCodeElementKindsString(Descriptor.Kind); // we always get data through VS rather than Roslyn OOP directly since we want final data rather than // raw data from Roslyn OOP such as razor find all reference results var referenceCount = await _callbackService.InvokeAsync <ReferenceCount>( _owner, nameof(ICodeLensContext.GetReferenceCountAsync), new object[] { Descriptor, descriptorContext }, cancellationToken).ConfigureAwait(false); if (referenceCount == null) { return(null); } var referenceCountString = $"{referenceCount.Count}{(referenceCount.IsCapped ? "+" : string.Empty)}"; return(new CodeLensDataPointDescriptor() { Description = referenceCount.Count == 1 ? string.Format(CodeLensVSResources._0_reference, referenceCountString) : string.Format(CodeLensVSResources._0_references, referenceCountString), IntValue = referenceCount.Count, TooltipText = string.Format(CodeLensVSResources.This_0_has_1_references, codeElementKind, referenceCountString), ImageId = null }); string GetCodeElementKindsString(CodeElementKinds kind) { switch (kind) { case CodeElementKinds.Method: return(CodeLensVSResources.method); case CodeElementKinds.Type: return(CodeLensVSResources.type); case CodeElementKinds.Property: return(CodeLensVSResources.property); default: // code lens engine will catch and ignore exception // basically not showing data point throw new NotSupportedException(nameof(kind)); } } }
private async Task <DpdtBindingReferenceSet?> GetReferenceSetAsync( CodeLensDescriptorContext context, CancellationToken token ) { DpdtBindingReferenceSet?bindings = null; try { bindings = await _callbackService .InvokeAsync <DpdtBindingReferenceSet>( this, nameof(IDpdtCodeLensListener.GetReferenceSet), new object[] { new CodeLensTarget( _descriptor.ProjectGuid, _descriptor.FilePath, (string)context.Properties["FullyQualifiedName"], context.ApplicableSpan.HasValue ? context.ApplicableSpan.Value.Start : (int?)null, context.ApplicableSpan.HasValue ? context.ApplicableSpan.Value.Length : (int?)null ) }, token ) .ConfigureAwait(false) ; } catch (Exception ex) { LogCL(ex); } return(bindings); }
public async Task <CodeLensDataPointDescriptor?> GetDataAsync(CodeLensDescriptorContext descriptorContext, CancellationToken cancellationToken) { var codeElementKind = GetCodeElementKindsString(Descriptor.Kind); // we always get data through VS rather than Roslyn OOP directly since we want final data rather than // raw data from Roslyn OOP such as razor find all reference results var referenceCountOpt = await _callbackService.InvokeAsync <ReferenceCount?>( _owner, nameof(ICodeLensContext.GetReferenceCountAsync), new object[] { Descriptor, descriptorContext }, cancellationToken).ConfigureAwait(false); if (!referenceCountOpt.HasValue) { return(null); } var referenceCount = referenceCountOpt.Value; var referenceCountString = $"{referenceCount.Count}{(referenceCount.IsCapped ? "+" : string.Empty)}"; return(new CodeLensDataPointDescriptor() { Description = referenceCount.Count == 1 ? string.Format(CodeLensVSResources._0_reference, referenceCountString) : string.Format(CodeLensVSResources._0_references, referenceCountString), IntValue = referenceCount.Count, TooltipText = string.Format(CodeLensVSResources.This_0_has_1_references, codeElementKind, referenceCountString), ImageId = null });