@@ -3,7 +3,7 @@ import * as lc from 'vscode-languageclient';
33import * as ra from '../rust-analyzer-api' ;
44
55import { Ctx , Cmd } from '../ctx' ;
6- import { startDebugSession } from '../debug' ;
6+ import { startDebugSession , getDebugConfiguration } from '../debug' ;
77
88async function selectRunnable ( ctx : Ctx , prevRunnable : RunnableQuickPick | undefined ) : Promise < RunnableQuickPick | undefined > {
99 const editor = ctx . activeRustEditor ;
@@ -86,6 +86,34 @@ export function debugSingle(ctx: Ctx): Cmd {
8686 } ;
8787}
8888
89+ export function newDebugConfig ( ctx : Ctx ) : Cmd {
90+ return async ( ) => {
91+ const scope = ctx . activeRustEditor ?. document . uri ;
92+ if ( ! scope ) return ;
93+
94+ const item = await selectRunnable ( ctx , undefined ) ;
95+ if ( ! item ) return ;
96+
97+ const debugConfig = await getDebugConfiguration ( ctx , item . runnable ) ;
98+ if ( ! debugConfig ) return ;
99+
100+ const wsLaunchSection = vscode . workspace . getConfiguration ( "launch" , scope ) ;
101+ const configurations = wsLaunchSection . get < any [ ] > ( "configurations" ) || [ ] ;
102+
103+ const index = configurations . findIndex ( c => c . name === debugConfig . name ) ;
104+ if ( index !== - 1 ) {
105+ const answer = await vscode . window . showErrorMessage ( `Launch configuration '${ debugConfig . name } ' already exists!` , 'Cancel' , 'Update' ) ;
106+ if ( answer === "Cancel" ) return ;
107+
108+ configurations [ index ] = debugConfig ;
109+ } else {
110+ configurations . push ( debugConfig ) ;
111+ }
112+
113+ await wsLaunchSection . update ( "configurations" , configurations ) ;
114+ } ;
115+ }
116+
89117class RunnableQuickPick implements vscode . QuickPickItem {
90118 public label : string ;
91119 public description ?: string | undefined ;
0 commit comments