public override RichText GetSignature(string[] namedArguments, AnnotationsDisplayKind showAnnotations, out TextRange[] parameterRanges, out int[] mapToOriginalOrder, out ExtensionMethodInfo extensionMethodInfo) { var parameters = myCandidate.StaticParameters; var text = new StringBuilder(myTypeName + "<"); var newParameterRanges = new TextRange[parameters.Length]; var originalOrder = new int[parameters.Length]; for (var i = 0; i < parameters.Length; i++) { var paramRangeStart = text.Length; text.Append(parameters[i].Display); var paramRangeEnd = text.Length; newParameterRanges[i] = new TextRange(paramRangeStart, paramRangeEnd); if (i < parameters.Length - 1) { text.Append(", "); } } text.Append(">"); extensionMethodInfo = ExtensionMethodInfo.NoExtension; parameterRanges = newParameterRanges; mapToOriginalOrder = originalOrder; return(text.ToString()); }
private static void MigrateValue( [NotNull] IContextBoundSettingsStore store, [NotNull] Expression <Func <IdentifierTooltipSettings, AnnotationsDisplayKind> > oldSettingExpr, [NotNull] Expression <Func <IdentifierTooltipSettings, AttributesDisplayKind> > newSettingExpr) { if (!store.IsEntryEqualToDefault(oldSettingExpr) && store.IsEntryEqualToDefault(newSettingExpr)) { AnnotationsDisplayKind annotationsDisplayKind = store.GetValue(oldSettingExpr); store.SetValue(newSettingExpr, annotationsDisplayKind.ToAttributesDisplayKind()); } }
public RichText GetSignature( string[] namedArguments, AnnotationsDisplayKind showAnnotations, out TextRange[] parameterRanges, out int[] mapToOriginalOrder, out ExtensionMethodInfo extensionMethodInfo) { // TODO: handle named arguments with reordering; currently falling back to non-colored display if (namedArguments.Any(s => s != null)) { string signature = UnderlyingCandidate.GetSignature(namedArguments, showAnnotations, out parameterRanges, out mapToOriginalOrder, out extensionMethodInfo); if (!IsIdentityMap(mapToOriginalOrder)) { return(signature); } } var options = PresenterOptions.ForParameterInfo(_settings, showAnnotations); var highlighterIdProvider = _highlighterIdProviderFactory.CreateProvider(_settings); PresentedInfo presentedInfo; InvocationCandidate invocationCandidate = UnderlyingCandidate.InvocationCandidate; var elementInstance = new DeclaredElementInstance(invocationCandidate.Element, invocationCandidate.Substitution); RichText richText = _colorizerPresenter.TryPresent(elementInstance, options, UnderlyingCandidate.Language, highlighterIdProvider, out presentedInfo); if (richText == null) { return(UnderlyingCandidate.GetSignature(namedArguments, showAnnotations, out parameterRanges, out mapToOriginalOrder, out extensionMethodInfo)); } if (presentedInfo.Parameters.Count == 0) { parameterRanges = EmptyArray <TextRange> .Instance; mapToOriginalOrder = EmptyArray <int> .Instance; extensionMethodInfo = ExtensionMethodInfo.NoExtension; } else if (presentedInfo.IsExtensionMethod && UnderlyingCandidate.InvocationCandidate.IsExtensionMethod) { parameterRanges = presentedInfo.Parameters.Skip(1).ToArray(); mapToOriginalOrder = CreateOffsetMap(presentedInfo.Parameters.Count - 1, 1); TextRange firstParameterRange = presentedInfo.Parameters[0].TrimLeft(5); // keeps "this " highlighted with the keyword color extensionMethodInfo = new ExtensionMethodInfo(firstParameterRange, TextRange.InvalidRange); } else { parameterRanges = presentedInfo.Parameters.ToArray(); mapToOriginalOrder = CreateOffsetMap(presentedInfo.Parameters.Count, 0); extensionMethodInfo = ExtensionMethodInfo.NoExtension; } return(richText); }
public static AttributesDisplayKind ToAttributesDisplayKind(this AnnotationsDisplayKind annotationsDisplayKind) { switch (annotationsDisplayKind) { case AnnotationsDisplayKind.None: return(AttributesDisplayKind.Never); case AnnotationsDisplayKind.Nullness: return(AttributesDisplayKind.NullnessAnnotations); case AnnotationsDisplayKind.All: return(AttributesDisplayKind.AllAnnotations); default: return(AttributesDisplayKind.Never); } }
public override RichText GetSignature(string[] namedArguments, AnnotationsDisplayKind showAnnotations, out TextRange[] parameterRanges, out int[] mapToOriginalOrder, out ExtensionMethodInfo extensionMethodInfo) { var parameters = myCandidate.Parameters; var text = new StringBuilder("("); var newParameterRanges = new TextRange[parameters.Length]; var parametersOrder = SortParameters(parameters, namedArguments, out var orderChanged); if (parameters.IsEmpty()) { text.Append("<no parameters>"); } else { for (var i = 0; i < parameters.Length; i++) { var paramRangeStart = text.Length; if (orderChanged) { text.Append("["); } text.Append(parameters[parametersOrder[i]].Display); if (orderChanged) { text.Append("]"); } var paramRangeEnd = text.Length; newParameterRanges[i] = new TextRange(paramRangeStart, paramRangeEnd); if (i < parameters.Length - 1) { text.Append(", "); } } } text.Append(")" + myCandidate.ReturnTypeText); extensionMethodInfo = ExtensionMethodInfo.NoExtension; parameterRanges = newParameterRanges; mapToOriginalOrder = parametersOrder; return(text.ToString()); }
private RichText GetSignatureCore(string[] namedArguments, AnnotationsDisplayKind? showAnnotations, out TextRange[] parameterRanges, out int[] mapToOriginalOrder, out ExtensionMethodInfo extensionMethodInfo) { if (showAnnotations == null) showAnnotations = _settings.GetValue((ParameterInfoSettings s) => s.ShowAnnotations); // TODO: handle named arguments with reordering; currently falling back to non-colored display if (namedArguments.Any(s => s != null)) { string signature = _underlyingCandidate.GetSignature(namedArguments, showAnnotations.Value, out parameterRanges, out mapToOriginalOrder, out extensionMethodInfo); if (!IsIdentityMap(mapToOriginalOrder)) return signature; } var options = PresenterOptions.ForParameterInfo(_settings, showAnnotations.Value); bool useReSharperColors = _settings.GetValue(HighlightingSettingsAccessor.IdentifierHighlightingEnabled); PresentedInfo presentedInfo; InvocationCandidate invocationCandidate = _underlyingCandidate.InvocationCandidate; var elementInstance = new DeclaredElementInstance(invocationCandidate.Element, invocationCandidate.Substitution); RichText richText = _colorizerPresenter.TryPresent(elementInstance, options, _underlyingCandidate.Language, useReSharperColors, out presentedInfo); if (richText == null) return _underlyingCandidate.GetSignature(namedArguments, showAnnotations.Value, out parameterRanges, out mapToOriginalOrder, out extensionMethodInfo); if (presentedInfo.Parameters.Count == 0) { parameterRanges = EmptyArray<TextRange>.Instance; mapToOriginalOrder = EmptyArray<int>.Instance; extensionMethodInfo = ExtensionMethodInfo.NoExtension; } else if (presentedInfo.IsExtensionMethod) { parameterRanges = presentedInfo.Parameters.Skip(1).ToArray(); mapToOriginalOrder = CreateIdentityMap(presentedInfo.Parameters.Count - 1); TextRange firstParameterRange = presentedInfo.Parameters[0].TrimLeft(5); // keeps "this " highlighted with the keyword color extensionMethodInfo = new ExtensionMethodInfo(firstParameterRange, TextRange.InvalidRange); } else { parameterRanges = presentedInfo.Parameters.ToArray(); mapToOriginalOrder = CreateIdentityMap(presentedInfo.Parameters.Count); extensionMethodInfo = ExtensionMethodInfo.NoExtension; } return richText; }
public static PresenterOptions ForParameterInfo([NotNull] IContextBoundSettingsStore settings, AnnotationsDisplayKind showAnnotations) { return new PresenterOptions { FormatDelegatesAsLambdas = settings.GetValue((ParameterInfoSettingsKey key) => key.DelegatesAsLambdas), ShowAccessRights = false, ShowConstantValue = false, ShowDefaultValues = true, ShowElementKind = false, ShowElementAnnotations = AnnotationsDisplayKind.None, ShowElementType = ElementTypeDisplay.After, ShowEmptyParametersText = settings.GetValue((ParameterInfoSettings s) => s.ShowEmptyParametersText), ShowExplicitInterface = false, ShowModifiers = false, ShowName = false, ShowParametersName = true, ShowParametersAnnotations = showAnnotations, ShowParametersType = true, ShowQualifiers = QualifierDisplays.None, UseTypeKeywords = settings.GetValue((ParameterInfoSettings s) => s.UseTypeKeywords) }; }
private void AppendAnnotations([NotNull] IAttributesSet attributesSet, AnnotationsDisplayKind showAnnotations) { if (showAnnotations == AnnotationsDisplayKind.None) { return; } IList <IAttributeInstance> attributes = attributesSet.GetAttributeInstances(false); if (attributes.Count == 0) { return; } List <string> annotations = attributes .SelectNotNull(attr => TryGetAnnotationShortName(attr, showAnnotations)) .Distinct() .OrderBy(annotation => annotation) .ToList(); if (annotations.Count == 0) { return; } string highlighterId = _useReSharperColors ? HighlightingAttributeIds.TYPE_CLASS_ATTRIBUTE : VsHighlightingAttributeIds.Classes; AppendText("[", null); for (int i = 0; i < annotations.Count; i++) { if (i > 0) { AppendText(", ", null); } AppendText(annotations[i], highlighterId); } AppendText("] ", null); }
private bool IsDisplayedAnnotation([CanBeNull] IAttributeInstance attribute, [CanBeNull] string shortName, AnnotationsDisplayKind showAnnotations) { if (attribute == null || shortName == null) { return(false); } switch (showAnnotations) { case AnnotationsDisplayKind.Nullness: return(shortName == NullnessProvider.CanBeNullAttributeShortName || shortName == NullnessProvider.NotNullAttributeShortName); case AnnotationsDisplayKind.All: return(_codeAnnotationsConfiguration.IsAnnotationAttribute(attribute, shortName)); default: return(false); } }
public static RichText GetSignature(this ICandidate candidate, string[] namedArguments, AnnotationsDisplayKind showAnnotations, out TextRange[] parameterRanges, out int[] mapToOriginalOrder, out ExtensionMethodInfo extensionMethodInfo) { return candidate.GetSignature(namedArguments, out parameterRanges, out mapToOriginalOrder, out extensionMethodInfo); }
public static RichText GetSignature(this ICandidate candidate, string[] namedArguments, AnnotationsDisplayKind showAnnotations, out TextRange[] parameterRanges, out int[] mapToOriginalOrder, out ExtensionMethodInfo extensionMethodInfo) { return(candidate.GetSignature(namedArguments, out parameterRanges, out mapToOriginalOrder, out extensionMethodInfo)); }
private string TryGetAnnotationShortName([CanBeNull] IAttributeInstance attribute, AnnotationsDisplayKind showAnnotations) { if (attribute != null && showAnnotations != AnnotationsDisplayKind.None) { string shortName = attribute.GetClrName().ShortName; if (IsDisplayedAnnotation(attribute, shortName, showAnnotations)) { return(shortName.TrimFromEnd("Attribute")); } } return(null); }
protected override PresenterOptions GetPresenterOptions(IContextBoundSettingsStore settings, AnnotationsDisplayKind showAnnotations) => PresenterOptions.ForParameterInfo(settings, showAnnotations.ToAttributesDisplayKind());
public static AttributesDisplayKind ToAttributesDisplayKind(this AnnotationsDisplayKind annotationsDisplayKind) => annotationsDisplayKind switch {
private void AppendAnnotations([NotNull] IAttributesSet attributesSet, AnnotationsDisplayKind showAnnotations) { if (showAnnotations == AnnotationsDisplayKind.None) return; IList<IAttributeInstance> attributes = attributesSet.GetAttributeInstances(false); if (attributes.Count == 0) return; List<string> annotations = attributes .SelectNotNull(attr => TryGetAnnotationShortName(attr, showAnnotations)) .Distinct() .OrderBy(annotation => annotation) .ToList(); if (annotations.Count == 0) return; string highlighterId = _useReSharperColors ? HighlightingAttributeIds.TYPE_CLASS_ATTRIBUTE : VsHighlightingAttributeIds.Classes; AppendText("[", null); for (int i = 0; i < annotations.Count; i++) { if (i > 0) AppendText(", ", null); AppendText(annotations[i], highlighterId); } AppendText("] ", null); }
public static PresenterOptions ForParameterInfo([NotNull] IContextBoundSettingsStore settings, AnnotationsDisplayKind showAnnotations) { return(new PresenterOptions { FormatDelegatesAsLambdas = settings.GetValue((ParameterInfoSettingsKey key) => key.DelegatesAsLambdas), ShowAccessRights = false, ShowConstantValue = false, ShowDefaultValues = true, ShowElementKind = false, ShowElementAnnotations = AnnotationsDisplayKind.None, ShowElementType = ElementTypeDisplay.After, ShowEmptyParametersText = settings.GetValue((ParameterInfoSettings s) => s.ShowEmptyParametersText), ShowExplicitInterface = false, ShowModifiers = false, ShowName = false, ShowParametersName = true, ShowParametersAnnotations = showAnnotations, ShowParametersType = true, ShowQualifiers = QualifierDisplays.None, UseTypeKeywords = settings.GetValue((ParameterInfoSettings s) => s.UseTypeKeywords) }); }
public abstract RichText GetSignature(string[] namedArguments, AnnotationsDisplayKind showAnnotations, out TextRange[] parameterRanges, out int[] mapToOriginalOrder, out ExtensionMethodInfo extensionMethodInfo);
private string TryGetAnnotationShortName([CanBeNull] IAttributeInstance attribute, AnnotationsDisplayKind showAnnotations) { if (attribute != null && showAnnotations != AnnotationsDisplayKind.None) { string shortName = attribute.GetClrName().ShortName; if (IsDisplayedAnnotation(attribute, shortName, showAnnotations)) return shortName.TrimFromEnd("Attribute"); } return null; }
private bool IsDisplayedAnnotation([CanBeNull] IAttributeInstance attribute, [CanBeNull] string shortName, AnnotationsDisplayKind showAnnotations) { if (attribute == null || shortName == null) return false; switch (showAnnotations) { case AnnotationsDisplayKind.Nullness: return shortName == CodeAnnotationsCache.CanBeNullAttributeShortName || shortName == CodeAnnotationsCache.NotNullAttributeShortName; case AnnotationsDisplayKind.All: return _codeAnnotationsCache.IsAnnotationAttribute(attribute, shortName); default: return false; } }