daveleroy / SublimeDebugger

Graphical Debugger for Sublime Text for debuggers that support the debug adapter protocol
MIT License
371 stars 44 forks source link

Python debugging will not start on Windows 10 + Sublime build 4126 #157

Closed scrovy closed 2 years ago

scrovy commented 2 years ago

I've installed the latest version v0.6.7 of the debugger, the python adapter and copy pasted the example under C:\[sublime install dir]\Data\Packages\Debugger\examples\python to a local directory called example_python.

With the default configuration python.sublime-project which comes with the example:

{
    "folders": [
        {
            "path": ".",
        },
    ],
    "debugger_configurations": [
        {
            "name": "Python",
            "type": "python",
            "request": "launch",
            "program": "${project_path}/main.py",
        },
    ],
}

the debugger will not start and the command log (CTRL+`) is as follows:

Debugger: startup
Debugger: -- Commands --
Debugger: command: open
Debugger: command: quit
Debugger: command: settings
Debugger: command: generate_commands
Debugger: command: install_adapters
Debugger: command: change_configuration
Debugger: command: add_configuration
Debugger: command: start
Debugger: command: start_no_debug
Debugger: command: stop
Debugger: command: continue
Debugger: command: pause
Debugger: command: step_over
Debugger: command: step_in
Debugger: command: step_out
Debugger: command: input_command
Debugger: command: run_task
Debugger: command: run_last_task
Debugger: command: add_function_breakpoint
Debugger: command: clear_breakpoints
Debugger: command: clear_console
Debugger: command: show_protocol
Debugger: command: add_watch_expression
Debugger: command: save_data
Debugger: command: toggle_breakpoint
Debugger: command: toggle_column_breakpoint
Debugger: command: run_to_current_line
Debugger: -- LLDBCommands --
Debugger: command: lldb_toggle_disassembly
Debugger: command: lldb_display
Debugger: command: lldb_toggle_dereference
Debugger: ProjectConfiguration.reload
font face "Monospace" could not be found, defaulting to "Consolas"
Package Control: Skipping automatic upgrade, last run at 2022-03-29 12:13:52, next run at 2022-03-29 13:13:52 or after
Traceback (most recent call last):
  File "C:\[sublime install dir]\Data\Packages\Debugger\modules\core\sublime_event_loop.py", line 13, in __call__
    self.callback(*self.args)
  File "C:\[sublime install dir]\Data\Packages\Debugger\modules\core\core.py", line 67, in done
    exception = task.exception() 
asyncio.exceptions.CancelledError

Changed the font setting "font_face": "Monospace" to "font_face": "Consolas" in the file debugger.sublime-settings inside the package, and the error changes to

Debugger: error: Closing Debugger Console View it is not attached to a console
Package Control: Skipping automatic upgrade, last run at 2022-03-29 12:13:52, next run at 2022-03-29 13:13:52 or after
Traceback (most recent call last):
  File "C:\[sublime install dir]\Data\Packages\Debugger\modules\core\sublime_event_loop.py", line 13, in __call__
    self.callback(*self.args)
  File "C:\[sublime install dir]\Data\Packages\Debugger\modules\core\core.py", line 67, in done
    exception = task.exception() 
asyncio.exceptions.CancelledError

Tried all options "console": "integratedTerminal", "internalConsole" and "externalTerminal" and all give the same error, except that now the error message Debugger: error: Closing Debugger Console View it is not attached to a console disappears (but still CancelledError occurs). (Note: the terminus package is installed, hence externalTerminal should also work?) Also tried a more extensive configuration file

{
    "folders": [
        {
            "path": "C:\\explicit\\path\\to\\example_python",
        },
    ],
    "debugger_configurations": [
        {
            "name": "Python",
            "type": "python",
            "request": "launch",
            "console": "integratedTerminal",
            "program": "C:\\explicit\\path\\to\\example_python\\main.py",
            "justMyCode": true,
            "RedirectOutput": true,
            "debugOptions" : {
                "RedirectOutput": true,
            },
            "python": "C:\\[pythonpath]\\Python310\\python.exe",
            "cwd": "C:\\explicit\\path\\to\\example_python",
            "stopOnEntry": true,
        },
    ],
}

but it didn't help. Tried to fiddle with the open_at_startup option of debugger.sublime-settings, but with no avail. Any ideas?

daveleroy commented 2 years ago

What does running Debugger: Show Protocol reveal?

scrovy commented 2 years ago

Apparently the debugger is having trouble finding python:

⟸ process/starting :: ['python3', 'C:\\[...]\\Sublime Text Build 3211 x64\\Data\\Packages\\Debugger/data/adapters/python/extension/pythonFiles/lib/python/debugpy/adapter']
⟸ process/started ::
⟸ request/initialize(1) :: {'clientID': 'sublime', 'clientName': 'Sublime Text', 'adapterID': 'python', 'pathFormat': 'path', 'linesStartAt1': True, 'columnsStartAt1': True, 'supportsVariableType': True, 'supportsVariablePaging': False, 'supportsRunInTerminalRequest': True, 'supportsMemoryReferences': True, 'locale': 'en-us'}
⟸ process/stderr :: P
⟸ process/stderr :: ython was not found; run without arguments to install from the Microsoft Store
⟸ process/stderr :: ,
⟸ process/stderr ::  or disable this shortcut from Settings > Manage App 
⟸ process/stderr :: E
⟸ process/stderr :: xecution Aliases.

⟸ process/stopped :: 

But I do have the python executable in the configuration file:

            "python": "C:\\[...]\\Programs\\Python\\Python310\\python.exe",

All the mentioned paths/executables exist, I've double checked it.

daveleroy commented 2 years ago

The adapter configuration looks at pythonPath not python. I see python in the json schema though so it probably was changed to use python instead of pythonPath on Microsoft side.

https://github.com/daveleroy/sublime_debugger/blob/34c8b11336f9058d7d195bf9cf904c142e4fa18d/modules/adapters/python.py#L35

scrovy commented 2 years ago

That was it, thanks! Some config elements were wrong so hereby the (most simple) configuration that made it work:

{
        "folders": [
                {
                        "path": ".",
                },
        ],
        "debugger_configurations": [
                {
                        "name": "Python",
                        "type": "python",
                        "request": "launch",
                        "program": "${project_path}/main.py",
                        "pythonPath": "C:\\path\\to\\Python310\\python.exe"
                },
        ],
}

Also you might need "console": "internalConsole", if it still doesn't work.