@@ -21,12 +21,12 @@ type CommandObject = {
21
21
library ?: string
22
22
}
23
23
24
- type ActionTarget = {
24
+ export type ActionTarget = {
25
25
uri : vscode . Uri
26
26
extension : string
27
27
fragment : string
28
28
protected : boolean
29
- workspaceFolder : vscode . WorkspaceFolder
29
+ workspaceFolder ? : vscode . WorkspaceFolder
30
30
executionOK : boolean ,
31
31
hasRun : boolean ,
32
32
processed : boolean ,
@@ -42,6 +42,20 @@ export function registerActionTools(context: vscode.ExtensionContext) {
42
42
) ;
43
43
}
44
44
45
+ export function uriToActionTarget ( uri : vscode . Uri , workspaceFolder ?: WorkspaceFolder ) : ActionTarget {
46
+ return {
47
+ uri,
48
+ extension : uri . path . substring ( uri . path . lastIndexOf ( `.` ) + 1 ) . toUpperCase ( ) ,
49
+ fragment : uri . fragment . toUpperCase ( ) ,
50
+ protected : parseFSOptions ( uri ) . readonly || false ,
51
+ workspaceFolder : workspaceFolder || vscode . workspace . getWorkspaceFolder ( uri ) ,
52
+ executionOK : false ,
53
+ hasRun : false ,
54
+ processed : false ,
55
+ output : [ ]
56
+ } ;
57
+ }
58
+
45
59
export async function runAction ( instance : Instance , uris : vscode . Uri | vscode . Uri [ ] , customAction ?: Action , method ?: DeploymentMethod , browserItems ?: BrowserItem [ ] , workspaceFolder ?: WorkspaceFolder ) : Promise < boolean > {
46
60
uris = Array . isArray ( uris ) ? uris : [ uris ] ;
47
61
//Global scheme: all URIs share the same
@@ -56,17 +70,7 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur
56
70
const config = connection . getConfig ( ) ;
57
71
const content = connection . getContent ( ) ;
58
72
59
- const targets = uris . map ( uri => ( {
60
- uri,
61
- extension : uri . path . substring ( uri . path . lastIndexOf ( `.` ) + 1 ) . toUpperCase ( ) ,
62
- fragment : uri . fragment . toUpperCase ( ) ,
63
- protected : parseFSOptions ( uri ) . readonly || config ?. readOnlyMode ,
64
- workspaceFolder : workspaceFolder || vscode . workspace . getWorkspaceFolder ( uri ) ,
65
- executionOK : false ,
66
- hasRun : false ,
67
- processed : false ,
68
- output : [ ]
69
- } ) as ActionTarget ) ;
73
+ const targets = uris . map ( uri => uriToActionTarget ( uri , workspaceFolder ) ) ;
70
74
71
75
workspaceFolder = targets [ 0 ] . workspaceFolder ;
72
76
if ( ! targets . every ( target => target . workspaceFolder === workspaceFolder ) ) {
@@ -76,34 +80,10 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur
76
80
77
81
let remoteCwd = config ?. homeDirectory || `.` ;
78
82
79
- let availableActions : { label : string ; action : Action ; } [ ] = [ ] ;
83
+ let availableActions : AvailableAction [ ] = [ ] ;
80
84
if ( ! customAction ) {
81
85
// First we grab a copy the predefined Actions in the VS Code settings
82
- const allActions = [ ...IBMi . connectionManager . get < Action [ ] > ( `actions` ) || [ ] ] ;
83
-
84
- // Then, if we're being called from a local file
85
- // we fetch the Actions defined from the workspace.
86
- if ( targets [ 0 ] . workspaceFolder && scheme === `file` ) {
87
- const localActions = await getLocalActions ( targets [ 0 ] . workspaceFolder ) ;
88
- allActions . push ( ...localActions ) ;
89
- }
90
-
91
- // We make sure all extensions are uppercase
92
- allActions . forEach ( action => {
93
- if ( action . extensions ) {
94
- action . extensions = action . extensions . map ( ext => ext . toUpperCase ( ) ) ;
95
- } ;
96
- } ) ;
97
-
98
- // Then we get all the available Actions for the current context
99
- availableActions = allActions . filter ( action => action . type === scheme )
100
- . filter ( action => ! action . extensions || action . extensions . every ( e => ! e ) || targets . every ( t => action . extensions ! . includes ( t . extension ) || action . extensions ! . includes ( t . fragment ) ) || action . extensions . includes ( `GLOBAL` ) )
101
- . filter ( action => action . runOnProtected || ! targets . some ( t => t . protected ) )
102
- . sort ( ( a , b ) => ( actionUsed . get ( b . name ) || 0 ) - ( actionUsed . get ( a . name ) || 0 ) )
103
- . map ( action => ( {
104
- label : action . name ,
105
- action
106
- } ) ) ;
86
+ availableActions = await getAllAvailableActions ( targets , scheme ) ;
107
87
}
108
88
109
89
if ( customAction || availableActions . length ) {
@@ -416,7 +396,7 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur
416
396
else if ( evfeventInfo . object && evfeventInfo . library ) {
417
397
if ( chosenAction . command . includes ( `*EVENTF` ) ) {
418
398
writeEmitter . fire ( `Fetching errors for ${ evfeventInfo . library } /${ evfeventInfo . object } .` + CompileTools . NEWLINE ) ;
419
- refreshDiagnosticsFromServer ( instance , evfeventInfo ) ;
399
+ await refreshDiagnosticsFromServer ( instance , evfeventInfo ) ;
420
400
problemsFetched = true ;
421
401
} else if ( chosenAction . command . trimStart ( ) . toUpperCase ( ) . startsWith ( `CRT` ) ) {
422
402
writeEmitter . fire ( `*EVENTF not found in command string. Not fetching errors for ${ evfeventInfo . library } /${ evfeventInfo . object } .` + CompileTools . NEWLINE ) ;
@@ -501,7 +481,7 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur
501
481
502
482
// Process locally downloaded evfevent files:
503
483
if ( useLocalEvfevent ) {
504
- refreshDiagnosticsFromLocal ( instance , evfeventInfo ) ;
484
+ await refreshDiagnosticsFromLocal ( instance , evfeventInfo ) ;
505
485
problemsFetched = true ;
506
486
}
507
487
} )
@@ -561,17 +541,11 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur
561
541
const now = new Date ( ) ;
562
542
const resultsPanel = new CustomUI ( ) ;
563
543
if ( targets . length === 1 ) {
564
- resultsPanel . addParagraph ( `<pre>${ targets [ 0 ] . output . join ( "" ) } </pre>` )
565
- . setOptions ( { fullPage : true ,
566
- css : /* css */ `
567
- pre{
568
- background-color: transparent;
569
- }
570
- `
571
- } ) ;
544
+ resultsPanel . addParagraph ( `<pre><code>${ targets [ 0 ] . output . join ( "" ) } </code></pre>` )
545
+ . setOptions ( { fullPage : true } ) ;
572
546
}
573
547
else {
574
- resultsPanel . addBrowser ( "results" , targets . filter ( target => target . processed ) . map ( target => ( { label : `${ getTargetResultIcon ( target ) } ${ path . basename ( target . uri . path ) } ` , value : `<pre>${ target . output . join ( "" ) } </pre>` } as TreeListItem ) ) )
548
+ resultsPanel . addBrowser ( "results" , targets . filter ( target => target . processed ) . map ( target => ( { label : `${ getTargetResultIcon ( target ) } ${ path . basename ( target . uri . path ) } ` , value : `<pre><code> ${ target . output . join ( "" ) } </code> </pre>` } as TreeListItem ) ) )
575
549
. setOptions ( {
576
550
fullPage : true ,
577
551
css : /* css */ `
@@ -583,7 +557,6 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur
583
557
584
558
pre {
585
559
margin: 1em;
586
- background-color: transparent;
587
560
}
588
561
`
589
562
} ) ;
@@ -604,6 +577,37 @@ export async function runAction(instance: Instance, uris: vscode.Uri | vscode.Ur
604
577
}
605
578
}
606
579
580
+ export type AvailableAction = { label : string ; action : Action ; }
581
+
582
+ export async function getAllAvailableActions ( targets : ActionTarget [ ] , scheme : string ) {
583
+ const allActions = [ ...IBMi . connectionManager . get < Action [ ] > ( `actions` ) || [ ] ] ;
584
+
585
+ // Then, if we're being called from a local file
586
+ // we fetch the Actions defined from the workspace.
587
+ if ( targets [ 0 ] . workspaceFolder && scheme === `file` ) {
588
+ const localActions = await getLocalActions ( targets [ 0 ] . workspaceFolder ) ;
589
+ allActions . push ( ...localActions ) ;
590
+ }
591
+
592
+ // We make sure all extensions are uppercase
593
+ allActions . forEach ( action => {
594
+ if ( action . extensions ) {
595
+ action . extensions = action . extensions . map ( ext => ext . toUpperCase ( ) ) ;
596
+ } ;
597
+ } ) ;
598
+
599
+ // Then we get all the available Actions for the current context
600
+ const availableActions : AvailableAction [ ] = allActions . filter ( action => action . type === scheme )
601
+ . filter ( action => ! action . extensions || action . extensions . every ( e => ! e ) || targets . every ( t => action . extensions ! . includes ( t . extension ) || action . extensions ! . includes ( t . fragment ) ) || action . extensions . includes ( `GLOBAL` ) )
602
+ . filter ( action => action . runOnProtected || ! targets . some ( t => t . protected ) )
603
+ . sort ( ( a , b ) => ( actionUsed . get ( b . name ) || 0 ) - ( actionUsed . get ( a . name ) || 0 ) )
604
+ . map ( action => ( {
605
+ label : action . name ,
606
+ action
607
+ } ) ) ;
608
+
609
+ return availableActions ;
610
+ }
607
611
608
612
function getObjectFromCommand ( baseCommand ?: string ) : CommandObject | undefined {
609
613
if ( baseCommand ) {
0 commit comments