44 "bufio"
55 "context"
66 "fmt"
7- "log"
87 "os"
98 "os/exec"
109 "strings"
@@ -48,12 +47,8 @@ func (c *customCompleter) Do(line []rune, pos int) ([][]rune, int) {
4847 // Extract the current word being completed
4948 currentWord := string (line [wordStart :pos ])
5049
51- // Debug logging
52- log .Printf ("[DEBUG] Tab completion: line='%s', pos=%d, currentWord='%s', wordStart=%d" , lineStr , pos , currentWord , wordStart )
53-
5450 // Get completions using our existing logic
5551 completions := Completer (lineStr , c .hosts , c .user )
56- log .Printf ("[DEBUG] Got %d raw completions: %v" , len (completions ), completions )
5752
5853 // Filter and process completions
5954 var filtered []string
@@ -64,23 +59,13 @@ func (c *customCompleter) Do(line []rune, pos int) ([][]rune, int) {
6459 }
6560
6661 // For file completions, we need to handle the path properly
67- if strings .Contains (currentWord , "/" ) {
68- // For paths like "/v", we expect completions like "/var", "/vagrant", etc.
69- // readline expects only the suffix that completes the current word
70- if strings .HasPrefix (completion , currentWord ) {
71- // Extract only the part that should be appended
72- // For currentWord="/v" and completion="/var", we want "ar"
73- suffix := completion [len (currentWord ):]
74- filtered = append (filtered , suffix )
75- }
76- } else {
77- // For simple completions (like command names), extract suffix
78- if strings .HasPrefix (completion , currentWord ) {
79- // Extract only the part that should be appended
80- // For currentWord="l" and completion="ls", we want "s"
81- suffix := completion [len (currentWord ):]
82- filtered = append (filtered , suffix )
83- }
62+ // Both path and simple completions use the same suffix extraction logic
63+ if strings .HasPrefix (completion , currentWord ) {
64+ // Extract only the part that should be appended
65+ // For currentWord="/v" and completion="/var", we want "ar"
66+ // For currentWord="l" and completion="ls", we want "s"
67+ suffix := completion [len (currentWord ):]
68+ filtered = append (filtered , suffix )
8469 }
8570 }
8671
@@ -90,7 +75,6 @@ func (c *customCompleter) Do(line []rune, pos int) ([][]rune, int) {
9075 result [i ] = []rune (completion )
9176 }
9277
93- log .Printf ("[DEBUG] Returning %d filtered completions: %v, wordStart=%d" , len (filtered ), filtered , wordStart )
9478 // Return completions and the position where the word starts
9579 return result , wordStart
9680}
@@ -103,7 +87,6 @@ func getSSHCompletions(line string, hosts []string, user string) []string {
10387
10488 // Use the first host for completion
10589 host := hosts [0 ]
106- log .Printf ("[DEBUG] Using host '%s' for completion (first of %d hosts)" , host , len (hosts ))
10790
10891 // Extract the word being completed
10992 words := strings .Fields (line )
@@ -143,8 +126,6 @@ func getSSHCompletions(line string, hosts []string, user string) []string {
143126 }
144127 }
145128
146- log .Printf ("[DEBUG] Parsed path: dir='%s', pattern='%s' from lastWord='%s'" , dir , pattern , lastWord )
147-
148129 // Build the correct completion command
149130 if pattern == "" {
150131 compCommand = fmt .Sprintf ("ls -1a '%s'/ 2>/dev/null | head -20" , dir )
@@ -160,22 +141,16 @@ func getSSHCompletions(line string, hosts []string, user string) []string {
160141
161142 args = append (args , host , compCommand )
162143
163- log .Printf ("[DEBUG] SSH completion command: ssh %v" , args )
164-
165144 // Create context with timeout
166145 ctx , cancel := context .WithTimeout (context .Background (), 2 * time .Second )
167146 defer cancel ()
168147
169148 cmd := exec .CommandContext (ctx , "ssh" , args ... )
170149 output , err := cmd .CombinedOutput ()
171-
172150 if err != nil {
173- log .Printf ("[DEBUG] SSH completion failed: %v" , err )
174151 return []string {}
175152 }
176153
177- // log.Printf("[DEBUG] SSH completion output: %s", string(output))
178-
179154 // Parse the output and return as suggestions
180155 completions := []string {}
181156 lines := strings .Split (strings .TrimSpace (string (output )), "\n " )
0 commit comments