@@ -255,8 +255,9 @@ func completePath(ctx context.Context, client *github.Client, resolved map[strin
255255 return nil , nil
256256 }
257257
258- // Collect immediate children of the prefix (both files and directories)
259- children := map [string ]struct {}{}
258+ // Collect immediate children of the prefix (files and directories, no duplicates)
259+ dirs := map [string ]struct {}{}
260+ files := map [string ]struct {}{}
260261 prefixLen := len (prefix )
261262 for _ , entry := range tree .Entries {
262263 if ! strings .HasPrefix (entry .GetPath (), prefix ) {
@@ -266,31 +267,56 @@ func completePath(ctx context.Context, client *github.Client, resolved map[strin
266267 if rel == "" {
267268 continue
268269 }
269- // Only immediate children (no deeper paths)
270+ // Only immediate children
270271 slashIdx := strings .Index (rel , "/" )
271272 if slashIdx >= 0 {
272- // Directory: only add the directory name (with trailing slash)
273- rel = rel [:slashIdx + 1 ]
273+ // Directory: only add the directory name (with trailing slash), prefixed with full path
274+ dirName := prefix + rel [:slashIdx + 1 ]
275+ dirs [dirName ] = struct {}{}
276+ } else if entry .GetType () == "blob" {
277+ // File: add as-is, prefixed with full path
278+ fileName := prefix + rel
279+ files [fileName ] = struct {}{}
280+ }
281+ }
282+
283+ // Optionally filter by argValue (if user is typing after last slash)
284+ var filter string
285+ if argValue != "" {
286+ if lastSlash := strings .LastIndex (argValue , "/" ); lastSlash >= 0 {
287+ filter = argValue [lastSlash + 1 :]
274288 } else {
275- // File: leave as-is
289+ filter = argValue
276290 }
277- // Optionally filter by argValue (if user is typing after last slash)
278- if argValue != "" {
279- afterSlash := argValue
280- if lastSlash := strings .LastIndex (argValue , "/" ); lastSlash >= 0 {
281- afterSlash = argValue [lastSlash + 1 :]
291+ }
292+
293+ var values []string
294+ // Add directories first, then files, both filtered
295+ for dir := range dirs {
296+ // Only filter on the last segment after the last slash
297+ if filter == "" {
298+ values = append (values , dir )
299+ } else {
300+ last := dir
301+ if idx := strings .LastIndex (strings .TrimRight (dir , "/" ), "/" ); idx >= 0 {
302+ last = dir [idx + 1 :]
282303 }
283- if afterSlash != "" && ! strings .HasPrefix (rel , afterSlash ) {
284- continue
304+ if strings .HasPrefix (last , filter ) {
305+ values = append ( values , dir )
285306 }
286307 }
287- children [rel ] = struct {}{}
288308 }
289-
290- var values []string
291- for name := range children {
292- if name != "" {
293- values = append (values , name )
309+ for file := range files {
310+ if filter == "" {
311+ values = append (values , file )
312+ } else {
313+ last := file
314+ if idx := strings .LastIndex (file , "/" ); idx >= 0 {
315+ last = file [idx + 1 :]
316+ }
317+ if strings .HasPrefix (last , filter ) {
318+ values = append (values , file )
319+ }
294320 }
295321 }
296322
0 commit comments