예제 #1
0
        /////////////////////////////////////////////////////////////////////////////
        // Overriden Package Implementation

        /// <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 initilaization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", this.ToString()));
            base.Initialize();

            var services = (IServiceContainer)this;

            // register our options service which provides registry access for various options
            var optionsService = new PythonToolsOptionsService(this);

            services.AddService(typeof(IPythonToolsOptionsService), optionsService, promote: true);

            services.AddService(typeof(IClipboardService), new ClipboardService(), promote: true);

            services.AddService(typeof(IPythonToolsToolWindowService), this, promote: true);

            // register our PythonToolsService which provides access to core PTVS functionality
            var pyService = _pyService = new PythonToolsService(services);

            services.AddService(typeof(PythonToolsService), pyService, promote: true);

            _autoObject = new PythonAutomation(this);

            services.AddService(
                typeof(ErrorTaskProvider),
                (container, serviceType) => {
                var errorList     = GetService(typeof(SVsErrorList)) as IVsTaskList;
                var model         = ComponentModel;
                var errorProvider = model != null ? model.GetService <IErrorProviderFactory>() : null;
                return(new ErrorTaskProvider(this, errorList, errorProvider));
            },
                promote: true);

            services.AddService(
                typeof(CommentTaskProvider),
                (container, serviceType) => {
                var taskList      = GetService(typeof(SVsTaskList)) as IVsTaskList;
                var model         = ComponentModel;
                var errorProvider = model != null ? model.GetService <IErrorProviderFactory>() : null;
                return(new CommentTaskProvider(this, taskList, errorProvider));
            },
                promote: true);

            var solutionEventListener = new SolutionEventsListener(this);

            solutionEventListener.StartListeningForChanges();

            services.AddService(
                typeof(SolutionEventsListener),
                solutionEventListener,
                promote: true
                );

            // Register custom debug event service
            var customDebuggerEventHandler = new CustomDebuggerEventHandler(this);

            services.AddService(customDebuggerEventHandler.GetType(), customDebuggerEventHandler, promote: true);

            // Enable the mixed-mode debugger UI context
            UIContext.FromUIContextGuid(DkmEngineId.NativeEng).IsActive = true;

            // Add our command handlers for menu (commands must exist in the .vsct file)
            RegisterCommands(new Command[] {
                new OpenDebugReplCommand(this),
                new ExecuteInReplCommand(this),
                new SendToReplCommand(this),
                new StartWithoutDebuggingCommand(this),
                new StartDebuggingCommand(this),
                new FillParagraphCommand(this),
                new SendToDefiningModuleCommand(this),
                new DiagnosticsCommand(this),
                new RemoveImportsCommand(this),
                new RemoveImportsCurrentScopeCommand(this),
                new OpenInterpreterListCommand(this),
                new ImportWizardCommand(this),
                new SurveyNewsCommand(this),
                new ShowPythonViewCommand(this),
                new ShowCppViewCommand(this),
                new ShowNativePythonFrames(this),
                new UsePythonStepping(this),
            }, GuidList.guidPythonToolsCmdSet);

            try {
                RegisterCommands(new Command[] {
                    new AzureExplorerAttachDebuggerCommand(this)
                }, GuidList.guidPythonToolsCmdSet);
            } catch (NotSupportedException) {
            }


            RegisterCommands(GetReplCommands(), GuidList.guidPythonToolsCmdSet);

            RegisterProjectFactory(new PythonWebProjectFactory(this));

            // Enable the Python debugger UI context
            UIContext.FromUIContextGuid(AD7Engine.DebugEngineGuid).IsActive = true;

            var interpreterService = ComponentModel.GetService <IInterpreterOptionsService>();

            interpreterService.InterpretersChanged       += RefreshReplCommands;
            interpreterService.DefaultInterpreterChanged += RefreshReplCommands;

            var loadedProjectProvider = interpreterService.KnownProviders
                                        .OfType <LoadedProjectInterpreterFactoryProvider>()
                                        .FirstOrDefault();

            // Ensure the provider is available - if not, you probably need to
            // rebuild or clean your experimental hive.
            Debug.Assert(loadedProjectProvider != null, "Expected LoadedProjectInterpreterFactoryProvider");
            if (loadedProjectProvider != null)
            {
                loadedProjectProvider.SetSolution((IVsSolution)GetService(typeof(SVsSolution)));
            }

            // The variable is inherited by child processes backing Test Explorer, and is used in PTVS
            // test discoverer and test executor to connect back to VS.
            Environment.SetEnvironmentVariable("_PTVS_PID", Process.GetCurrentProcess().Id.ToString());
        }
예제 #2
0
        /////////////////////////////////////////////////////////////////////////////
        // Overriden Package Implementation

        /// <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 initilaization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            Trace.WriteLine("Entering Initialize() of: {0}".FormatUI(this));
            base.Initialize();

            var services = (IServiceContainer)this;

            services.AddService(typeof(IPythonToolsOptionsService), PythonToolsOptionsService.CreateService, promote: true);
            services.AddService(typeof(IClipboardService), new ClipboardService(), promote: true);
            services.AddService(typeof(IPythonToolsToolWindowService), this, promote: true);
            services.AddService(typeof(PythonLanguageInfo), (container, serviceType) => new PythonLanguageInfo(container), true);
            services.AddService(typeof(PythonToolsService), PythonToolsService.CreateService, promote: true);
            services.AddService(typeof(ErrorTaskProvider), ErrorTaskProvider.CreateService, promote: true);
            services.AddService(typeof(CommentTaskProvider), CommentTaskProvider.CreateService, promote: true);

            var solutionEventListener = new SolutionEventsListener(this);

            solutionEventListener.StartListeningForChanges();

            services.AddService(typeof(SolutionEventsListener), solutionEventListener, promote: true);

            // Register custom debug event service
            var customDebuggerEventHandler = new CustomDebuggerEventHandler(this);

            services.AddService(customDebuggerEventHandler.GetType(), customDebuggerEventHandler, promote: true);

            // Enable the mixed-mode debugger UI context
            UIContext.FromUIContextGuid(DkmEngineId.NativeEng).IsActive = true;

            // Add our command handlers for menu (commands must exist in the .vsct file)
            RegisterCommands(new Command[] {
                new OpenReplCommand(this, (int)PkgCmdIDList.cmdidReplWindow),
                new OpenReplCommand(this, (int)PythonConstants.OpenInteractiveForEnvironment),
                new OpenDebugReplCommand(this),
                new ExecuteInReplCommand(this),
                new SendToReplCommand(this),
                new StartWithoutDebuggingCommand(this),
                new StartDebuggingCommand(this),
                new FillParagraphCommand(this),
                new DiagnosticsCommand(this),
                new RemoveImportsCommand(this, true),
                new RemoveImportsCommand(this, false),
                new OpenInterpreterListCommand(this),
                new ImportWizardCommand(this),
                new SurveyNewsCommand(this),
                new ImportCoverageCommand(this),
                new ShowPythonViewCommand(this),
                new ShowCppViewCommand(this),
                new ShowNativePythonFrames(this),
                new UsePythonStepping(this),
                new AzureExplorerAttachDebuggerCommand(this),
                new OpenWebUrlCommand(this, "https://go.microsoft.com/fwlink/?linkid=832525", PkgCmdIDList.cmdidWebPythonAtMicrosoft),
                new OpenWebUrlCommand(this, Strings.IssueTrackerUrl, PkgCmdIDList.cmdidWebPTVSSupport, false),
                new OpenWebUrlCommand(this, "https://go.microsoft.com/fwlink/?linkid=832517", PkgCmdIDList.cmdidWebDGProducts),
            }, GuidList.guidPythonToolsCmdSet);


            // Enable the Python debugger UI context
            UIContext.FromUIContextGuid(AD7Engine.DebugEngineGuid).IsActive = true;

            // The variable is inherited by child processes backing Test Explorer, and is used in PTVS
            // test discoverer and test executor to connect back to VS.
            Environment.SetEnvironmentVariable("_PTVS_PID", Process.GetCurrentProcess().Id.ToString());

            Trace.WriteLine("Leaving Initialize() of: {0}".FormatUI(this));
        }
예제 #3
0
        /////////////////////////////////////////////////////////////////////////////
        // Overriden Package Implementation

        /// <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 initilaization code that rely on services provided by VisualStudio.
        /// </summary>
        protected override void Initialize()
        {
            Trace.WriteLine("Entering Initialize() of: {0}".FormatUI(this));
            base.Initialize();

            var services = (IServiceContainer)this;

            // register our options service which provides registry access for various options
            services.AddService(typeof(IPythonToolsOptionsService), PythonToolsOptionsService.CreateService, promote: true);

            services.AddService(typeof(IClipboardService), new ClipboardService(), promote: true);

            services.AddService(typeof(IPythonToolsToolWindowService), this, promote: true);

            // register our PythonToolsService which provides access to core PTVS functionality
            PythonToolsService pyService;

            try {
                pyService = _pyService = new PythonToolsService(services);
            } catch (Exception ex) when(!ex.IsCriticalException())
            {
                ex.ReportUnhandledException(services, GetType(), allowUI: false);
                throw;
            }

            services.AddService(typeof(PythonToolsService), pyService, promote: true);

            _autoObject = new PythonAutomation(this);

            services.AddService(
                typeof(ErrorTaskProvider),
                (container, serviceType) => {
                var errorList     = GetService(typeof(SVsErrorList)) as IVsTaskList;
                var model         = ComponentModel;
                var errorProvider = model != null ? model.GetService <IErrorProviderFactory>() : null;
                return(new ErrorTaskProvider(this, errorList, errorProvider));
            },
                promote: true);

            services.AddService(
                typeof(CommentTaskProvider),
                (container, serviceType) => {
                var taskList      = GetService(typeof(SVsTaskList)) as IVsTaskList;
                var model         = ComponentModel;
                var errorProvider = model != null ? model.GetService <IErrorProviderFactory>() : null;
                return(new CommentTaskProvider(this, taskList, errorProvider));
            },
                promote: true);


            var solutionEventListener = new SolutionEventsListener(this);

            solutionEventListener.StartListeningForChanges();

            services.AddService(
                typeof(SolutionEventsListener),
                solutionEventListener,
                promote: true
                );

            // Register custom debug event service
            var customDebuggerEventHandler = new CustomDebuggerEventHandler(this);

            services.AddService(customDebuggerEventHandler.GetType(), customDebuggerEventHandler, promote: true);

            // Enable the mixed-mode debugger UI context
            UIContext.FromUIContextGuid(DkmEngineId.NativeEng).IsActive = true;

            // Add our command handlers for menu (commands must exist in the .vsct file)
            RegisterCommands(new Command[] {
                new OpenReplCommand(this, (int)PkgCmdIDList.cmdidReplWindow),
                new OpenReplCommand(this, (int)PythonConstants.OpenInteractiveForEnvironment),
                new OpenDebugReplCommand(this),
                new ExecuteInReplCommand(this),
                new SendToReplCommand(this),
                new StartWithoutDebuggingCommand(this),
                new StartDebuggingCommand(this),
                new FillParagraphCommand(this),
                new DiagnosticsCommand(this),
                new RemoveImportsCommand(this, true),
                new RemoveImportsCommand(this, false),
                new OpenInterpreterListCommand(this),
                new ImportWizardCommand(this),
                new SurveyNewsCommand(this),
                new ImportCoverageCommand(this),
                new ShowPythonViewCommand(this),
                new ShowCppViewCommand(this),
                new ShowNativePythonFrames(this),
                new UsePythonStepping(this),
                new AzureExplorerAttachDebuggerCommand(this),
            }, GuidList.guidPythonToolsCmdSet);


            // Enable the Python debugger UI context
            UIContext.FromUIContextGuid(AD7Engine.DebugEngineGuid).IsActive = true;

            var interpreters       = ComponentModel.GetService <IInterpreterRegistryService>();
            var interpreterService = ComponentModel.GetService <IInterpreterOptionsService>();

            // The variable is inherited by child processes backing Test Explorer, and is used in PTVS
            // test discoverer and test executor to connect back to VS.
            Environment.SetEnvironmentVariable("_PTVS_PID", Process.GetCurrentProcess().Id.ToString());

            Trace.WriteLine("Leaving Initialize() of: {0}".FormatUI(this));
        }
예제 #4
0
        /////////////////////////////////////////////////////////////////////////////
        // Overriden Package Implementation

        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            Trace.WriteLine("Entering InitializeAsync() of: {0}".FormatUI(this));

            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);

            await base.InitializeAsync(cancellationToken, progress);

            AddService <IClipboardService>(new ClipboardService(), true);
            AddService <IPythonToolsToolWindowService>(this, true);
            AddService <PythonLanguageInfo>((container, serviceType) => new PythonLanguageInfo(this), promote: true);
            AddService <CustomDebuggerEventHandler>((container, serviceType) => new CustomDebuggerEventHandler(this), promote: true);
            AddService <IPythonToolsOptionsService>(PythonToolsOptionsService.CreateService, promote: true);
            AddService <IPythonToolsLogger>(PythonToolsLogger.CreateService, promote: true);
            AddService <PythonToolsService>(PythonToolsService.CreateService, promote: true);
            AddService <ErrorTaskProvider>(ErrorTaskProvider.CreateService, promote: true);
            AddService <CommentTaskProvider>(CommentTaskProvider.CreateService, promote: true);
            AddService <IPythonDebugOptionsService>((container, serviceType) => new PythonDebugOptionsService(this), promote: true);

            var solutionEventListener = new SolutionEventsListener(this);

            solutionEventListener.StartListeningForChanges();
            AddService <SolutionEventsListener>(solutionEventListener, true);

            // Enable the mixed-mode debugger UI context
            UIContext.FromUIContextGuid(DkmEngineId.NativeEng).IsActive = true;

            // Add our command handlers for menu (commands must exist in the .vsct file)
            RegisterCommands(GuidList.guidPythonToolsCmdSet,
                             new OpenReplCommand(this, (int)PkgCmdIDList.cmdidReplWindow),
                             new OpenReplCommand(this, PythonConstants.OpenInteractiveForEnvironment),
                             new OpenDebugReplCommand(this),
                             new ExecuteInReplCommand(this),
                             new SendToReplCommand(this),
                             new FillParagraphCommand(this),
                             new DiagnosticsCommand(this),
                             new RemoveImportsCommand(this, true),
                             new RemoveImportsCommand(this, false),
                             new OpenInterpreterListCommand(this),
                             new ImportWizardCommand(this),
                             new ImportCoverageCommand(this),
                             new ShowPythonViewCommand(this),
                             new ShowCppViewCommand(this),
                             new ShowNativePythonFrames(this),
                             new UsePythonStepping(this),
                             new ViewAllEnvironmentsCommand(this),
                             new OpenWebUrlCommand(this, "https://go.microsoft.com/fwlink/?linkid=832525", PkgCmdIDList.cmdidWebPythonAtMicrosoft),
                             new OpenWebUrlCommand(this, Strings.IssueTrackerUrl, PkgCmdIDList.cmdidWebPTVSSupport),
                             new OpenWebUrlCommand(this, "https://go.microsoft.com/fwlink/?linkid=832517", PkgCmdIDList.cmdidWebDGProducts));

            RegisterCommands(
                CommandAsyncToOleMenuCommandShimFactory.CreateCommand(GuidList.guidPythonToolsCmdSet, (int)PkgCmdIDList.cmdidAddEnvironment, new AddEnvironmentCommand(this)),
                CommandAsyncToOleMenuCommandShimFactory.CreateCommand(GuidList.guidPythonToolsCmdSet, PythonConstants.InstallPythonPackage, new ManagePackagesCommand(this)),
                new CurrentEnvironmentCommand(this),
                new CurrentEnvironmentListCommand(this)
                );

            // Enable the Python debugger UI context
            UIContext.FromUIContextGuid(AD7Engine.DebugEngineGuid).IsActive = true;

            // The variable is inherited by child processes backing Test Explorer, and is used in PTVS
            // test discoverer and test executor to connect back to VS.
            Environment.SetEnvironmentVariable("_PTVS_PID", Process.GetCurrentProcess().Id.ToString());

            Trace.WriteLine("Leaving Initialize() of: {0}".FormatUI(this));
        }
        /// <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 Visual Studio.
        /// </summary>
        protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress <ServiceProgressData> progress)
        {
            Trace.WriteLine(string.Format(CultureInfo.CurrentCulture, "Entering Initialize() of: {0}", ToString()));

            testRunner    = TestRunner.Create();
            processHelper = ChutzpahContainer.Get <IProcessHelper>();

            await JoinableTaskFactory.SwitchToMainThreadAsync(cancellationToken);


            dte = (DTE2)(await GetServiceAsync(typeof(EnvDTE.DTE)) as EnvDTE.DTE);
            if (dte == null)
            {
                //if dte is null then we throw a exception
                //this is a fatal errorma
                throw new ArgumentNullException("dte");
            }

            Logger   = new Logger(this);
            Settings = GetDialogPage(typeof(ChutzpahSettings)) as ChutzpahSettings;

            statusBar      = GetService(typeof(SVsStatusbar)) as IVsStatusbar;
            runnerCallback = new ParallelRunnerCallbackAdapter(new VisualStudioRunnerCallback(dte, statusBar));


            // Add our command handlers for menu (commands must exist in the .vsct file)
            var mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService;

            if (null != mcs)
            {
                // Command - Run JS Tests
                var runJsTestsCmd    = new CommandID(GuidList.guidChutzpahCmdSet, (int)PkgCmdIDList.cmdidRunJSTests);
                var runJsTestMenuCmd = new OleMenuCommand(RunJSTestCmdCallback, runJsTestsCmd);
                runJsTestMenuCmd.BeforeQueryStatus += RunJSTestsCmdQueryStatus;
                mcs.AddCommand(runJsTestMenuCmd);

                // Command - Run JS tests in browser
                var runJsTestsInBrowserCmd    = new CommandID(GuidList.guidChutzpahCmdSet, (int)PkgCmdIDList.cmdidRunInBrowser);
                var runJsTestInBrowserMenuCmd = new OleMenuCommand(RunJSTestInBrowserCmdCallback, runJsTestsInBrowserCmd);
                runJsTestInBrowserMenuCmd.BeforeQueryStatus += RunJSTestsInBrowserCmdQueryStatus;
                mcs.AddCommand(runJsTestInBrowserMenuCmd);

                // Command - Run Code Coverage
                var runJsTestCodeCoverageCmd     = new CommandID(GuidList.guidChutzpahCmdSet, (int)PkgCmdIDList.cmdidRunCodeCoverage);
                var runJsTestCodeCoverageMenuCmd = new OleMenuCommand(RunCodeCoverageCmdCallback, runJsTestCodeCoverageCmd);
                runJsTestCodeCoverageMenuCmd.BeforeQueryStatus += RunCodeCoverageCmdQueryStatus;
                mcs.AddCommand(runJsTestCodeCoverageMenuCmd);


                var runJsTestDebuggerCmd     = new CommandID(GuidList.guidChutzpahCmdSet, (int)PkgCmdIDList.cmdidDebugTests);
                var runJsTestDebuggerMenuCmd = new OleMenuCommand(RunDebuggerCmdCallback, runJsTestDebuggerCmd);
                runJsTestDebuggerMenuCmd.BeforeQueryStatus += RunDebuggerCmdQueryStatus;
                mcs.AddCommand(runJsTestDebuggerMenuCmd);
            }


            this.solutionListener = new SolutionEventsListener(this);
            this.solutionListener.SolutionUnloaded       += OnSolutionUnloaded;
            this.solutionListener.SolutionProjectChanged += OnSolutionProjectChanged;
            this.solutionListener.StartListeningForChanges();
        }