1
- import { stat } from 'fs' ;
2
- import { basename } from 'path' ;
1
+ import * as fs from 'fs' ;
2
+ import * as path from 'path' ;
3
3
import { promisify } from 'util' ;
4
4
import { spawnSync } from 'child_process' ;
5
5
import deepEqual from 'deep-equal' ;
6
6
import WebRequest from 'web-request' ;
7
+ import deepmerge from 'deepmerge' ;
7
8
import vscode , { ExtensionContext } from 'vscode' ;
8
9
import { LanguageClient , CloseAction , ErrorAction , InitializeError , Message , RevealOutputChannelOn } from 'vscode-languageclient' ;
9
10
@@ -80,7 +81,7 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
80
81
if ( ! rawStdout ) {
81
82
if ( rawStdErr ) {
82
83
if ( rawStdErr . indexOf ( 'compiled sketch not found in' ) !== - 1 ) {
83
- vscode . window . showErrorMessage ( `Sketch '${ basename ( config . sketchPath ) } ' was not compiled. Please compile the sketch and start debugging again.` ) ;
84
+ vscode . window . showErrorMessage ( `Sketch '${ path . basename ( config . sketchPath ) } ' was not compiled. Please compile the sketch and start debugging again.` ) ;
84
85
} else {
85
86
vscode . window . showErrorMessage ( rawStdErr ) ;
86
87
}
@@ -95,7 +96,7 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
95
96
if ( ! info ) {
96
97
return false ;
97
98
}
98
- const debugConfig = {
99
+ const defaultDebugConfig = {
99
100
cwd : '${workspaceRoot}' ,
100
101
name : 'Arduino' ,
101
102
request : 'launch' ,
@@ -108,18 +109,26 @@ async function startDebug(_: ExtensionContext, config: DebugConfig): Promise<boo
108
109
info . server_configuration . script
109
110
]
110
111
} ;
112
+
113
+ let customDebugConfig = { } ;
114
+ try {
115
+ const raw = await promisify ( fs . readFile ) ( path . join ( config . sketchPath , 'debug_custom.json' ) , { encoding : 'utf8' } ) ;
116
+ customDebugConfig = JSON . parse ( raw ) ;
117
+ } catch { }
118
+ const mergedDebugConfig = deepmerge ( defaultDebugConfig , customDebugConfig ) ;
119
+
111
120
// Create the `launch.json` if it does not exist. Otherwise, update the existing.
112
121
const configuration = vscode . workspace . getConfiguration ( ) ;
113
122
const launchConfig = {
114
123
version : '0.2.0' ,
115
124
'configurations' : [
116
125
{
117
- ...debugConfig
126
+ ...mergedDebugConfig
118
127
}
119
128
]
120
129
} ;
121
130
await configuration . update ( 'launch' , launchConfig , false ) ;
122
- return vscode . debug . startDebugging ( undefined , debugConfig ) ;
131
+ return vscode . debug . startDebugging ( undefined , mergedDebugConfig ) ;
123
132
}
124
133
125
134
async function startLanguageServer ( context : ExtensionContext , config : LanguageServerConfig ) : Promise < void > {
@@ -162,7 +171,7 @@ async function buildLanguageClient(config: LanguageServerConfig): Promise<Langua
162
171
let logPath : string | undefined = undefined ;
163
172
if ( typeof log === 'string' ) {
164
173
try {
165
- const stats = await promisify ( stat ) ( log ) ;
174
+ const stats = await promisify ( fs . stat ) ( log ) ;
166
175
if ( stats . isDirectory ( ) ) {
167
176
logPath = log ;
168
177
}
0 commit comments