Example #1
0
 public override int GetHashCode()
 {
     return(SymbolMarkManager.GetHashCode(this));
 }
Example #2
0
 public int GetHashCode(IBookmarkedSymbol obj)
 {
     return(SymbolMarkManager.GetHashCode(obj));
 }
Example #3
0
        static IEnumerable <IClassificationType> GetClassificationType(SyntaxNode node, SemanticModel semanticModel)
        {
            node = node.Kind() == SyntaxKind.Argument ? (node as ArgumentSyntax).Expression : node;
            //System.Diagnostics.Debug.WriteLine(node.GetType().Name + node.Span.ToString());
            var symbol = semanticModel.GetSymbolInfo(node).Symbol;

            if (symbol == null)
            {
                symbol = semanticModel.GetDeclaredSymbol(node);
                if (symbol != null)
                {
                    switch (symbol.Kind)
                    {
                    case SymbolKind.NamedType:
                        yield return(symbol.ContainingType != null ? _Classifications.NestedDeclaration : _Classifications.Declaration);

                        break;

                    case SymbolKind.Event:
                        yield return(_Classifications.NestedDeclaration);

                        break;

                    case SymbolKind.Method:
                        if (Config.Instance.SpecialHighlightOptions.MatchFlags(SpecialHighlightOptions.LocalFunctionDeclaration) ||
                            (symbol as IMethodSymbol).MethodKind != MethodKind.LocalFunction)
                        {
                            yield return(_Classifications.NestedDeclaration);
                        }
                        break;

                    case SymbolKind.Property:
                        if (symbol.ContainingType.IsAnonymousType == false)
                        {
                            yield return(_Classifications.NestedDeclaration);
                        }
                        break;

                    case SymbolKind.Field:
                        if (node.IsKind(SyntaxKind.TupleElement) && (node as TupleElementSyntax).Identifier.IsKind(SyntaxKind.None))
                        {
                            symbol = semanticModel.GetTypeInfo((node as TupleElementSyntax).Type).Type;
                        }
                        break;
                    }
                }
                else
                {
                    // NOTE: handle alias in using directive
                    if ((node.Parent as NameEqualsSyntax)?.Parent is UsingDirectiveSyntax)
                    {
                        yield return(_Classifications.AliasNamespace);
                    }
                    else if (node is AttributeArgumentSyntax)
                    {
                        symbol = semanticModel.GetSymbolInfo((node as AttributeArgumentSyntax).Expression).Symbol;
                        if (symbol != null && symbol.Kind == SymbolKind.Field && (symbol as IFieldSymbol)?.IsConst == true)
                        {
                            yield return(_Classifications.ConstField);

                            yield return(_Classifications.StaticMember);
                        }
                    }
                    symbol = node.Parent is MemberAccessExpressionSyntax?semanticModel.GetSymbolInfo(node.Parent).CandidateSymbols.FirstOrDefault()
                                 : node.Parent.IsKind(SyntaxKind.Argument) ? semanticModel.GetSymbolInfo((node.Parent as ArgumentSyntax).Expression).CandidateSymbols.FirstOrDefault()
                                                : node.IsKind(SyntaxKind.SimpleBaseType) ? semanticModel.GetTypeInfo((node as SimpleBaseTypeSyntax).Type).Type
                                                : node.IsKind(SyntaxKind.TypeConstraint) ? semanticModel.GetTypeInfo((node as TypeConstraintSyntax).Type).Type
                                                : null;

                    if (symbol == null)
                    {
                        yield break;
                    }
                }
            }
            switch (symbol.Kind)
            {
            case SymbolKind.Alias:
            case SymbolKind.ArrayType:
            case SymbolKind.Assembly:
            case SymbolKind.DynamicType:
            case SymbolKind.ErrorType:
            case SymbolKind.NetModule:
            case SymbolKind.PointerType:
            case SymbolKind.RangeVariable:
            case SymbolKind.Preprocessing:
                //case SymbolKind.Discard:
                yield break;

            case SymbolKind.Label:
                yield return(_Classifications.Label);

                yield break;

            case SymbolKind.TypeParameter:
                yield return(_Classifications.TypeParameter);

                yield break;

            case SymbolKind.Field:
                var f = symbol as IFieldSymbol;
                yield return(f.IsConst ? _Classifications.ConstField
                                                : f.IsReadOnly ? _Classifications.ReadonlyField
                                                : f.IsVolatile ? _Classifications.VolatileField
                                                : _Classifications.Field);

                break;

            case SymbolKind.Property:
                yield return(_Classifications.Property);

                break;

            case SymbolKind.Event:
                yield return(_Classifications.Event);

                break;

            case SymbolKind.Local:
                var localSymbol = symbol as ILocalSymbol;
                yield return(localSymbol.IsConst ? _Classifications.ConstField : _Classifications.LocalVariable);

                break;

            case SymbolKind.Namespace:
                yield return(_Classifications.Namespace);

                yield break;

            case SymbolKind.Parameter:
                yield return(_Classifications.Parameter);

                break;

            case SymbolKind.Method:
                var methodSymbol = symbol as IMethodSymbol;
                switch (methodSymbol.MethodKind)
                {
                case MethodKind.Constructor:
                    yield return
                        (node is AttributeSyntax || node.Parent is AttributeSyntax || node.Parent?.Parent is AttributeSyntax
                                                                        ? _Classifications.AttributeName
                                                                        : _Classifications.ConstructorMethod);

                    break;

                case MethodKind.Destructor:
                case MethodKind.StaticConstructor:
                    yield return(_Classifications.ConstructorMethod);

                    break;

                default:
                    yield return(methodSymbol.IsExtensionMethod ? _Classifications.ExtensionMethod
                                                                : methodSymbol.IsExtern ? _Classifications.ExternMethod
                                                                : _Classifications.Method);

                    break;
                }
                break;

            case SymbolKind.NamedType:
                break;

            default:
                yield break;
            }

            if (SymbolMarkManager.HasBookmark)
            {
                var markerStyle = SymbolMarkManager.GetSymbolMarkerStyle(symbol);
                if (markerStyle != null)
                {
                    yield return(markerStyle);
                }
            }

            if (TextEditorHelper.IdentifySymbolSource && symbol.IsMemberOrType() && symbol.ContainingAssembly != null)
            {
                yield return(symbol.ContainingAssembly.GetSourceType() == AssemblySource.Metadata
                                        ? _Classifications.MetadataSymbol
                                        : _Classifications.UserSymbol);
            }

            if (symbol.IsStatic)
            {
                if (symbol.Kind != SymbolKind.Namespace)
                {
                    yield return(_Classifications.StaticMember);
                }
            }
            else if (symbol.IsSealed)
            {
                if (symbol.Kind == SymbolKind.NamedType && (symbol as ITypeSymbol).TypeKind != TypeKind.Class)
                {
                    yield break;
                }
                yield return(_Classifications.SealedMember);
            }
            else if (symbol.IsOverride)
            {
                yield return(_Classifications.OverrideMember);
            }
            else if (symbol.IsVirtual)
            {
                yield return(_Classifications.VirtualMember);
            }
            else if (symbol.IsAbstract)
            {
                yield return(_Classifications.AbstractMember);
            }
        }