@@ -102,35 +102,15 @@ local function register_default_configurations(paths, is_flutter_project, projec
102102 end
103103end
104104
105- function DebuggerRunner :run (
106- paths ,
107- args ,
108- cwd ,
109- on_run_data ,
110- on_run_exit ,
111- is_flutter_project ,
112- project_config ,
113- last_launch_config
114- )
115- --- @type dap.Configuration
116- local selected_launch_config = nil
117-
105+ local function register_dap_listeners (on_run_data , on_run_exit )
118106 local started = false
119107 local before_start_logs = {}
120- vm_service_extensions .reset ()
121108 dap .listeners .after [" event_output" ][plugin_identifier ] = function (_ , body )
122- if body and body .output then
123- for line in body .output :gmatch (" [^\r\n ]+" ) do
124- if not started then table.insert (before_start_logs , line ) end
125- on_run_data (body .category == " sterr" , line )
126- end
127- end
109+ on_run_data (started , before_start_logs , body )
128110 end
129111
130112 local handle_termination = function ()
131- if next (before_start_logs ) ~= nil then
132- on_run_exit (before_start_logs , args , project_config , selected_launch_config )
133- end
113+ if next (before_start_logs ) ~= nil then on_run_exit (before_start_logs ) end
134114 end
135115
136116 dap .listeners .before [" event_exited" ][plugin_identifier ] = function (_ , _ ) handle_termination () end
@@ -160,6 +140,35 @@ function DebuggerRunner:run(
160140 vm_service_extensions .set_service_extensions_state (body .extension , body .value )
161141 end
162142 end
143+ end
144+
145+ function DebuggerRunner :run (
146+ paths ,
147+ args ,
148+ cwd ,
149+ on_run_data ,
150+ on_run_exit ,
151+ is_flutter_project ,
152+ project_config ,
153+ last_launch_config
154+ )
155+ vm_service_extensions .reset ()
156+ --- @type dap.Configuration
157+ local selected_launch_config = nil
158+
159+ register_dap_listeners (
160+ function (started , before_start_logs , body )
161+ if body and body .output then
162+ for line in body .output :gmatch (" [^\r\n ]+" ) do
163+ if not started then table.insert (before_start_logs , line ) end
164+ on_run_data (body .category == " sterr" , line )
165+ end
166+ end
167+ end ,
168+ function (before_start_logs )
169+ on_run_exit (before_start_logs , args , project_config , selected_launch_config )
170+ end
171+ )
163172
164173 register_debug_adapter (paths , is_flutter_project )
165174 local launch_configurations = {}
@@ -212,6 +221,60 @@ function DebuggerRunner:run(
212221 end
213222end
214223
224+ function DebuggerRunner :attach (paths , args , cwd , on_run_data , on_run_exit )
225+ vm_service_extensions .reset ()
226+ register_dap_listeners (function (started , before_start_logs , body )
227+ if body and body .output then
228+ for line in body .output :gmatch (" [^\r\n ]+" ) do
229+ if not started then table.insert (before_start_logs , line ) end
230+ on_run_data (body .category == " sterr" , line )
231+ end
232+ end
233+ end , function (before_start_logs ) on_run_exit (before_start_logs , args ) end )
234+
235+ register_debug_adapter (paths , true )
236+ local launch_configurations = {}
237+ local launch_configuration_count = 0
238+ register_default_configurations (paths , true )
239+ if config .debugger .register_configurations then config .debugger .register_configurations (paths ) end
240+ local all_configurations = require (" dap" ).configurations .dart
241+ if not all_configurations then
242+ ui .notify (" No launch configuration for DAP found" , ui .ERROR )
243+ return
244+ end
245+ for _ , c in ipairs (all_configurations ) do
246+ if c .request == " attach" then
247+ table.insert (launch_configurations , c )
248+ launch_configuration_count = launch_configuration_count + 1
249+ end
250+ end
251+
252+ if launch_configuration_count == 0 then
253+ ui .notify (" No launch configuration for DAP found" , ui .ERROR )
254+ return
255+ else
256+ require (" dap.ui" ).pick_if_many (
257+ launch_configurations ,
258+ " Select launch configuration" ,
259+ function (item )
260+ return fmt (" %s : %s | %s" , item .name , item .program or item .cwd , vim .inspect (item .args ))
261+ end ,
262+ function (launch_config )
263+ if not launch_config then return end
264+ launch_config = vim .deepcopy (launch_config )
265+ if not launch_config .cwd then launch_config .cwd = cwd end
266+ launch_config .args = vim .list_extend (launch_config .args or {}, args or {})
267+ launch_config .dartSdkPath = paths .dart_sdk
268+ launch_config .flutterSdkPath = paths .flutter_sdk
269+ if config .debugger .evaluate_to_string_in_debug_views then
270+ launch_config .evaluateToStringInDebugViews = true
271+ end
272+ dap .run (launch_config )
273+ end
274+ )
275+ end
276+ end
277+
215278function DebuggerRunner :send (cmd , quiet )
216279 if cmd == " open_dev_tools" then
217280 dev_tools .open_dev_tools ()
0 commit comments