daveleroy / SublimeDebugger

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

Bash adapter #251

Open arturolinares opened 4 months ago

arturolinares commented 4 months ago

It would be great if there were an adapter for debugging Bash scripts that use this library: https://github.com/rogalmic/vscode-bash-debug

I would also like to know how to create new adapters. Should they live in this package? Is it possible to create a new package that provides new adapters?

Thank you very much for your hard work. This plugin really helps Sublime Text ecosystem :)

daveleroy commented 4 months ago

If its for other people to use they should live in this package because there isn't a stable api for adapters to use. For testing and custom adapters you can add them outside the package and they will be picked up.

Here is the current adapters https://github.com/daveleroy/SublimeDebugger/tree/master/modules/adapters you can add to that and import it in the init.py and open a pull request.

Something like the following should get you started.


from . import util
from .. import dap
from .. import core

class Bash(dap.AdapterConfiguration):

    type = 'bashdb'
    docs = 'https://github.com/rogalmic/vscode-bash-debug#vs-code-bash-debug'

    installer = util.GitInstaller (
        type='bashdb',
        repo='rogalmic/vscode-bash-debug'
    )

    async def start(self, log: core.Logger, configuration: dap.ConfigurationExpanded):
        node = await util.get_and_warn_require_node(self.type, log)

        install_path = self.installer.install_path()
        command = [
            node,
            f'{install_path}/extension/out/bashDebug.js'
        ]
        return dap.StdioTransport(command)

    async def configuration_resolve(self, configuration: dap.ConfigurationExpanded) -> dap.ConfigurationExpanded:

        defaults = {
            'pathBash': 'bash',
            'pathBashdb': f'{self.installer.install_path()}/extension/bashdb_dir/bashdb',
            'pathBashdbLib': f'{self.installer.install_path()}/extension/bashdb_dir',
            'args': [],
            'env': {},
            'argsString': '',
            'pathCat': 'cat',
            'pathMkfifo': 'mkfifo',
            'pathPkill': 'pkill',
            'cwd': configuration.variables['folder']
        }

        for key, value in defaults.items():
            if not configuration.get(key):
                configuration[key] = value

        return configuration
daveleroy commented 4 months ago

They verify some things here https://github.com/rogalmic/vscode-bash-debug/blob/e9ae6ea07c05ce621d2f25b899b5560d000d9c57/src/extension.ts#L46 which I did not add