本文整理汇总了C#中Document.ShouldHideAdvancedMembers方法的典型用法代码示例。如果您正苦于以下问题:C# Document.ShouldHideAdvancedMembers方法的具体用法?C# Document.ShouldHideAdvancedMembers怎么用?C# Document.ShouldHideAdvancedMembers使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Document
的用法示例。
在下文中一共展示了Document.ShouldHideAdvancedMembers方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetCompletionsOffOfExplicitInterfaceAsync
private async Task<IEnumerable<CompletionItem>> GetCompletionsOffOfExplicitInterfaceAsync(
Document document, SemanticModel semanticModel, int position, NameSyntax name, CancellationToken cancellationToken)
{
// Bind the interface name which is to the left of the dot
var syntaxTree = semanticModel.SyntaxTree;
var nameBinding = semanticModel.GetSymbolInfo(name, cancellationToken);
var context = CSharpSyntaxContext.CreateContext(document.Project.Solution.Workspace, semanticModel, position, cancellationToken);
var symbol = nameBinding.Symbol as ITypeSymbol;
if (symbol == null || symbol.TypeKind != TypeKind.Interface)
{
return SpecializedCollections.EmptyEnumerable<CompletionItem>();
}
var members = semanticModel.LookupSymbols(
position: name.SpanStart,
container: symbol)
.Where(s => !s.IsStatic)
.FilterToVisibleAndBrowsableSymbols(document.ShouldHideAdvancedMembers(), semanticModel.Compilation);
// We're going to create a entry for each one, including the signature
var completions = new List<CompletionItem>();
var signatureDisplayFormat =
new SymbolDisplayFormat(
genericsOptions: SymbolDisplayGenericsOptions.IncludeTypeParameters,
memberOptions:
SymbolDisplayMemberOptions.IncludeParameters,
parameterOptions:
SymbolDisplayParameterOptions.IncludeName |
SymbolDisplayParameterOptions.IncludeType |
SymbolDisplayParameterOptions.IncludeParamsRefOut,
miscellaneousOptions:
SymbolDisplayMiscellaneousOptions.EscapeKeywordIdentifiers |
SymbolDisplayMiscellaneousOptions.UseSpecialTypes);
var namePosition = name.SpanStart;
var text = await context.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false);
var textChangeSpan = CompletionUtilities.GetTextChangeSpan(text, context.Position);
foreach (var member in members)
{
var displayString = member.ToMinimalDisplayString(semanticModel, namePosition, signatureDisplayFormat);
var memberCopied = member;
var insertionText = displayString;
completions.Add(new SymbolCompletionItem(
this,
displayString,
insertionText: insertionText,
filterSpan: textChangeSpan,
position: position,
symbols: new List<ISymbol> { member },
context: context,
rules: ItemRules.Instance));
}
return completions;
}
示例2: GetItemsWorkerAsync
protected override async Task<IEnumerable<CompletionItem>> GetItemsWorkerAsync(Document document, int position, CompletionTriggerInfo triggerInfo, System.Threading.CancellationToken cancellationToken)
{
var tree = await document.GetCSharpSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
if (!tree.IsEntirelyWithinCrefSyntax(position, cancellationToken))
{
return null;
}
var token = tree.FindTokenOnLeftOfPosition(position, cancellationToken);
token = token.GetPreviousTokenIfTouchingWord(position);
if (token.Kind() == SyntaxKind.None)
{
return null;
}
var result = SpecializedCollections.EmptyEnumerable<ISymbol>();
var semanticModel = await document.GetCSharpSemanticModelForNodeAsync(token.Parent, cancellationToken).ConfigureAwait(false);
// cref ""|, ""|"", ""a|""
if (token.IsKind(SyntaxKind.DoubleQuoteToken, SyntaxKind.SingleQuoteToken) && token.Parent.IsKind(SyntaxKind.XmlCrefAttribute))
{
result = semanticModel.LookupSymbols(token.SpanStart)
.FilterToVisibleAndBrowsableSymbols(document.ShouldHideAdvancedMembers(), semanticModel.Compilation);
result = result.Concat(GetOperatorsAndIndexers(token, semanticModel, cancellationToken));
}
else if (IsSignatureContext(token))
{
result = semanticModel.LookupNamespacesAndTypes(token.SpanStart)
.FilterToVisibleAndBrowsableSymbols(document.ShouldHideAdvancedMembers(), semanticModel.Compilation);
}
else if (token.IsKind(SyntaxKind.DotToken) && token.Parent.IsKind(SyntaxKind.QualifiedCref))
{
// cref "a.|"
var parent = token.Parent as QualifiedCrefSyntax;
var leftType = semanticModel.GetTypeInfo(parent.Container, cancellationToken).Type;
var leftSymbol = semanticModel.GetSymbolInfo(parent.Container, cancellationToken).Symbol;
var container = leftSymbol ?? leftType;
result = semanticModel.LookupSymbols(token.SpanStart, container: (INamespaceOrTypeSymbol)container)
.FilterToVisibleAndBrowsableSymbols(document.ShouldHideAdvancedMembers(), semanticModel.Compilation);
if (container is INamedTypeSymbol)
{
result = result.Concat(((INamedTypeSymbol)container).InstanceConstructors);
}
}
return await CreateItemsAsync(document.Project.Solution.Workspace, semanticModel,
position, result, token, cancellationToken).ConfigureAwait(false);
}
示例3: GetNormalTypeConstructors
private IList<SignatureHelpItem> GetNormalTypeConstructors(
Document document,
ObjectCreationExpressionSyntax objectCreationExpression,
SemanticModel semanticModel,
ISymbolDisplayService symbolDisplayService,
IAnonymousTypeDisplayService anonymousTypeDisplayService,
IDocumentationCommentFormattingService documentationCommentFormattingService,
INamedTypeSymbol normalType,
ISymbol within,
CancellationToken cancellationToken)
{
var accessibleConstructors = normalType.InstanceConstructors
.Where(c => c.IsAccessibleWithin(within))
.Where(s => s.IsEditorBrowsable(document.ShouldHideAdvancedMembers(), semanticModel.Compilation))
.Sort(symbolDisplayService, semanticModel, objectCreationExpression.SpanStart);
return accessibleConstructors.Select(c =>
ConvertNormalTypeConstructor(c, objectCreationExpression, semanticModel, symbolDisplayService, anonymousTypeDisplayService, documentationCommentFormattingService, cancellationToken)).ToList();
}
示例4: GetItemsWorkerAsync
protected override async Task<IEnumerable<CompletionItem>> GetItemsWorkerAsync(Document document, int position, CompletionTriggerInfo triggerInfo, CancellationToken cancellationToken)
{
var workspace = document.Project.Solution.Workspace;
var semanticModel = await document.GetSemanticModelForSpanAsync(new TextSpan(position, 0), cancellationToken).ConfigureAwait(false);
var typeAndLocation = GetInitializedType(document, semanticModel, position, cancellationToken);
if (typeAndLocation == null)
{
return null;
}
var initializedType = typeAndLocation.Item1 as INamedTypeSymbol;
var initializerLocation = typeAndLocation.Item2;
if (initializedType == null)
{
return null;
}
// Find the members that can be initialized. If we have a NamedTypeSymbol, also get the overridden members.
IEnumerable<ISymbol> members = semanticModel.LookupSymbols(position, initializedType);
members = members.Where(m => IsInitializable(m, initializedType) &&
m.CanBeReferencedByName &&
IsLegalFieldOrProperty(m) &&
!m.IsImplicitlyDeclared);
// Filter out those members that have already been typed
var alreadyTypedMembers = GetInitializedMembers(semanticModel.SyntaxTree, position, cancellationToken);
var uninitializedMembers = members.Where(m => !alreadyTypedMembers.Contains(m.Name));
uninitializedMembers = uninitializedMembers.Where(m => m.IsEditorBrowsable(document.ShouldHideAdvancedMembers(), semanticModel.Compilation));
var text = await semanticModel.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false);
var changes = GetTextChangeSpan(text, position);
// Return the members
return uninitializedMembers.Select(
m => CreateItem(workspace, m.Name, changes,
CommonCompletionUtilities.CreateDescriptionFactory(workspace, semanticModel, initializerLocation.SourceSpan.Start, m),
m.GetGlyph()));
}
示例5: GetOptions
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;
}
示例6: GetItemsWorkerAsync
protected override async Task<IEnumerable<CompletionItem>> GetItemsWorkerAsync(
Document document, int position, CompletionTriggerInfo triggerInfo,
CancellationToken cancellationToken)
{
var tree = await document.GetSyntaxTreeAsync(cancellationToken).ConfigureAwait(false);
if (tree.IsInNonUserCode(position, cancellationToken))
{
return null;
}
var token = tree.FindTokenOnLeftOfPosition(position, cancellationToken);
if (token.IsMandatoryNamedParameterPosition())
{
return null;
}
var typeInferenceService = document.GetLanguageService<ITypeInferenceService>();
var span = new TextSpan(position, 0);
var semanticModel = await document.GetSemanticModelForSpanAsync(span, cancellationToken).ConfigureAwait(false);
var type = typeInferenceService.InferType(semanticModel, position,
objectAsDefault: true,
cancellationToken: cancellationToken);
// If we have a Nullable<T>, unwrap it.
if (type.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T)
{
type = type.GetTypeArguments().FirstOrDefault();
if (type == null)
{
return null;
}
}
if (type.TypeKind != TypeKind.Enum)
{
type = GetCompletionListType(type, semanticModel.GetEnclosingNamedType(position, cancellationToken), semanticModel.Compilation);
if (type == null)
{
return null;
}
}
if (!type.IsEditorBrowsable(document.ShouldHideAdvancedMembers(), semanticModel.Compilation))
{
return null;
}
// Does type have any aliases?
ISymbol alias = await type.FindApplicableAlias(position, semanticModel, cancellationToken).ConfigureAwait(false);
var displayService = document.GetLanguageService<ISymbolDisplayService>();
var displayText = alias != null
? alias.Name
: displayService.ToMinimalDisplayString(semanticModel, position, type);
var workspace = document.Project.Solution.Workspace;
var text = await semanticModel.SyntaxTree.GetTextAsync(cancellationToken).ConfigureAwait(false);
var textChangeSpan = CompletionUtilities.GetTextChangeSpan(text, position);
var item = new CSharpCompletionItem(
workspace,
this,
displayText: displayText,
filterSpan: textChangeSpan,
descriptionFactory: CommonCompletionUtilities.CreateDescriptionFactory(workspace, semanticModel, position, alias ?? type),
glyph: (alias ?? type).GetGlyph(),
preselect: true);
return SpecializedCollections.SingletonEnumerable(item);
}