Skip to content

Commit b0e99b5

Browse files
committed
Normalize preprocessed output
Solves autocomplete over grcp SOlves arduino/Arduino#6816
1 parent 6d29a54 commit b0e99b5

File tree

3 files changed

+18
-10
lines changed

3 files changed

+18
-10
lines changed

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

+10-1
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,15 @@ func RunParseHardwareAndDumpBuildProperties(ctx *types.Context) error {
230230
}
231231

232232
func RunPreprocess(ctx *types.Context) error {
233+
oldlogger := ctx.GetLogger()
234+
if ctx.CodeCompleteAt != "" {
235+
logger := i18n.NoopLogger{}
236+
ctx.SetLogger(logger)
237+
}
233238
command := Preprocess{}
234-
return command.Run(ctx)
239+
ret := command.Run(ctx)
240+
if ctx.CodeCompleteAt != "" {
241+
ctx.SetLogger(oldlogger)
242+
}
243+
return ret
235244
}

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

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

1111
"arduino.cc/builder"
12-
"arduino.cc/builder/i18n"
1312
"arduino.cc/builder/types"
1413
"arduino.cc/builder/utils"
1514
"github.com/fsnotify/fsnotify"
@@ -98,14 +97,10 @@ func (s *builderServer) Autocomplete(ctx context.Context, args *pb.BuildParams)
9897
s.ctx.ImportedLibraries = s.ctx.ImportedLibraries[0:0]
9998

10099
s.watch()
101-
oldlogger := s.ctx.GetLogger()
102-
logger := i18n.NoopLogger{}
103-
s.ctx.SetLogger(logger)
104100

105101
err := builder.RunPreprocess(s.ctx)
106102

107103
response := pb.Response{Line: s.ctx.CodeCompletions}
108-
s.ctx.SetLogger(oldlogger)
109104

110105
return &response, err
111106
}

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

+8-4
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@
3030
package builder
3131

3232
import (
33+
"errors"
3334
"fmt"
35+
"os/exec"
3436
"path/filepath"
3537
"runtime"
3638
"strings"
@@ -118,14 +120,16 @@ func (s *ArduinoPreprocessorRunner) Run(ctx *types.Context) error {
118120

119121
buf, err := command.Output()
120122
if err != nil {
121-
return i18n.WrapError(err)
123+
return errors.New(i18n.WrapError(err).Error() + string(err.(*exec.ExitError).Stderr))
122124
}
123-
output := string(buf)
125+
126+
result := utils.NormalizeUTF8(buf)
127+
124128
//fmt.Printf("PREPROCESSOR OUTPUT:\n%s\n", output)
125129
if ctx.CodeCompleteAt != "" {
126-
ctx.CodeCompletions = output
130+
ctx.CodeCompletions = string(result)
127131
} else {
128-
ctx.Source = output
132+
ctx.Source = string(result)
129133
}
130134
return nil
131135
}

0 commit comments

Comments
 (0)