protected override async Task <ImmutableArray <ISymbol> > GetPreselectedSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken) { var recommender = context.GetLanguageService <IRecommendationService>(); var typeInferrer = context.GetLanguageService <ITypeInferenceService>(); var inferredTypes = typeInferrer.InferTypes(context.SemanticModel, position, cancellationToken) .Where(t => t.SpecialType != SpecialType.System_Void) .ToSet(); if (inferredTypes.Count == 0) { return(ImmutableArray <ISymbol> .Empty); } var symbols = await recommender.GetRecommendedSymbolsAtPositionAsync( context.Workspace, context.SemanticModel, context.Position, options, cancellationToken).ConfigureAwait(false); // Don't preselect intrinsic type symbols so we can preselect their keywords instead. We will also ignore nullability for purposes of preselection // -- if a method is returning a string? but we've inferred we're assigning to a string or vice versa we'll still count those as the same. return(symbols.WhereAsArray(s => inferredTypes.Contains(GetSymbolType(s), AllNullabilityIgnoringSymbolComparer.Instance) && !IsInstrinsic(s))); }
public static bool TryRemoveAttributeSuffix( ISymbol symbol, SyntaxContext context, out string name ) { var isAttributeNameContext = context.IsAttributeNameContext; var syntaxFacts = context.GetLanguageService <ISyntaxFactsService>(); if (!isAttributeNameContext) { name = null; return(false); } // Do the symbol textual check first. Then the more expensive symbolic check. if ( !symbol.Name.TryGetWithoutAttributeSuffix(syntaxFacts.IsCaseSensitive, out name) || !symbol.IsAttribute() ) { return(false); } return(true); }
protected override (string displayText, string suffix, string insertionText) GetDisplayAndSuffixAndInsertionText( ISymbol symbol, SyntaxContext context) { var displayService = context.GetLanguageService <ISymbolDisplayService>(); var displayString = displayService.ToMinimalDisplayString(context.SemanticModel, context.Position, symbol); return(displayString, "", displayString); }
protected override ValueTuple <string, string> GetDisplayAndInsertionText( ISymbol symbol, SyntaxContext context) { var displayService = context.GetLanguageService <ISymbolDisplayService>(); var displayString = displayService.ToMinimalDisplayString(context.SemanticModel, context.Position, symbol); return(ValueTuple.Create(displayString, displayString)); }
protected override async Task<ImmutableArray<ISymbol>> GetPreselectedSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken) { var recommender = context.GetLanguageService<IRecommendationService>(); var typeInferrer = context.GetLanguageService<ITypeInferenceService>(); var inferredTypes = typeInferrer.InferTypes(context.SemanticModel, position, cancellationToken) .Where(t => t.SpecialType != SpecialType.System_Void) .ToSet(); if (inferredTypes.Count == 0) { return ImmutableArray<ISymbol>.Empty; } var symbols = await recommender.GetRecommendedSymbolsAtPositionAsync( context.Workspace, context.SemanticModel, position, options, cancellationToken).ConfigureAwait(false); // Don't preselect intrinsic type symbols so we can preselect their keywords instead. return symbols.WhereAsArray(s => inferredTypes.Contains(GetSymbolType(s)) && !IsInstrinsic(s)); }
protected override async Task <ImmutableArray <ISymbol> > GetPreselectedSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken) { var recommender = context.GetLanguageService <IRecommendationService>(); var typeInferrer = context.GetLanguageService <ITypeInferenceService>(); var inferredTypes = typeInferrer.InferTypes(context.SemanticModel, position, cancellationToken) .Where(t => t.SpecialType != SpecialType.System_Void) .ToSet(); if (inferredTypes.Count == 0) { return(ImmutableArray <ISymbol> .Empty); } var symbols = await recommender.GetRecommendedSymbolsAtPositionAsync( context.Workspace, context.SemanticModel, context.Position, options, cancellationToken).ConfigureAwait(false); // Don't preselect intrinsic type symbols so we can preselect their keywords instead. return(symbols.WhereAsArray(s => inferredTypes.Contains(GetSymbolType(s)) && !IsInstrinsic(s))); }
protected override Task <ImmutableArray <ISymbol> > GetSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken) { var recommender = context.GetLanguageService <IRecommendationService>(); return(recommender.GetRecommendedSymbolsAtPositionAsync(context.Workspace, context.SemanticModel, position, options, cancellationToken)); }
private bool IsCandidateProject(SyntaxContext context, CancellationToken cancellationToken) { var syntaxFacts = context.GetLanguageService<ISyntaxFactsService>(); return !syntaxFacts.IsInInactiveRegion(context.SyntaxTree, context.Position, cancellationToken); }
private Task <ImmutableArray <ISymbol> > GetSymbolsCoreAsync( SyntaxContext context, int position, OptionSet options, bool preselect, CancellationToken cancellationToken) { var newExpression = GetObjectCreationNewExpression(context.SyntaxTree, position, cancellationToken); if (newExpression == null) { return(SpecializedTasks.EmptyImmutableArray <ISymbol>()); } var typeInferenceService = context.GetLanguageService <ITypeInferenceService>(); var type = typeInferenceService.InferType( context.SemanticModel, position, objectAsDefault: false, cancellationToken: cancellationToken); // Unwrap an array type fully. We only want to offer the underlying element type in the // list of completion items. var isArray = false; while (type is IArrayTypeSymbol) { isArray = true; type = ((IArrayTypeSymbol)type).ElementType; } if (type == null || (isArray && preselect)) { // In the case of array creation, we don't offer a preselected/hard-selected item because // the user may want an implicitly-typed array creation return(SpecializedTasks.EmptyImmutableArray <ISymbol>()); } // Unwrap nullable if (type.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T) { type = type.GetTypeArguments().FirstOrDefault(); } if (type.SpecialType == SpecialType.System_Void) { return(SpecializedTasks.EmptyImmutableArray <ISymbol>()); } if (type.ContainsAnonymousType()) { return(SpecializedTasks.EmptyImmutableArray <ISymbol>()); } if (!type.CanBeReferencedByName) { return(SpecializedTasks.EmptyImmutableArray <ISymbol>()); } // Normally the user can't say things like "new IList". Except for "IList[] x = new |". // In this case we do want to allow them to preselect certain types in the completion // list even if they can't new them directly. if (!isArray) { if (type.TypeKind == TypeKind.Interface || type.TypeKind == TypeKind.Pointer || type.TypeKind == TypeKind.Dynamic || type.IsAbstract) { return(SpecializedTasks.EmptyImmutableArray <ISymbol>()); } if (type.TypeKind == TypeKind.TypeParameter && !((ITypeParameterSymbol)type).HasConstructorConstraint) { return(SpecializedTasks.EmptyImmutableArray <ISymbol>()); } } if (!type.IsEditorBrowsable(options.GetOption(RecommendationOptions.HideAdvancedMembers, context.SemanticModel.Language), context.SemanticModel.Compilation)) { return(SpecializedTasks.EmptyImmutableArray <ISymbol>()); } return(Task.FromResult(ImmutableArray.Create((ISymbol)type))); }
private bool IsCandidateProject(SyntaxContext context, CancellationToken cancellationToken) { var syntaxFacts = context.GetLanguageService <ISyntaxFactsService>(); return(!syntaxFacts.IsInInactiveRegion(context.SyntaxTree, context.Position, cancellationToken)); }
protected override Task<ImmutableArray<ISymbol>> GetSymbolsWorker(SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken) { var recommender = context.GetLanguageService<IRecommendationService>(); return recommender.GetRecommendedSymbolsAtPositionAsync(context.Workspace, context.SemanticModel, position, options, cancellationToken); }
protected override Task<ImmutableArray<ISymbol>> GetPreselectedSymbolsWorker( SyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken) { var newExpression = this.GetObjectCreationNewExpression(context.SyntaxTree, position, cancellationToken); if (newExpression == null) { return SpecializedTasks.EmptyImmutableArray<ISymbol>(); } var typeInferenceService = context.GetLanguageService<ITypeInferenceService>(); var type = typeInferenceService.InferType( context.SemanticModel, position, objectAsDefault: false, cancellationToken: cancellationToken); // Unwrap an array type fully. We only want to offer the underlying element type in the // list of completion items. bool isArray = false; while (type is IArrayTypeSymbol) { isArray = true; type = ((IArrayTypeSymbol)type).ElementType; } if (type == null) { return SpecializedTasks.EmptyImmutableArray<ISymbol>(); } // Unwrap nullable if (type.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T) { type = type.GetTypeArguments().FirstOrDefault(); } if (type.SpecialType == SpecialType.System_Void) { return SpecializedTasks.EmptyImmutableArray<ISymbol>(); } if (type.ContainsAnonymousType()) { return SpecializedTasks.EmptyImmutableArray<ISymbol>(); } if (!type.CanBeReferencedByName) { return SpecializedTasks.EmptyImmutableArray<ISymbol>(); } // Normally the user can't say things like "new IList". Except for "IList[] x = new |". // In this case we do want to allow them to preselect certain types in the completion // list even if they can't new them directly. if (!isArray) { if (type.TypeKind == TypeKind.Interface || type.TypeKind == TypeKind.Pointer || type.TypeKind == TypeKind.Dynamic || type.IsAbstract) { return SpecializedTasks.EmptyImmutableArray<ISymbol>(); } if (type.TypeKind == TypeKind.TypeParameter && !((ITypeParameterSymbol)type).HasConstructorConstraint) { return SpecializedTasks.EmptyImmutableArray<ISymbol>(); } } if (!type.IsEditorBrowsable(options.GetOption(RecommendationOptions.HideAdvancedMembers, context.SemanticModel.Language), context.SemanticModel.Compilation)) { return SpecializedTasks.EmptyImmutableArray<ISymbol>(); } return Task.FromResult(ImmutableArray.Create((ISymbol)type)); }
protected override ValueTuple<string, string> GetDisplayAndInsertionText( ISymbol symbol, SyntaxContext context) { var displayService = context.GetLanguageService<ISymbolDisplayService>(); var displayString = displayService.ToMinimalDisplayString(context.SemanticModel, context.Position, symbol); return ValueTuple.Create(displayString, displayString); }
public static bool TryRemoveAttributeSuffix(ISymbol symbol, SyntaxContext context, out string name) { var isAttributeNameContext = context.IsAttributeNameContext; var syntaxFacts = context.GetLanguageService<ISyntaxFactsService>(); if (!isAttributeNameContext) { name = null; return false; } // Do the symbol textual check first. Then the more expensive symbolic check. if (!symbol.Name.TryGetWithoutAttributeSuffix(syntaxFacts.IsCaseSensitive, out name) || !symbol.IsAttribute()) { return false; } return true; }
protected override(string displayText, string insertionText) GetDisplayAndInsertionText( ISymbol symbol, SyntaxContext context) { var displayService = context.GetLanguageService<ISymbolDisplayService>(); var displayString = displayService.ToMinimalDisplayString(context.SemanticModel, context.Position, symbol); return (displayString, displayString); }