Convert Figma logo to code with AI

emacs-lsp logodap-mode

Emacs :heart: Debug Adapter Protocol

1,288
181
1,288
231

Top Related Projects

Official repository for the Microsoft C/C++ extension for VS Code.

2,243

A client for Language Server Protocol servers

Emacs client/library for the Language Server Protocol

1,038

UI integrations for lsp-mode

Quick Overview

DAP-mode is a Debug Adapter Protocol (DAP) client for Emacs. It provides a unified interface for debugging various programming languages in Emacs, leveraging the Debug Adapter Protocol to communicate with language-specific debug servers.

Pros

  • Supports multiple programming languages through a single interface
  • Integrates seamlessly with Emacs and other development tools
  • Provides a rich set of debugging features, including breakpoints, step debugging, and variable inspection
  • Actively maintained and regularly updated

Cons

  • Requires some initial setup and configuration
  • May have a steeper learning curve for users new to Emacs or debugging
  • Performance can vary depending on the specific language and debug adapter
  • Some advanced debugging features may not be available for all supported languages

Code Examples

  1. Setting up DAP-mode for Python debugging:
(require 'dap-python)
(setq dap-python-executable "python3")
(dap-python-setup)
  1. Configuring a debug template for Node.js:
(dap-register-debug-template
  "Node.js :: Run Current File"
  (list :type "node"
        :request "launch"
        :program "${file}"
        :cwd "${workspaceFolder}"))
  1. Adding a breakpoint and starting a debug session:
(dap-breakpoint-add nil (point))
(dap-debug (dap-debug-template-name "Node.js :: Run Current File"))

Getting Started

To get started with DAP-mode, follow these steps:

  1. Install DAP-mode using your preferred Emacs package manager (e.g., use-package, straight.el).
  2. Add the following configuration to your Emacs init file:
(require 'dap-mode)
(dap-mode 1)
(dap-ui-mode 1)
(dap-tooltip-mode 1)
(tooltip-mode 1)
(dap-ui-controls-mode 1)

;; Configure language-specific adapters
(require 'dap-python)
(require 'dap-node)
;; Add more language adapters as needed

;; Optional: Configure key bindings
(define-key dap-mode-map (kbd "<f5>") #'dap-debug)
(define-key dap-mode-map (kbd "<f9>") #'dap-breakpoint-toggle)
  1. Restart Emacs or evaluate the configuration.
  2. Open a file in your desired programming language and use M-x dap-debug to start debugging.

Competitor Comparisons

Official repository for the Microsoft C/C++ extension for VS Code.

Pros of vscode-cpptools

  • More extensive C/C++ language support and features
  • Larger user base and community support
  • Regular updates and active development from Microsoft

Cons of vscode-cpptools

  • Limited to Visual Studio Code editor
  • Heavier resource usage compared to dap-mode
  • Less customizable than Emacs-based solutions

Code comparison

dap-mode (Emacs):

(dap-register-debug-template
  "C++ (GDB) Launch"
  (list :type "gdb"
        :request "launch"
        :name "GDB::Launch"
        :target "${workspaceFolder}/a.out"
        :cwd "${workspaceFolder}"))

vscode-cpptools (VS Code):

{
  "type": "cppdbg",
  "request": "launch",
  "name": "Debug C++ Program",
  "program": "${workspaceFolder}/a.out",
  "cwd": "${workspaceFolder}"
}

Both examples show debug configuration setup, with dap-mode using Emacs Lisp and vscode-cpptools using JSON. The vscode-cpptools configuration is more straightforward, while dap-mode offers more flexibility for advanced users familiar with Emacs Lisp.

2,243

A client for Language Server Protocol servers

Pros of eglot

  • Lightweight and minimalistic approach to LSP integration
  • Built-in support for many language servers without additional configuration
  • Seamless integration with Emacs' built-in features like xref and completion-at-point

Cons of eglot

  • Limited debugging capabilities compared to dap-mode
  • Fewer customization options for advanced LSP features
  • May require additional setup for some language-specific functionalities

Code comparison

eglot:

(use-package eglot
  :ensure t
  :config
  (add-to-list 'eglot-server-programs '(python-mode . ("pyls")))
  (add-hook 'python-mode-hook 'eglot-ensure))

dap-mode:

(use-package dap-mode
  :ensure t
  :config
  (require 'dap-python)
  (dap-mode 1)
  (dap-ui-mode 1))

eglot focuses on simplicity and integration with Emacs' built-in features, making it easier to set up and use for basic LSP functionality. dap-mode, on the other hand, offers more comprehensive debugging capabilities and customization options, but may require more configuration and has a steeper learning curve.

While eglot is suitable for users who prefer a lightweight solution and primarily use LSP for code navigation and completion, dap-mode is better suited for developers who require advanced debugging features and are willing to invest time in configuring a more powerful development environment.

Emacs client/library for the Language Server Protocol

Pros of lsp-mode

  • Broader language support with a wide range of Language Server Protocol (LSP) implementations
  • More mature and feature-rich, with extensive configuration options
  • Larger community and more frequent updates

Cons of lsp-mode

  • Can be more complex to set up and configure for specific languages
  • May have higher resource usage due to its comprehensive feature set

Code Comparison

lsp-mode:

(use-package lsp-mode
  :hook ((python-mode . lsp)
         (rust-mode . lsp))
  :commands lsp)

dap-mode:

(use-package dap-mode
  :after lsp-mode
  :config (dap-auto-configure-mode))

Summary

lsp-mode is a comprehensive LSP client for Emacs, offering broad language support and extensive features. dap-mode, on the other hand, is specifically focused on debugging and builds upon lsp-mode. While lsp-mode provides a wide range of IDE-like features, dap-mode complements it by adding robust debugging capabilities. Users often use both packages together to create a full-featured development environment in Emacs.

1,038

UI integrations for lsp-mode

Pros of lsp-ui

  • Provides rich UI enhancements for LSP features, including inline documentation, sideline information, and code actions
  • Offers customizable visual feedback for diagnostics and code analysis
  • Integrates seamlessly with other LSP-related packages in Emacs

Cons of lsp-ui

  • Can be resource-intensive, especially on larger projects or slower machines
  • May require more configuration to fine-tune the UI elements to personal preferences
  • Some users find the additional UI elements distracting or overwhelming

Code Comparison

lsp-ui:

(use-package lsp-ui
  :ensure t
  :commands lsp-ui-mode
  :config
  (setq lsp-ui-sideline-enable t
        lsp-ui-doc-enable t))

dap-mode:

(use-package dap-mode
  :ensure t
  :after lsp-mode
  :config
  (dap-mode 1)
  (dap-ui-mode 1))

While lsp-ui focuses on enhancing the UI for LSP features, dap-mode is specifically designed for debugging support. lsp-ui provides visual improvements for code navigation and information display, whereas dap-mode offers a comprehensive debugging experience with features like breakpoints, watch expressions, and step-through debugging.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

[[https://melpa.org/#/dap-mode][file:https://melpa.org/packages/dap-mode-badge.svg]] [[https://stable.melpa.org/#/dap-mode][file:https://stable.melpa.org/packages/dap-mode-badge.svg]] [[http://spacemacs.org][file:https://cdn.rawgit.com/syl20bnr/spacemacs/442d025779da2f62fc86c2082703697714db6514/assets/spacemacs-badge.svg]] [[https://github.com/emacs-lsp/dap-mode/actions][file:https://github.com/emacs-lsp/dap-mode/workflows/CI/badge.svg]] [[https://discord.gg/swuxy5AAgT][file:https://discordapp.com/api/guilds/789885435026604033/widget.png?style=shield]]

  • dap-mode ** Table of Contents :TOC_4_gh:noexport:
  • [[#dap-mode][dap-mode]]
    • [[#summary][Summary]]
      • [[#project-status][Project status]]
    • [[#usage][Usage]]
      • [[#docker-usage][Docker usage]]
    • [[#features][Features]]
    • [[#configuration][Configuration]]
    • [[#gallery][Gallery]]
    • [[#extending-dap-with-new-debug-servers][Extending DAP with new Debug servers]]
    • [[#links][Links]]
    • [[#acknowledgments][Acknowledgments]]

** Summary Emacs client/library for [[https://microsoft.github.io/debug-adapter-protocol/][Debug Adapter Protocol]] is a wire protocol for communication between client and Debug Server. It's similar to the [[https://github.com/Microsoft/language-server-protocol][LSP]] but provides integration with debug server. *** Project status The API considered unstable until 1.0 release is out. It is tested against Java, Python, Ruby, Elixir and LLDB (C/C++/Objective-C/Swift). ** Usage The main entry points are dap-debug and dap-debug-edit-template. The first one asks for a registered debug template and starts the configuration using the default values for that particular configuration. The latter creates a debug template which could be customized before running. dap-debug-edit-template will prepare a template declaration inside a temporary buffer. You should execute this code using C-M-x for the changes to apply. You should also copy this code into your Emacs configuration if you wish to make it persistent.

dap-mode also provides a [[https://github.com/abo-abo/hydra][hydra]] with dap-hydra. You can automatically trigger the hydra when the program hits a breakpoint by using the following code.

#+BEGIN_SRC elisp (add-hook 'dap-stopped-hook (lambda (arg) (call-interactively #'dap-hydra))) #+END_SRC

*** Docker usage You can also use this tool with dockerized debug servers: configure it either with a .dir-locals file or drop an .lsp-docker.yml configuration file (use [[https://github.com/emacs-lsp/lsp-docker][lsp-docker]] for general reference). Basically you have one function dap-docker-register that performs all the heavy lifting (finding the original debug template, patching it, registering a debug provider e.t.c). This function examines a configuration file or falls back to the default configuration (which can be patched using the .dir-locals approach, take a note that the default configuration doesn't provide any sane defaults for debugging) and then operates on the combination of the two. This mechanism is the same as in lsp-docker.

Note: currently you cannot use this mode when using a network connection to connect to debuggers (this part is yet to be implemented).
Still want to talk to debuggers over network? In order to do so you have to look at the ~launch-args~ patching
done by ~dap-docker--dockerize-start-file-args~, you have to somehow assign ~nil~ to ~dap-server-path~ before it is passed further into session creation.

If you want to stick to a configuration file, take a look at the example below:

#+begin_src yaml
lsp:
  server:
    # 'lsp-docker' fields
  mappings:
    - source: "/your/host/source/path" # used both by 'lsp-docker' and 'dap-docker'
      destination: "/your/local/path/inside/a/container" # used both by 'lsp-docker' and 'dap-docker'
  debug:
    type: docker # only docker is supported
    subtype: image # or 'container'
    name: <docker image or container that has the debugger in> # you can omit this field
    # in this case the 'lsp-docker' ('server' section) image name is used
    enabled: true # you can explicitly disable 'dap-docker' by using 'false'
    provider: <your default language debug provider, double quoted string>
    template: <your default language debug template, double quoted string>
    launch_command: <an explicit command if you want to override a default one provided by the debug provider>
    # e.g. if you have installed a debug server in a different directory, not used with 'container' subtype debuggers
#+end_src

** [[https://emacs-lsp.github.io/dap-mode/page/features/][Features]] ** [[https://emacs-lsp.github.io/dap-mode/page/configuration/][Configuration]] ** [[https://emacs-lsp.github.io/dap-mode/page/gallery][Gallery]] ** [[https://emacs-lsp.github.io/dap-mode/page/adding-debug-server][Extending DAP with new Debug servers]] ** Links