private void AddParts( IStructuralTypeDisplayService anonymousTypeService, ArrayBuilder <SymbolDisplayPart> finalParts, ImmutableArray <SymbolDisplayPart> parts, SemanticModel semanticModel, int position, HashSet <INamedTypeSymbol>?seenSymbols = null) { seenSymbols ??= new(); foreach (var part in parts) { if (part.Symbol is INamedTypeSymbol { IsAnonymousType: true } anonymousType) { if (seenSymbols.Add(anonymousType)) { var anonymousParts = anonymousTypeService.GetAnonymousTypeParts(anonymousType, semanticModel, position); AddParts(anonymousTypeService, finalParts, anonymousParts, semanticModel, position, seenSymbols); seenSymbols.Remove(anonymousType); } else { finalParts.Add(new SymbolDisplayPart(SymbolDisplayPartKind.Text, symbol: null, "...")); } }
private static (IList <SignatureHelpItem>?items, int?selectedItem) GetDelegateTypeConstructors( BaseObjectCreationExpressionSyntax objectCreationExpression, SemanticModel semanticModel, IStructuralTypeDisplayService structuralTypeDisplayService, INamedTypeSymbol delegateType) { var invokeMethod = delegateType.DelegateInvokeMethod; if (invokeMethod == null) { return(null, null); } var position = objectCreationExpression.SpanStart; var item = CreateItem( invokeMethod, semanticModel, position, structuralTypeDisplayService, isVariadic: false, documentationFactory: null, prefixParts: GetDelegateTypePreambleParts(invokeMethod, semanticModel, position), separatorParts: GetSeparatorParts(), suffixParts: GetDelegateTypePostambleParts(), parameters: GetDelegateTypeParameters(invokeMethod, semanticModel, position)); return(SpecializedCollections.SingletonList(item), 0); }
protected static SignatureHelpItem CreateItemImpl( ISymbol orderSymbol, SemanticModel semanticModel, int position, IStructuralTypeDisplayService structuralTypeDisplayService, bool isVariadic, Func <CancellationToken, IEnumerable <TaggedText> >?documentationFactory, IList <SymbolDisplayPart> prefixParts, IList <SymbolDisplayPart> separatorParts, IList <SymbolDisplayPart> suffixParts, IList <SignatureHelpSymbolParameter> parameters, IList <SymbolDisplayPart>?descriptionParts) { descriptionParts = descriptionParts == null ? SpecializedCollections.EmptyList <SymbolDisplayPart>() : descriptionParts; var allParts = prefixParts.Concat(separatorParts) .Concat(suffixParts) .Concat(parameters.SelectMany(p => p.GetAllParts())) .Concat(descriptionParts); var structuralTypes = from part in allParts where part.Symbol.IsAnonymousType() || part.Symbol.IsTupleType() select(INamedTypeSymbol) part.Symbol !; var info = structuralTypeDisplayService.GetTypeDisplayInfo( orderSymbol, structuralTypes.ToImmutableArray(), semanticModel, position); if (info.TypesParts.Count > 0) { var structuralTypeParts = new List <SymbolDisplayPart> { new SymbolDisplayPart(SymbolDisplayPartKind.Space, null, "\r\n\r\n") }; structuralTypeParts.AddRange(info.TypesParts); return(new SymbolKeySignatureHelpItem( orderSymbol, isVariadic, documentationFactory, info.ReplaceStructuralTypes(prefixParts, semanticModel, position).ToTaggedText(), info.ReplaceStructuralTypes(separatorParts, semanticModel, position).ToTaggedText(), info.ReplaceStructuralTypes(suffixParts, semanticModel, position).ToTaggedText(), parameters.Select(p => ReplaceStructuralTypes(p, info, semanticModel, position)).Select(p => (SignatureHelpParameter)p), structuralTypeParts.ToTaggedText())); } return(new SymbolKeySignatureHelpItem( orderSymbol, isVariadic, documentationFactory, prefixParts.ToTaggedText(), separatorParts.ToTaggedText(), suffixParts.ToTaggedText(), parameters.Select(p => (SignatureHelpParameter)p), descriptionParts.ToTaggedText())); }
public SymbolDescriptionBuilder( SemanticModel semanticModel, int position, HostWorkspaceServices workspaceServices, IStructuralTypeDisplayService structuralTypeDisplayService, SymbolDescriptionOptions options, CancellationToken cancellationToken) : base(semanticModel, position, workspaceServices, structuralTypeDisplayService, options, cancellationToken) { }
private static SignatureHelpSymbolParameter InlineDelegateAnonymousTypes( SignatureHelpSymbolParameter parameter, SemanticModel semanticModel, int position, IStructuralTypeDisplayService structuralTypeDisplayService) { return(new SignatureHelpSymbolParameter( parameter.Name, parameter.IsOptional, parameter.DocumentationFactory, structuralTypeDisplayService.InlineDelegateAnonymousTypes(parameter.DisplayParts, semanticModel, position), structuralTypeDisplayService.InlineDelegateAnonymousTypes(parameter.PrefixDisplayParts, semanticModel, position), structuralTypeDisplayService.InlineDelegateAnonymousTypes(parameter.SuffixDisplayParts, semanticModel, position), structuralTypeDisplayService.InlineDelegateAnonymousTypes(parameter.SelectedDisplayParts, semanticModel, position))); }
protected static SignatureHelpItem CreateItem( ISymbol orderSymbol, SemanticModel semanticModel, int position, IStructuralTypeDisplayService structuralTypeDisplayService, bool isVariadic, Func <CancellationToken, IEnumerable <TaggedText> >?documentationFactory, IList <SymbolDisplayPart> prefixParts, IList <SymbolDisplayPart> separatorParts, IList <SymbolDisplayPart> suffixParts, IList <SignatureHelpSymbolParameter> parameters, IList <SymbolDisplayPart>?descriptionParts = null) { return(CreateItemImpl(orderSymbol, semanticModel, position, structuralTypeDisplayService, isVariadic, documentationFactory, prefixParts, separatorParts, suffixParts, parameters, descriptionParts)); }
private static SignatureHelpItem ConvertNormalTypeConstructor( IMethodSymbol constructor, BaseObjectCreationExpressionSyntax objectCreationExpression, SemanticModel semanticModel, IStructuralTypeDisplayService structuralTypeDisplayService, IDocumentationCommentFormattingService documentationCommentFormattingService) { var position = objectCreationExpression.SpanStart; var item = CreateItem( constructor, semanticModel, position, structuralTypeDisplayService, constructor.IsParams(), constructor.GetDocumentationPartsFactory(semanticModel, position, documentationCommentFormattingService), GetNormalTypePreambleParts(constructor, semanticModel, position), GetSeparatorParts(), GetNormalTypePostambleParts(), constructor.Parameters.Select(p => Convert(p, semanticModel, position, documentationCommentFormattingService)).ToList()); return(item); }
public static IList <SymbolDisplayPart> InlineDelegateAnonymousTypes( this IStructuralTypeDisplayService service, IList <SymbolDisplayPart> parts, SemanticModel semanticModel, int position) { var result = parts; while (true) { var delegateAnonymousType = result.Select(p => p.Symbol).OfType <INamedTypeSymbol>().FirstOrDefault(s => s.IsAnonymousDelegateType()); if (delegateAnonymousType == null) { break; } result = result == parts ? new List <SymbolDisplayPart>(parts) : result; ReplaceAnonymousType(result, delegateAnonymousType, service.GetAnonymousTypeParts(delegateAnonymousType, semanticModel, position)); } return(result); }
private static ImmutableArray <SignatureHelpItem> ConvertDelegateTypeConstructor( BaseObjectCreationExpressionSyntax objectCreationExpression, IMethodSymbol invokeMethod, SemanticModel semanticModel, IStructuralTypeDisplayService structuralTypeDisplayService, int position) { var item = CreateItem( invokeMethod, semanticModel, objectCreationExpression.SpanStart, structuralTypeDisplayService, isVariadic: false, documentationFactory: null, prefixParts: GetDelegateTypePreambleParts(invokeMethod, semanticModel, position), separatorParts: GetSeparatorParts(), suffixParts: GetDelegateTypePostambleParts(), parameters: GetDelegateTypeParameters(invokeMethod, semanticModel, position)); return(ImmutableArray.Create <SignatureHelpItem>(item)); }
private static (IList <SignatureHelpItem> items, int?selectedItem) GetNormalTypeConstructors( BaseObjectCreationExpressionSyntax objectCreationExpression, SemanticModel semanticModel, IStructuralTypeDisplayService structuralTypeDisplayService, IDocumentationCommentFormattingService documentationCommentFormattingService, INamedTypeSymbol normalType, ISymbol within, SignatureHelpOptions options, CancellationToken cancellationToken) { var accessibleConstructors = normalType.InstanceConstructors .WhereAsArray(c => c.IsAccessibleWithin(within)) .WhereAsArray(s => s.IsEditorBrowsable(options.HideAdvancedMembers, semanticModel.Compilation)) .Sort(semanticModel, objectCreationExpression.SpanStart); var symbolInfo = semanticModel.GetSymbolInfo(objectCreationExpression, cancellationToken); var selectedItem = TryGetSelectedIndex(accessibleConstructors, symbolInfo.Symbol); var items = accessibleConstructors.SelectAsArray(c => ConvertNormalTypeConstructor(c, objectCreationExpression, semanticModel, structuralTypeDisplayService, documentationCommentFormattingService)); return(items, selectedItem); }
private static IList <SignatureHelpItem> GetDelegateOrFunctionPointerInvokeItems(InvocationExpressionSyntax invocationExpression, IMethodSymbol invokeMethod, SemanticModel semanticModel, IStructuralTypeDisplayService structuralTypeDisplayService, IDocumentationCommentFormattingService documentationCommentFormattingService, out int?selectedItem, CancellationToken cancellationToken) { var position = invocationExpression.SpanStart; var item = CreateItem( invokeMethod, semanticModel, position, structuralTypeDisplayService, isVariadic: invokeMethod.IsParams(), documentationFactory: null, prefixParts: GetDelegateOrFunctionPointerInvokePreambleParts(invokeMethod, semanticModel, position), separatorParts: GetSeparatorParts(), suffixParts: GetDelegateOrFunctionPointerInvokePostambleParts(), parameters: GetDelegateOrFunctionPointerInvokeParameters(invokeMethod, semanticModel, position, documentationCommentFormattingService, cancellationToken)); // Since we're returning a single item, we can selected it as the "best one". selectedItem = 0; return(SpecializedCollections.SingletonList(item)); }
private static IList <SignatureHelpItem> GetFunctionPointerInvokeItems( InvocationExpressionSyntax invocationExpression, SemanticModel semanticModel, IStructuralTypeDisplayService structuralTypeDisplayService, IDocumentationCommentFormattingService documentationCommentFormattingService, IFunctionPointerTypeSymbol functionPointerType, out int?selectedItem, CancellationToken cancellationToken) { return(GetDelegateOrFunctionPointerInvokeItems(invocationExpression, functionPointerType.Signature, semanticModel, structuralTypeDisplayService, documentationCommentFormattingService, out selectedItem, cancellationToken)); }
private static IList <SignatureHelpItem>?GetDelegateInvokeItems( InvocationExpressionSyntax invocationExpression, SemanticModel semanticModel, IStructuralTypeDisplayService structuralTypeDisplayService, IDocumentationCommentFormattingService documentationCommentFormattingService, ISymbol within, INamedTypeSymbol delegateType, out int?selectedItem, CancellationToken cancellationToken) { selectedItem = null; var invokeMethod = delegateType.DelegateInvokeMethod; if (invokeMethod == null) { return(null); } // Events can only be invoked directly from the class they were declared in. var expressionSymbol = semanticModel.GetSymbolInfo(invocationExpression.Expression, cancellationToken).GetAnySymbol(); if (expressionSymbol.IsKind(SymbolKind.Event) && !expressionSymbol.ContainingType.OriginalDefinition.Equals(within.OriginalDefinition)) { return(null); } return(GetDelegateOrFunctionPointerInvokeItems(invocationExpression, invokeMethod, semanticModel, structuralTypeDisplayService, documentationCommentFormattingService, out selectedItem, cancellationToken)); }
protected override void InlineAllDelegateAnonymousTypes(SemanticModel semanticModel, int position, IStructuralTypeDisplayService structuralTypeDisplayService, Dictionary <SymbolDescriptionGroups, IList <SymbolDisplayPart> > groupMap) { // In C#, anonymous delegates are typically represented with System.Action<> or System.Func<>, // and we prefer to display those types rather than a structural delegate type. }
protected AbstractSymbolDisplayService(HostLanguageServices services) { Services = services; AnonymousTypeDisplayService = services.GetService <IStructuralTypeDisplayService>(); }
protected abstract void InlineAllDelegateAnonymousTypes(SemanticModel semanticModel, int position, IStructuralTypeDisplayService structuralTypeDisplayService, Dictionary <SymbolDescriptionGroups, IList <SymbolDisplayPart> > groupMap);