Skip to content

Commit 2389e3d

Browse files
committed
Fixed compiler query driver on Windows
1 parent ff898bf commit 2389e3d

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Diff for: handler/handler.go

+14-2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"log"
99
"os"
1010
"regexp"
11+
"runtime"
1112
"strconv"
1213
"strings"
1314
"sync"
@@ -602,15 +603,26 @@ func startClangd(compileCommandsDir, sketchCpp *paths.Path) (io.WriteCloser, io.
602603
panic("could not find compile_commands.json")
603604
}
604605
compilers := map[string]bool{}
605-
for _, cmd := range compileCommands.Contents {
606+
for i, cmd := range compileCommands.Contents {
606607
if len(cmd.Arguments) == 0 {
607608
panic("invalid empty argument field in compile_commands.json")
608609
}
609-
compilers[cmd.Arguments[0]] = true
610+
611+
// clangd requires full path to compiler (including extension .exe on Windows!)
612+
compilerPath := paths.New(cmd.Arguments[0]).Canonical()
613+
compiler := compilerPath.String()
614+
if runtime.GOOS == "windows" && strings.ToLower(compilerPath.Ext()) != ".exe" {
615+
compiler += ".exe"
616+
}
617+
compileCommands.Contents[i].Arguments[0] = compiler
618+
619+
compilers[compiler] = true
610620
}
611621
if len(compilers) == 0 {
612622
panic("main compiler not found")
613623
}
624+
// Save back compile_commands.json with OS native file separator and extension
625+
compileCommands.SaveToFile()
614626

615627
// Start clangd
616628
args := []string{

0 commit comments

Comments
 (0)