Beispiel #1
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
        /// <param name="progress">A provider for progress updates.</param>
        /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress);

            VSColorTheme.ThemeChanged += (args) => {
                System.Diagnostics.Debug.WriteLine("Theme changed.");
                ThemeHelper.RefreshThemeCache();
            };
            SolutionEvents.OnAfterOpenSolution += (s, args) => {
                Classifiers.SymbolMarkManager.Clear();
            };

            Instance = this;
            // When initialized asynchronously, the current thread may be a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread.
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            if ((Config.Instance.DisplayOptimizations & DisplayOptimizations.MainWindow) != 0)
            {
                WpfHelper.SetUITextRenderOptions(Application.Current.MainWindow, true);
            }
            await Commands.SymbolFinderWindowCommand.InitializeAsync(this);

            Commands.ScreenshotCommand.Initialize(this);
            Commands.IncrementVsixVersionCommand.Initialize(this);
            Commands.NaviBarSearchDeclarationCommand.Initialize(this);
        }
Beispiel #2
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
        /// <param name="progress">A provider for progress updates.</param>
        /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress);

            VSColorTheme.ThemeChanged += _ => {
                System.Diagnostics.Debug.WriteLine("Theme changed.");
                ThemeHelper.RefreshThemeCache();
            };
            SolutionEvents.OnAfterOpenSolution += (s, args) => {
                Classifiers.SymbolMarkManager.Clear();
            };
            // When initialized asynchronously, the current thread may be a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread.
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            if ((Config.Instance.DisplayOptimizations & DisplayOptimizations.MainWindow) != 0)
            {
                WpfHelper.SetUITextRenderOptions(Application.Current.MainWindow, true);
            }
            _dteEvents   = DTE2.Events;
            _buildEvents = _dteEvents.BuildEvents;
            _buildEvents.OnBuildBegin          += BuildEvents_OnBuildBegin;
            _buildEvents.OnBuildDone           += BuildEvents_OnBuildEnd;
            _buildEvents.OnBuildProjConfigDone += BuildEvents_OnBuildProjConfigDone;
            //_extenderCookie = DTE.ObjectExtenders.RegisterExtenderProvider(VSConstants.CATID.CSharpFileProperties_string, BuildBots.AutoReplaceExtenderProvider.Name, new BuildBots.AutoReplaceExtenderProvider());
            //await Commands.SymbolFinderWindowCommand.InitializeAsync(this);
            Commands.ScreenshotCommand.Initialize(this);
            Commands.IncrementVsixVersionCommand.Initialize(this);
            Commands.NaviBarSearchDeclarationCommand.Initialize(this);
        }
Beispiel #3
0
        public static Controls.ThemedToolTip CreateToolTip(ISymbol symbol, Compilation compilation)
        {
            var tip = new Controls.ThemedToolTip();

            if ((Config.Instance.DisplayOptimizations & DisplayOptimizations.CodeWindow) != 0)
            {
                WpfHelper.SetUITextRenderOptions(tip, true);
            }
            tip.Title
            .Append(symbol.GetAccessibility() + symbol.GetAbstractionModifier() + symbol.GetSymbolKindName() + " ")
            .Append(symbol.Name, true)
            .Append(symbol.GetParameterString());
            var content = tip.Content;
            var t       = symbol.GetReturnType();

            if (t != null)
            {
                content.Append("member type: ")
                .Append(t.ToDisplayString(WpfHelper.MemberNameFormat), true);
            }
            t = symbol.ContainingType;
            if (t != null)
            {
                if (content.Inlines.FirstInline != null)
                {
                    content.AppendLine();
                }
                content.Append(t.GetSymbolKindName() + ": ")
                .Append(t.ToDisplayString(WpfHelper.MemberNameFormat), true);
            }
            if (content.Inlines.FirstInline != null)
            {
                content.AppendLine();
            }
            content.Append("namespace: " + symbol.ContainingNamespace?.ToString())
            .Append("\nassembly: " + symbol.GetAssemblyModuleName());
            var f = symbol as IFieldSymbol;

            if (f != null && f.IsConst)
            {
                content.Append("\nconst: " + f.ConstantValue?.ToString());                 // sometimes the const value could be null
            }
            foreach (var attr in symbol.GetAttributes())
            {
                SymbolFormatter.Empty.ToUIText(content.AppendLine().Inlines, attr);
            }
            var doc     = new XmlDoc(symbol, compilation);
            var summary = doc.Summary ?? (Config.Instance.QuickInfoOptions.MatchFlags(QuickInfoOptions.DocumentationFromInheritDoc) ? doc.ExplicitInheritDoc?.Summary : null);

            if (summary != null)
            {
                content.AppendLine().AppendLine();
                new XmlDocRenderer(compilation, SymbolFormatter.Empty, symbol).Render(summary, content.Inlines);
                tip.MaxWidth = Config.Instance.QuickInfoMaxWidth;
            }
            return(tip);
        }
Beispiel #4
0
        /// <summary>
        /// Initialization of the package; this method is called right after the package is sited, so this is the place
        /// where you can put all the initialization code that rely on services provided by VisualStudio.
        /// </summary>
        /// <param name="cancellationToken">A cancellation token to monitor for initialization cancellation, which can occur when VS is shutting down.</param>
        /// <param name="progress">A provider for progress updates.</param>
        /// <returns>A task representing the async work of package initialization, or an already completed task if there is none. Do not return null from this method.</returns>
        protected override async System.Threading.Tasks.Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            await base.InitializeAsync(cancellationToken, progress);

            SolutionEvents.OnAfterOpenSolution += (s, args) => {
                Taggers.SymbolMarkManager.Clear();
            };
            // When initialized asynchronously, the current thread may be a background thread at this point.
            // Do any initialization that requires the UI thread after switching to the UI thread.
            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            if (Config.Instance.DisplayOptimizations.MatchFlags(DisplayOptimizations.CompactMenu))
            {
                Controls.LayoutOverrider.CompactMenu();
            }

            if (Config.Instance.DisplayOptimizations.MatchFlags(DisplayOptimizations.MainWindow))
            {
                WpfHelper.SetUITextRenderOptions(Application.Current.MainWindow, true);
            }

            _dteEvents   = DTE2.Events;
            _buildEvents = _dteEvents.BuildEvents;
            _buildEvents.OnBuildBegin          += BuildEvents_OnBuildBegin;
            _buildEvents.OnBuildDone           += BuildEvents_OnBuildEnd;
            _buildEvents.OnBuildProjConfigDone += BuildEvents_OnBuildProjConfigDone;
            //_extenderCookie = DTE.ObjectExtenders.RegisterExtenderProvider(VSConstants.CATID.CSharpFileProperties_string, BuildBots.AutoReplaceExtenderProvider.Name, new BuildBots.AutoReplaceExtenderProvider());
            //Commands.SymbolFinderWindowCommand.Initialize();
            Commands.ScreenshotCommand.Initialize();
            Commands.GetContentTypeCommand.Initialize();
            Commands.IncrementVsixVersionCommand.Initialize();
            Commands.NaviBarSearchDeclarationCommand.Initialize();
            if (Config.Instance.InitStatus != InitStatus.Normal)
            {
                Config.Instance.SaveConfig(Config.ConfigPath);                 // save the file to prevent this notification from reoccurrence
                new Commands.VersionInfoBar(this).Show(Config.Instance.InitStatus);
                if (Config.Instance.InitStatus == InitStatus.FirstLoad)
                {
                    // automatically load theme when first load
                    if (ThemeHelper.DocumentPageColor.ToWpfColor().IsDark())
                    {
                        Config.LoadConfig(Config.DarkTheme, StyleFilters.All);
                    }
                    else
                    {
                        Config.LoadConfig(Config.LightTheme, StyleFilters.All);
                    }
                }
            }
            Commands.SyntaxCustomizerWindowCommand.Initialize();
            //ListEditorCommands();
        }
Beispiel #5
0
        internal void Format(InlineCollection block, AttributeData item, bool isReturn)
        {
            var a = item.AttributeClass.Name;

            block.Add("[");
            if (isReturn)
            {
                block.Add("return".Render(Keyword));
                block.Add(": ");
            }
            block.Add(WpfHelper.Render(item.AttributeConstructor ?? (ISymbol)item.AttributeClass, a.EndsWith("Attribute", StringComparison.Ordinal) ? a.Substring(0, a.Length - 9) : a, Class));
            if (item.ConstructorArguments.Length == 0 && item.NamedArguments.Length == 0)
            {
                var node = item.ApplicationSyntaxReference?.GetSyntax() as Microsoft.CodeAnalysis.CSharp.Syntax.AttributeSyntax;
                if (node?.ArgumentList?.Arguments.Count > 0)
                {
                    block.Add(node.ArgumentList.ToString().Render(ThemeHelper.SystemGrayTextBrush));
                }
                block.Add("]");
                return;
            }
            block.Add("(");
            int i = 0;

            foreach (var arg in item.ConstructorArguments)
            {
                if (++i > 1)
                {
                    block.Add(", ");
                }
                Format(block, arg);
            }
            foreach (var arg in item.NamedArguments)
            {
                if (++i > 1)
                {
                    block.Add(", ");
                }
                var attrMember = item.AttributeClass.GetMembers(arg.Key).FirstOrDefault(m => m.Kind == SymbolKind.Field || m.Kind == SymbolKind.Property);
                if (attrMember != null)
                {
                    block.Add(arg.Key.Render(attrMember.Kind == SymbolKind.Property ? Property : Field));
                }
                else
                {
                    block.Add(arg.Key.Render(false, true, null));
                }
                block.Add("=");
                Format(block, arg.Value);
            }
            block.Add(")]");
        }
Beispiel #6
0
        void Format(InlineCollection block, TypedConstant constant)
        {
            if (constant.IsNull)
            {
                block.Add("null".Render(Keyword));
                return;
            }
            switch (constant.Kind)
            {
            case TypedConstantKind.Primitive:
                if (constant.Value is bool)
                {
                    block.Add(WpfHelper.Render((bool)constant.Value ? "true" : "false", Keyword));
                }
                else if (constant.Value is string)
                {
                    block.Add(constant.ToCSharpString().Render(Text));
                }
                else
                {
                    block.Add(constant.ToCSharpString().Render(Number));
                }
                break;

            case TypedConstantKind.Enum:
                var en = constant.ToCSharpString();
                if (en.IndexOf('|') != -1)
                {
                    var items = constant.Type.GetMembers().Where(i => {
                        var field = i as IFieldSymbol;
                        return(field != null &&
                               field.HasConstantValue &&
                               UnsafeArithmeticHelper.Equals(UnsafeArithmeticHelper.And(constant.Value, field.ConstantValue), field.ConstantValue) &&
                               UnsafeArithmeticHelper.IsZero(field.ConstantValue) == false);
                    });
                    var flags = items.ToArray();
                    for (int i = 0; i < flags.Length; i++)
                    {
                        if (i > 0)
                        {
                            block.Add(" | ");
                        }
                        block.Add((constant.Type.Name + "." + flags[i].Name).Render(Enum));
                    }
                }
                else
                {
                    block.Add((constant.Type.Name + en.Substring(en.LastIndexOf('.'))).Render(Enum));
                }
                break;

            case TypedConstantKind.Type:
                block.Add("typeof".Render(Keyword));
                block.Add("(");
                Format(block, constant.Value as ISymbol, null, false);
                block.Add(")");
                break;

            case TypedConstantKind.Array:
                block.Add("new".Render(Keyword));
                block.Add("[] { ");
                bool c = false;
                foreach (var item in constant.Values)
                {
                    if (c)
                    {
                        block.Add(", ");
                    }
                    else
                    {
                        c = true;
                    }
                    Format(block, item);
                }
                block.Add(" }");
                break;

            default:
                block.Add(constant.ToCSharpString());
                break;
            }
        }
Beispiel #7
0
        public static ThemedToolTip CreateToolTip(ISymbol symbol, bool forMemberList, SemanticContext context)
        {
            var tip = new ThemedToolTip();

            if (Config.Instance.DisplayOptimizations.MatchFlags(DisplayOptimizations.CodeWindow))
            {
                WpfHelper.SetUITextRenderOptions(tip, true);
            }
            if (forMemberList == false)
            {
                tip.Title.Append(ThemeHelper.GetImage(symbol.GetImageId()).WrapMargin(WpfHelper.GlyphMargin));
            }
            tip.Title
            .Append(symbol.GetAccessibility() + symbol.GetAbstractionModifier() + (symbol as IMethodSymbol).GetSpecialMethodModifier() + symbol.GetSymbolKindName() + " ")
            .Append(symbol.Name, true)
            .Append(symbol.GetParameterString());
            var content = tip.Content;
            var t       = symbol.GetReturnType();

            if (t != null)
            {
                content.Append(R.T_MemberType)
                .Append(t.ToDisplayString(CodeAnalysisHelper.MemberNameFormat), true);
            }
            else if (symbol.Kind == SymbolKind.TypeParameter)
            {
                content.Append(R.T_DefinedInType)
                .Append(symbol.ContainingSymbol?.ToDisplayString(CodeAnalysisHelper.MemberNameFormat) ?? String.Empty, true);
                var tp = symbol as ITypeParameterSymbol;
                if (tp.HasConstraint())
                {
                    content.AppendLine().Append(R.T_Constraint);
                    SymbolFormatter.Instance.ShowTypeConstaints(tp, content);
                }
            }
            t = symbol.ContainingType;
            if (t != null && t.TypeKind != TypeKind.Enum)
            {
                content.AppendLineBreak()
                .Append(t.GetSymbolKindName(), SymbolFormatter.Instance.Keyword).Append(": ")
                .Append(t.ToDisplayString(CodeAnalysisHelper.MemberNameFormat), true);
            }
            if (forMemberList == false)
            {
                content.AppendLineBreak()
                .Append(R.T_Namespace + symbol.ContainingNamespace?.ToString()).AppendLine();
                if (symbol.Kind == SymbolKind.Namespace)
                {
                    // hack: workaround to exclude references that returns null from GetDocument
                    content.Append(R.T_Assembly).Append(String.Join(", ", ((INamespaceSymbol)symbol).ConstituentNamespaces.Select(n => n.GetAssemblyModuleName()).Distinct()))
                    .AppendLine().Append(R.T_Project).Append(String.Join(", ", symbol.GetSourceReferences().Select(r => context.GetProject(r.SyntaxTree)).Where(p => p != null).Distinct().Select(p => p.Name)))
                    .AppendLine().Append(R.T_Location).Append(symbol.Locations.Length);
                }
                else
                {
                    if (symbol.HasSource())
                    {
                        content.Append(R.T_SourceFile).Append(String.Join(", ", symbol.GetSourceReferences().Select(r => System.IO.Path.GetFileName(r.SyntaxTree.FilePath))))
                        .AppendLine().Append(R.T_Project).Append(String.Join(", ", symbol.GetSourceReferences().Select(r => context.GetProject(r.SyntaxTree)).Where(p => p != null).Distinct().Select(p => p.Name)));
                    }
                    else
                    {
                        content.Append(R.T_Assembly).Append(symbol.GetAssemblyModuleName());
                    }

                    if (symbol.Kind == SymbolKind.NamedType)
                    {
                        switch (((INamedTypeSymbol)symbol).TypeKind)
                        {
                        case TypeKind.Delegate:
                            ShowDelegateSignature(content, (INamedTypeSymbol)symbol);
                            break;

                        case TypeKind.Enum:
                            ShowEnumType(content, symbol);
                            break;
                        }
                    }
                }
            }
            ShowAttributes(symbol, content);
            if (context.SemanticModel?.Compilation != null && Config.Instance.SymbolToolTipOptions.MatchFlags(SymbolToolTipOptions.XmlDocSummary))
            {
                ShowXmlDocSummary(symbol, context.SemanticModel.Compilation, tip);
            }
            ShowNumericForms(symbol, tip);
            return(tip);
        }
Beispiel #8
0
        public static ThemedToolTip CreateToolTip(ISymbol symbol, bool forMemberList, Compilation compilation)
        {
            var tip = new ThemedToolTip();

            if ((Config.Instance.DisplayOptimizations & DisplayOptimizations.CodeWindow) != 0)
            {
                WpfHelper.SetUITextRenderOptions(tip, true);
            }
            if (forMemberList == false)
            {
                tip.Title.Append(ThemeHelper.GetImage(symbol.GetImageId()).WrapMargin(WpfHelper.GlyphMargin));
            }
            tip.Title
            .Append(symbol.GetAccessibility() + symbol.GetAbstractionModifier() + (symbol as IMethodSymbol).GetSpecialMethodModifier() + symbol.GetSymbolKindName() + " ")
            .Append(symbol.Name, true)
            .Append(symbol.GetParameterString());
            var content = tip.Content;
            var t       = symbol.GetReturnType();

            if (t != null)
            {
                content.Append("member type: ")
                .Append(t.ToDisplayString(WpfHelper.MemberNameFormat), true);
            }
            else if (symbol.Kind == SymbolKind.TypeParameter)
            {
                content.Append("defined in: ")
                .Append(symbol.ContainingSymbol.ToDisplayString(WpfHelper.MemberNameFormat), true);
                var tp = symbol as ITypeParameterSymbol;
                if (tp.HasConstraint())
                {
                    content.Append(" (");
                    SymbolFormatter.Empty.ShowTypeConstaints(tp, content);
                    content.Append(")");
                }
            }
            t = symbol.ContainingType;
            if (t != null)
            {
                if (content.Inlines.FirstInline != null)
                {
                    content.AppendLine();
                }
                content.Append(t.GetSymbolKindName() + ": ")
                .Append(t.ToDisplayString(WpfHelper.MemberNameFormat), true);
            }
            if (forMemberList == false)
            {
                if (content.Inlines.FirstInline != null)
                {
                    content.AppendLine();
                }
                content.Append("namespace: " + symbol.ContainingNamespace?.ToString())
                .Append("\nassembly: " + symbol.GetAssemblyModuleName());

                if (symbol.Kind == SymbolKind.NamedType &&
                    ((INamedTypeSymbol)symbol).TypeKind == TypeKind.Delegate)
                {
                    ShowDelegateSignature(content, (INamedTypeSymbol)symbol);
                }
            }
            ShowAttributes(symbol, content);
            if (compilation != null && Config.Instance.SymbolToolTipOptions.MatchFlags(SymbolToolTipOptions.XmlDocSummary))
            {
                ShowXmlDocSummary(symbol, compilation, tip);
            }
            ShowNumericForms(symbol, tip);
            return(tip);
        }