File tree 1 file changed +15
-1
lines changed
1 file changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -33,7 +33,8 @@ type CompilationDatabase struct {
33
33
// CompilationCommand keeps track of a single run of a compile command
34
34
type CompilationCommand struct {
35
35
Directory string `json:"directory"`
36
- Arguments []string `json:"arguments"`
36
+ Command string `json:"command,omitempty"`
37
+ Arguments []string `json:"arguments,omitempty"`
37
38
File string `json:"file"`
38
39
}
39
40
@@ -44,6 +45,19 @@ func NewCompilationDatabase(filename *paths.Path) *CompilationDatabase {
44
45
}
45
46
}
46
47
48
+ // LoadCompilationDatabase reads a compilation database from a file
49
+ func LoadCompilationDatabase (file * paths.Path ) (* CompilationDatabase , error ) {
50
+ f , err := file .ReadFile ()
51
+ if err != nil {
52
+ return nil , err
53
+ }
54
+ res := & CompilationDatabase {
55
+ File : file ,
56
+ Contents : []CompilationCommand {},
57
+ }
58
+ return res , json .Unmarshal (f , & res .Contents )
59
+ }
60
+
47
61
// SaveToFile save the CompilationDatabase to file as a clangd-compatible compile_commands.json,
48
62
// see https://clang.llvm.org/docs/JSONCompilationDatabase.html
49
63
func (db * CompilationDatabase ) SaveToFile () {
You can’t perform that action at this time.
0 commit comments