Skip to content

Commit abc9720

Browse files
authored
Merge pull request #5555 from unisonweb/cp/switch-by-recency
2 parents f605cec + 838b8b8 commit abc9720

File tree

4 files changed

+28
-24
lines changed

4 files changed

+28
-24
lines changed

codebase2/codebase-sqlite/U/Codebase/Sqlite/Queries.hs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ module U.Codebase.Sqlite.Queries
111111
loadProjectByName,
112112
expectProject,
113113
loadAllProjects,
114+
loadAllProjectsByRecentlyAccessed,
114115
loadAllProjectsBeginningWith,
115116
insertProject,
116117
renameProject,
@@ -3602,6 +3603,17 @@ loadAllProjects =
36023603
ORDER BY name ASC
36033604
|]
36043605

3606+
-- | Load all projects.
3607+
loadAllProjectsByRecentlyAccessed :: Transaction [Project]
3608+
loadAllProjectsByRecentlyAccessed =
3609+
queryListRow
3610+
[sql|
3611+
SELECT project.id, project.name
3612+
FROM project
3613+
JOIN project_branch ON project.id = project_branch.project_id
3614+
ORDER BY project_branch.last_accessed DESC NULLS LAST, project.name ASC
3615+
|]
3616+
36053617
-- | Load all projects whose name matches a prefix.
36063618
loadAllProjectsBeginningWith :: Maybe Text -> Transaction [Project]
36073619
loadAllProjectsBeginningWith mayPrefix = do
@@ -3740,7 +3752,7 @@ loadAllProjectBranchNamePairs =
37403752
FROM
37413753
project
37423754
JOIN project_branch ON project.id = project_branch.project_id
3743-
ORDER BY project.name ASC, project_branch.name ASC
3755+
ORDER BY project_branch.last_accessed DESC NULLS LAST, project.name ASC, project_branch.name ASC
37443756
|]
37453757
<&> fmap \(projectName, branchName, projectId, branchId) ->
37463758
( ProjectAndBranch projectName branchName,

unison-cli/src/Unison/CommandLine/FZFResolvers.hs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,25 +164,20 @@ projectNameResolver = FZFResolver {getOptions = projectNameOptions}
164164
-- E.g. '@unison/base'
165165
projectNameOptions :: OptionFetcher
166166
projectNameOptions codebase _projCtx _searchBranch0 = do
167-
fmap (into @Text . SqliteProject.name) <$> Codebase.runTransaction codebase Q.loadAllProjects
167+
fmap (into @Text . SqliteProject.name) <$> Codebase.runTransaction codebase Q.loadAllProjectsByRecentlyAccessed
168168

169169
-- | All possible local project/branch names.
170170
-- E.g. '@unison/base/main'
171171
projectBranchOptions :: OptionFetcher
172172
projectBranchOptions codebase projCtx _searchBranch0 = do
173173
projs <- Codebase.runTransaction codebase Q.loadAllProjectBranchNamePairs
174174
projs
175-
& foldMap
176-
( \(names, projIds) ->
177-
if projIds.project == projCtx.project.projectId
178-
then -- If the branch is in the current project, put a shortened version of the branch name first,
179-
-- then the long-form name at the end of the list (in case the user still types the full name)
180-
[(0 :: Int, "/" <> into @Text names.branch), (2, into @Text names)]
181-
else [(1, into @Text names)]
175+
& filter
176+
( \(_names, projIds) ->
177+
-- If it's the same as the current branch, just omit it.
178+
projIds.branch /= projCtx.branch.branchId
182179
)
183-
-- Put branches in this project first.
184-
& List.sort
185-
& fmap snd
180+
& fmap (into @Text . fst)
186181
& pure
187182

188183
-- | All possible local branch names within the current project.

unison-src/transcripts/idempotent/api-list-projects-branches.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,19 @@ scratch/main> project.create-empty project-banana
1414
1515
scratch/main> project.create-empty project-apple
1616
17-
project-apple/main> branch z-branch-cherry
17+
project-apple/main> branch a-branch-cherry
1818
19-
project-apple/main> branch z-branch-banana
19+
project-apple/main> branch a-branch-banana
2020
21-
project-apple/main> branch z-branch-apple
21+
project-apple/main> branch a-branch-apple
2222
```
2323

2424
``` api
2525
-- Should list all projects
2626
GET /api/projects
2727
[
2828
{
29-
"activeBranchRef": "z-branch-apple",
29+
"activeBranchRef": "a-branch-apple",
3030
"projectName": "project-apple"
3131
},
3232
{
@@ -54,23 +54,23 @@ GET /api/projects?query=bana
5454
GET /api/projects/project-apple/branches
5555
[
5656
{
57-
"branchName": "main"
57+
"branchName": "a-branch-apple"
5858
},
5959
{
60-
"branchName": "z-branch-apple"
60+
"branchName": "a-branch-banana"
6161
},
6262
{
63-
"branchName": "z-branch-banana"
63+
"branchName": "a-branch-cherry"
6464
},
6565
{
66-
"branchName": "z-branch-cherry"
66+
"branchName": "main"
6767
}
6868
]
6969
-- Can query for some infix of the project name
7070
GET /api/projects/project-apple/branches?query=bana
7171
[
7272
{
73-
"branchName": "z-branch-banana"
73+
"branchName": "a-branch-banana"
7474
}
7575
]
7676
```

unison-src/transcripts/idempotent/fuzzy-options.md

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,9 @@ myproject/main> branch mybranch
7171
scratch/main> debug.fuzzy-options switch _
7272
7373
Select a project or branch to switch to:
74-
* /empty
75-
* /main
7674
* myproject/main
7775
* myproject/mybranch
7876
* scratch/empty
79-
* scratch/main
8077
* myproject
8178
* scratch
8279
```

0 commit comments

Comments
 (0)