Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor!: use OO & add tests #100

Merged
merged 44 commits into from
Aug 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
4c9a606
chore: add .gitignore
delphinus Jun 10, 2023
2b20fd9
refactor: rewrite the logic wholly
delphinus Jul 26, 2023
4251b21
chore: remove duplicated types in old sources
delphinus Jul 26, 2023
1cd8d2b
chore: make the new logic work as `frecency2`
delphinus Jul 26, 2023
03d0bc6
test: make it testable and add simple tests
delphinus Jul 26, 2023
3ac1988
test: make tests work on CI
delphinus Jul 26, 2023
00d8bff
feat: use dynamic finder not to block Neovim
delphinus Jul 26, 2023
81f8853
test: add type checking in CI
delphinus Jul 28, 2023
bf08574
chore: fix types
delphinus Jul 28, 2023
5b3e0a5
refactor: change type for logging module
delphinus Jul 28, 2023
a15766e
refactor!: remove old logic
delphinus Jul 28, 2023
c4316e7
refactor: clean up class definitions
delphinus Jul 29, 2023
1ef1d64
fix: use opts for picker for updated finder
delphinus Jul 29, 2023
3507921
chore: fix types
delphinus Jul 29, 2023
ee36a3d
test: disable tests on macOS because of SIP
delphinus Jul 29, 2023
a9647a1
test: add tests for picker
delphinus Jul 29, 2023
399de85
chore: use nil-guard to call iterators
delphinus Jul 29, 2023
92b87d7
test: avoid tests for picker in v0.9.0
delphinus Jul 29, 2023
9fd9168
refactor: use logging plenary.log instead of mine
delphinus Jul 29, 2023
759a349
fix: record count = 1 at the first time
delphinus Jul 29, 2023
6b60dcf
test: add tests for frecency:register()
delphinus Jul 29, 2023
d8e2058
test: add benchmarking tests
delphinus Jul 29, 2023
ad25eb1
feat: use faster logic to fetch results
delphinus Jul 29, 2023
7c9b737
chore: add more logging
delphinus Jul 30, 2023
4264839
fix: update workspace with user input
delphinus Jul 30, 2023
1855a3a
fix: treat workspace as a directory
delphinus Jul 30, 2023
166606f
feat: validate and treat `auto_validate` option
delphinus Jul 30, 2023
0b753ed
test: add tests for validate_database()
delphinus Jul 30, 2023
e753e66
feat: export Frecency instance
delphinus Jul 31, 2023
d213d30
feat: deal with disable_devicons option
delphinus Jul 31, 2023
7ee7ad3
chore: fix typo
delphinus Jul 31, 2023
dd98fd4
feat: add healthcheck
delphinus Jul 31, 2023
9cd46cf
test: add tests for ignore_patterns
delphinus Aug 2, 2023
93130ed
chore: do not need the default value
delphinus Aug 2, 2023
d888275
fix: reset workspace and reload with the default
delphinus Aug 3, 2023
0542914
fix: detect should_show_tail() validly
delphinus Aug 3, 2023
c107e22
refactor: fix types
delphinus Aug 3, 2023
6084b95
feat: introduce AsyncFinder
delphinus Aug 6, 2023
bd1c1c9
test: fix tests
delphinus Aug 6, 2023
b8aaaef
fix: remove duplications from DB and workspace
delphinus Aug 6, 2023
0cd00ff
Merge branch 'master' into feature/oo
delphinus Aug 6, 2023
53c4f63
refactor: fix types & rename funcs
delphinus Aug 6, 2023
9d29eff
chore: remoe unneeded nil_wrap
delphinus Aug 6, 2023
284f764
refactor: simplify logic
delphinus Aug 6, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: CI
on:
- push
- pull_request
jobs:
test:
name: Run tests
strategy:
matrix:
os:
- ubuntu-latest
# TODO: nix seems not to work with SIP
# - macos-latest
# TODO: PlenaryBustedDirectory seems not to run on Windows
# - windows-latest
version:
- v0.9.0
- nightly
runs-on: ${{ matrix.os }}
timeout-minutes: 15
steps:
- uses: actions/checkout@v3
- name: Checkout plenary.nvim
uses: actions/checkout@v3
with:
repository: nvim-lua/plenary.nvim
path: plenary.nvim
- name: Checkout telescope.nvim
uses: actions/checkout@v3
with:
repository: nvim-telescope/telescope.nvim
path: telescope.nvim
- name: Checkout sqlite.lua
uses: actions/checkout@v3
with:
repository: kkharji/sqlite.lua
path: sqlite.lua
- name: Install Neovim
uses: rhysd/action-setup-vim@v1
id: nvim
with:
neovim: true
version: ${{ matrix.version }}
- name: Run tests
env:
PLENARY_PATH: plenary.nvim
TELESCOPE_PATH: telescope.nvim
SQLITE_PATH: sqlite.lua
DEBUG_PLENARY: 1
EXE: ${{ steps.nvim.outputs.executable }}
run: |-
TEST_DIR=lua/frecency/tests/
MINIMAL_LUA=${TEST_DIR}minimal.lua
NVIM=$(perl -e '$_ = $ENV{EXE}; s,\\,/,g; print')
$NVIM --headless --clean -u $MINIMAL_LUA -c "PlenaryBustedDirectory $TEST_DIR {minimal_init = '$MINIMAL_LUA'}"
- name: Type Check Code Base
uses: mrcjkb/lua-typecheck-action@v0.2.0
with:
checkLevel: Hint
configpath: .luarc.json
76 changes: 76 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
### Generated by gibo (https://github.com/simonwhitaker/gibo)
### https://raw.github.com/github/gitignore/4488915eec0b3a45b5c63ead28f286819c0917de/Lua.gitignore

# Compiled Lua sources
luac.out

# luarocks build files
*.src.rock
*.zip
*.tar.gz

# Object files
*.o
*.os
*.ko
*.obj
*.elf

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo
*.def
*.exp

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex



### https://raw.github.com/github/gitignore/4488915eec0b3a45b5c63ead28f286819c0917de/Global/macOS.gitignore

# General
.DS_Store
.AppleDouble
.LSOverride

# Icon must end with two \r
Icon

# Thumbnails
._*

# Files that might appear in the root of a volume
.DocumentRevisions-V100
.fseventsd
.Spotlight-V100
.TemporaryItems
.Trashes
.VolumeIcon.icns
.com.apple.timemachine.donotpresent

# Directories potentially created on remote AFP share
.AppleDB
.AppleDesktop
Network Trash Folder
Temporary Items
.apdisk


Expand Down
14 changes: 14 additions & 0 deletions .luarc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"diagnostics": {
"globals": [
"describe",
"it",
"vim"
]
},
"runtime.version": "LuaJIT",
"runtime.path": [
"lua/?.lua",
"lua/?/init.lua"
]
}
21 changes: 0 additions & 21 deletions lua/frecency/algo.lua

This file was deleted.

98 changes: 98 additions & 0 deletions lua/frecency/async_finder.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
local async = require "plenary.async"

---@class FrecencyAsyncFinder
---@field closed boolean
---@field entries FrecencyEntry[]
---@field rx FrecencyRx
---@overload fun(_: string, process_result: (fun(entry: FrecencyEntry): nil), process_complete: fun(): nil): nil
local AsyncFinder = {}

---@class FrecencyRx
---@field recv fun(): FrecencyEntry?

---@class FrecencyTx
---@field send fun(entry: FrecencyEntry?): nil

---@param fs FrecencyFS
---@param path string
---@param entry_maker fun(file: FrecencyFile): FrecencyEntry
---@param initial_results FrecencyFile[]
---@return FrecencyAsyncFinder
AsyncFinder.new = function(fs, path, entry_maker, initial_results)
local self = setmetatable({ closed = false, entries = {} }, {
__index = AsyncFinder,
---@param self FrecencyAsyncFinder
__call = function(self, ...)
return self:find(...)
end,
})
local seen = {}
for i, file in ipairs(initial_results) do
local entry = entry_maker(file)
seen[entry.filename] = true
entry.index = i
table.insert(self.entries, entry)
end
---@type FrecencyTx, FrecencyRx
local tx, rx = async.control.channel.mpsc()
self.rx = rx
async.run(function()
local index = #initial_results
local count = 0
for name in fs:scan_dir(path) do
if self.closed then
break
end
local fullpath = vim.fs.joinpath(path, name)
if not seen[fullpath] then
seen[fullpath] = true
index = index + 1
count = count + 1
local entry = entry_maker { id = 0, count = 0, path = vim.fs.joinpath(path, name), score = 0 }
if entry then
entry.index = index
table.insert(self.entries, entry)
tx.send(entry)
if count % 1000 == 0 then
-- NOTE: This is needed not to lock text input.
async.util.sleep(0)
end
end
end
end
self:close()
tx.send(nil)
end)
return self
end

---@param _ string
---@param process_result fun(entry: FrecencyEntry): nil
---@param process_complete fun(): nil
---@return nil
function AsyncFinder:find(_, process_result, process_complete)
for _, entry in ipairs(self.entries) do
if process_result(entry) then
return
end
end
local last_index = self.entries[#self.entries].index
while true do
if self.closed then
break
end
local entry = self.rx.recv()
if not entry then
break
elseif entry.index > last_index and process_result(entry) then
return
end
end
process_complete()
end

function AsyncFinder:close()
self.closed = true
end

return AsyncFinder
18 changes: 0 additions & 18 deletions lua/frecency/const.lua

This file was deleted.

Loading