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