@@ -5,62 +5,69 @@ import * as path from "path";
5
5
import * as vscode from "vscode" ;
6
6
7
7
import { ArduinoApp } from "../arduino/arduino" ;
8
- import { IArduinoSettings } from "../arduino/arduinoSettings" ;
9
- import { BoardManager } from "../arduino/boardManager" ;
8
+ import ArduinoActivator from "../arduinoActivator" ;
9
+ import ArduinoContext from "../arduinoContext" ;
10
+
10
11
import { VscodeSettings } from "../arduino/vscodeSettings" ;
11
12
import * as platform from "../common/platform" ;
12
13
import * as util from "../common/util" ;
13
14
import { DeviceContext } from "../deviceContext" ;
14
15
import * as Logger from "../logger/logger" ;
15
- import { DebuggerManager } from "./debuggerManager" ;
16
-
17
- /**
18
- * Automatically generate the Arduino board's debug settings.
19
- */
20
- export class DebugConfigurator {
21
- constructor (
22
- private _arduinoApp : ArduinoApp ,
23
- private _arduinoSettings : IArduinoSettings ,
24
- private _boardManager : BoardManager ,
25
- private _debuggerManager : DebuggerManager ,
26
- ) {
16
+
17
+ export class ArduinoDebugConfigurationProvider implements vscode . DebugConfigurationProvider {
18
+
19
+ constructor ( ) { }
20
+
21
+ public provideDebugConfigurations ( folder : vscode . WorkspaceFolder | undefined , token ?: vscode . CancellationToken ) :
22
+ vscode . ProviderResult < vscode . DebugConfiguration [ ] > {
23
+ return [ {
24
+ name : "Arduino" ,
25
+ type : "arduino" ,
26
+ request : "launch" ,
27
+ program : "${file}" ,
28
+ cwd : folder ,
29
+ MIMode : "gdb" ,
30
+ targetArchitecture : "arm" ,
31
+ miDebuggerPath : "" ,
32
+ debugServerPath : "" ,
33
+ debugServerArgs : "" ,
34
+ customLaunchSetupCommands : [
35
+ {
36
+ text : "target remote localhost:3333" ,
37
+ } ,
38
+ {
39
+ text : "file ${file}" ,
40
+ } ,
41
+ {
42
+ text : "load" ,
43
+ } ,
44
+ {
45
+ text : "monitor reset halt" ,
46
+ } ,
47
+ {
48
+ text : "monitor reset init" ,
49
+ } ,
50
+ ] ,
51
+ stopAtEntry : true ,
52
+ serverStarted : "Info\\ :\\ [\\w\\d\\.]*:\\ hardware" ,
53
+ launchCompleteCommand : "exec-continue" ,
54
+ filterStderr : true ,
55
+ args : [ ] ,
56
+ } ] ;
27
57
}
28
58
29
- public async run ( config ) {
30
- // Default settings:
31
- if ( ! config . request ) {
32
- config = {
33
- name : "Arduino" ,
34
- type : "arduino" ,
35
- request : "launch" ,
36
- program : "${file}" ,
37
- cwd : "${workspaceRoot}" ,
38
- MIMode : "gdb" ,
39
-
40
- targetArchitecture : "arm" ,
41
- customLaunchSetupCommands : [
42
- {
43
- text : "target remote localhost:3333" ,
44
- } ,
45
- {
46
- text : "file ${file}" ,
47
- } ,
48
- {
49
- text : "load" ,
50
- } ,
51
- {
52
- text : "monitor reset halt" ,
53
- } ,
54
- {
55
- text : "monitor reset init" ,
56
- } ,
57
- ] ,
58
- stopAtEntry : true ,
59
- serverStarted : "Info\\ :\\ [\\w\\d\\.]*:\\ hardware" ,
60
- launchCompleteCommand : "exec-continue" ,
61
- filterStderr : true ,
62
- args : [ ] ,
63
- } ;
59
+ // Try to add all missing attributes to the debug configuration being launched.
60
+ public resolveDebugConfiguration ( folder : vscode . WorkspaceFolder | undefined , config : vscode . DebugConfiguration , token ?: vscode . CancellationToken ) :
61
+ vscode . ProviderResult < vscode . DebugConfiguration > {
62
+ if ( config && ! config . cwd ) {
63
+ config . cwd = folder ;
64
+ }
65
+ return this . resolveDebugConfigurationAsync ( config ) ;
66
+ }
67
+
68
+ private async resolveDebugConfigurationAsync ( config : vscode . DebugConfiguration ) {
69
+ if ( ! ArduinoContext . initialized ) {
70
+ await ArduinoActivator . activate ( ) ;
64
71
}
65
72
66
73
if ( VscodeSettings . getInstance ( ) . logLevel === "verbose" && ! config . logging ) {
@@ -71,40 +78,40 @@ export class DebugConfigurator {
71
78
} ;
72
79
}
73
80
74
- if ( ! this . _boardManager . currentBoard ) {
81
+ if ( ! ArduinoContext . boardManager . currentBoard ) {
75
82
vscode . window . showErrorMessage ( "Please select a board." ) ;
76
- return ;
83
+ return undefined ;
77
84
}
78
85
79
86
if ( ! this . resolveOpenOcd ( config ) ) {
80
- return ;
87
+ return undefined ;
81
88
}
82
89
83
90
if ( ! await this . resolveOpenOcdOptions ( config ) ) {
84
- return ;
91
+ return undefined ;
85
92
}
86
93
87
94
if ( ! this . resolveDebuggerPath ( config ) ) {
88
- return ;
95
+ return undefined ;
89
96
}
90
97
91
98
if ( ! await this . resolveProgramPath ( config ) ) {
92
- return ;
99
+ return undefined ;
93
100
}
94
101
95
102
// Use the C++ debugger MIEngine as the real internal debugger
96
103
config . type = "cppdbg" ;
97
- vscode . commands . executeCommand ( "vscode.startDebug" , config ) ;
98
104
const dc = DeviceContext . getInstance ( ) ;
99
105
Logger . traceUserData ( "start-cppdbg" , { board : dc . board } ) ;
106
+ return config ;
100
107
}
101
108
102
109
private async resolveProgramPath ( config ) {
103
110
const dc = DeviceContext . getInstance ( ) ;
104
111
105
112
if ( ! config . program || config . program === "${file}" ) {
106
113
// make a unique temp folder because keeping same temp folder will corrupt the build when board is changed
107
- const outputFolder = path . join ( dc . output || `.build` , this . _boardManager . currentBoard . board ) ;
114
+ const outputFolder = path . join ( dc . output || `.build` , ArduinoContext . boardManager . currentBoard . board ) ;
108
115
util . mkdirRecursivelySync ( path . join ( vscode . workspace . rootPath , outputFolder ) ) ;
109
116
if ( ! dc . sketch || ! util . fileExistsSync ( path . join ( vscode . workspace . rootPath , dc . sketch ) ) ) {
110
117
await dc . resolveMainSketch ( ) ;
@@ -122,7 +129,7 @@ export class DebugConfigurator {
122
129
config . program = path . join ( vscode . workspace . rootPath , outputFolder , `${ path . basename ( dc . sketch ) } .elf` ) ;
123
130
124
131
// always compile elf to make sure debug the right elf
125
- if ( ! await this . _arduinoApp . verify ( outputFolder ) ) {
132
+ if ( ! await ArduinoContext . arduinoApp . verify ( outputFolder ) ) {
126
133
vscode . window . showErrorMessage ( "Failure to verify the program, please check output for details." ) ;
127
134
return false ;
128
135
}
@@ -145,10 +152,10 @@ export class DebugConfigurator {
145
152
private resolveDebuggerPath ( config ) {
146
153
if ( ! config . miDebuggerPath ) {
147
154
config . miDebuggerPath = platform . findFile ( platform . getExecutableFileName ( "arm-none-eabi-gdb" ) ,
148
- path . join ( this . _arduinoSettings . packagePath , "packages" , this . _boardManager . currentBoard . getPackageName ( ) ) ) ;
155
+ path . join ( ArduinoContext . arduinoApp . settings . packagePath , "packages" , ArduinoContext . boardManager . currentBoard . getPackageName ( ) ) ) ;
149
156
}
150
157
if ( ! util . fileExistsSync ( config . miDebuggerPath ) ) {
151
- config . miDebuggerPath = this . _debuggerManager . miDebuggerPath ;
158
+ config . miDebuggerPath = ArduinoContext . debuggerManager . miDebuggerPath ;
152
159
}
153
160
if ( ! util . fileExistsSync ( config . miDebuggerPath ) ) {
154
161
vscode . window . showErrorMessage ( "Cannot find the debugger path." ) ;
@@ -160,11 +167,11 @@ export class DebugConfigurator {
160
167
private resolveOpenOcd ( config ) {
161
168
if ( ! config . debugServerPath ) {
162
169
config . debugServerPath = platform . findFile ( platform . getExecutableFileName ( "openocd" ) ,
163
- path . join ( this . _arduinoSettings . packagePath , "packages" ,
164
- this . _boardManager . currentBoard . getPackageName ( ) ) ) ;
170
+ path . join ( ArduinoContext . arduinoApp . settings . packagePath , "packages" ,
171
+ ArduinoContext . boardManager . currentBoard . getPackageName ( ) ) ) ;
165
172
}
166
173
if ( ! util . fileExistsSync ( config . debugServerPath ) ) {
167
- config . debugServerPath = this . _debuggerManager . debugServerPath ;
174
+ config . debugServerPath = ArduinoContext . debuggerManager . debugServerPath ;
168
175
}
169
176
if ( ! util . fileExistsSync ( config . debugServerPath ) ) {
170
177
vscode . window . showErrorMessage ( "Cannot find the OpenOCD from the launch.json debugServerPath property." +
@@ -176,10 +183,9 @@ export class DebugConfigurator {
176
183
}
177
184
178
185
private async resolveOpenOcdOptions ( config ) {
179
-
180
186
if ( config . debugServerPath && ! config . debugServerArgs ) {
181
187
try {
182
- config . debugServerArgs = await this . _debuggerManager . resolveOpenOcdOptions ( config ) ;
188
+ config . debugServerArgs = await ArduinoContext . debuggerManager . resolveOpenOcdOptions ( config ) ;
183
189
if ( ! config . debugServerArgs ) {
184
190
return false ;
185
191
}
0 commit comments