Пример #1
0
        internal override void OnConnected()
        {
            // Finish initialization now that the socket connection has been established
            var          threads      = _process.GetThreads();
            PythonThread activeThread = null;

            var dte = _serviceProvider.GetDTE();

            if (dte != null)
            {
                // If we are broken into the debugger, let's set the debug REPL active thread
                // to be the one that is active in the debugger
                var dteDebugger = dte.Debugger;
                if (dteDebugger.CurrentMode == EnvDTE.dbgDebugMode.dbgBreakMode &&
                    dteDebugger.CurrentProcess != null &&
                    dteDebugger.CurrentThread != null)
                {
                    if (_process.Id == dteDebugger.CurrentProcess.ProcessID)
                    {
                        var activeThreadId = _threadIdMapper.GetPythonThreadId((uint)dteDebugger.CurrentThread.ID);
                        activeThread = threads.SingleOrDefault(t => t.Id == activeThreadId);
                    }
                }
            }

            if (activeThread == null)
            {
                activeThread = threads.Count > 0 ? threads[0] : null;
            }

            if (activeThread != null)
            {
                SwitchThread(activeThread, false);
            }
        }
Пример #2
0
        public override async Task <ExecutionResult> InitializeAsync()
        {
            var result = await base.InitializeAsync();

            if (!result.IsSuccessful)
            {
                return(result);
            }

            result = await _serviceProvider.GetUIThread().InvokeTask(async() => {
                try {
                    UpdatePropertiesFromProjectMoniker();
                } catch (NoInterpretersException ex) {
                    WriteError(ex.ToString());
                } catch (MissingInterpreterException ex) {
                    WriteError(ex.ToString());
                } catch (DirectoryNotFoundException ex) {
                    WriteError(ex.ToString());
                } catch (Exception ex) when(!ex.IsCriticalException())
                {
                    WriteError(ex.ToUnhandledExceptionMessage(GetType()));
                }

                var remoteProcess = _process as PythonRemoteProcess;

                try {
                    _serviceProvider.GetPythonToolsService().Logger.LogEvent(Logging.PythonLogEvent.DebugRepl, new Logging.DebugReplInfo {
                        RemoteProcess = remoteProcess != null,
                        Version       = _process.LanguageVersion.ToVersion().ToString()
                    });
                } catch (Exception ex) {
                    Debug.Fail(ex.ToUnhandledExceptionMessage(GetType()));
                }

                _process.ModulesChanged += OnModulesChanged;

                var threads = _process.GetThreads();
                PythonThread activeThread = null;

                var dte = _serviceProvider.GetDTE();
                if (dte != null)
                {
                    // If we are broken into the debugger, let's set the debug REPL active thread
                    // to be the one that is active in the debugger
                    var dteDebugger = dte.Debugger;
                    if (dteDebugger.CurrentMode == EnvDTE.dbgDebugMode.dbgBreakMode &&
                        dteDebugger.CurrentProcess != null &&
                        dteDebugger.CurrentThread != null)
                    {
                        if (_process.Id == dteDebugger.CurrentProcess.ProcessID)
                        {
                            var activeThreadId = _threadIdMapper.GetPythonThreadId((uint)dteDebugger.CurrentThread.ID);
                            activeThread       = threads.SingleOrDefault(t => t.Id == activeThreadId);
                        }
                    }
                }

                if (activeThread == null)
                {
                    activeThread = threads.Count > 0 ? threads[0] : null;
                }

                if (activeThread != null)
                {
                    SwitchThread(activeThread, false);
                }

                return(ExecutionResult.Success);
            });

            return(result);
        }