@@ -32,6 +32,7 @@ import {
32
32
PortIdentifier ,
33
33
Port ,
34
34
UploadResponse as ApiUploadResponse ,
35
+ portIdentifierEquals ,
35
36
} from '../common/protocol' ;
36
37
import { ArduinoCoreServiceClient } from './cli-protocol/cc/arduino/cli/commands/v1/commands_grpc_pb' ;
37
38
import { Port as RpcPort } from './cli-protocol/cc/arduino/cli/commands/v1/port_pb' ;
@@ -44,7 +45,7 @@ import { firstToUpperCase, notEmpty } from '../common/utils';
44
45
import { ServiceError } from './service-error' ;
45
46
import { ExecuteWithProgress , ProgressResponse } from './grpc-progressible' ;
46
47
import type { Mutable } from '@theia/core/lib/common/types' ;
47
- import { BoardDiscovery } from './board-discovery' ;
48
+ import { BoardDiscovery , createApiPort } from './board-discovery' ;
48
49
49
50
namespace Uploadable {
50
51
export type Request = UploadRequest | UploadUsingProgrammerRequest ;
@@ -208,14 +209,53 @@ export class CoreServiceImpl extends CoreClientAware implements CoreService {
208
209
) : Promise < ApiUploadResponse > {
209
210
const uploadResponseFragment : Mutable < Partial < ApiUploadResponse > > = {
210
211
portBeforeUpload : options . port ,
212
+ portAfterUpload : options . port , // assume no port changes during the upload
211
213
} ;
212
214
const coreClient = await this . coreClient ;
213
215
const { client, instance } = coreClient ;
214
216
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
+ }
219
259
} ;
220
260
const handler = this . createOnDataHandler (
221
261
progressHandler ,
0 commit comments