diff options
author | Jesse Duffield <jessedduffield@gmail.com> | 2023-07-24 13:06:42 +1000 |
---|---|---|
committer | Jesse Duffield <jessedduffield@gmail.com> | 2023-07-30 18:51:23 +1000 |
commit | e33fe37a99d4b3866970b1b2f40169d1bc9afa2e (patch) | |
tree | 0027f612fb72b2603044d04389da0236df28d864 /pkg/gui/controllers/helpers | |
parent | ea54cb6e9c07ebca4a53e691fcb3cf993c793a50 (diff) |
Standardise on using lo for slice functions
We've been sometimes using lo and sometimes using my slices package, and we need to pick one
for consistency. Lo is more extensive and better maintained so we're going with that.
My slices package was a superset of go's own slices package so in some places I've just used
the official one (the methods were just wrappers anyway).
I've also moved the remaining methods into the utils package.
Diffstat (limited to 'pkg/gui/controllers/helpers')
-rw-r--r-- | pkg/gui/controllers/helpers/merge_and_rebase_helper.go | 4 | ||||
-rw-r--r-- | pkg/gui/controllers/helpers/mode_helper.go | 6 | ||||
-rw-r--r-- | pkg/gui/controllers/helpers/refresh_helper.go | 4 | ||||
-rw-r--r-- | pkg/gui/controllers/helpers/refs_helper.go | 4 | ||||
-rw-r--r-- | pkg/gui/controllers/helpers/repos_helper.go | 4 | ||||
-rw-r--r-- | pkg/gui/controllers/helpers/suggestions_helper.go | 16 | ||||
-rw-r--r-- | pkg/gui/controllers/helpers/upstream_helper_test.go | 4 |
7 files changed, 21 insertions, 21 deletions
diff --git a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go index 0e83ccf25..e9140e102 100644 --- a/pkg/gui/controllers/helpers/merge_and_rebase_helper.go +++ b/pkg/gui/controllers/helpers/merge_and_rebase_helper.go @@ -4,11 +4,11 @@ import ( "fmt" "strings" - "github.com/jesseduffield/generics/slices" "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/types/enums" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" + "github.com/samber/lo" ) type MergeAndRebaseHelper struct { @@ -51,7 +51,7 @@ func (self *MergeAndRebaseHelper) CreateRebaseOptionsMenu() error { }) } - menuItems := slices.Map(options, func(row optionAndKey) *types.MenuItem { + menuItems := lo.Map(options, func(row optionAndKey, _ int) *types.MenuItem { return &types.MenuItem{ Label: row.option, OnPress: func() error { diff --git a/pkg/gui/controllers/helpers/mode_helper.go b/pkg/gui/controllers/helpers/mode_helper.go index e58fe6cb9..f5f3c738c 100644 --- a/pkg/gui/controllers/helpers/mode_helper.go +++ b/pkg/gui/controllers/helpers/mode_helper.go @@ -4,11 +4,11 @@ import ( "fmt" "strings" - "github.com/jesseduffield/generics/slices" "github.com/jesseduffield/lazygit/pkg/commands/types/enums" "github.com/jesseduffield/lazygit/pkg/gui/presentation" "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" + "github.com/samber/lo" ) type ModeHelper struct { @@ -135,13 +135,13 @@ func (self *ModeHelper) withResetButton(content string, textStyle style.TextStyl } func (self *ModeHelper) GetActiveMode() (ModeStatus, bool) { - return slices.Find(self.Statuses(), func(mode ModeStatus) bool { + return lo.Find(self.Statuses(), func(mode ModeStatus) bool { return mode.IsActive() }) } func (self *ModeHelper) IsAnyModeActive() bool { - return slices.Some(self.Statuses(), func(mode ModeStatus) bool { + return lo.SomeBy(self.Statuses(), func(mode ModeStatus) bool { return mode.IsActive() }) } diff --git a/pkg/gui/controllers/helpers/refresh_helper.go b/pkg/gui/controllers/helpers/refresh_helper.go index 5682bbb1f..182e20d85 100644 --- a/pkg/gui/controllers/helpers/refresh_helper.go +++ b/pkg/gui/controllers/helpers/refresh_helper.go @@ -7,7 +7,6 @@ import ( "time" "github.com/jesseduffield/generics/set" - "github.com/jesseduffield/generics/slices" "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" @@ -18,6 +17,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/gui/presentation" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" + "github.com/samber/lo" ) type RefreshHelper struct { @@ -211,7 +211,7 @@ func getScopeNames(scopes []types.RefreshableView) []string { types.MERGE_CONFLICTS: "mergeConflicts", } - return slices.Map(scopes, func(scope types.RefreshableView) string { + return lo.Map(scopes, func(scope types.RefreshableView, _ int) string { return scopeNameMap[scope] }) } diff --git a/pkg/gui/controllers/helpers/refs_helper.go b/pkg/gui/controllers/helpers/refs_helper.go index 3c96add84..765b01cd5 100644 --- a/pkg/gui/controllers/helpers/refs_helper.go +++ b/pkg/gui/controllers/helpers/refs_helper.go @@ -4,13 +4,13 @@ import ( "fmt" "strings" - "github.com/jesseduffield/generics/slices" "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/git_commands" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" + "github.com/samber/lo" ) type IRefsHelper interface { @@ -132,7 +132,7 @@ func (self *RefsHelper) CreateGitResetMenu(ref string) error { {strength: "hard", label: "Hard reset", key: 'h'}, } - menuItems := slices.Map(strengths, func(row strengthWithKey) *types.MenuItem { + menuItems := lo.Map(strengths, func(row strengthWithKey, _ int) *types.MenuItem { return &types.MenuItem{ LabelColumns: []string{ row.label, diff --git a/pkg/gui/controllers/helpers/repos_helper.go b/pkg/gui/controllers/helpers/repos_helper.go index 939d7eb05..d4bd46f40 100644 --- a/pkg/gui/controllers/helpers/repos_helper.go +++ b/pkg/gui/controllers/helpers/repos_helper.go @@ -7,7 +7,6 @@ import ( "strings" "sync" - "github.com/jesseduffield/generics/slices" "github.com/jesseduffield/gocui" appTypes "github.com/jesseduffield/lazygit/pkg/app/types" "github.com/jesseduffield/lazygit/pkg/commands" @@ -18,6 +17,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/gui/style" "github.com/jesseduffield/lazygit/pkg/gui/types" "github.com/jesseduffield/lazygit/pkg/utils" + "github.com/samber/lo" ) type onNewRepoFn func(startArgs appTypes.StartArgs, contextKey types.ContextKey) error @@ -115,7 +115,7 @@ func (self *ReposHelper) CreateRecentReposMenu() error { wg.Wait() - menuItems := slices.Map(recentRepoPaths, func(path string) *types.MenuItem { + menuItems := lo.Map(recentRepoPaths, func(path string, _ int) *types.MenuItem { branchName, _ := currentBranches.Load(path) if icons.IsIconEnabled() { branchName = icons.BRANCH_ICON + " " + fmt.Sprintf("%v", branchName) diff --git a/pkg/gui/controllers/helpers/suggestions_helper.go b/pkg/gui/controllers/helpers/suggestions_helper.go index 65ddf70aa..2ae9d2158 100644 --- a/pkg/gui/controllers/helpers/suggestions_helper.go +++ b/pkg/gui/controllers/helpers/suggestions_helper.go @@ -4,7 +4,6 @@ import ( "fmt" "os" - "github.com/jesseduffield/generics/slices" "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazygit/pkg/commands/models" "github.com/jesseduffield/lazygit/pkg/gui/presentation" @@ -12,6 +11,7 @@ import ( "github.com/jesseduffield/lazygit/pkg/utils" "github.com/jesseduffield/minimal/gitignore" "github.com/samber/lo" + "golang.org/x/exp/slices" "gopkg.in/ozeidan/fuzzy-patricia.v3/patricia" ) @@ -48,13 +48,13 @@ func NewSuggestionsHelper( } func (self *SuggestionsHelper) getRemoteNames() []string { - return slices.Map(self.c.Model().Remotes, func(remote *models.Remote) string { + return lo.Map(self.c.Model().Remotes, func(remote *models.Remote, _ int) string { return remote.Name }) } func matchesToSuggestions(matches []string) []*types.Suggestion { - return slices.Map(matches, func(match string) *types.Suggestion { + return lo.Map(matches, func(match string, _ int) *types.Suggestion { return &types.Suggestion{ Value: match, Label: match, @@ -69,7 +69,7 @@ func (self *SuggestionsHelper) GetRemoteSuggestionsFunc() func(string) []*types. } func (self *SuggestionsHelper) getBranchNames() []string { - return slices.Map(self.c.Model().Branches, func(branch *models.Branch) string { + return lo.Map(self.c.Model().Branches, func(branch *models.Branch, _ int) string { return branch.Name }) } @@ -85,7 +85,7 @@ func (self *SuggestionsHelper) GetBranchNameSuggestionsFunc() func(string) []*ty matchingBranchNames = utils.FuzzySearch(input, branchNames) } - return slices.Map(matchingBranchNames, func(branchName string) *types.Suggestion { + return lo.Map(matchingBranchNames, func(branchName string, _ int) *types.Suggestion { return &types.Suggestion{ Value: branchName, Label: presentation.GetBranchTextStyle(branchName).Sprint(branchName), @@ -141,8 +141,8 @@ func (self *SuggestionsHelper) GetFilePathSuggestionsFunc() func(string) []*type } func (self *SuggestionsHelper) getRemoteBranchNames(separator string) []string { - return slices.FlatMap(self.c.Model().Remotes, func(remote *models.Remote) []string { - return slices.Map(remote.Branches, func(branch *models.RemoteBranch) string { + return lo.FlatMap(self.c.Model().Remotes, func(remote *models.Remote, _ int) []string { + return lo.Map(remote.Branches, func(branch *models.RemoteBranch, _ int) string { return fmt.Sprintf("%s%s%s", remote.Name, separator, branch.Name) }) }) @@ -153,7 +153,7 @@ func (self *SuggestionsHelper) GetRemoteBranchesSuggestionsFunc(separator string } func (self *SuggestionsHelper) getTagNames() []string { - return slices.Map(self.c.Model().Tags, func(tag *models.Tag) string { + return lo.Map(self.c.Model().Tags, func(tag *models.Tag, _ int) string { return tag.Name }) } diff --git a/pkg/gui/controllers/helpers/upstream_helper_test.go b/pkg/gui/controllers/helpers/upstream_helper_test.go index ac7a6a8bf..9742ef944 100644 --- a/pkg/gui/controllers/helpers/upstream_helper_test.go +++ b/pkg/gui/controllers/helpers/upstream_helper_test.go @@ -3,8 +3,8 @@ package helpers import ( "testing" - "github.com/jesseduffield/generics/slices" "github.com/jesseduffield/lazygit/pkg/commands/models" + "github.com/samber/lo" "github.com/stretchr/testify/assert" ) @@ -25,7 +25,7 @@ func TestGetSuggestedRemote(t *testing.T) { } func mkRemoteList(names ...string) []*models.Remote { - return slices.Map(names, func(name string) *models.Remote { + return lo.Map(names, func(name string, _ int) *models.Remote { return &models.Remote{Name: name} }) } |