本文整理汇总了C#中AbstractSyntaxContext.GetLanguageService方法的典型用法代码示例。如果您正苦于以下问题:C# AbstractSyntaxContext.GetLanguageService方法的具体用法?C# AbstractSyntaxContext.GetLanguageService怎么用?C# AbstractSyntaxContext.GetLanguageService使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AbstractSyntaxContext
的用法示例。
在下文中一共展示了AbstractSyntaxContext.GetLanguageService方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetInsertionText
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);
}
示例2: GetPreselectedSymbolsWorker
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));
}
示例3: GetInsertionText
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);
}
示例4: GetPreselectedSymbolsWorker
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));
}
示例5: GetDisplayAndInsertionText
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);
}
示例6: IsCandidateProject
private bool IsCandidateProject(AbstractSyntaxContext context, CancellationToken cancellationToken)
{
var syntaxFacts = context.GetLanguageService<ISyntaxFactsService>();
return !syntaxFacts.IsInInactiveRegion(context.SyntaxTree, context.Position, cancellationToken);
}
示例7: GetSymbolsWorker
protected override Task<IEnumerable<ISymbol>> GetSymbolsWorker(AbstractSyntaxContext context, int position, OptionSet options, CancellationToken cancellationToken)
{
var recommender = context.GetLanguageService<IRecommendationService>();
return recommender.GetRecommendedSymbolsAtPositionAsync(context.Workspace, context.SemanticModel, position, options, cancellationToken);
}