Skip to content

Commit 4611d13

Browse files
committed
Merged together DebugConfigReq protoc type
It makes no sense to have two separate types to create a debug session or to create a debug configuration.
1 parent afd8d6c commit 4611d13

File tree

6 files changed

+133
-275
lines changed

6 files changed

+133
-275
lines changed

cli/debug/debug.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,18 @@ func run(command *cobra.Command, args []string) {
7878
}
7979
sketchPath := initSketchPath(path)
8080

81+
debugConfigRequested := &dbg.DebugConfigReq{
82+
Instance: instance,
83+
Fqbn: fqbn,
84+
SketchPath: sketchPath.String(),
85+
Port: port,
86+
Interpreter: interpreter,
87+
ImportDir: importDir,
88+
}
89+
8190
if printInfo {
8291

83-
if res, err := debug.GetDebugInfo(context.Background(), &dbg.GetDebugInfoReq{
84-
Instance: instance,
85-
Fqbn: fqbn,
86-
SketchPath: sketchPath.String(),
87-
Port: port,
88-
ImportDir: importDir,
89-
}); err != nil {
92+
if res, err := debug.GetDebugConfig(context.Background(), debugConfigRequested); err != nil {
9093
feedback.Errorf("Error getting Debug info: %v", err)
9194
os.Exit(errorcodes.ErrGeneric)
9295
} else {
@@ -99,14 +102,7 @@ func run(command *cobra.Command, args []string) {
99102
ctrlc := make(chan os.Signal, 1)
100103
signal.Notify(ctrlc, os.Interrupt)
101104

102-
if _, err := debug.Debug(context.Background(), &dbg.DebugConfigReq{
103-
Instance: instance,
104-
Fqbn: fqbn,
105-
SketchPath: sketchPath.String(),
106-
Port: port,
107-
Interpreter: interpreter,
108-
ImportDir: importDir,
109-
}, os.Stdin, os.Stdout, ctrlc); err != nil {
105+
if _, err := debug.Debug(context.Background(), debugConfigRequested, os.Stdin, os.Stdout, ctrlc); err != nil {
110106
feedback.Errorf("Error during Debug: %v", err)
111107
os.Exit(errorcodes.ErrGeneric)
112108
}
@@ -130,7 +126,7 @@ func initSketchPath(sketchPath *paths.Path) *paths.Path {
130126
}
131127

132128
type debugInfoResult struct {
133-
info *dbg.GetDebugInfoResp
129+
info *dbg.GetDebugConfigResp
134130
}
135131

136132
func (r *debugInfoResult) Data() interface{} {

commands/daemon/debug.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (s *DebugService) Debug(stream dbg.Debug_DebugServer) error {
6767
return stream.Send(resp)
6868
}
6969

70-
// GetDebugInfo return metadata about a debug session
71-
func (s *DebugService) GetDebugInfo(ctx context.Context, req *debug.GetDebugInfoReq) (*debug.GetDebugInfoResp, error) {
72-
return cmd.GetDebugInfo(ctx, req)
70+
// GetDebugConfig return metadata about a debug session
71+
func (s *DebugService) GetDebugConfig(ctx context.Context, req *debug.DebugConfigReq) (*debug.GetDebugConfigResp, error) {
72+
return cmd.GetDebugConfig(ctx, req)
7373
}

commands/debug/debug.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func Debug(ctx context.Context, req *dbg.DebugConfigReq, inStream io.Reader, out
109109

110110
// getCommandLine compose a debug command represented by a core recipe
111111
func getCommandLine(req *dbg.DebugConfigReq, pm *packagemanager.PackageManager) ([]string, error) {
112-
debugInfo, err := GetDebugInfo(context.Background(), &dbg.GetDebugInfoReq{
112+
debugInfo, err := GetDebugConfig(context.Background(), &dbg.DebugConfigReq{
113113
Instance: req.GetInstance(),
114114
Fqbn: req.GetFqbn(),
115115
SketchPath: req.GetSketchPath(),

commands/debug/debug_info.go

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ import (
3131
"github.com/sirupsen/logrus"
3232
)
3333

34-
// GetDebugInfo returns metadata to start debugging with the specified board
35-
func GetDebugInfo(ctx context.Context, req *debug.GetDebugInfoReq) (*debug.GetDebugInfoResp, error) {
34+
// GetDebugConfig returns metadata to start debugging with the specified board
35+
func GetDebugConfig(ctx context.Context, req *debug.DebugConfigReq) (*debug.GetDebugConfigResp, error) {
3636
pm := commands.GetPackageManager(req.GetInstance().GetId())
3737

3838
props, err := getDebugProperties(req, pm)
@@ -42,7 +42,7 @@ func GetDebugInfo(ctx context.Context, req *debug.GetDebugInfoReq) (*debug.GetDe
4242

4343
server := props.Get("server")
4444
toolchain := props.Get("toolchain")
45-
resp := &debug.GetDebugInfoResp{
45+
resp := &debug.GetDebugConfigResp{
4646
Executable: props.Get("executable"),
4747
Server: server,
4848
ServerPath: props.Get("server." + server + ".path"),
@@ -55,15 +55,7 @@ func GetDebugInfo(ctx context.Context, req *debug.GetDebugInfoReq) (*debug.GetDe
5555
return resp, nil
5656
}
5757

58-
// Target represents a target for a debug action
59-
type Target interface {
60-
GetSketchPath() string
61-
GetFqbn() string
62-
GetImportDir() string
63-
GetPort() string
64-
}
65-
66-
func getDebugProperties(req Target, pm *packagemanager.PackageManager) (*properties.Map, error) {
58+
func getDebugProperties(req *debug.DebugConfigReq, pm *packagemanager.PackageManager) (*properties.Map, error) {
6759
// TODO: make a generic function to extract sketch from request
6860
// and remove duplication in commands/compile.go
6961
if req.GetSketchPath() == "" {

0 commit comments

Comments
 (0)