Skip to content

Commit 57ad932

Browse files
committed
Added proper result structure for diagnostics
1 parent 3190022 commit 57ad932

File tree

3 files changed

+82
-10
lines changed

3 files changed

+82
-10
lines changed

Diff for: internal/cli/compile/compile.go

+9-10
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) {
348348
UpdatedUploadPort: result.NewPort(uploadRes.GetUpdatedUploadPort()),
349349
},
350350
ProfileOut: profileOut,
351-
Diagnostics: compileRes.GetDiagnostics(),
351+
Diagnostics: result.NewCompileDiagnostics(compileRes.GetDiagnostics()),
352352
Success: compileError == nil,
353353
showPropertiesMode: showProperties,
354354
hideStats: preprocess,
@@ -393,15 +393,14 @@ type updatedUploadPortResult struct {
393393
}
394394

395395
type compileResult struct {
396-
CompilerOut string `json:"compiler_out"`
397-
CompilerErr string `json:"compiler_err"`
398-
BuilderResult *result.CompileResponse `json:"builder_result"`
399-
UploadResult updatedUploadPortResult `json:"upload_result"`
400-
Success bool `json:"success"`
401-
ProfileOut string `json:"profile_out,omitempty"`
402-
Error string `json:"error,omitempty"`
403-
// TODO: make a proper result.* structure
404-
Diagnostics []*rpc.CompileDiagnostic `json:"diagnostics"`
396+
CompilerOut string `json:"compiler_out"`
397+
CompilerErr string `json:"compiler_err"`
398+
BuilderResult *result.CompileResponse `json:"builder_result"`
399+
UploadResult updatedUploadPortResult `json:"upload_result"`
400+
Success bool `json:"success"`
401+
ProfileOut string `json:"profile_out,omitempty"`
402+
Error string `json:"error,omitempty"`
403+
Diagnostics []*result.CompileDiagnostic `json:"diagnostics"`
405404
showPropertiesMode arguments.ShowPropertiesMode
406405
hideStats bool
407406
}

Diff for: internal/cli/feedback/result/rpc.go

+61
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package result
1818
import (
1919
"cmp"
2020

21+
f "github.com/arduino/arduino-cli/internal/algorithms"
2122
"github.com/arduino/arduino-cli/internal/orderedmap"
2223
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
2324
semver "go.bug.st/relaxed-semver"
@@ -880,6 +881,7 @@ type CompileResponse struct {
880881
BoardPlatform *InstalledPlatformReference `json:"board_platform,omitempty"`
881882
BuildPlatform *InstalledPlatformReference `json:"build_platform,omitempty"`
882883
BuildProperties []string `json:"build_properties,omitempty"`
884+
Diagnostics []*CompileDiagnostic `json:"diagnostics,omitempty"`
883885
}
884886

885887
func NewCompileResponse(c *rpc.CompileResponse) *CompileResponse {
@@ -904,6 +906,7 @@ func NewCompileResponse(c *rpc.CompileResponse) *CompileResponse {
904906
BoardPlatform: NewInstalledPlatformReference(c.GetBoardPlatform()),
905907
BuildPlatform: NewInstalledPlatformReference(c.GetBuildPlatform()),
906908
BuildProperties: c.GetBuildProperties(),
909+
Diagnostics: NewCompileDiagnostics(c.GetDiagnostics()),
907910
}
908911
}
909912

@@ -959,3 +962,61 @@ func NewBoardListWatchResponse(r *rpc.BoardListWatchResponse) *BoardListWatchRes
959962
Error: r.Error,
960963
}
961964
}
965+
966+
type CompileDiagnostic struct {
967+
Severity string `json:"severity,omitempty"`
968+
Message string `json:"message,omitempty"`
969+
File string `json:"file,omitempty"`
970+
Line int64 `json:"line,omitempty"`
971+
Column int64 `json:"column,omitempty"`
972+
Context []*CompileDiagnosticContext `json:"context,omitempty"`
973+
Notes []*CompileDiagnosticNote `json:"notes,omitempty"`
974+
}
975+
976+
func NewCompileDiagnostics(cd []*rpc.CompileDiagnostic) []*CompileDiagnostic {
977+
return f.Map(cd, NewCompileDiagnostic)
978+
}
979+
980+
func NewCompileDiagnostic(cd *rpc.CompileDiagnostic) *CompileDiagnostic {
981+
return &CompileDiagnostic{
982+
Severity: cd.GetSeverity(),
983+
Message: cd.GetMessage(),
984+
File: cd.GetFile(),
985+
Line: cd.GetLine(),
986+
Column: cd.GetColumn(),
987+
Context: f.Map(cd.GetContext(), NewCompileDiagnosticContext),
988+
Notes: f.Map(cd.GetNotes(), NewCompileDiagnosticNote),
989+
}
990+
}
991+
992+
type CompileDiagnosticContext struct {
993+
Message string `json:"message,omitempty"`
994+
File string `json:"file,omitempty"`
995+
Line int64 `json:"line,omitempty"`
996+
Column int64 `json:"column,omitempty"`
997+
}
998+
999+
func NewCompileDiagnosticContext(cdc *rpc.CompileDiagnosticContext) *CompileDiagnosticContext {
1000+
return &CompileDiagnosticContext{
1001+
Message: cdc.GetMessage(),
1002+
File: cdc.GetFile(),
1003+
Line: cdc.GetLine(),
1004+
Column: cdc.GetColumn(),
1005+
}
1006+
}
1007+
1008+
type CompileDiagnosticNote struct {
1009+
Message string `json:"message,omitempty"`
1010+
File string `json:"file,omitempty"`
1011+
Line int64 `json:"line,omitempty"`
1012+
Column int64 `json:"column,omitempty"`
1013+
}
1014+
1015+
func NewCompileDiagnosticNote(cdn *rpc.CompileDiagnosticNote) *CompileDiagnosticNote {
1016+
return &CompileDiagnosticNote{
1017+
Message: cdn.GetMessage(),
1018+
File: cdn.GetFile(),
1019+
Line: cdn.GetLine(),
1020+
Column: cdn.GetColumn(),
1021+
}
1022+
}

Diff for: internal/cli/feedback/result/rpc_test.go

+12
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,18 @@ func TestAllFieldAreMapped(t *testing.T) {
205205
boardListWatchResponseRpc := &rpc.BoardListWatchResponse{}
206206
boardListWatchResponseResult := result.NewBoardListWatchResponse(boardListWatchResponseRpc)
207207
mustContainsAllPropertyOfRpcStruct(t, boardListWatchResponseRpc, boardListWatchResponseResult)
208+
209+
compileDiagnosticRpc := &rpc.CompileDiagnostic{}
210+
compileDiagnosticResult := result.NewCompileDiagnostic(compileDiagnosticRpc)
211+
mustContainsAllPropertyOfRpcStruct(t, compileDiagnosticRpc, compileDiagnosticResult)
212+
213+
compileDiagnosticContextRpc := &rpc.CompileDiagnosticContext{}
214+
compileDiagnosticContextResult := result.NewCompileDiagnosticContext(compileDiagnosticContextRpc)
215+
mustContainsAllPropertyOfRpcStruct(t, compileDiagnosticContextRpc, compileDiagnosticContextResult)
216+
217+
compileDiagnosticNoteRpc := &rpc.CompileDiagnosticNote{}
218+
compileDiagnosticNoteResult := result.NewCompileDiagnosticNote(compileDiagnosticNoteRpc)
219+
mustContainsAllPropertyOfRpcStruct(t, compileDiagnosticNoteRpc, compileDiagnosticNoteResult)
208220
}
209221

210222
func TestEnumsMapsEveryRpcCounterpart(t *testing.T) {

0 commit comments

Comments
 (0)