@@ -18,7 +18,7 @@ import * as vscode from 'vscode';
1818import * as manifest from '../../manifest' ;
1919import * as Messages from './messages' ;
2020import path , { dirname } from 'path' ;
21- import { ComponentInstance , CsolutionService , CtAggregate , CtRoot , PackReference , PacksInfo , Results , UsedItems } from '../../json-rpc/csolution-rpc-client' ;
21+ import { ComponentInstance , CsolutionService , CtAggregate , CtRoot , Pack , PackReference , PacksInfo , Results , UsedItems } from '../../json-rpc/csolution-rpc-client' ;
2222import { IOpenFileExternal } from '../../open-file-external-if' ;
2323import { ProjectFileUpdater , ProjectFileUpdaterImpl } from '../../solutions/edit/project-file-updater' ;
2424import { SolutionLoadStateChangeEvent , SolutionManager } from '../../solutions/solution-manager' ;
@@ -29,9 +29,9 @@ import { COutlineItem } from '../solution-outline/tree-structure/solution-outlin
2929import { WebviewManager , WebviewManagerOptions } from '../webview-manager' ;
3030import { BuildContext , Project , TargetSetData } from './components-data' ;
3131import { ComponentsPacksActions , CurrentProject , normalizeForCompare } from './components-packs-actions' ;
32- import { ComponentRowDataType , ComponentScope } from './data/component-tools' ;
32+ import { ComponentRowDataType , ComponentScope , PackRowDataType , PackRowReferenceDataType } from './data/component-tools' ;
3333import { componentTreeWalker } from './data/component-tree-walker' ;
34- import { uniqWith , cloneDeep } from 'lodash' ;
34+ import { cloneDeep , uniqWith } from 'lodash' ;
3535import { parsePackId } from './data/pack-parse' ;
3636import { lineOf , readTextFile } from '../../utils/fs-utils' ;
3737import { stripTwoExtensions } from '../../utils/string-utils' ;
@@ -52,6 +52,32 @@ const createProject = (cprojectPath: string): Project => {
5252 return { projectId : cprojectPath , projectName : getFileNameNoExt ( cprojectPath ) } ;
5353} ;
5454
55+ const packsRowFromInfo = ( packInfo : Pack , solutionPath : string ) : PackRowDataType => {
56+ const pack = parsePackId ( packInfo . id ) ;
57+ const solutionDir = dirname ( solutionPath ) ;
58+ const references = uniqWith ( ( packInfo . references || [ ] ) . map ( ref => ( {
59+ ...ref ,
60+ relOrigin : backToForwardSlashes ( path . relative ( solutionDir , ref . origin ) ) ,
61+ relPath : ref . path ? backToForwardSlashes ( path . relative ( solutionDir , ref . path ) ) : undefined ,
62+ } satisfies PackRowReferenceDataType ) ) , ( left , right ) => left . origin === right . origin && left . pack === right . pack ) ;
63+
64+ return {
65+ key : packInfo . id ,
66+ name : pack ? ( pack . vendor ? `${ pack . vendor } ::${ pack . packName } ` : pack . packName ) : packInfo . id ,
67+ packId : packInfo . id ,
68+ versionUsed : pack ?. versionOperator ? pack . versionOperator + pack . version : ( pack ?. version || '' ) ,
69+ versionTarget : '' ,
70+ description : packInfo . description || '' ,
71+ used : packInfo . used || false ,
72+ references,
73+ overviewLink : packInfo . doc || ''
74+ } ;
75+ } ;
76+
77+ const packsRowsFromInfo = ( packsInfo : PacksInfo , solutionPath : string ) : PackRowDataType [ ] => {
78+ return ( packsInfo . packs || [ ] ) . map ( pack => packsRowFromInfo ( pack , solutionPath ) ) ;
79+ } ;
80+
5581export class ComponentsPacksWebviewMain {
5682 private readonly webviewManager : WebviewManager < Messages . IncomingMessage , Messages . OutgoingMessage > ;
5783
@@ -618,8 +644,11 @@ export class ComponentsPacksWebviewMain {
618644 const actx = this . getActiveContext ( ) ;
619645 await action ( actx , target , packId ) ;
620646 const requestAll = this . scope === ComponentScope . All ;
621- const packs = this . mapPacksFromService ( await this . csolutionService . getPacksInfo ( { context : actx , all : requestAll } ) ) ;
622- await this . webviewManager . sendMessage ( { type : 'SET_PACKS_INFO' , packs : packs ?. packs || [ ] } ) ;
647+ const packs = await this . csolutionService . getPacksInfo ( { context : actx , all : requestAll } ) ;
648+ await this . webviewManager . sendMessage ( {
649+ type : 'SET_PACKS_INFO' ,
650+ packs : packsRowsFromInfo ( packs , this . currentProject ?. solutionPath ?? '' )
651+ } ) ;
623652 await this . sendDirtyState ( ) ;
624653 } finally {
625654 await this . webviewManager . sendMessage ( { type : 'SET_SOLUTION_STATE' , stateMessage : undefined } ) ;
@@ -678,7 +707,10 @@ export class ComponentsPacksWebviewMain {
678707
679708 this . componentTree = this . manageComponentsActions . mapComponentsFromService ( await this . csolutionService . getComponentsTree ( { context : activeContext , all : requestAll } ) ) ;
680709 this . validations = await this . csolutionService . validateComponents ( { context : activeContext } ) ;
681- const packsInfo = this . mapPacksFromService ( await this . csolutionService . getPacksInfo ( { context : activeContext , all : requestAll } ) ) ;
710+ const packs = packsRowsFromInfo (
711+ await this . csolutionService . getPacksInfo ( { context : activeContext , all : requestAll } ) ,
712+ this . currentProject ?. solutionPath ?? ''
713+ ) ;
682714
683715 componentTreeWalker ( this . componentTree , ( node , type ) => {
684716 if ( type === 'aggregate' && ( node as CtAggregate ) . options ?. layer ) {
@@ -698,7 +730,7 @@ export class ComponentsPacksWebviewMain {
698730 componentScope : this . scope ,
699731 availableTargetTypes : this . getTargetSetData ( ) ,
700732 selectedTargetType : this . getSelectedTargetSetData ( ) ,
701- packs : packsInfo . packs ,
733+ packs,
702734 cbuildPackPath : cbuildPackPath ,
703735 solution : {
704736 dir : this . solutionManager . getCsolution ( ) ?. solutionDir ,
@@ -717,33 +749,6 @@ export class ComponentsPacksWebviewMain {
717749 await this . sendDirtyState ( ) ;
718750 } ;
719751
720- private mapPacksFromService ( packs : PacksInfo ) {
721- if ( packs . packs ) {
722- // merge duplicate versions to one.
723- packs . packs = uniqWith ( packs . packs , ( a , b ) => {
724- const pa = parsePackId ( a . id ) ;
725- const pb = parsePackId ( b . id ) ;
726- if ( pa ?. vendor === pb ?. vendor && pa ?. packName === pb ?. packName ) {
727- const refs = uniqWith ( [ ... ( a . references || [ ] ) , ...( b . references || [ ] ) ] , ( a , b ) => a . origin === b . origin && a . pack === b . pack ) ;
728- a . references = b . references = refs ;
729- return true ;
730- }
731- return false ;
732- } ) ;
733-
734- // replace origin file names to relative
735- packs . packs . forEach ( pack => {
736- pack . references ?. forEach ( ref => {
737- ref . origin = backToForwardSlashes ( ref . origin ) ;
738- ref . path = backToForwardSlashes (
739- path . relative ( dirname ( this . currentProject ?. solutionPath ?? '' ) , ref . origin )
740- ) ;
741- } ) ;
742- } ) ;
743- }
744- return packs ;
745- }
746-
747752 private async clearComponents ( ) {
748753 if ( this . componentTree ) {
749754 this . componentTree . classes = [ ] ;
0 commit comments