Example #1
0
        public bool ExecuteCommand(SaveCommandArgs args, CommandExecutionContext ctx)
        {
            try {
                var opts = GeneralOptions.Instance;

                if (opts.Enabled && opts.RefreshOnSave)
                {
                    _ = ThreadHelper.JoinableTaskFactory.RunAsync(async delegate {
                        // CodeLenses usually only live as long as the document is open so we just refresh all the connected ones.
                        await CodeLensConnectionHandler.RefreshAllCodeLensDataPoints();
                    });
                }

                return(true);
            } catch (Exception ex) {
                LogVS(ex);
                throw;
            }
        }
Example #2
0
        private void AsyncStartScanInternal()
        {
            try
            {
                var taskStatusCenterService = AsyncPackage.GetGlobalService(typeof(SVsTaskStatusCenterService)) as IVsTaskStatusCenterService;
                if (taskStatusCenterService == null)
                {
                    return;
                }

                var options = default(TaskHandlerOptions);
                options.Title = "Scanning solution for Dpdt clusters and its bindings...";
                options.ActionsAfterCompletion = CompletionActions.None;

                _data = default(TaskProgressData);
                _data.CanBeCanceled = false;

                var handler = taskStatusCenterService.PreRegister(options, _data);


                _backgroundScanner = new BackgroundScanner(
                    _outputPane !,
                    _buildStatusContainer
                    );

                CodeLensConnectionHandler.RefreshAllCodeLensDataPointsAsync()
                .FileAndForget(nameof(CodeLensConnectionHandler.RefreshAllCodeLensDataPointsAsync))
                ;

                _backgroundScanner.AsyncStart();

                handler.RegisterTask(
                    Task.Run(
                        async() => await ShowProgressAsync(handler)
                        )
                    );
            }
            catch (Exception excp)
            {
                LogVS(excp);
            }
        }
Example #3
0
 public CodeLensDetailsControl(CodeLensDetails details)
 {
     InitializeComponent();
     DataContext = CodeLensConnectionHandler.GetDetailsData(details.DataPointId);
 }
Example #4
0
        private void PerformScanBackground(
            )
        {
            var token = _cancellationTokenSource.Token;

            SolutionBindContainer?sbc = null;

            try
            {
                //const int max = 100;
                //for (var cc = 0; cc <= max; cc++)
                //{
                //    if (token.IsCancellationRequested)
                //    {
                //        return;
                //    }

                //    Thread.Sleep(100);

                //    Progress = ((float)cc) / max;
                //}

                if (_buildStatusContainer.BuildIsInProgress)
                {
                    _outputPane !.OutputStringThreadSafe($"Dpdt scanning is cancelled due to build/cleanup is in progress{Environment.NewLine}");
                    return;
                }

                _outputPane !.OutputStringThreadSafe($"Dpdt scanning is started{Environment.NewLine}");

                var componentModel = (IComponentModel)Package.GetGlobalService(typeof(SComponentModel));

                var workspace = (Workspace)componentModel.GetService <VisualStudioWorkspace>();

                if (workspace == null)
                {
                    return;
                }

                if (!workspace.CurrentSolution.Projects.Any())
                {
                    return;
                }

                sbc = new SolutionBindContainer();
                var index        = -1;
                var projectCount = workspace.CurrentSolution.Projects.Count();
                foreach (var project in workspace.CurrentSolution.Projects)
                {
                    Progress = ((float)(++index)) / projectCount;

                    if (token.IsCancellationRequested)
                    {
                        _outputPane !.OutputStringThreadSafe($"  Dpdt scanning is cancelled{Environment.NewLine}");
                        break;
                    }

                    if (_buildStatusContainer.BuildIsInProgress)
                    {
                        _outputPane !.OutputStringThreadSafe($"  Dpdt scanning is cancelled due to build/cleanup is in progress{Environment.NewLine}");
                        break;
                    }

                    if (project == null)
                    {
                        continue;
                    }

                    if (!project.SupportsCompilation)
                    {
                        continue;
                    }

                    if (project.Language != "C#")
                    {
                        continue;
                    }

                    var letsgo = false;
                    foreach (var reference in project.AnalyzerReferences)
                    {
                        //surrogate marker for nuget Dpdt.Injector has installed to the project
                        if (reference.Display == "DpdtInject.Generator")
                        {
                            letsgo = true;

                            break;
                        }
                    }

                    if (!letsgo)
                    {
                        _outputPane !.OutputStringThreadSafe($"  {project.Name}: Project skipped due to absense of Dpdt package installed{Environment.NewLine}");
                        continue;
                    }

                    var swt = Stopwatch.StartNew();

                    Compilation?compilation = null;
                    ThreadHelper.JoinableTaskFactory.Run(
                        async() =>
                    {
                        try
                        {
                            compilation = await project.GetCompilationAsync(token);
                        }
                        catch (OperationCanceledException ope)
                        {
                            //ok
                        }
                        catch (Exception excp)
                        {
                            LogVS(excp);
                        }
                    });

                    //first check for cancellation...
                    if (token.IsCancellationRequested)
                    {
                        _outputPane !.OutputStringThreadSafe($"  Dpdt scanning is cancelled{Environment.NewLine}");

                        break;
                    }

                    //..next for compilation errors, because both will result with compilation == null
                    if (compilation == null)
                    {
                        continue;
                    }

                    _outputPane !.OutputStringThreadSafe($"    {project.Name}: compilation taken {swt.Elapsed}{Environment.NewLine}");

                    var diag = compilation.GetDiagnostics();

                    var errors = diag.Where(j => j.Severity == DiagnosticSeverity.Error).ToList();
                    if (errors.Count > 0)
                    {
                        var errorMessage = string.Join(
                            Environment.NewLine,
                            errors.Select(j => j.ToString())
                            );

                        //DpdtPackage.ShowMessageBox(
                        //    "Error has been found",
                        //    errorMessage
                        //    );

                        _outputPane !.OutputStringThreadSafe($"     {project.Name}: compilation error {Environment.NewLine}");
                        _outputPane !.OutputStringThreadSafe("     " + errorMessage);
                        _outputPane !.OutputStringThreadSafe(Environment.NewLine);

                        //do not skip this project analysis, it may be partially fine
                        //continue;
                    }

                    swt.Restart();

                    var meta = new BuiltinMeta();
                    if (!meta.TryExtract(compilation, out var projectXml))
                    {
                        continue;
                    }
                    sbc.Append(projectXml !);

                    _outputPane !.OutputStringThreadSafe($"    {project.Name}: Binding extraction taken {swt.Elapsed}{Environment.NewLine}");
                    _outputPane !.OutputStringThreadSafe($"    {project.Name}: Found {projectXml.TotalBindingCount} binding{Environment.NewLine}");

                    if (token.IsCancellationRequested)
                    {
                        _outputPane !.OutputStringThreadSafe($"  Dpdt scanning is cancelled{Environment.NewLine}");

                        break;
                    }
                }
            }
            catch (Exception excp)
            {
                LogVS(excp);
                _outputPane !.OutputStringThreadSafe($"  Dpdt scanning failed: {excp.Message}{Environment.NewLine}");
                _outputPane !.OutputStringThreadSafe($"  Dpdt scanning failed: {excp.StackTrace}{Environment.NewLine}");
            }
            finally
            {
                if (sbc != null)
                {
                    this.SolutionBindContainer = sbc;
                }

                _outputPane !.OutputStringThreadSafe($"Dpdt scanning is finished{Environment.NewLine}");

                // CodeLenses usually only live as long as the document is open so we just refresh all the connected ones.
                //they will show actual status
                CodeLensConnectionHandler.RefreshAllCodeLensDataPointsAsync()
                .FileAndForget(nameof(PerformScanBackground))
                ;
                BindingListViewModel.RefreshAction?.Invoke();

                Progress   = 1f;
                IsFinished = true;
            }
        }
Example #5
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 Task InitializeAsync(
            CancellationToken cancellationToken,
            IProgress <ServiceProgressData> progress
            )
        {
            LogVS("Start 1");

            await base.InitializeAsync(cancellationToken, progress);

            LogVS("Start 2");

            // 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 this.JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            await DpdtInstallCommand.InitializeAsync(this);

            await DoCreateClusterCommand.InitializeAsync(this);

            await BindingListWindowCommand.InitializeAsync(this);

            LogVS("Start 3");

            //we do not wait it for its completion.
            CodeLensConnectionHandler.AcceptCodeLensConnectionsAsync()
            .FileAndForget(nameof(CodeLensConnectionHandler.AcceptCodeLensConnectionsAsync))
            ;

            LogVS("Start 4");

            var container = (await this.GetServiceAsync(typeof(SComponentModel)) as IComponentModel) !;

            LogVS("Start 5");

            var bsc = container.GetService <BuildStatusContainer>();

            bsc.Subscribe();

            var solution = await this.GetServiceAsync(typeof(SVsSolution)) as IVsSolution;

            if (solution != null)
            {
                LogVS("Start 6");

                var sEventsExt0 = container.GetService <ExtensionStatusContainer>();
                foreach (var sEventExt in new[] { sEventsExt0 })
                {
                    uint cookie;
                    solution !.AdviseSolutionEvents(sEventExt, out cookie);

                    sEventExt.Cookie = cookie;
                }
            }

            LogVS("Start 7");

            var isc = container !.GetService <IntellisenseStatusContainer>();
            await isc.StartAsync();

            isc.StartScanningInThreadPool();

            LogVS("Start 8");
        }