@@ -24,9 +24,11 @@ import { l10n } from '../localiser';
2424import { StreamDebugAdapter } from './streamDebugAdapter' ;
2525import { globalVars } from '../extension' ;
2626import { extCommands , nbCommands } from '../commands/commands' ;
27+ import { argumentsNode , environmentVariablesNode , vmOptionsNode , workingDirectoryNode } from '../views/runConfiguration' ;
28+ import { initializeRunConfiguration } from '../utils' ;
2729
2830export function registerDebugger ( context : ExtensionContext ) : void {
29- let debugTrackerFactory = new NetBeansDebugAdapterTrackerFactory ( ) ;
31+ let debugTrackerFactory = new NetBeansDebugAdapterTrackerFactory ( ) ;
3032 context . subscriptions . push ( vscode . debug . registerDebugAdapterTrackerFactory ( extConstants . COMMAND_PREFIX , debugTrackerFactory ) ) ;
3133 let configInitialProvider = new NetBeansConfigurationInitialProvider ( ) ;
3234 context . subscriptions . push ( vscode . debug . registerDebugConfigurationProvider ( extConstants . COMMAND_PREFIX , configInitialProvider , vscode . DebugConfigurationProviderTriggerKind . Initial ) ) ;
@@ -36,7 +38,12 @@ export function registerDebugger(context: ExtensionContext): void {
3638 context . subscriptions . push ( vscode . debug . registerDebugConfigurationProvider ( extConstants . COMMAND_PREFIX , configResolver ) ) ;
3739 context . subscriptions . push ( vscode . debug . onDidTerminateDebugSession ( ( ( session ) => onDidTerminateSession ( session ) ) ) ) ;
3840 let debugDescriptionFactory = new NetBeansDebugAdapterDescriptionFactory ( ) ;
39- context . subscriptions . push ( vscode . debug . registerDebugAdapterDescriptorFactory ( extConstants . COMMAND_PREFIX , debugDescriptionFactory ) ) ;
41+ context . subscriptions . push ( vscode . debug . registerDebugAdapterDescriptorFactory ( extConstants . COMMAND_PREFIX , debugDescriptionFactory ) ) ;
42+ initializeRunConfiguration ( ) . then ( initialized => {
43+ if ( initialized ) {
44+ context . subscriptions . push ( vscode . debug . registerDebugConfigurationProvider ( extConstants . COMMAND_PREFIX , new RunConfigurationProvider ( ) ) ) ;
45+ }
46+ } ) ;
4047} ;
4148
4249class NetBeansDebugAdapterTrackerFactory implements vscode . DebugAdapterTrackerFactory {
@@ -66,13 +73,13 @@ class NetBeansDebugAdapterDescriptionFactory implements vscode.DebugAdapterDescr
6673 }
6774 } else {
6875 // resolve(new vscode.DebugAdapterServer(debugPort));
69- const socket = net . connect ( globalVars . debugPort , "127.0.0.1" , ( ) => { } ) ;
70- socket . on ( "connect" , ( ) => {
71- const adapter = new StreamDebugAdapter ( ) ;
72- socket . write ( globalVars . debugHash ? globalVars . debugHash : "" ) ;
73- adapter . connect ( socket , socket ) ;
74- resolve ( new vscode . DebugAdapterInlineImplementation ( adapter ) ) ;
75- } ) ;
76+ const socket = net . connect ( globalVars . debugPort , "127.0.0.1" , ( ) => { } ) ;
77+ socket . on ( "connect" , ( ) => {
78+ const adapter = new StreamDebugAdapter ( ) ;
79+ socket . write ( globalVars . debugHash ? globalVars . debugHash : "" ) ;
80+ adapter . connect ( socket , socket ) ;
81+ resolve ( new vscode . DebugAdapterInlineImplementation ( adapter ) ) ;
82+ } ) ;
7683 }
7784 }
7885 fnc ( ) ;
@@ -84,26 +91,26 @@ class NetBeansDebugAdapterDescriptionFactory implements vscode.DebugAdapterDescr
8491class NetBeansConfigurationInitialProvider implements vscode . DebugConfigurationProvider {
8592
8693 provideDebugConfigurations ( folder : vscode . WorkspaceFolder | undefined , token ?: vscode . CancellationToken ) : vscode . ProviderResult < vscode . DebugConfiguration [ ] > {
87- return this . doProvideDebugConfigurations ( folder , token ) ;
94+ return this . doProvideDebugConfigurations ( folder , token ) ;
8895 }
8996
90- async doProvideDebugConfigurations ( folder : vscode . WorkspaceFolder | undefined , _token ?: vscode . CancellationToken ) : Promise < vscode . DebugConfiguration [ ] > {
91- let c : LanguageClient = await globalVars . clientPromise . client ;
97+ async doProvideDebugConfigurations ( folder : vscode . WorkspaceFolder | undefined , _token ?: vscode . CancellationToken ) : Promise < vscode . DebugConfiguration [ ] > {
98+ let c : LanguageClient = await globalVars . clientPromise . client ;
9299 if ( ! folder ) {
93100 return [ ] ;
94101 }
95- var u : vscode . Uri | undefined ;
102+ var u : vscode . Uri | undefined ;
96103 if ( folder && folder . uri ) {
97104 u = folder . uri ;
98105 } else {
99106 u = vscode . window . activeTextEditor ?. document ?. uri
100107 }
101- let result : vscode . DebugConfiguration [ ] = [ ] ;
102- const configNames : string [ ] | null | undefined = await vscode . commands . executeCommand ( nbCommands . projectConfigurations , u ?. toString ( ) ) ;
108+ let result : vscode . DebugConfiguration [ ] = [ ] ;
109+ const configNames : string [ ] | null | undefined = await vscode . commands . executeCommand ( nbCommands . projectConfigurations , u ?. toString ( ) ) ;
103110 if ( configNames ) {
104- let first : boolean = true ;
111+ let first : boolean = true ;
105112 for ( let cn of configNames ) {
106- let cname : string ;
113+ let cname : string ;
107114
108115 if ( first ) {
109116 // ignore the default config, comes first.
@@ -112,7 +119,7 @@ class NetBeansConfigurationInitialProvider implements vscode.DebugConfigurationP
112119 } else {
113120 cname = "Launch Java: " + cn ;
114121 }
115- const debugConfig : vscode . DebugConfiguration = {
122+ const debugConfig : vscode . DebugConfiguration = {
116123 name : cname ,
117124 type : extConstants . COMMAND_PREFIX ,
118125 request : "launch" ,
@@ -135,19 +142,19 @@ class NetBeansConfigurationDynamicProvider implements vscode.DebugConfigurationP
135142 }
136143
137144 provideDebugConfigurations ( folder : vscode . WorkspaceFolder | undefined , token ?: vscode . CancellationToken ) : vscode . ProviderResult < vscode . DebugConfiguration [ ] > {
138- return this . doProvideDebugConfigurations ( folder , this . context , this . commandValues , token ) ;
145+ return this . doProvideDebugConfigurations ( folder , this . context , this . commandValues , token ) ;
139146 }
140147
141- async doProvideDebugConfigurations ( folder : vscode . WorkspaceFolder | undefined , context : ExtensionContext , commandValues : Map < string , string > , _token ?: vscode . CancellationToken ) : Promise < vscode . DebugConfiguration [ ] > {
142- let c : LanguageClient = await globalVars . clientPromise . client ;
148+ async doProvideDebugConfigurations ( folder : vscode . WorkspaceFolder | undefined , context : ExtensionContext , commandValues : Map < string , string > , _token ?: vscode . CancellationToken ) : Promise < vscode . DebugConfiguration [ ] > {
149+ let c : LanguageClient = await globalVars . clientPromise . client ;
143150 if ( ! folder ) {
144151 return [ ] ;
145152 }
146- let result : vscode . DebugConfiguration [ ] = [ ] ;
147- const attachConnectors : DebugConnector [ ] | null | undefined = await vscode . commands . executeCommand ( extCommands . attachDebugger ) ;
153+ let result : vscode . DebugConfiguration [ ] = [ ] ;
154+ const attachConnectors : DebugConnector [ ] | null | undefined = await vscode . commands . executeCommand ( extCommands . attachDebugger ) ;
148155 if ( attachConnectors ) {
149156 for ( let ac of attachConnectors ) {
150- const debugConfig : vscode . DebugConfiguration = {
157+ const debugConfig : vscode . DebugConfiguration = {
151158 name : ac . name ,
152159 type : ac . type ,
153160 request : "attach" ,
@@ -207,6 +214,61 @@ class NetBeansConfigurationResolver implements vscode.DebugConfigurationProvider
207214 }
208215}
209216
217+ class RunConfigurationProvider implements vscode . DebugConfigurationProvider {
218+
219+ resolveDebugConfiguration ( _folder : vscode . WorkspaceFolder | undefined , config : vscode . DebugConfiguration , _token ?: vscode . CancellationToken ) : vscode . ProviderResult < vscode . DebugConfiguration > {
220+ return new Promise < vscode . DebugConfiguration > ( resolve => {
221+ resolve ( config ) ;
222+ } ) ;
223+ }
224+
225+ resolveDebugConfigurationWithSubstitutedVariables ?( _folder : vscode . WorkspaceFolder | undefined , config : vscode . DebugConfiguration , _token ?: vscode . CancellationToken ) : vscode . ProviderResult < vscode . DebugConfiguration > {
226+ return new Promise < vscode . DebugConfiguration > ( resolve => {
227+ const args = argumentsNode . getValue ( ) ;
228+ if ( args ) {
229+ if ( ! config . args ) {
230+ config . args = args ;
231+ } else {
232+ config . args = `${ config . args } ${ args } ` ;
233+ }
234+ }
235+
236+ const vmArgs = vmOptionsNode . getValue ( ) ;
237+ if ( vmArgs ) {
238+ if ( ! config . vmArgs ) {
239+ config . vmArgs = vmArgs ;
240+ } else {
241+ config . vmArgs = `${ config . vmArgs } ${ vmArgs } ` ;
242+ }
243+ }
244+
245+ const env = environmentVariablesNode . getValue ( ) ;
246+ if ( env ) {
247+ const envs = env . split ( ',' ) ;
248+ if ( ! config . env ) {
249+ config . env = { } ;
250+ }
251+ for ( let val of envs ) {
252+ val = val . trim ( ) ;
253+ const div = val . indexOf ( '=' ) ;
254+ if ( div > 0 ) { // div === 0 means bad format (no ENV name)
255+ config . env [ val . substring ( 0 , div ) ] = val . substring ( div + 1 , val . length ) ;
256+ }
257+ }
258+ }
259+
260+ const cwd = workingDirectoryNode . getValue ( ) ;
261+ if ( cwd ) {
262+ config . cwd = cwd ;
263+ }
264+
265+ resolve ( config ) ;
266+ } ) ;
267+ }
268+
269+ }
270+
271+
210272function onDidTerminateSession ( session : vscode . DebugSession ) : any {
211273 const config = session . configuration ;
212274 if ( config . env ) {
0 commit comments