private static ILookupItem CreateMethodItem(CSharpCodeCompletionContext context, UnityMessage message, IClassLikeDeclaration declaration) { if (CSharpLanguage.Instance == null) { return(null); } var method = message.CreateDeclaration(CSharpElementFactory.GetInstance(declaration), declaration); if (method.DeclaredElement == null) { return(null); } var instance = new DeclaredElementInstance(method.DeclaredElement); var declaredElementInfo = new DeclaredElementInfo(method.DeclaredName, instance, CSharpLanguage.Instance, context.BasicContext.LookupItemsOwner, context, context.BasicContext); return(LookupItemFactory.CreateLookupItem(declaredElementInfo). WithPresentation( _ => new GenerateMemberPresentation(declaredElementInfo, PresenterStyles.DefaultPresenterStyle)). WithBehavior(_ => { var behavior = new UnityMessageBehavior(declaredElementInfo, message); behavior.InitializeRanges(context.CompletionRanges, context.BasicContext); return behavior; }). WithMatcher(_ => new DeclaredElementMatcher(declaredElementInfo, context.BasicContext.IdentifierMatchingStyle))); }
private static ILookupItem CreateMethodItem(CSharpCodeCompletionContext context, UnityEventFunction eventFunction, IClassLikeDeclaration declaration) { if (CSharpLanguage.Instance == null) { return(null); } var method = eventFunction.CreateDeclaration(CSharpElementFactory.GetInstance(declaration), declaration); if (method.DeclaredElement == null) { return(null); } var instance = new DeclaredElementInstance(method.DeclaredElement); var declaredElementInfo = new DeclaredElementInfo(method.DeclaredName, instance, CSharpLanguage.Instance, context.BasicContext.LookupItemsOwner, context) { Ranges = context.CompletionRanges }; var withMatcher = LookupItemFactory.CreateLookupItem(declaredElementInfo). WithPresentation(_ => new GenerateMemberPresentation(declaredElementInfo, PresenterStyles.DefaultPresenterStyle)). WithBehavior(_ => new UnityEventFunctionBehavior(declaredElementInfo, eventFunction)). WithMatcher(_ => new DeclaredElementMatcher(declaredElementInfo, context.BasicContext.IdentifierMatchingStyle)); return(withMatcher); }
private static bool IsLengthOrCountProperty([NotNull] DeclaredElementInfo declaredElementInfo) { switch (declaredElementInfo.ShortName) { case LENGTH: case COUNT: break; default: return(false); } var preferredElement = declaredElementInfo.PreferredDeclaredElement; if (preferredElement == null) { return(false); } var property = preferredElement.Element as IProperty; if (property == null) { return(false); } var propertyType = property.Type; return(propertyType.IsResolved && propertyType.IsInt()); }
private IdentifierTooltipContent[] GetIdentifierContentsCore( DocumentRange documentRange, [NotNull] IContextBoundSettingsStore settings, [CanBeNull] IHighlighter highlighter) { DeclaredElementInfo info = FindDeclaredElement(documentRange); if (info == null) { return(EmptyArray <IdentifierTooltipContent> .Instance); } IdentifierTooltipContent standardContent = TryPresentColorized(info, settings) ?? TryPresentNonColorized(highlighter, info.DeclaredElement, settings); bool replacesStandardContent; IdentifierTooltipContent additionalContent = TryGetAdditionalIdentifierContent(info, settings, out replacesStandardContent); if (replacesStandardContent) { standardContent = additionalContent; additionalContent = null; } var results = new FrugalLocalList <IdentifierTooltipContent>(); if (standardContent != null) { results.Add(standardContent); } if (additionalContent != null) { results.Add(additionalContent); } return(results.ToArray()); }
private IdentifierTooltipContent TryGetAdditionalIdentifierContent( [CanBeNull] DeclaredElementInfo info, [NotNull] IContextBoundSettingsStore settings, out bool replacesStandardContent) { replacesStandardContent = false; if (info == null) { return(null); } var constructor = info.DeclaredElement as IConstructor; ITypeElement typeElement = constructor?.GetContainingType(); if (typeElement == null) { return(null); } ConstructorReferenceDisplay display = settings.GetValue(GetConstructorSettingsKey(typeElement.IsAttribute())); switch (display) { case ConstructorReferenceDisplay.TypeOnly: replacesStandardContent = true; return(TryGetTypeIdentifierContentFromConstructor(constructor, info, settings)); case ConstructorReferenceDisplay.Both: return(TryGetTypeIdentifierContentFromConstructor(constructor, info, settings)); default: return(null); } }
public ShiftedDeclaredElementMatcher(string customText, int shiftOffset, DeclaredElementInfo declaredElementInfo, IdentifierMatchingStyle matchingStyle) : base(customText, declaredElementInfo, matchingStyle) { myShiftOffset = shiftOffset; }
private IdentifierTooltipContent TryGetTypeIdentifierContentFromConstructor( [NotNull] IConstructor constructor, [NotNull] DeclaredElementInfo constructorInfo, [NotNull] IContextBoundSettingsStore settings) { ITypeElement typeElement = constructor.GetContainingType(); if (typeElement == null) { return(null); } var typeInfo = new DeclaredElementInfo(typeElement, constructorInfo.Substitution, constructorInfo.TreeNode, constructorInfo.SourceRange, null); return(TryPresentColorized(typeInfo, settings)); }
private static DeclaredElementPresentation <DeclaredElementInfo> GetOrCreatePresentation( DeclaredElementInfo info, DeclaredElementPresenterStyle style, string typeParameterString = null) { var preferredDeclaredElement = info.PreferredDeclaredElement; if (preferredDeclaredElement != null && preferredDeclaredElement.Element is ICompiledElement && preferredDeclaredElement.Element.Type() == null) { return(CSharpLookupItemFactory.GetPresentationCache(preferredDeclaredElement.Element.GetSolution()) .GetPresentation(info, (ICompiledElement)preferredDeclaredElement.Element, style, typeParameterString)); } return(new DeclaredElementPresentation <DeclaredElementInfo>(info, style, typeParameterString, LogoThemedIcons.NukeLogo.Id)); }
private IdentifierTooltipContent TryPresentColorized([NotNull] DeclaredElementInfo info, [NotNull] IContextBoundSettingsStore settings) { PsiLanguageType languageType = info.File.Language; IDeclaredElement element = info.DeclaredElement; IPsiModule psiModule = info.File.GetPsiModule(); RichText identifierText = _colorizerPresenter.TryPresent( new DeclaredElementInstance(element, info.Substitution), PresenterOptions.ForToolTip(settings), languageType, settings.GetValue(HighlightingSettingsAccessor.IdentifierHighlightingEnabled)); if (identifierText == null || identifierText.IsEmpty) { return(null); } var identifierContent = new IdentifierTooltipContent(identifierText, info.SourceRange) { Description = TryGetDescription(element, psiModule, languageType, DeclaredElementDescriptionStyle.NO_OBSOLETE_SUMMARY_STYLE), }; if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowIcon)) { identifierContent.Icon = TryGetIcon(element); } if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowObsolete)) { identifierContent.Obsolete = TryRemoveObsoletePrefix(TryGetDescription(element, psiModule, languageType, DeclaredElementDescriptionStyle.OBSOLETE_DESCRIPTION)); } if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowExceptions)) { identifierContent.Exceptions.AddRange(GetExceptions(element, languageType, psiModule, info.File.GetResolveContext())); } if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowOverloadCount)) { identifierContent.OverloadCount = TryGetOverloadCountCount(element as IFunction, info.Reference, languageType); } return(identifierContent); }
private IdentifierContentGroup GetIdentifierContentGroupCore( DocumentRange documentRange, [NotNull] IContextBoundSettingsStore settings, [CanBeNull] IHighlighter highlighter) { DeclaredElementInfo info = FindDeclaredElement(documentRange); if (info == null) { return(null); } IdentifierTooltipContent standardContent = TryPresentColorized(info, settings) ?? TryPresentNonColorized(highlighter, info.DeclaredElement, settings); bool replacesStandardContent; IdentifierTooltipContent additionalContent = TryGetAdditionalIdentifierContent(info, settings, out replacesStandardContent); if (replacesStandardContent) { standardContent = additionalContent; additionalContent = null; } var result = new IdentifierContentGroup(); if (standardContent != null) { result.Identifiers.Add(standardContent); } if (additionalContent != null) { result.Identifiers.Add(additionalContent); } result.ArgumentRole = TryGetArgumentRoleContent(info.TreeNode, settings); return(result); }
private IdentifierTooltipContent TryGetAdditionalIdentifierContent([NotNull] DeclaredElementInfo info, [NotNull] IContextBoundSettingsStore settings, out bool replacesStandardContent) { replacesStandardContent = false; var constructor = info.DeclaredElement as IConstructor; if (constructor == null) { return(null); } ITypeElement typeElement = constructor.GetContainingType(); if (typeElement == null) { return(null); } IDeclaredType attributeType = info.File.GetPsiModule().GetPredefinedType(constructor.ResolveContext).Attribute; var settingsKey = GetConstructorSettingsKey(typeElement, info.Substitution, attributeType); ConstructorReferenceDisplay display = settings.GetValue(settingsKey); switch (display) { case ConstructorReferenceDisplay.TypeOnly: replacesStandardContent = true; return(TryGetTypeIdentifierContentFromConstructor(constructor, info, settings)); case ConstructorReferenceDisplay.Both: return(TryGetTypeIdentifierContentFromConstructor(constructor, info, settings)); default: return(null); } }
public PresentableInfo(PresentableNode presentableNode) { DeclaredElementInfo = null; PresentableNode = presentableNode; }
public PresentableInfo([CanBeNull] DeclaredElementInfo declaredElementInfo) { DeclaredElementInfo = declaredElementInfo; PresentableNode = default; }
private IdentifierTooltipContent TryPresentColorized([CanBeNull] DeclaredElementInfo info, [NotNull] IContextBoundSettingsStore settings) { if (info == null) { return(null); } PsiLanguageType languageType = info.TreeNode.Language; IDeclaredElement element = info.DeclaredElement; IPsiModule psiModule = info.TreeNode.GetPsiModule(); HighlighterIdProvider highlighterIdProvider = _highlighterIdProviderFactory.CreateProvider(settings); RichText identifierText; if (info.DeclaredElement is ICppDeclaredElement cppDeclaredElement) { identifierText = _solution.TryGetComponent <CppDeclaredElementTooltipProvider>()?.GetTooltip(cppDeclaredElement)?.RichText; } else { identifierText = _colorizerPresenter.TryPresent( new DeclaredElementInstance(element, info.Substitution), PresenterOptions.ForIdentifierToolTip(settings, !element.IsEnumMember()), languageType, highlighterIdProvider, info.TreeNode, out _); } if (identifierText == null || identifierText.IsEmpty) { return(null); } var identifierContent = new IdentifierTooltipContent(identifierText, info.SourceRange); if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowIcon)) { identifierContent.Icon = TryGetIcon(element); } if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowDocumentation)) { XmlNode xmlDoc = element.GetXMLDoc(true); identifierContent.Description = TryGetDescription(element, xmlDoc, psiModule, languageType); if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowObsolete)) { identifierContent.Obsolete = TryRemoveObsoletePrefix(TryGetObsolete(element, psiModule, languageType)); } if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowReturn)) { identifierContent.Return = TryPresentDocNode(xmlDoc, "returns", languageType, psiModule); } if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowValue)) { identifierContent.Value = TryPresentDocNode(xmlDoc, "value", languageType, psiModule); } if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowRemarks)) { identifierContent.Remarks = TryPresentDocNode(xmlDoc, "remarks", languageType, psiModule); } if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowExceptions)) { identifierContent.Exceptions.AddRange(GetExceptions(xmlDoc, languageType, psiModule)); } } if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowOverloadCount)) { identifierContent.OverloadCount = TryGetOverloadCount(element as IFunction, info.Reference, languageType); } if (info.DeclaredElement is ITypeElement typeElement) { var baseTypeDisplayKind = settings.GetValue((IdentifierTooltipSettings s) => s.BaseTypeDisplayKind); var implementedInterfacesDisplayKind = settings.GetValue((IdentifierTooltipSettings s) => s.ImplementedInterfacesDisplayKind); if (baseTypeDisplayKind != BaseTypeDisplayKind.Never || implementedInterfacesDisplayKind != ImplementedInterfacesDisplayKind.Never) { AddSuperTypes(identifierContent, typeElement, baseTypeDisplayKind, implementedInterfacesDisplayKind, languageType, info.TreeNode, highlighterIdProvider, settings); } if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowAttributesUsage) && typeElement.IsAttribute()) { identifierContent.AttributeUsage = GetAttributeUsage((IClass)info.DeclaredElement); } } return(identifierContent); }
private IdentifierTooltipContent TryGetTypeIdentifierContentFromConstructor( [NotNull] IConstructor constructor, [NotNull] DeclaredElementInfo constructorInfo, [NotNull] IContextBoundSettingsStore settings) { ITypeElement typeElement = constructor.GetContainingType(); if (typeElement == null) return null; var typeInfo = new DeclaredElementInfo(typeElement, constructorInfo.Substitution, constructorInfo.File, constructorInfo.SourceRange, null); return TryPresentColorized(typeInfo, settings); }
private static string InvertName([NotNull] DeclaredElementInfo info) { return((info.ShortName == COUNT) ? LENGTH : COUNT); }
private IdentifierTooltipContent TryPresentColorized([NotNull] DeclaredElementInfo info, [NotNull] IContextBoundSettingsStore settings) { PsiLanguageType languageType = info.TreeNode.Language; IDeclaredElement element = info.DeclaredElement; IPsiModule psiModule = info.TreeNode.GetPsiModule(); HighlighterIdProvider highlighterIdProvider = _highlighterIdProviderFactory.CreateProvider(settings); RichText identifierText = _colorizerPresenter.TryPresent( new DeclaredElementInstance(element, info.Substitution), PresenterOptions.ForIdentifierToolTip(settings), languageType, highlighterIdProvider); if (identifierText == null || identifierText.IsEmpty) { return(null); } var identifierContent = new IdentifierTooltipContent(identifierText, info.SourceRange) { Description = TryGetDescription(element, psiModule, languageType, DeclaredElementDescriptionStyle.NO_OBSOLETE_SUMMARY_STYLE), }; if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowIcon)) { identifierContent.Icon = TryGetIcon(element); } if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowObsolete)) { identifierContent.Obsolete = TryRemoveObsoletePrefix(TryGetDescription(element, psiModule, languageType, DeclaredElementDescriptionStyle.OBSOLETE_DESCRIPTION)); } if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowExceptions)) { identifierContent.Exceptions.AddRange(GetExceptions(element, languageType, psiModule)); } if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowOverloadCount)) { identifierContent.OverloadCount = TryGetOverloadCountCount(element as IFunction, info.Reference, languageType); } var typeElement = info.DeclaredElement as ITypeElement; if (typeElement != null) { bool showBaseType = settings.GetValue((IdentifierTooltipSettings s) => s.ShowBaseType); bool showImplementedInterfaces = settings.GetValue((IdentifierTooltipSettings s) => s.ShowImplementedInterfaces); if (showBaseType || showImplementedInterfaces) { AddSuperTypes(identifierContent, typeElement, showBaseType, showImplementedInterfaces, languageType, highlighterIdProvider); } if (settings.GetValue((IdentifierTooltipSettings s) => s.ShowAttributesUsage) && typeElement.IsAttribute()) { identifierContent.AttributeUsage = GetAttributeUsage((IClass)info.DeclaredElement); } } return(identifierContent); }