Skip to content

Can feed clangd with the compile commands dir. #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 4, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"flag"
"fmt"
"io"
"log"
"os"
Expand All @@ -11,6 +12,7 @@ import (
)

var clangdPath string
var compileCommandsDir string
var cliPath string
var initialFqbn string
var initialBoardName string
Expand All @@ -19,6 +21,7 @@ var loggingBasePath string

func main() {
flag.StringVar(&clangdPath, "clangd", "clangd", "Path to clangd executable")
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.")
flag.StringVar(&cliPath, "cli", "arduino-cli", "Path to arduino-cli executable")
flag.StringVar(&initialFqbn, "fqbn", "arduino:avr:uno", "Fully qualified board name to use initially (can be changed via JSON-RPC)")
flag.StringVar(&initialBoardName, "board-name", "", "User-friendly board name to use initially (can be changed via JSON-RPC)")
Expand Down Expand Up @@ -53,7 +56,12 @@ func startClangd() (clangdIn io.WriteCloser, clangdOut io.ReadCloser, clangdErr
if enableLogging {
log.Println("Starting clangd process:", clangdPath)
}
clangdCmd := exec.Command(clangdPath)
var clangdCmd *exec.Cmd
if compileCommandsDir != "" {
clangdCmd = exec.Command(clangdPath)
} else {
clangdCmd = exec.Command(clangdPath, fmt.Sprintf(`--compile-commands-dir="%s"`, compileCommandsDir))
}
clangdIn, _ = clangdCmd.StdinPipe()
clangdOut, _ = clangdCmd.StdoutPipe()
clangdErr, _ = clangdCmd.StderrPipe()
Expand Down