9
9
10
10
builder "github.com/arduino/arduino-builder"
11
11
"github.com/arduino/arduino-builder/types"
12
+ "github.com/arduino/arduino-builder/utils"
12
13
"github.com/fsnotify/fsnotify"
13
14
"golang.org/x/net/context"
14
15
"google.golang.org/grpc"
@@ -50,6 +51,24 @@ type builderServer struct {
50
51
watcher * fsnotify.Watcher
51
52
}
52
53
54
+ func (s * builderServer ) watch () {
55
+ folders := [][]string {s .ctx .HardwareFolders , s .ctx .ToolsFolders , s .ctx .BuiltInLibrariesFolders , s .ctx .OtherLibrariesFolders }
56
+
57
+ for _ , category := range folders {
58
+ for _ , folder := range category {
59
+ if ! utils .SliceContains (s .ctx .WatchedLocations , folder ) {
60
+ var subfolders []string
61
+ utils .FindAllSubdirectories (folder , & subfolders )
62
+ subfolders = append (subfolders , folder )
63
+ for _ , element := range subfolders {
64
+ s .watcher .Add (element )
65
+ s .ctx .WatchedLocations = utils .AppendIfNotPresent (s .ctx .WatchedLocations , element )
66
+ }
67
+ }
68
+ }
69
+ }
70
+ }
71
+
53
72
// GetFeature returns the feature at the given point.
54
73
func (s * builderServer ) Autocomplete (ctx context.Context , args * pb.BuildParams ) (* pb.Response , error ) {
55
74
@@ -75,6 +94,8 @@ func (s *builderServer) Autocomplete(ctx context.Context, args *pb.BuildParams)
75
94
76
95
s .ctx .ImportedLibraries = s .ctx .ImportedLibraries [0 :0 ]
77
96
97
+ s .watch ()
98
+
78
99
err := builder .RunPreprocess (s .ctx )
79
100
if err != nil {
80
101
return & pb.Response {Line : s .ctx .GetLogger ().Flush ()}, err
@@ -114,6 +135,8 @@ func (s *builderServer) Build(args *pb.BuildParams, stream pb.Builder_BuildServe
114
135
logger := StreamLogger {stream }
115
136
s .ctx .SetLogger (logger )
116
137
138
+ s .watch ()
139
+
117
140
err := builder .RunBuilder (s .ctx )
118
141
s .ctx .SetLogger (oldlogger )
119
142
if err != nil {
0 commit comments