@@ -32,6 +32,7 @@ import {
3232 PortIdentifier ,
3333 Port ,
3434 UploadResponse as ApiUploadResponse ,
35+ portIdentifierEquals ,
3536} from '../common/protocol' ;
3637import { ArduinoCoreServiceClient } from './cli-protocol/cc/arduino/cli/commands/v1/commands_grpc_pb' ;
3738import { Port as RpcPort } from './cli-protocol/cc/arduino/cli/commands/v1/port_pb' ;
@@ -44,7 +45,7 @@ import { firstToUpperCase, notEmpty } from '../common/utils';
4445import { ServiceError } from './service-error' ;
4546import { ExecuteWithProgress , ProgressResponse } from './grpc-progressible' ;
4647import type { Mutable } from '@theia/core/lib/common/types' ;
47- import { BoardDiscovery } from './board-discovery' ;
48+ import { BoardDiscovery , createApiPort } from './board-discovery' ;
4849
4950namespace Uploadable {
5051 export type Request = UploadRequest | UploadUsingProgrammerRequest ;
@@ -208,14 +209,53 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
208209 ) : Promise < ApiUploadResponse > {
209210 const uploadResponseFragment : Mutable < Partial < ApiUploadResponse > > = {
210211 portBeforeUpload : options . port ,
212+ portAfterUpload : options . port , // assume no port changes during the upload
211213 } ;
212214 const coreClient = await this . coreClient ;
213215 const { client, instance } = coreClient ;
214216 const progressHandler = this . createProgressHandler ( options ) ;
215- // eslint-disable-next-line @typescript-eslint/no-unused-vars
216- const updateUploadResponseFragmentHandler = ( _ : RESP ) => {
217- // TODO: update the upload response fragment with the new port.
218- // https://github.com/arduino/arduino-cli/issues/2245
217+ // Track responses for port changes:
218+ // No port changes are expected when uploading using a programmer.
219+ // When the `updatedUploadPort` is missing, the port did not change.
220+ // The CLI does not tell anything when no changes.
221+ // IDE2 provides the same port for after as before when no changes.
222+ const updateUploadResponseFragmentHandler = ( response : RESP ) => {
223+ if ( response instanceof UploadResponse ) {
224+ // TODO: this instanceof should not be here
225+ if ( response . hasResult ( ) ) {
226+ const port = response . getResult ( ) ?. getUpdatedUploadPort ( ) ;
227+ if ( port ) {
228+ const portAfterUpload = createApiPort ( port ) ;
229+ if (
230+ portIdentifierEquals (
231+ uploadResponseFragment . portBeforeUpload ,
232+ portAfterUpload
233+ )
234+ ) {
235+ console . info (
236+ `Detected a port change during the upload from the CLI [${
237+ options . port ? Port . keyOf ( options . port ) : ''
238+ } , ${ options . fqbn } , ${
239+ options . sketch . name
240+ } ], but they are the same. Before port: ${ JSON . stringify (
241+ uploadResponseFragment . portBeforeUpload
242+ ) } , after port: ${ JSON . stringify ( portAfterUpload ) } `
243+ ) ;
244+ } else {
245+ console . info (
246+ `Detected a port change during the upload from the CLI [${
247+ options . port ? Port . keyOf ( options . port ) : ''
248+ } , ${ options . fqbn } , ${
249+ options . sketch . name
250+ } ]. Before port: ${ JSON . stringify (
251+ uploadResponseFragment . portBeforeUpload
252+ ) } , after port: ${ JSON . stringify ( portAfterUpload ) } `
253+ ) ;
254+ uploadResponseFragment . portAfterUpload = portAfterUpload ;
255+ }
256+ }
257+ }
258+ }
219259 } ;
220260 const handler = this . createOnDataHandler (
221261 progressHandler ,
0 commit comments