예제 #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);
        }
예제 #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);
        }
예제 #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);
        }
예제 #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();
        }
예제 #5
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);
        }
예제 #6
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);
        }