Skip to content

Commit 662ed1f

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 662ed1f

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

main.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
)
1212

1313
var clangdPath string
14+
var compileCommandsDir string
1415
var cliPath string
1516
var initialFqbn string
1617
var initialBoardName string
@@ -19,6 +20,7 @@ var loggingBasePath string
1920

2021
func main() {
2122
flag.StringVar(&clangdPath, "clangd", "clangd", "Path to clangd executable")
23+
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.")
2224
flag.StringVar(&cliPath, "cli", "arduino-cli", "Path to arduino-cli executable")
2325
flag.StringVar(&initialFqbn, "fqbn", "arduino:avr:uno", "Fully qualified board name to use initially (can be changed via JSON-RPC)")
2426
flag.StringVar(&initialBoardName, "board-name", "", "User-friendly board name to use initially (can be changed via JSON-RPC)")
@@ -53,7 +55,12 @@ func startClangd() (clangdIn io.WriteCloser, clangdOut io.ReadCloser, clangdErr
5355
if enableLogging {
5456
log.Println("Starting clangd process:", clangdPath)
5557
}
56-
clangdCmd := exec.Command(clangdPath)
58+
var clangdCmd *exec.Cmd
59+
if compileCommandsDir != "" {
60+
clangdCmd = exec.Command(clangdPath)
61+
} else {
62+
clangdCmd = exec.Command(clangdPath, "--compile-commands-dir=\""+compileCommandsDir+"\"")
63+
}
5764
clangdIn, _ = clangdCmd.StdinPipe()
5865
clangdOut, _ = clangdCmd.StdoutPipe()
5966
clangdErr, _ = clangdCmd.StderrPipe()

0 commit comments

Comments
 (0)