Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit998724d

Browse files
chore: sort agent/list-directory output (#17218)
This sorts the `contents` list alphabetically, but with directories before everything else.This is purely for UX on the Coder Desktop side, where the user only really cares about directories, and files are just for providing context in the file picker.
1 parent5979c32 commit998724d

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

‎agent/ls.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"path/filepath"
88
"regexp"
99
"runtime"
10+
"slices"
1011
"strings"
1112

1213
"github.com/shirou/gopsutil/v4/disk"
@@ -103,6 +104,17 @@ func listFiles(query LSRequest) (LSResponse, error) {
103104
})
104105
}
105106

107+
// Sort alphabetically: directories then files
108+
slices.SortFunc(respContents,func(a,bLSFile)int {
109+
ifa.IsDir&&!b.IsDir {
110+
return-1
111+
}
112+
if!a.IsDir&&b.IsDir {
113+
return1
114+
}
115+
returnstrings.Compare(a.Name,b.Name)
116+
})
117+
106118
absolutePath:=pathToArray(absolutePathString)
107119

108120
returnLSResponse{

‎agent/ls_internal_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,16 @@ func TestListFilesSuccess(t *testing.T) {
137137
require.NoError(t,err)
138138

139139
require.Equal(t,tmpDir,resp.AbsolutePathString)
140-
require.ElementsMatch(t, []LSFile{
140+
// Output is sorted
141+
require.Equal(t, []LSFile{
141142
{
142-
Name:"repos",
143-
AbsolutePathString:reposDir,
143+
Name:"Downloads",
144+
AbsolutePathString:downloadsDir,
144145
IsDir:true,
145146
},
146147
{
147-
Name:"Downloads",
148-
AbsolutePathString:downloadsDir,
148+
Name:"repos",
149+
AbsolutePathString:reposDir,
149150
IsDir:true,
150151
},
151152
{

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp