Skip to content

Commit b7eb0c2

Browse files
64-bitmanchrisbra
authored andcommitted
patch 9.2.0060: No support for the DAP channel mode
Problem: No support for the DAP channel mode Solution: Add native channel support for the debug-adapter-protocol (Foxe Chen) closes: #19432 Signed-off-by: Foxe Chen <[email protected]> Signed-off-by: Christian Brabandt <[email protected]>
1 parent e8432bc commit b7eb0c2

File tree

9 files changed

+362
-71
lines changed

9 files changed

+362
-71
lines changed

runtime/doc/channel.txt

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*channel.txt* For Vim version 9.2. Last change: 2026 Feb 18
1+
*channel.txt* For Vim version 9.2. Last change: 2026 Feb 25
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -26,6 +26,7 @@ The Netbeans interface also uses a channel. |netbeans|
2626
13. Controlling a job |job-control|
2727
14. Using a prompt buffer |prompt-buffer|
2828
15. Language Server Protocol |language-server-protocol|
29+
16. Debug Adapter Protocol |debug-adapter-protocol|
2930

3031
*E1277*
3132
{only when compiled with the |+channel| feature for channel stuff}
@@ -56,6 +57,7 @@ NL every message ends in a NL (newline) character
5657
JSON JSON encoding |json_encode()|
5758
JS JavaScript style JSON-like encoding |js_encode()|
5859
LSP Language Server Protocol encoding |language-server-protocol|
60+
DAP Debug Adapter Protocol encoding |debug-adapter-protocol|
5961

6062
Common combination are:
6163
- Using a job connected through pipes in NL mode. E.g., to run a style
@@ -143,6 +145,7 @@ unreachable on the network.
143145
"nl" - Use messages that end in a NL character
144146
"raw" - Use raw messages
145147
"lsp" - Use language server protocol encoding
148+
"dap" - Use debug adapter protocol encoding
146149
*channel-callback* *E921*
147150
"callback" A function that is called when a message is received that is
148151
not handled otherwise (e.g. a JSON message with ID zero). It
@@ -153,8 +156,9 @@ unreachable on the network.
153156
endfunc
154157
let channel = ch_open("localhost:8765", {"callback": "Handle"})
155158
<
156-
When "mode" is "json" or "js" or "lsp" the "msg" argument is
157-
the body of the received message, converted to Vim types.
159+
When "mode" is any of "json", "js", "lsp" or "dap" the "msg"
160+
argument is the body of the received message, converted to Vim
161+
types.
158162
When "mode" is "nl" the "msg" argument is one message,
159163
excluding the NL.
160164
When "mode" is "raw" the "msg" argument is the whole message
@@ -537,16 +541,17 @@ ch_evalexpr({handle}, {expr} [, {options}]) *ch_evalexpr()*
537541
according to the type of channel. The function cannot be used
538542
with a raw channel. See |channel-use|.
539543
{handle} can be a Channel or a Job that has a Channel.
540-
When using the "lsp" channel mode, {expr} must be a |Dict|.
544+
When using the "lsp" or "dap" channel mode, {expr} must be a
545+
|Dict|.
541546
*E917*
542547
{options} must be a Dictionary. It must not have a "callback"
543548
entry. It can have a "timeout" entry to specify the timeout
544549
for this specific request.
545550

546551
ch_evalexpr() waits for a response and returns the decoded
547552
expression. When there is an error or timeout it returns an
548-
empty |String| or, when using the "lsp" channel mode, returns an
549-
empty |Dict|.
553+
empty |String| or, when using the "lsp" or "dap" channel mode,
554+
returns an empty |Dict|.
550555

551556
Note that while waiting for the response, Vim handles other
552557
messages. You need to make sure this doesn't cause trouble.
@@ -627,7 +632,7 @@ ch_info({handle}) *ch_info()*
627632
"err_io" "out", "null", "pipe", "file" or "buffer"
628633
"err_timeout" timeout in msec
629634
"in_status" "open" or "closed"
630-
"in_mode" "NL", "RAW", "JSON", "JS" or "LSP"
635+
"in_mode" "NL", "RAW", "JSON", "JS" or "LSP" or "DAP"
631636
"in_io" "null", "pipe", "file" or "buffer"
632637
"in_timeout" timeout in msec
633638

@@ -733,14 +738,15 @@ ch_sendexpr({handle}, {expr} [, {options}]) *ch_sendexpr()*
733738
with a raw channel.
734739
See |channel-use|. *E912*
735740
{handle} can be a Channel or a Job that has a Channel.
736-
When using the "lsp" channel mode, {expr} must be a |Dict|.
741+
When using the "lsp" or "dap" channel mode, {expr} must be a
742+
|Dict|.
737743

738-
If the channel mode is "lsp", then returns a Dict. Otherwise
739-
returns an empty String. If the "callback" item is present in
740-
{options}, then the returned Dict contains the ID of the
741-
request message. The ID can be used to send a cancellation
742-
request to the LSP server (if needed). Returns an empty Dict
743-
on error.
744+
If the channel mode is "lsp" or "dap", then returns a Dict.
745+
Otherwise returns an empty String. If the "callback" item is
746+
present in {options}, then the returned Dict contains the ID
747+
of the request message. The ID can be used to send a
748+
cancellation request to the LSP server or debug adapter (if
749+
needed). Returns an empty Dict on error.
744750

745751
If a response message is not expected for {expr}, then don't
746752
specify the "callback" item in {options}.
@@ -1607,5 +1613,33 @@ The "params" field is optional: >
16071613
"params": <list|dict>
16081614
}
16091615
1610-
<
1616+
==============================================================================
1617+
16. Debug Adapter Protocol *debug-adapter-protocol*
1618+
1619+
The debug adapter protocol is very similar to the language server protocol,
1620+
with the main difference being that it does not use the JSON-RPC format. The
1621+
specification can be found here:
1622+
1623+
https://microsoft.github.io/debug-adapter-protocol/specification
1624+
1625+
The protocol uses the same header format as the LSP protocol.
1626+
1627+
To encode and send a DAP request/notification message in a Vim |Dict| into a
1628+
JSON message and to receive and decode a DAP JSON response/notification
1629+
message into a Vim |Dict|, connect to the debug adapter with the
1630+
|channel-mode| set to "dap".
1631+
1632+
For messages received on a channel with |channel-mode| set to "dap", Vim will
1633+
process the HTTP header and decode the JSON payload into a Vim |Dict| type.
1634+
When sending messages on a channel using the |ch_evalexpr()| or
1635+
|ch_sendexpr()| functions, Vim will add the HTTP header and encode the Vim
1636+
expression into JSON.
1637+
1638+
Vim will automatically add the "seq" field to the JSON DAP message, and manage
1639+
the "request_seq" field as well for responses. However it will not add the
1640+
"type" field, it should be manually specified in the |Dict|.
1641+
1642+
Otherwise the behaviour is the same as how Vim handles the "lsp" channel mode
1643+
|language-server-protocol|.
1644+
16111645
vim:tw=78:ts=8:noet:ft=help:norl:

runtime/doc/tags

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6989,6 +6989,7 @@ dav pi_netrw.txt /*dav*
69896989
davs pi_netrw.txt /*davs*
69906990
daw motion.txt /*daw*
69916991
dd change.txt /*dd*
6992+
debug-adapter-protocol channel.txt /*debug-adapter-protocol*
69926993
debug-gcc debug.txt /*debug-gcc*
69936994
debug-highlight debugger.txt /*debug-highlight*
69946995
debug-leaks debug.txt /*debug-leaks*

runtime/doc/version9.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
*version9.txt* For Vim version 9.2. Last change: 2026 Feb 24
1+
*version9.txt* For Vim version 9.2. Last change: 2026 Feb 25
22

33

44
VIM REFERENCE MANUAL by Bram Moolenaar
@@ -52592,6 +52592,7 @@ Other ~
5259252592
-----
5259352593
- The new |xdg.vim| script for full XDG compatibility is included.
5259452594
- |ConPTY| support is considered stable as of Windows 11.
52595+
- Support for "dap" channel mode for the |debug-adapter-protocol|.
5259552596

5259652597
*changed-9.3*
5259752598
Changed~

0 commit comments

Comments
 (0)