public SymbolCompletionItem( CompletionListProvider completionProvider, string displayText, string insertionText, string filterText, TextSpan filterSpan, int position, List<ISymbol> symbols, string sortText, AbstractSyntaxContext context, Glyph glyph, bool preselect = false, SupportedPlatformData supportedPlatforms = null, CompletionItemRules rules = null) : base(completionProvider, displayText, filterSpan, descriptionFactory: null, glyph: glyph, sortText: sortText, filterText: filterText, preselect: preselect, showsWarningIcon: supportedPlatforms != null, rules: rules, filters: GetFilters(symbols)) { this.InsertionText = insertionText; this.Position = position; this.Symbols = symbols; this.Context = context; _supportedPlatforms = supportedPlatforms; }
protected override ValueTuple<string, string> GetDisplayAndInsertionText(ISymbol symbol, AbstractSyntaxContext context) { var insertionText = ItemRules.GetInsertionText(symbol, context); var displayText = symbol.GetArity() == 0 ? insertionText : string.Format("{0}<>", insertionText); return ValueTuple.Create(displayText, insertionText); }
public SymbolCompletionItem( CompletionListProvider completionProvider, string displayText, string insertionText, string filterText, TextSpan filterSpan, int position, List <ISymbol> symbols, string sortText, AbstractSyntaxContext context, Glyph glyph, bool preselect = false, SupportedPlatformData supportedPlatforms = null, CompletionItemRules rules = null) : base(completionProvider, displayText, filterSpan, descriptionFactory : null, glyph : glyph, sortText : sortText, filterText : filterText, preselect : preselect, showsWarningIcon : supportedPlatforms != null, rules : rules, filters : GetFilters(symbols)) { this.InsertionText = insertionText; this.Position = position; this.Symbols = symbols; this.Context = context; _supportedPlatforms = supportedPlatforms; }
/// <summary> /// Given a Symbol, creates the completion item for it. /// </summary> private CompletionItem CreateItem( ValueTuple <string, string> displayAndInsertionText, int position, List <ISymbol> symbols, AbstractSyntaxContext context, TextSpan textChangeSpan, Dictionary <ISymbol, List <ProjectId> > invalidProjectMap, List <ProjectId> totalProjects, bool preselect, CancellationToken cancellationToken) { Contract.ThrowIfNull(symbols); SupportedPlatformData supportedPlatformData = null; if (invalidProjectMap != null) { List <ProjectId> invalidProjects = null; foreach (var symbol in symbols) { if (invalidProjectMap.TryGetValue(symbol, out invalidProjects)) { break; } } if (invalidProjects != null) { supportedPlatformData = new SupportedPlatformData(invalidProjects, totalProjects, context.Workspace); } } return(CreateItem(displayAndInsertionText, position, symbols, context, textChangeSpan, preselect, supportedPlatformData)); }
/// <summary> /// Given a Symbol, creates the completion item for it. /// </summary> private CompletionItem CreateItem( string displayText, string insertionText, int position, List<ISymbol> symbols, AbstractSyntaxContext context, Dictionary<ISymbol, List<ProjectId>> invalidProjectMap, List<ProjectId> totalProjects, bool preselect) { Contract.ThrowIfNull(symbols); SupportedPlatformData supportedPlatformData = null; if (invalidProjectMap != null) { List<ProjectId> invalidProjects = null; foreach (var symbol in symbols) { if (invalidProjectMap.TryGetValue(symbol, out invalidProjects)) { break; } } if (invalidProjects != null) { supportedPlatformData = new SupportedPlatformData(invalidProjects, totalProjects, context.Workspace); } } return CreateItem(displayText, insertionText, position, symbols, context, preselect, supportedPlatformData); }
protected virtual string GetFilterText(ISymbol symbol, string displayText, AbstractSyntaxContext context) { return((displayText == symbol.Name) || (displayText.Length > 0 && displayText[0] == '@') || (context.IsAttributeNameContext && symbol.IsAttribute()) ? displayText : symbol.Name); }
protected override IEnumerable<INamedTypeSymbol> LookupCandidateSymbols(AbstractSyntaxContext context, INamedTypeSymbol declaredSymbol, CancellationToken cancellationToken) { var candidates = base.LookupCandidateSymbols(context, declaredSymbol, cancellationToken); // The base class applies a broad filter when finding candidates, but since C# requires // that all parts have the "partial" modifier, the results can be trimmed further here. return candidates?.Where(symbol => symbol.DeclaringSyntaxReferences.Any(reference => IsPartialTypeDeclaration(reference.GetSyntax(cancellationToken)))); }
protected override ValueTuple<string, string> GetDisplayAndInsertionText(ISymbol symbol, AbstractSyntaxContext context) { if (symbol is IAliasSymbol) { return ValueTuple.Create(symbol.Name, symbol.Name); } return base.GetDisplayAndInsertionText(symbol, context); }
protected override string GetInsertionText(ISymbol symbol, AbstractSyntaxContext context, char ch) { if (symbol is IAliasSymbol) { return ((IAliasSymbol)symbol).Name; } var displayService = context.GetLanguageService<ISymbolDisplayService>(); return displayService.ToMinimalDisplayString(context.SemanticModel, context.Position, symbol); }
protected override string GetInsertionText(ISymbol symbol, AbstractSyntaxContext context, char ch) { if (symbol is IAliasSymbol) { return(((IAliasSymbol)symbol).Name); } var displayService = context.GetLanguageService <ISymbolDisplayService>(); return(displayService.ToMinimalDisplayString(context.SemanticModel, context.Position, symbol)); }
private CompletionItem CreateCompletionItem(INamedTypeSymbol symbol, TextSpan textSpan, int position, AbstractSyntaxContext context) { var displayAndInsertionText = GetDisplayAndInsertionText(symbol, context); return SymbolCompletionItem.Create( displayText: displayAndInsertionText.Item1, insertionText: displayAndInsertionText.Item2, symbol: symbol, contextPosition: context.Position, descriptionPosition: position, rules: CompletionItemRules.Default); }
protected override async Task<IEnumerable<ISymbol>> GetPreselectedSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken) { var result = await base.GetPreselectedSymbolsWorker(context, position, options, cancellationToken).ConfigureAwait(false); if (result.Any()) { var type = (ITypeSymbol)result.Single(); var alias = await type.FindApplicableAlias(position, context.SemanticModel, cancellationToken).ConfigureAwait(false); if (alias != null) { return SpecializedCollections.SingletonEnumerable(alias); } } return result; }
protected override CompletionItem CreateItem(string displayText, string insertionText, int position, List<ISymbol> symbols, AbstractSyntaxContext context, TextSpan span, bool preselect, SupportedPlatformData supportedPlatformData) { return SymbolCompletionItem.Create( displayText: displayText, insertionText: insertionText, filterText: GetFilterText(symbols[0], displayText, context), span: span, contextPosition: context.Position, descriptionPosition: position, symbols: symbols, supportedPlatforms: supportedPlatformData, preselect: preselect, tags: s_Tags, rules: GetCompletionItemRules(symbols, context)); }
public static string GetInsertionText(ISymbol symbol, AbstractSyntaxContext context) { string name; if (CommonCompletionUtilities.TryRemoveAttributeSuffix(symbol, context.IsAttributeNameContext, context.GetLanguageService<ISyntaxFactsService>(), out name)) { // Cannot escape Attribute name with the suffix removed. Only use the name with // the suffix removed if it does not need to be escaped. if (name.Equals(name.EscapeIdentifier())) { return name; } } return symbol.Name.EscapeIdentifier(isQueryContext: context.IsInQuery); }
public static string GetInsertionText(ISymbol symbol, AbstractSyntaxContext context) { string name; if (CommonCompletionUtilities.TryRemoveAttributeSuffix(symbol, context.IsAttributeNameContext, context.GetLanguageService <ISyntaxFactsService>(), out name)) { // Cannot escape Attribute name with the suffix removed. Only use the name with // the suffix removed if it does not need to be escaped. if (name.Equals(name.EscapeIdentifier())) { return(name); } } return(symbol.Name.EscapeIdentifier(isQueryContext: context.IsInQuery)); }
/// <summary> /// Given a list of symbols, creates the list of completion items for them. /// </summary> protected IEnumerable<CompletionItem> CreateItems( int position, IEnumerable<ISymbol> symbols, AbstractSyntaxContext context, Dictionary<ISymbol, List<ProjectId>> invalidProjectMap, List<ProjectId> totalProjects, bool preselect) { var tree = context.SyntaxTree; var q = from symbol in symbols let texts = GetDisplayAndInsertionText(symbol, context) group symbol by texts into g select this.CreateItem(g.Key.Item1, g.Key.Item2, position, g.ToList(), context, invalidProjectMap, totalProjects, preselect); return q.ToList(); }
public SymbolCompletionItem( CompletionListProvider completionProvider, string displayText, string insertionText, string filterText, TextSpan filterSpan, int position, List <ISymbol> symbols, AbstractSyntaxContext context, bool preselect = false, SupportedPlatformData supportedPlatforms = null, CompletionItemRules rules = null) : this(completionProvider, displayText, insertionText, filterText, filterSpan, position, symbols, sortText : symbols[0].Name, context : context, glyph : symbols[0].GetGlyph(), preselect : preselect, supportedPlatforms : supportedPlatforms, rules : rules) { }
public SymbolCompletionItem( CompletionListProvider completionProvider, string displayText, string insertionText, string filterText, TextSpan filterSpan, int position, List<ISymbol> symbols, AbstractSyntaxContext context, bool preselect = false, SupportedPlatformData supportedPlatforms = null, CompletionItemRules rules = null) : this(completionProvider, displayText, insertionText, filterText, filterSpan, position, symbols, sortText: symbols[0].Name, context: context, glyph: symbols[0].GetGlyph(), preselect: preselect, supportedPlatforms: supportedPlatforms, rules: rules) { }
/// <summary> /// Given a list of symbols, creates the list of completion items for them. /// </summary> protected IEnumerable <CompletionItem> CreateItems( int position, IEnumerable <ISymbol> symbols, TextSpan span, AbstractSyntaxContext context, Dictionary <ISymbol, List <ProjectId> > invalidProjectMap, List <ProjectId> totalProjects, bool preselect) { var tree = context.SyntaxTree; var q = from symbol in symbols let texts = GetDisplayAndInsertionText(symbol, context) group symbol by texts into g select this.CreateItem(g.Key.Item1, g.Key.Item2, position, g.ToList(), context, span, invalidProjectMap, totalProjects, preselect); return(q.ToList()); }
public SymbolCompletionItem( ICompletionProvider completionProvider, string displayText, string insertionText, TextSpan filterSpan, int position, List <ISymbol> symbols, AbstractSyntaxContext context, bool preselect = false, SupportedPlatformData supportedPlatforms = null) : this(completionProvider, displayText, insertionText, filterText : displayText.Length > 0 && displayText[0] == '@' ? displayText : symbols[0].Name, filterSpan : filterSpan, position : position, symbols : symbols, context : context, preselect : preselect, supportedPlatforms : supportedPlatforms) { }
public SymbolCompletionItem( CompletionListProvider completionProvider, string displayText, string insertionText, TextSpan filterSpan, int position, List<ISymbol> symbols, AbstractSyntaxContext context, bool preselect = false, SupportedPlatformData supportedPlatforms = null) : this(completionProvider, displayText, insertionText, filterText: displayText.Length > 0 && displayText[0] == '@' ? displayText : symbols[0].Name, filterSpan: filterSpan, position: position, symbols: symbols, context: context, preselect: preselect, supportedPlatforms: supportedPlatforms) { }
/// <summary> /// Given a list of symbols, creates the list of completion items for them. /// </summary> protected async Task<IEnumerable<CompletionItem>> CreateItemsAsync( int position, IEnumerable<ISymbol> symbols, AbstractSyntaxContext context, Dictionary<ISymbol, List<ProjectId>> invalidProjectMap, List<ProjectId> totalProjects, bool preselect, CancellationToken cancellationToken) { var tree = context.SyntaxTree; var text = await context.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false); var textChangeSpan = this.GetTextChangeSpan(text, position); var q = from symbol in symbols let texts = GetDisplayAndInsertionText(symbol, context) group symbol by texts into g select this.CreateItem(g.Key, position, g.ToList(), context, textChangeSpan, invalidProjectMap, totalProjects, preselect, cancellationToken); return q.ToList(); }
protected override CompletionItem CreateItem(string displayText, string insertionText, int position, List<ISymbol> symbols, AbstractSyntaxContext context, bool preselect, SupportedPlatformData supportedPlatformData) { var matchPriority = preselect ? ComputeSymbolMatchPriority(symbols[0]) : MatchPriority.Default; var rules = GetCompletionItemRules(symbols, context, preselect); if (preselect) { rules = rules.WithSelectionBehavior(PreselectedItemSelectionBehavior); } return SymbolCompletionItem.Create( displayText: displayText, insertionText: insertionText, filterText: GetFilterText(symbols[0], displayText, context), contextPosition: context.Position, descriptionPosition: position, symbols: symbols, supportedPlatforms: supportedPlatformData, matchPriority: matchPriority, rules: rules); }
/// <summary> /// Given a list of symbols, creates the list of completion items for them. /// </summary> protected async Task <IEnumerable <CompletionItem> > CreateItemsAsync( int position, IEnumerable <ISymbol> symbols, AbstractSyntaxContext context, Dictionary <ISymbol, List <ProjectId> > invalidProjectMap, List <ProjectId> totalProjects, bool preselect, CancellationToken cancellationToken) { var tree = context.SyntaxTree; var text = await context.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false); var textChangeSpan = this.GetTextChangeSpan(text, position); var q = from symbol in symbols let texts = GetDisplayAndInsertionText(symbol, context) group symbol by texts into g select this.CreateItem(g.Key, position, g.ToList(), context, textChangeSpan, invalidProjectMap, totalProjects, preselect, cancellationToken); return(q.ToList()); }
public SymbolCompletionItem( ICompletionProvider completionProvider, string displayText, string insertionText, string filterText, TextSpan filterSpan, int position, List<ISymbol> symbols, AbstractSyntaxContext context, bool preselect = false, SupportedPlatformData supportedPlatforms = null) : base(completionProvider, displayText, filterSpan, descriptionFactory: null, glyph: symbols[0].GetGlyph(), sortText: symbols[0].Name, filterText: filterText, preselect: preselect, showsWarningIcon: supportedPlatforms != null) { this.InsertionText = insertionText; this.Position = position; this.Symbols = symbols; this.Context = context; _supportedPlatorms = supportedPlatforms; }
public SymbolCompletionItem( ICompletionProvider completionProvider, string displayText, string insertionText, string filterText, TextSpan filterSpan, int position, List <ISymbol> symbols, AbstractSyntaxContext context, bool preselect = false, SupportedPlatformData supportedPlatforms = null) : base(completionProvider, displayText, filterSpan, descriptionFactory : null, glyph : symbols[0].GetGlyph(), sortText : symbols[0].Name, filterText : filterText, preselect : preselect, showsWarningIcon : supportedPlatforms != null) { this.InsertionText = insertionText; this.Position = position; this.Symbols = symbols; this.Context = context; this.supportedPlatorms = supportedPlatforms; }
protected virtual IEnumerable<INamedTypeSymbol> LookupCandidateSymbols(AbstractSyntaxContext context, INamedTypeSymbol declaredSymbol, CancellationToken cancellationToken) { if (declaredSymbol == null) { throw new ArgumentNullException(nameof(declaredSymbol)); } SemanticModel semanticModel = context.SemanticModel; INamespaceOrTypeSymbol containingSymbol = declaredSymbol.ContainingSymbol as INamespaceOrTypeSymbol; if (containingSymbol == null) { return SpecializedCollections.EmptyEnumerable<INamedTypeSymbol>(); } return semanticModel.LookupNamespacesAndTypes(context.Position, containingSymbol) .OfType<INamedTypeSymbol>() .Where(symbol => declaredSymbol.TypeKind == symbol.TypeKind && NotNewDeclaredMember(symbol, context) && InSameProject(symbol, semanticModel.Compilation)); }
protected override async Task<IEnumerable<ISymbol>> GetPreselectedSymbolsWorker(AbstractSyntaxContext 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 SpecializedCollections.EmptyEnumerable<ISymbol>(); } 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.Where(s => inferredTypes.Contains(GetSymbolType(s)) && !IsInstrinsic(s)); }
protected abstract string GetInsertionText(ISymbol symbol, AbstractSyntaxContext context, char ch);
protected override Task<IEnumerable<ISymbol>> GetSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken) { return SpecializedTasks.EmptyEnumerable<ISymbol>(); }
protected abstract ValueTuple <string, string> GetDisplayAndInsertionText(ISymbol symbol, AbstractSyntaxContext context);
private Task<IEnumerable<ISymbol>> GetSymbolsWorker(int position, bool preselect, AbstractSyntaxContext context, OptionSet options, CancellationToken cancellationToken) { return preselect ? GetPreselectedSymbolsWorker(context, position, options, cancellationToken) : GetSymbolsWorker(context, position, options, cancellationToken); }
protected OptionSet GetOptions(Document document, CompletionTriggerInfo triggerInfo, AbstractSyntaxContext context) { var optionService = context.GetWorkspaceService<IOptionService>(); var filterOutOfScopeLocals = !triggerInfo.IsDebugger; var hideAdvancedMembers = document.ShouldHideAdvancedMembers(); var options = optionService .GetOptions() .WithChangedOption(RecommendationOptions.FilterOutOfScopeLocals, context.SemanticModel.Language, filterOutOfScopeLocals) .WithChangedOption(RecommendationOptions.HideAdvancedMembers, context.SemanticModel.Language, hideAdvancedMembers); return options; }
protected virtual CompletionItem CreateItem(ValueTuple<string, string> displayAndInsertionText, int position, List<ISymbol> symbols, AbstractSyntaxContext context, TextSpan textChangeSpan, bool preselect, SupportedPlatformData supportedPlatformData) { return new SymbolCompletionItem( this, displayAndInsertionText.Item1, displayAndInsertionText.Item2, GetFilterText(symbols[0], displayAndInsertionText.Item1, context), textChangeSpan, position, symbols, context, supportedPlatforms: supportedPlatformData, preselect: preselect); }
protected abstract Task<IEnumerable<ISymbol>> GetSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken);
protected override Task <IEnumerable <ISymbol> > GetSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken) { return(Task.FromResult(Recommender.GetRecommendedSymbolsAtPosition(context.SemanticModel, position, context.Workspace, options, cancellationToken))); }
protected abstract Task <IEnumerable <ISymbol> > GetSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken);
internal ShouldIncludeSymbolContext(AbstractSyntaxContext context, CancellationToken cancellationToken) { _context = context; _cancellationToken = cancellationToken; }
protected virtual CompletionItem CreateItem(ValueTuple <string, string> displayAndInsertionText, int position, List <ISymbol> symbols, AbstractSyntaxContext context, TextSpan textChangeSpan, bool preselect, SupportedPlatformData supportedPlatformData) { return(new SymbolCompletionItem( this, displayAndInsertionText.Item1, displayAndInsertionText.Item2, GetFilterText(symbols[0], displayAndInsertionText.Item1, context), textChangeSpan, position, symbols, context, supportedPlatforms: supportedPlatformData, preselect: preselect)); }
protected override Task <IEnumerable <ISymbol> > GetPreselectedSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken) { var newExpression = this.GetObjectCreationNewExpression(context.SyntaxTree, position, cancellationToken); if (newExpression == null) { return(SpecializedTasks.EmptyEnumerable <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.EmptyEnumerable <ISymbol>()); } // Unwrap nullable if (type.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T) { type = type.GetTypeArguments().FirstOrDefault(); } if (type.SpecialType == SpecialType.System_Void) { return(SpecializedTasks.EmptyEnumerable <ISymbol>()); } if (type.ContainsAnonymousType()) { return(SpecializedTasks.EmptyEnumerable <ISymbol>()); } if (!type.CanBeReferencedByName) { return(SpecializedTasks.EmptyEnumerable <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.EmptyEnumerable <ISymbol>()); } if (type.TypeKind == TypeKind.TypeParameter && !((ITypeParameterSymbol)type).HasConstructorConstraint) { return(SpecializedTasks.EmptyEnumerable <ISymbol>()); } } if (!type.IsEditorBrowsable(options.GetOption(RecommendationOptions.HideAdvancedMembers, context.SemanticModel.Language), context.SemanticModel.Compilation)) { return(SpecializedTasks.EmptyEnumerable <ISymbol>()); } return(Task.FromResult(SpecializedCollections.SingletonEnumerable((ISymbol)type))); }
protected override CompletionItem CreateItem(string displayText, string insertionText, int position, List <ISymbol> symbols, AbstractSyntaxContext context, TextSpan span, bool preselect, SupportedPlatformData supportedPlatformData) { return(SymbolCompletionItem.Create( displayText: displayText, insertionText: insertionText, filterText: GetFilterText(symbols[0], displayText, context), span: span, contextPosition: context.Position, descriptionPosition: position, symbols: symbols, supportedPlatforms: supportedPlatformData, matchPriority: MatchPriority.Preselect, // Always preselect tags: s_Tags, rules: GetCompletionItemRules(symbols, context))); }
protected override async Task <IEnumerable <ISymbol> > GetPreselectedSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken) { var result = await base.GetPreselectedSymbolsWorker(context, position, options, cancellationToken).ConfigureAwait(false); if (result.Any()) { var type = (ITypeSymbol)result.Single(); var alias = await type.FindApplicableAlias(position, context.SemanticModel, cancellationToken).ConfigureAwait(false); if (alias != null) { return(SpecializedCollections.SingletonEnumerable(alias)); } } return(result); }
protected override ValueTuple <string, string> GetDisplayAndInsertionText(ISymbol symbol, AbstractSyntaxContext context) { if (symbol is IAliasSymbol) { return(ValueTuple.Create(symbol.Name, symbol.Name)); } return(base.GetDisplayAndInsertionText(symbol, context)); }
private bool ShouldIncludeSymbol(ISymbol symbol, AbstractSyntaxContext context, CancellationToken cancellationToken) { var isMember = false; switch (symbol.Kind) { case SymbolKind.NamedType: var namedType = (INamedTypeSymbol)symbol; if (namedType.SpecialType == SpecialType.System_Void) { return(false); } break; case SymbolKind.Method: var methodSymbol = (IMethodSymbol)symbol; if (methodSymbol.MethodKind == MethodKind.EventAdd || methodSymbol.MethodKind == MethodKind.EventRemove || methodSymbol.MethodKind == MethodKind.EventRaise || methodSymbol.MethodKind == MethodKind.PropertyGet || methodSymbol.MethodKind == MethodKind.PropertySet) { return(false); } isMember = true; break; case SymbolKind.Event: case SymbolKind.Field: case SymbolKind.Property: isMember = true; break; } if (context.IsAttributeNameContext) { return(symbol.IsOrContainsAccessibleAttribute(context.SemanticModel.Compilation)); } if (context.IsEnumTypeMemberAccessContext) { return(symbol.Kind == SymbolKind.Field); } // In an expression or statement context, we don't want to display instance members declared in outer containing types. if ((context.IsStatementContext || context.IsAnyExpressionContext) && !symbol.IsStatic && isMember && context.GetOuterTypes(cancellationToken).Contains(symbol.ContainingType)) { return(false); } var namespaceSymbol = symbol as INamespaceSymbol; if (namespaceSymbol != null) { return(namespaceSymbol.ContainsAccessibleTypesOrNamespaces(context.SemanticModel.Compilation.Assembly)); } return(true); }
protected abstract CompletionItemRules GetCompletionItemRules(IReadOnlyList <ISymbol> symbols, AbstractSyntaxContext context);
protected virtual string GetFilterText(ISymbol symbol, string displayText, AbstractSyntaxContext context) { return (displayText == symbol.Name) || (displayText.Length > 0 && displayText[0] == '@') || (context.IsAttributeNameContext && symbol.IsAttribute()) ? displayText : symbol.Name; }
protected virtual CompletionItem CreateItem(string displayText, string insertionText, int position, List <ISymbol> symbols, AbstractSyntaxContext context, TextSpan span, bool preselect, SupportedPlatformData supportedPlatformData) { return(SymbolCompletionItem.Create( displayText: displayText, insertionText: insertionText, filterText: GetFilterText(symbols[0], displayText, context), span: span, contextPosition: context.Position, descriptionPosition: position, symbols: symbols, supportedPlatforms: supportedPlatformData, preselect: preselect, rules: GetCompletionItemRules(symbols, context))); }
private async Task<TextSpan> GetTextChangeSpanAsync(int position, AbstractSyntaxContext context, CancellationToken cancellationToken) { var text = await context.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false); return GetTextChangeSpan(text, position); }
private bool IsCandidateProject(AbstractSyntaxContext context, CancellationToken cancellationToken) { var syntaxFacts = context.GetLanguageService <ISyntaxFactsService>(); return(!syntaxFacts.IsInInactiveRegion(context.SyntaxTree, context.Position, cancellationToken)); }
private bool IsCandidateProject(AbstractSyntaxContext context, CancellationToken cancellationToken) { var syntaxFacts = context.GetLanguageService<ISyntaxFactsService>(); return !syntaxFacts.IsInInactiveRegion(context.SyntaxTree, context.Position, cancellationToken); }
protected OptionSet GetOptions(Document document, CompletionTriggerInfo triggerInfo, AbstractSyntaxContext context) { var optionService = context.GetWorkspaceService <IOptionService>(); var filterOutOfScopeLocals = !triggerInfo.IsDebugger; var hideAdvancedMembers = document.ShouldHideAdvancedMembers(); var options = optionService .GetOptions() .WithChangedOption(RecommendationOptions.FilterOutOfScopeLocals, context.SemanticModel.Language, filterOutOfScopeLocals) .WithChangedOption(RecommendationOptions.HideAdvancedMembers, context.SemanticModel.Language, hideAdvancedMembers); return(options); }
protected abstract ValueTuple<string, string> GetDisplayAndInsertionText(ISymbol symbol, AbstractSyntaxContext context);
protected override ValueTuple <string, string> GetDisplayAndInsertionText(ISymbol symbol, AbstractSyntaxContext context) { var insertionText = ItemRules.GetInsertionText(symbol, context); var displayText = symbol.GetArity() == 0 ? insertionText : string.Format("{0}<>", insertionText); return(ValueTuple.Create(displayText, insertionText)); }
protected virtual Task <IEnumerable <ISymbol> > GetPreselectedSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken) { return(SpecializedTasks.EmptyEnumerable <ISymbol>()); }
private Task <IEnumerable <ISymbol> > GetSymbolsWorker(int position, bool preselect, AbstractSyntaxContext context, OptionSet options, CancellationToken cancellationToken) { return(preselect ? GetPreselectedSymbolsWorker(context, position, options, cancellationToken) : GetSymbolsWorker(context, position, options, cancellationToken)); }
protected override ValueTuple<string, string> GetDisplayAndInsertionText(ISymbol symbol, AbstractSyntaxContext context) { var displayService = context.GetLanguageService<ISymbolDisplayService>(); var displayString = displayService.ToMinimalDisplayString(context.SemanticModel, context.Position, symbol); return ValueTuple.Create(displayString, displayString); }
private async Task <TextSpan> GetTextChangeSpanAsync(int position, AbstractSyntaxContext context, CancellationToken cancellationToken) { var text = await context.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false); return(GetTextChangeSpan(text, position)); }
protected override Task<IEnumerable<ISymbol>> GetPreselectedSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken) { var newExpression = this.GetObjectCreationNewExpression(context.SyntaxTree, position, cancellationToken); if (newExpression == null) { return SpecializedTasks.EmptyEnumerable<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.EmptyEnumerable<ISymbol>(); } // Unwrap nullable if (type.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T) { type = type.GetTypeArguments().FirstOrDefault(); } if (type.SpecialType == SpecialType.System_Void) { return SpecializedTasks.EmptyEnumerable<ISymbol>(); } if (type.ContainsAnonymousType()) { return SpecializedTasks.EmptyEnumerable<ISymbol>(); } if (!type.CanBeReferencedByName) { return SpecializedTasks.EmptyEnumerable<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.EmptyEnumerable<ISymbol>(); } if (type.TypeKind == TypeKind.TypeParameter && !((ITypeParameterSymbol)type).HasConstructorConstraint) { return SpecializedTasks.EmptyEnumerable<ISymbol>(); } } if (!type.IsEditorBrowsable(options.GetOption(RecommendationOptions.HideAdvancedMembers, context.SemanticModel.Language), context.SemanticModel.Compilation)) { return SpecializedTasks.EmptyEnumerable<ISymbol>(); } return Task.FromResult(SpecializedCollections.SingletonEnumerable((ISymbol)type)); }
protected override ValueTuple <string, string> GetDisplayAndInsertionText(ISymbol symbol, AbstractSyntaxContext context) { var displayService = context.GetLanguageService <ISymbolDisplayService>(); var displayString = displayService.ToMinimalDisplayString(context.SemanticModel, context.Position, symbol); return(ValueTuple.Create(displayString, displayString)); }