-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: separate sorting logic to expand
- Loading branch information
Showing
6 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
---@class FrecencySorterDefault: FrecencySorter | ||
local Default = {} | ||
|
||
---@return FrecencySorterDefault | ||
Default.new = function() | ||
return setmetatable({}, { __index = Default }) | ||
end | ||
|
||
---@param files FrecencyDatabaseEntry[] | ||
---@return FrecencyDatabaseEntry[] | ||
function Default.sort(_, files) | ||
table.sort(files, function(a, b) | ||
return a.score > b.score or (a.score == b.score and a.path > b.path) | ||
end) | ||
return files | ||
end | ||
|
||
return Default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
local config = require "frecency.config" | ||
local Default = require "frecency.sorter.default" | ||
local Opened = require "frecency.sorter.opened" | ||
local SameRepo = require "frecency.sorter.same_repo" | ||
|
||
---@class FrecencySorter | ||
---@field new fun(): FrecencySorter | ||
---@field sort fun(self: FrecencySorter, files: FrecencyDatabaseEntry[]): FrecencyDatabaseEntry[] | ||
|
||
return config.preceding == "opened" and Opened or config.preceding == "same_repo" and SameRepo or Default |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
local Default = require "frecency.sorter.default" | ||
|
||
---@class FrecencySorterOpened: FrecencySorter | ||
local Opened = setmetatable({}, { __index = Opened }) | ||
|
||
---@return FrecencySorterOpened | ||
Opened.new = function() | ||
return setmetatable({}, { __index = Opened }) | ||
end | ||
|
||
return Opened |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
local Default = require "frecency.sorter.default" | ||
|
||
---@class FrecencySorterSameRepo: FrecencySorterDefault | ||
local SameRepo = setmetatable({}, { __index = Default }) | ||
|
||
---@return FrecencySorterSameRepo | ||
SameRepo.new = function() | ||
return setmetatable({}, { __index = SameRepo }) | ||
end | ||
|
||
return SameRepo |