@@ -24,9 +24,11 @@ import { l10n } from '../localiser';
24
24
import { StreamDebugAdapter } from './streamDebugAdapter' ;
25
25
import { globalVars } from '../extension' ;
26
26
import { extCommands , nbCommands } from '../commands/commands' ;
27
+ import { argumentsNode , environmentVariablesNode , vmOptionsNode , workingDirectoryNode } from '../views/runConfiguration' ;
28
+ import { initializeRunConfiguration } from '../utils' ;
27
29
28
30
export function registerDebugger ( context : ExtensionContext ) : void {
29
- let debugTrackerFactory = new NetBeansDebugAdapterTrackerFactory ( ) ;
31
+ let debugTrackerFactory = new NetBeansDebugAdapterTrackerFactory ( ) ;
30
32
context . subscriptions . push ( vscode . debug . registerDebugAdapterTrackerFactory ( extConstants . COMMAND_PREFIX , debugTrackerFactory ) ) ;
31
33
let configInitialProvider = new NetBeansConfigurationInitialProvider ( ) ;
32
34
context . subscriptions . push ( vscode . debug . registerDebugConfigurationProvider ( extConstants . COMMAND_PREFIX , configInitialProvider , vscode . DebugConfigurationProviderTriggerKind . Initial ) ) ;
@@ -36,7 +38,12 @@ export function registerDebugger(context: ExtensionContext): void {
36
38
context . subscriptions . push ( vscode . debug . registerDebugConfigurationProvider ( extConstants . COMMAND_PREFIX , configResolver ) ) ;
37
39
context . subscriptions . push ( vscode . debug . onDidTerminateDebugSession ( ( ( session ) => onDidTerminateSession ( session ) ) ) ) ;
38
40
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
+ } ) ;
40
47
} ;
41
48
42
49
class NetBeansDebugAdapterTrackerFactory implements vscode . DebugAdapterTrackerFactory {
@@ -66,13 +73,13 @@ class NetBeansDebugAdapterDescriptionFactory implements vscode.DebugAdapterDescr
66
73
}
67
74
} else {
68
75
// 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
+ } ) ;
76
83
}
77
84
}
78
85
fnc ( ) ;
@@ -84,26 +91,26 @@ class NetBeansDebugAdapterDescriptionFactory implements vscode.DebugAdapterDescr
84
91
class NetBeansConfigurationInitialProvider implements vscode . DebugConfigurationProvider {
85
92
86
93
provideDebugConfigurations ( folder : vscode . WorkspaceFolder | undefined , token ?: vscode . CancellationToken ) : vscode . ProviderResult < vscode . DebugConfiguration [ ] > {
87
- return this . doProvideDebugConfigurations ( folder , token ) ;
94
+ return this . doProvideDebugConfigurations ( folder , token ) ;
88
95
}
89
96
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 ;
92
99
if ( ! folder ) {
93
100
return [ ] ;
94
101
}
95
- var u : vscode . Uri | undefined ;
102
+ var u : vscode . Uri | undefined ;
96
103
if ( folder && folder . uri ) {
97
104
u = folder . uri ;
98
105
} else {
99
106
u = vscode . window . activeTextEditor ?. document ?. uri
100
107
}
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 ( ) ) ;
103
110
if ( configNames ) {
104
- let first : boolean = true ;
111
+ let first : boolean = true ;
105
112
for ( let cn of configNames ) {
106
- let cname : string ;
113
+ let cname : string ;
107
114
108
115
if ( first ) {
109
116
// ignore the default config, comes first.
@@ -112,7 +119,7 @@ class NetBeansConfigurationInitialProvider implements vscode.DebugConfigurationP
112
119
} else {
113
120
cname = "Launch Java: " + cn ;
114
121
}
115
- const debugConfig : vscode . DebugConfiguration = {
122
+ const debugConfig : vscode . DebugConfiguration = {
116
123
name : cname ,
117
124
type : extConstants . COMMAND_PREFIX ,
118
125
request : "launch" ,
@@ -135,19 +142,19 @@ class NetBeansConfigurationDynamicProvider implements vscode.DebugConfigurationP
135
142
}
136
143
137
144
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 ) ;
139
146
}
140
147
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 ;
143
150
if ( ! folder ) {
144
151
return [ ] ;
145
152
}
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 ) ;
148
155
if ( attachConnectors ) {
149
156
for ( let ac of attachConnectors ) {
150
- const debugConfig : vscode . DebugConfiguration = {
157
+ const debugConfig : vscode . DebugConfiguration = {
151
158
name : ac . name ,
152
159
type : ac . type ,
153
160
request : "attach" ,
@@ -207,6 +214,61 @@ class NetBeansConfigurationResolver implements vscode.DebugConfigurationProvider
207
214
}
208
215
}
209
216
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
+
210
272
function onDidTerminateSession ( session : vscode . DebugSession ) : any {
211
273
const config = session . configuration ;
212
274
if ( config . env ) {
0 commit comments