Skip to content

Commit 0461079

Browse files
committed
Mute log output during autocomplete via rpc
Should solve arduino/Arduino#6818
1 parent b031a69 commit 0461079

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

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

+9-5
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010

1111
"arduino.cc/builder"
12+
"arduino.cc/builder/i18n"
1213
"arduino.cc/builder/types"
1314
"arduino.cc/builder/utils"
1415
"github.com/fsnotify/fsnotify"
@@ -87,6 +88,7 @@ func (s *builderServer) Autocomplete(ctx context.Context, args *pb.BuildParams)
8788
s.ctx.WarningsLevel = args.WarningsLevel
8889
s.ctx.PrototypesSection = ""
8990
s.ctx.CodeCompleteAt = args.CodeCompleteAt
91+
s.ctx.CodeCompletions = ""
9092

9193
s.ctx.IncludeFolders = s.ctx.IncludeFolders[0:0]
9294
s.ctx.LibrariesObjectFiles = s.ctx.LibrariesObjectFiles[0:0]
@@ -96,14 +98,16 @@ func (s *builderServer) Autocomplete(ctx context.Context, args *pb.BuildParams)
9698
s.ctx.ImportedLibraries = s.ctx.ImportedLibraries[0:0]
9799

98100
s.watch()
101+
oldlogger := s.ctx.GetLogger()
102+
logger := i18n.NoopLogger{}
103+
s.ctx.SetLogger(logger)
99104

100105
err := builder.RunPreprocess(s.ctx)
101-
if err != nil {
102-
return &pb.Response{Line: s.ctx.GetLogger().Flush()}, err
103-
}
104106

105-
// No feature was found, return an unnamed feature
106-
return &pb.Response{Line: s.ctx.GetLogger().Flush()}, nil
107+
response := pb.Response{Line: s.ctx.CodeCompletions}
108+
s.ctx.SetLogger(oldlogger)
109+
110+
return &response, err
107111
}
108112

109113
// GetFeature returns the feature at the given point.

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,10 @@ func (s *ArduinoPreprocessorRunner) Run(ctx *types.Context) error {
127127
type OutputCodeCompletions struct{}
128128

129129
func (s *OutputCodeCompletions) Run(ctx *types.Context) error {
130-
ctx.GetLogger().Println(constants.LOG_LEVEL_INFO, "%s", ctx.CodeCompletions)
130+
if ctx.CodeCompletions == "" {
131+
// we assume it is a json, let's make it compliant at least
132+
ctx.CodeCompletions = "[]"
133+
}
134+
ctx.GetLogger().Println(constants.LOG_LEVEL_INFO, ctx.CodeCompletions)
131135
return nil
132136
}

0 commit comments

Comments
 (0)