|
1 | 1 | // TODO: i do not see any completion functionality in this file. nothing is being provided for the defined commands of these package managers. this is a blocker for release. every each of them should be handled. |
2 | 2 | import { Completion } from '../src/index.js'; |
3 | | -import { execSync } from 'child_process'; |
4 | | - |
5 | | -const DEBUG = false; // for debugging purposes |
6 | | - |
7 | | -function debugLog(...args: any[]) { |
8 | | - if (DEBUG) { |
9 | | - console.error('[DEBUG]', ...args); |
10 | | - } |
11 | | -} |
12 | | - |
13 | | -async function checkCliHasCompletions( |
14 | | - cliName: string, |
15 | | - packageManager: string |
16 | | -): Promise<boolean> { |
17 | | - try { |
18 | | - debugLog(`Checking if ${cliName} has completions via ${packageManager}`); |
19 | | - const command = `${packageManager} ${cliName} complete --`; |
20 | | - const result = execSync(command, { |
21 | | - encoding: 'utf8', |
22 | | - stdio: ['pipe', 'pipe', 'ignore'], |
23 | | - timeout: 1000, // AMIR: we still havin issues with this, it still hangs if a cli doesn't have completions. longer timeout needed for shell completion system (shell → node → package manager → cli) |
24 | | - }); |
25 | | - const hasCompletions = !!result.trim(); |
26 | | - debugLog(`${cliName} supports completions: ${hasCompletions}`); |
27 | | - return hasCompletions; |
28 | | - } catch (error) { |
29 | | - debugLog(`Error checking completions for ${cliName}:`, error); |
30 | | - return false; |
31 | | - } |
32 | | -} |
33 | | - |
34 | | -async function getCliCompletions( |
35 | | - cliName: string, |
36 | | - packageManager: string, |
37 | | - args: string[] |
38 | | -): Promise<string[]> { |
39 | | - try { |
40 | | - const completeArgs = args.map((arg) => |
41 | | - arg.includes(' ') ? `"${arg}"` : arg |
42 | | - ); |
43 | | - const completeCommand = `${packageManager} ${cliName} complete -- ${completeArgs.join(' ')}`; |
44 | | - debugLog(`Getting completions with command: ${completeCommand}`); |
45 | | - |
46 | | - const result = execSync(completeCommand, { |
47 | | - encoding: 'utf8', |
48 | | - stdio: ['pipe', 'pipe', 'ignore'], |
49 | | - timeout: 1000, // same: longer timeout needed for shell completion system (shell → node → package manager → cli) |
50 | | - }); |
51 | | - |
52 | | - const completions = result.trim().split('\n').filter(Boolean); |
53 | | - debugLog(`Got ${completions.length} completions from ${cliName}`); |
54 | | - return completions; |
55 | | - } catch (error) { |
56 | | - debugLog(`Error getting completions from ${cliName}:`, error); |
57 | | - return []; |
58 | | - } |
59 | | -} |
60 | 3 |
|
61 | 4 | export function setupCompletionForPackageManager( |
62 | 5 | packageManager: string, |
|
0 commit comments