diff --git a/internal/cli/compile/compile.go b/internal/cli/compile/compile.go index 28227615562..46534eb59b3 100644 --- a/internal/cli/compile/compile.go +++ b/internal/cli/compile/compile.go @@ -348,7 +348,7 @@ func runCompileCommand(cmd *cobra.Command, args []string) { UpdatedUploadPort: result.NewPort(uploadRes.GetUpdatedUploadPort()), }, ProfileOut: profileOut, - Diagnostics: compileRes.GetDiagnostics(), + Diagnostics: result.NewCompileDiagnostics(compileRes.GetDiagnostics()), Success: compileError == nil, showPropertiesMode: showProperties, hideStats: preprocess, @@ -393,15 +393,14 @@ type updatedUploadPortResult struct { } type compileResult struct { - CompilerOut string `json:"compiler_out"` - CompilerErr string `json:"compiler_err"` - BuilderResult *result.CompileResponse `json:"builder_result"` - UploadResult updatedUploadPortResult `json:"upload_result"` - Success bool `json:"success"` - ProfileOut string `json:"profile_out,omitempty"` - Error string `json:"error,omitempty"` - // TODO: make a proper result.* structure - Diagnostics []*rpc.CompileDiagnostic `json:"diagnostics"` + CompilerOut string `json:"compiler_out"` + CompilerErr string `json:"compiler_err"` + BuilderResult *result.CompileResponse `json:"builder_result"` + UploadResult updatedUploadPortResult `json:"upload_result"` + Success bool `json:"success"` + ProfileOut string `json:"profile_out,omitempty"` + Error string `json:"error,omitempty"` + Diagnostics []*result.CompileDiagnostic `json:"diagnostics"` showPropertiesMode arguments.ShowPropertiesMode hideStats bool } diff --git a/internal/cli/feedback/result/rpc.go b/internal/cli/feedback/result/rpc.go index 6b19c138a6d..a632af7737c 100644 --- a/internal/cli/feedback/result/rpc.go +++ b/internal/cli/feedback/result/rpc.go @@ -18,6 +18,7 @@ package result import ( "cmp" + f "github.com/arduino/arduino-cli/internal/algorithms" "github.com/arduino/arduino-cli/internal/orderedmap" rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1" semver "go.bug.st/relaxed-semver" @@ -880,6 +881,7 @@ type CompileResponse struct { BoardPlatform *InstalledPlatformReference `json:"board_platform,omitempty"` BuildPlatform *InstalledPlatformReference `json:"build_platform,omitempty"` BuildProperties []string `json:"build_properties,omitempty"` + Diagnostics []*CompileDiagnostic `json:"diagnostics,omitempty"` } func NewCompileResponse(c *rpc.CompileResponse) *CompileResponse { @@ -904,6 +906,7 @@ func NewCompileResponse(c *rpc.CompileResponse) *CompileResponse { BoardPlatform: NewInstalledPlatformReference(c.GetBoardPlatform()), BuildPlatform: NewInstalledPlatformReference(c.GetBuildPlatform()), BuildProperties: c.GetBuildProperties(), + Diagnostics: NewCompileDiagnostics(c.GetDiagnostics()), } } @@ -959,3 +962,61 @@ func NewBoardListWatchResponse(r *rpc.BoardListWatchResponse) *BoardListWatchRes Error: r.Error, } } + +type CompileDiagnostic struct { + Severity string `json:"severity,omitempty"` + Message string `json:"message,omitempty"` + File string `json:"file,omitempty"` + Line int64 `json:"line,omitempty"` + Column int64 `json:"column,omitempty"` + Context []*CompileDiagnosticContext `json:"context,omitempty"` + Notes []*CompileDiagnosticNote `json:"notes,omitempty"` +} + +func NewCompileDiagnostics(cd []*rpc.CompileDiagnostic) []*CompileDiagnostic { + return f.Map(cd, NewCompileDiagnostic) +} + +func NewCompileDiagnostic(cd *rpc.CompileDiagnostic) *CompileDiagnostic { + return &CompileDiagnostic{ + Severity: cd.GetSeverity(), + Message: cd.GetMessage(), + File: cd.GetFile(), + Line: cd.GetLine(), + Column: cd.GetColumn(), + Context: f.Map(cd.GetContext(), NewCompileDiagnosticContext), + Notes: f.Map(cd.GetNotes(), NewCompileDiagnosticNote), + } +} + +type CompileDiagnosticContext struct { + Message string `json:"message,omitempty"` + File string `json:"file,omitempty"` + Line int64 `json:"line,omitempty"` + Column int64 `json:"column,omitempty"` +} + +func NewCompileDiagnosticContext(cdc *rpc.CompileDiagnosticContext) *CompileDiagnosticContext { + return &CompileDiagnosticContext{ + Message: cdc.GetMessage(), + File: cdc.GetFile(), + Line: cdc.GetLine(), + Column: cdc.GetColumn(), + } +} + +type CompileDiagnosticNote struct { + Message string `json:"message,omitempty"` + File string `json:"file,omitempty"` + Line int64 `json:"line,omitempty"` + Column int64 `json:"column,omitempty"` +} + +func NewCompileDiagnosticNote(cdn *rpc.CompileDiagnosticNote) *CompileDiagnosticNote { + return &CompileDiagnosticNote{ + Message: cdn.GetMessage(), + File: cdn.GetFile(), + Line: cdn.GetLine(), + Column: cdn.GetColumn(), + } +} diff --git a/internal/cli/feedback/result/rpc_test.go b/internal/cli/feedback/result/rpc_test.go index 46adbcd8acc..af5259d128e 100644 --- a/internal/cli/feedback/result/rpc_test.go +++ b/internal/cli/feedback/result/rpc_test.go @@ -205,6 +205,18 @@ func TestAllFieldAreMapped(t *testing.T) { boardListWatchResponseRpc := &rpc.BoardListWatchResponse{} boardListWatchResponseResult := result.NewBoardListWatchResponse(boardListWatchResponseRpc) mustContainsAllPropertyOfRpcStruct(t, boardListWatchResponseRpc, boardListWatchResponseResult) + + compileDiagnosticRpc := &rpc.CompileDiagnostic{} + compileDiagnosticResult := result.NewCompileDiagnostic(compileDiagnosticRpc) + mustContainsAllPropertyOfRpcStruct(t, compileDiagnosticRpc, compileDiagnosticResult) + + compileDiagnosticContextRpc := &rpc.CompileDiagnosticContext{} + compileDiagnosticContextResult := result.NewCompileDiagnosticContext(compileDiagnosticContextRpc) + mustContainsAllPropertyOfRpcStruct(t, compileDiagnosticContextRpc, compileDiagnosticContextResult) + + compileDiagnosticNoteRpc := &rpc.CompileDiagnosticNote{} + compileDiagnosticNoteResult := result.NewCompileDiagnosticNote(compileDiagnosticNoteRpc) + mustContainsAllPropertyOfRpcStruct(t, compileDiagnosticNoteRpc, compileDiagnosticNoteResult) } func TestEnumsMapsEveryRpcCounterpart(t *testing.T) {