@@ -6,6 +6,14 @@ import { RootCommand } from '../src/t.js';
66
77const noop = ( ) => { } ;
88
9+ const isTabDebug = Boolean ( process . env . TAB_DEBUG ) ;
10+
11+ function tabDebugLog ( ...args : unknown [ ] ) {
12+ if ( isTabDebug ) {
13+ console . error ( '[TAB_DEBUG]' , ...args ) ;
14+ }
15+ }
16+
917function debugLog ( ...args : unknown [ ] ) {
1018 if ( process . env . DEBUG ) {
1119 console . error ( '[DEBUG]' , ...args ) ;
@@ -23,12 +31,21 @@ function runCompletionCommand(
2331 leadingArgs : string [ ] ,
2432 completionArgs : string [ ]
2533) : string {
34+ const args = [ ...leadingArgs , 'complete' , '--' , ...completionArgs ] ;
35+ tabDebugLog ( 'spawn completion:' , command , args ) ;
36+
2637 const result = spawnSync (
2738 command ,
28- [ ... leadingArgs , 'complete' , '--' , ... completionArgs ] ,
39+ args ,
2940 completionSpawnOptions
3041 ) ;
3142
43+ tabDebugLog ( 'spawn result:' , {
44+ status : result . status ,
45+ error : result . error ?. message ,
46+ stdout : result . stdout ,
47+ } ) ;
48+
3249 if ( result . error ) {
3350 throw result . error ;
3451 }
@@ -50,13 +67,18 @@ async function checkCliHasCompletions(
5067 const result = runCompletionCommand ( cliName , [ ] , [ ] ) ;
5168 if ( result ) return true ;
5269 } catch {
70+ tabDebugLog ( 'checkCliHasCompletions direct call failed for' , cliName ) ;
5371 noop ( ) ;
5472 }
5573
5674 try {
5775 const result = runCompletionCommand ( packageManager , [ cliName ] , [ ] ) ;
5876 return ! ! result ;
5977 } catch {
78+ tabDebugLog (
79+ 'checkCliHasCompletions package-manager call failed for' ,
80+ cliName
81+ ) ;
6082 return false ;
6183 }
6284}
@@ -72,13 +94,19 @@ async function getCliCompletions(
7294 return result . split ( '\n' ) . filter ( Boolean ) ;
7395 }
7496 } catch {
97+ tabDebugLog ( 'getCliCompletions direct call failed for' , cliName , args ) ;
7598 noop ( ) ;
7699 }
77100
78101 try {
79102 const result = runCompletionCommand ( packageManager , [ cliName ] , args ) ;
80103 return result . split ( '\n' ) . filter ( Boolean ) ;
81104 } catch {
105+ tabDebugLog (
106+ 'getCliCompletions package-manager call failed for' ,
107+ cliName ,
108+ args
109+ ) ;
82110 return [ ] ;
83111 }
84112}
0 commit comments