Skip to content

Commit b33f583

Browse files
committed
add working watcher implementation
1 parent e00d695 commit b33f583

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

Diff for: client/client.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ func main() {
7979
Verbose: true,
8080
WarningsLevel: "all",
8181
BuildCachePath: "/tmp/arduino_cache_761418/",
82-
CodeCompleteAt: "/home/martino/eslov-sk/libraries/WiFi101/examples/ScanNetworks/ScanNetworks.ino:1:1",
82+
CodeCompleteAt: "/home/martino/eslov-sk/libraries/WiFi101/examples/ScanNetworks/ScanNetworks.ino:56:9",
8383
}
8484

85-
build(client, &exampleParames)
86-
//autocomplete(client, &exampleParames)
85+
//build(client, &exampleParames)
86+
autocomplete(client, &exampleParames)
8787
}

Diff for: src/arduino.cc/builder/grpc/rpc.go

+23
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99

1010
"arduino.cc/builder"
1111
"arduino.cc/builder/types"
12+
"arduino.cc/builder/utils"
1213
"github.com/fsnotify/fsnotify"
1314
"golang.org/x/net/context"
1415
"google.golang.org/grpc"
@@ -50,6 +51,24 @@ type builderServer struct {
5051
watcher *fsnotify.Watcher
5152
}
5253

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+
5372
// GetFeature returns the feature at the given point.
5473
func (s *builderServer) Autocomplete(ctx context.Context, args *pb.BuildParams) (*pb.Response, error) {
5574

@@ -75,6 +94,8 @@ func (s *builderServer) Autocomplete(ctx context.Context, args *pb.BuildParams)
7594

7695
s.ctx.ImportedLibraries = s.ctx.ImportedLibraries[0:0]
7796

97+
s.watch()
98+
7899
err := builder.RunPreprocess(s.ctx)
79100
if err != nil {
80101
return &pb.Response{Line: s.ctx.GetLogger().Flush()}, err
@@ -114,6 +135,8 @@ func (s *builderServer) Build(args *pb.BuildParams, stream pb.Builder_BuildServe
114135
logger := StreamLogger{stream}
115136
s.ctx.SetLogger(logger)
116137

138+
s.watch()
139+
117140
err := builder.RunBuilder(s.ctx)
118141
s.ctx.SetLogger(oldlogger)
119142
if err != nil {

Diff for: src/arduino.cc/builder/types/context.go

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ type Context struct {
1515
LibrariesFolders []string
1616
BuiltInLibrariesFolders []string
1717
OtherLibrariesFolders []string
18+
WatchedLocations []string
1819
SketchLocation string
1920
ArduinoAPIVersion string
2021
FQBN string

Diff for: src/arduino.cc/builder/utils/utils.go

+24
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,30 @@ func FilterOutFoldersByNames(folders []os.FileInfo, names ...string) []os.FileIn
325325

326326
type CheckExtensionFunc func(ext string) bool
327327

328+
func FindAllSubdirectories(folder string, output *[]string) error {
329+
walkFunc := func(path string, info os.FileInfo, err error) error {
330+
if err != nil {
331+
return err
332+
}
333+
334+
// Skip source control and hidden files and directories
335+
if IsSCCSOrHiddenFile(info) {
336+
if info.IsDir() {
337+
return filepath.SkipDir
338+
}
339+
return nil
340+
}
341+
342+
// Skip directories unless recurse is on, or this is the
343+
// root directory
344+
if info.IsDir() {
345+
*output = AppendIfNotPresent(*output, path)
346+
}
347+
return nil
348+
}
349+
return gohasissues.Walk(folder, walkFunc)
350+
}
351+
328352
func FindFilesInFolder(files *[]string, folder string, extensions CheckExtensionFunc, recurse bool) error {
329353
walkFunc := func(path string, info os.FileInfo, err error) error {
330354
if err != nil {

0 commit comments

Comments
 (0)