Skip to content

Commit 2e949ef

Browse files
author
Akos Kitta
committed
Can feed clangd with the compile commands dir.
If `compile-commands-dir` is not set or points to an invalid location, it is ignored. Signed-off-by: Akos Kitta <[email protected]>
1 parent 582ee28 commit 2e949ef

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Diff for: main.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"flag"
5+
"fmt"
56
"io"
67
"log"
78
"os"
@@ -11,6 +12,7 @@ import (
1112
)
1213

1314
var clangdPath string
15+
var compileCommandsDir string
1416
var cliPath string
1517
var initialFqbn string
1618
var initialBoardName string
@@ -19,6 +21,7 @@ var loggingBasePath string
1921

2022
func main() {
2123
flag.StringVar(&clangdPath, "clangd", "clangd", "Path to clangd executable")
24+
flag.StringVar(&compileCommandsDir, "compile-commands-dir", "", "Specify a path to look for compile_commands.json. If path is invalid, clangd will look in the current directory and parent paths of each source file. If not specified, the clangd process is started without the compilation database.")
2225
flag.StringVar(&cliPath, "cli", "arduino-cli", "Path to arduino-cli executable")
2326
flag.StringVar(&initialFqbn, "fqbn", "arduino:avr:uno", "Fully qualified board name to use initially (can be changed via JSON-RPC)")
2427
flag.StringVar(&initialBoardName, "board-name", "", "User-friendly board name to use initially (can be changed via JSON-RPC)")
@@ -53,7 +56,12 @@ func startClangd() (clangdIn io.WriteCloser, clangdOut io.ReadCloser, clangdErr
5356
if enableLogging {
5457
log.Println("Starting clangd process:", clangdPath)
5558
}
56-
clangdCmd := exec.Command(clangdPath)
59+
var clangdCmd *exec.Cmd
60+
if compileCommandsDir != "" {
61+
clangdCmd = exec.Command(clangdPath)
62+
} else {
63+
clangdCmd = exec.Command(clangdPath, fmt.Sprintf(`--compile-commands-dir="%s"`, compileCommandsDir))
64+
}
5765
clangdIn, _ = clangdCmd.StdinPipe()
5866
clangdOut, _ = clangdCmd.StdoutPipe()
5967
clangdErr, _ = clangdCmd.StderrPipe()

0 commit comments

Comments
 (0)