@@ -54,6 +54,7 @@ type INOLanguageServer struct {
54
54
removeTempMutex sync.Mutex
55
55
clangdStarted * sync.Cond
56
56
dataMux sync.RWMutex
57
+ tempDir * paths.Path
57
58
buildPath * paths.Path
58
59
buildSketchRoot * paths.Path
59
60
buildSketchCpp * paths.Path
@@ -146,18 +147,21 @@ func NewINOLanguageServer(stdin io.Reader, stdout io.Writer, config *Config) *IN
146
147
if tmp , err := paths .MkTempDir ("" , "arduino-language-server" ); err != nil {
147
148
log .Fatalf ("Could not create temp folder: %s" , err )
148
149
} else {
149
- ls .buildPath = tmp .Canonical ()
150
- ls .buildSketchRoot = ls .buildPath .Join ("sketch" )
150
+ ls .tempDir = tmp .Canonical ()
151
151
}
152
-
153
- if tmp , err := paths .MkTempDir ("" , "arduino-language-server" ); err != nil {
152
+ ls .buildPath = ls .tempDir .Join ("build" )
153
+ ls .buildSketchRoot = ls .buildPath .Join ("sketch" )
154
+ if err := ls .buildPath .MkdirAll (); err != nil {
155
+ log .Fatalf ("Could not create temp folder: %s" , err )
156
+ }
157
+ ls .fullBuildPath = ls .tempDir .Join ("fullbuild" )
158
+ if err := ls .fullBuildPath .MkdirAll (); err != nil {
154
159
log .Fatalf ("Could not create temp folder: %s" , err )
155
- } else {
156
- ls .fullBuildPath = tmp .Canonical ()
157
160
}
158
161
159
162
logger .Logf ("Initial board configuration: %s" , ls .config .Fqbn )
160
163
logger .Logf ("%s" , globals .VersionInfo .String ())
164
+ logger .Logf ("Language server temp directory: %s" , ls .tempDir )
161
165
logger .Logf ("Language server build path: %s" , ls .buildPath )
162
166
logger .Logf ("Language server build sketch root: %s" , ls .buildSketchRoot )
163
167
logger .Logf ("Language server FULL build path: %s" , ls .fullBuildPath )
@@ -1378,14 +1382,7 @@ func (ls *INOLanguageServer) removeTemporaryFiles(logger jsonrpc.FunctionLogger)
1378
1382
ls .removeTempMutex .Lock ()
1379
1383
defer ls .removeTempMutex .Unlock ()
1380
1384
1381
- args := []string {"remove-temp-files" }
1382
- if ls .buildPath != nil {
1383
- args = append (args , ls .buildPath .String ())
1384
- }
1385
- if ls .fullBuildPath != nil {
1386
- args = append (args , ls .fullBuildPath .String ())
1387
- }
1388
- if len (args ) == 1 {
1385
+ if ls .tempDir == nil {
1389
1386
// Nothing to remove
1390
1387
return
1391
1388
}
@@ -1396,15 +1393,15 @@ func (ls *INOLanguageServer) removeTemporaryFiles(logger jsonrpc.FunctionLogger)
1396
1393
logger .Logf ("Error getting current working directory: %s" , err )
1397
1394
return
1398
1395
}
1399
- cmd := exec .Command (os .Args [0 ], args ... )
1396
+ cmd := exec .Command (os .Args [0 ], "remove-temp-files" , ls . tempDir . String () )
1400
1397
cmd .Dir = cwd
1401
1398
if err := cmd .Start (); err != nil {
1402
1399
logger .Logf ("Error starting remove-temp-files process: %s" , err )
1403
1400
return
1404
1401
}
1405
1402
1406
1403
// The process is now started, we can reset the paths
1407
- ls .buildPath , ls .fullBuildPath = nil , nil
1404
+ ls .buildPath , ls .fullBuildPath , ls . buildSketchRoot , ls . tempDir = nil , nil , nil , nil
1408
1405
1409
1406
// Detach the process so it can continue running even if the parent process exits
1410
1407
if err := cmd .Process .Release (); err != nil {
0 commit comments