Skip to content

Commit de3db9b

Browse files
committed
Keep all language-server tmp files inside a single subdir
1 parent e8eee33 commit de3db9b

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

Diff for: ls/ls.go

+13-16
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type INOLanguageServer struct {
5454
removeTempMutex sync.Mutex
5555
clangdStarted *sync.Cond
5656
dataMux sync.RWMutex
57+
tempDir *paths.Path
5758
buildPath *paths.Path
5859
buildSketchRoot *paths.Path
5960
buildSketchCpp *paths.Path
@@ -146,18 +147,21 @@ func NewINOLanguageServer(stdin io.Reader, stdout io.Writer, config *Config) *IN
146147
if tmp, err := paths.MkTempDir("", "arduino-language-server"); err != nil {
147148
log.Fatalf("Could not create temp folder: %s", err)
148149
} else {
149-
ls.buildPath = tmp.Canonical()
150-
ls.buildSketchRoot = ls.buildPath.Join("sketch")
150+
ls.tempDir = tmp.Canonical()
151151
}
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 {
154159
log.Fatalf("Could not create temp folder: %s", err)
155-
} else {
156-
ls.fullBuildPath = tmp.Canonical()
157160
}
158161

159162
logger.Logf("Initial board configuration: %s", ls.config.Fqbn)
160163
logger.Logf("%s", globals.VersionInfo.String())
164+
logger.Logf("Language server temp directory: %s", ls.tempDir)
161165
logger.Logf("Language server build path: %s", ls.buildPath)
162166
logger.Logf("Language server build sketch root: %s", ls.buildSketchRoot)
163167
logger.Logf("Language server FULL build path: %s", ls.fullBuildPath)
@@ -1378,14 +1382,7 @@ func (ls *INOLanguageServer) removeTemporaryFiles(logger jsonrpc.FunctionLogger)
13781382
ls.removeTempMutex.Lock()
13791383
defer ls.removeTempMutex.Unlock()
13801384

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 {
13891386
// Nothing to remove
13901387
return
13911388
}
@@ -1396,15 +1393,15 @@ func (ls *INOLanguageServer) removeTemporaryFiles(logger jsonrpc.FunctionLogger)
13961393
logger.Logf("Error getting current working directory: %s", err)
13971394
return
13981395
}
1399-
cmd := exec.Command(os.Args[0], args...)
1396+
cmd := exec.Command(os.Args[0], "remove-temp-files", ls.tempDir.String())
14001397
cmd.Dir = cwd
14011398
if err := cmd.Start(); err != nil {
14021399
logger.Logf("Error starting remove-temp-files process: %s", err)
14031400
return
14041401
}
14051402

14061403
// 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
14081405

14091406
// Detach the process so it can continue running even if the parent process exits
14101407
if err := cmd.Process.Release(); err != nil {

0 commit comments

Comments
 (0)