1717import { describe , it , expect , beforeEach } from '@jest/globals' ;
1818import * as vscode from 'vscode' ;
1919import { ExtensionContext } from 'vscode' ;
20- import { MANAGE_COMPONENTS_PACKS_COMMAND_ID , MERGE_FILE_COMMAND_ID } from '../manifest' ;
20+ import { MANAGE_COMPONENTS_PACKS_COMMAND_ID , MERGE_FILE_COMMAND_ID , RUN_GENERATOR_COMMAND_ID } from '../manifest' ;
2121import * as fsUtils from '../utils/fs-utils' ;
2222import * as vscodeUtils from '../utils/vscode-utils' ;
2323import { ProblemDiagnosticActionResolver } from './problem-diagnostic-action-resolver' ;
@@ -329,7 +329,7 @@ describe('SolutionProblems', () => {
329329 expect ( relativeArgs ) . toEqual ( [ layerPath ] ) ;
330330 } ) ;
331331
332- it ( 'returns undefined merge diagnostic action for non-merge messages' , ( ) => {
332+ it ( 'returns generic find in files action for non-merge messages' , ( ) => {
333333 const result = diagnosticActionResolver . resolve (
334334 {
335335 message : "component 'Arm::Device@2.3.4' is missing" ,
@@ -352,7 +352,42 @@ describe('SolutionProblems', () => {
352352 const [ command , args ] = code . target . toString ( ) . split ( '?' ) ;
353353
354354 expect ( code . value ) . toBe ( 'Run Generator' ) ;
355- expect ( command ) . toContain ( 'command:cmsis-csolution.runGenerator' ) ;
355+ expect ( command ) . toBe ( `command:${ RUN_GENERATOR_COMMAND_ID } ` ) ;
356+ expect ( JSON . parse ( decodeURIComponent ( args ) ) ) . toEqual ( [ { generator : 'CubeMX2' , context : 'CubeMX2.Debug+STM32C531CBT6' } ] ) ;
357+ } ) ;
358+
359+ it ( 'attaches run generator command uri only when parsed diagnostic has no location' , async ( ) => {
360+ await solutionProblems . activate ( { subscriptions : [ ] } as unknown as ExtensionContext ) ;
361+ const setSpy = jest . spyOn ( vscode . languages . createDiagnosticCollection ( ) , 'set' ) ;
362+
363+ await eventHub . fireConvertCompleted ( {
364+ severity : 'error' ,
365+ detection : false ,
366+ logMessages : {
367+ success : false ,
368+ errors : [
369+ "mylayer.clayer.yml - cgen file was not found, run generator 'CubeMX2' for context 'CubeMX2.Debug+STM32C531CBT6'" ,
370+ "mylayer.clayer.yml:10:2 - cgen file was not found, run generator 'CubeMX2' for context 'CubeMX2.Debug+STM32C531CBT6'" ,
371+ ] ,
372+ warnings : [ ] ,
373+ info : [ ] ,
374+ } ,
375+ } ) ;
376+ await waitTimeout ( ) ;
377+
378+ const setCalls = setSpy . mock . calls as unknown as Array < [ vscode . Uri , readonly vscode . Diagnostic [ ] | undefined ] > ;
379+ const diagnostics = setCalls . flatMap ( ( [ , diagnosticEntries ] ) => diagnosticEntries ?? [ ] ) ;
380+ const runGeneratorDiagnostics = diagnostics . filter (
381+ d => typeof d . code === 'object' && d . code !== null && 'value' in d . code && d . code . value === 'Run Generator'
382+ ) ;
383+ const diagnosticWithoutCode = diagnostics . find ( d => d . code === undefined ) ;
384+
385+ expect ( runGeneratorDiagnostics ) . toHaveLength ( 1 ) ;
386+ expect ( diagnosticWithoutCode ) . toBeDefined ( ) ;
387+
388+ const code = runGeneratorDiagnostics [ 0 ] . code as { value : string ; target : vscode . Uri } ;
389+ const [ command , args ] = code . target . toString ( ) . split ( '?' ) ;
390+ expect ( command ) . toBe ( `command:${ RUN_GENERATOR_COMMAND_ID } ` ) ;
356391 expect ( JSON . parse ( decodeURIComponent ( args ) ) ) . toEqual ( [ { generator : 'CubeMX2' , context : 'CubeMX2.Debug+STM32C531CBT6' } ] ) ;
357392 } ) ;
358393
@@ -404,7 +439,7 @@ describe('SolutionProblems', () => {
404439 expect ( JSON . parse ( decodeURIComponent ( args ) ) ) . toEqual ( [ layerPath ] ) ;
405440 } ) ;
406441
407- it . each ( [ 'required' , 'recommended' , 'suggested' , 'mandatory' ] as const ) (
442+ it . each ( [ 'required' , 'recommended' , 'suggested' ] as const ) (
408443 'renders merge diagnostics for current toolbox wording with %s update levels' ,
409444 async updateLevel => {
410445 await solutionProblems . activate ( { subscriptions : [ ] } as unknown as ExtensionContext ) ;
0 commit comments