当前位置: 首页>>代码示例>>C#>>正文


C# AbstractSyntaxContext.GetLanguageService方法代码示例

本文整理汇总了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);
            }
开发者ID:rjmurillo,项目名称:roslyn,代码行数:10,代码来源:ObjectCreationCompletionProvider.ItemRules.cs

示例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));
        }
开发者ID:vslsnap,项目名称:roslyn,代码行数:23,代码来源:AbstractRecommendationServiceBasedCompletionProvider.cs

示例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);
        }
开发者ID:RoryVL,项目名称:roslyn,代码行数:16,代码来源:SymbolCompletionProvider.cs

示例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));
        }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:74,代码来源:AbstractObjectCreationCompletionProvider.cs

示例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);
 }
开发者ID:SoumikMukherjeeDOTNET,项目名称:roslyn,代码行数:6,代码来源:AbstractObjectCreationCompletionProvider.cs

示例6: IsCandidateProject

 private bool IsCandidateProject(AbstractSyntaxContext context, CancellationToken cancellationToken)
 {
     var syntaxFacts = context.GetLanguageService<ISyntaxFactsService>();
     return !syntaxFacts.IsInInactiveRegion(context.SyntaxTree, context.Position, cancellationToken);
 }
开发者ID:elemk0vv,项目名称:roslyn-1,代码行数:5,代码来源:AbstractSymbolCompletionProvider.cs

示例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);
 }
开发者ID:vslsnap,项目名称:roslyn,代码行数:5,代码来源:AbstractRecommendationServiceBasedCompletionProvider.cs


注:本文中的AbstractSyntaxContext.GetLanguageService方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。