Skip to content

Commit

Permalink
[FEATURE] favorite restore on load
Browse files Browse the repository at this point in the history
  • Loading branch information
vladevelops committed Nov 18, 2024
1 parent 26946d4 commit f692c18
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 12 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,4 @@ For more information, run the command:
**Author:** Developland (Vladyslav Topyekha)
**License:** MIT
**Description:** Easy to use golang run tests solution.

8 changes: 6 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@
- [x] run test in the list window
- [x] jump to test under the cursor
- [x] delete test in normal mode
- [ ] add new tests on top
- [ ] run tests by numbers
- [ ] close test buffer key
- [ ] BUG the project work dir with same name like backend are overlaping
- [ ] tests with similat names at beginig are all triggered
- [ ] show buffer with all the available test in current folder
- [ ] show all tests in whole project
- [ ] restore favorite
- [x] restore favorite
- [x] jump to first test in buffer even if not added
- [ ] highlight tests already in list
- [ ] run tests by numbers
- [ ] on favorite toggle with multiple tests jump to correct line
- [ ] add test file location, and search test location in that file
- [ ] add line to the floating buffer with fields to explain
Expand Down
34 changes: 25 additions & 9 deletions lua/gtestler/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ vim.api.nvim_create_autocmd({ "BufEnter" }, {
vim.api.nvim_create_autocmd("VimEnter", {

callback = function()
local retore_tabel = gtestler_utils.load_commands_table()
local retsore_tabel = gtestler_utils.load_commands_table()

if retore_tabel ~= nil then
tests_commands = retore_tabel
if retsore_tabel ~= nil then
tests_commands = retsore_tabel
if tests_commands[wd].current_favorite_test ~= nil then
current_favorite_test = tests_commands[wd].current_favorite_test
end
end
end,

Expand Down Expand Up @@ -182,6 +185,7 @@ function M.jump_to_next_test()
print("No test found")
end
end

function M.jump_to_previous_test()
local row, _ = unpack(vim.api.nvim_win_get_cursor(0))

Expand Down Expand Up @@ -223,12 +227,14 @@ function M.open_tests_list()
local count = 1
if tests_commands[wd] ~= nil then
for label, _ in pairs(tests_commands[wd]) do
if label == current_favorite_test then
table.insert(tests_list, count, "* " .. label)
else
table.insert(tests_list, count, label)
if label ~= "current_favorite_test" then
if label == current_favorite_test then
table.insert(tests_list, count, "* " .. label)
else
table.insert(tests_list, count, label)
end
count = count + 1
end
count = count + 1
end
end

Expand Down Expand Up @@ -301,6 +307,7 @@ function M.add_test()
end

local file_path = vim.fn.expand("%:p")
-- Create the new entry
tests_commands[wd][test_name] = {
command_name = new_cmd,
file_name = "",
Expand All @@ -317,17 +324,26 @@ end
function M.toggle_favorite()
local command_alias = gtestler_utils.get_command_alias()
if command_alias ~= "" then
print("command_alias:", command_alias)
command_alias = command_alias:gsub("^%s+", ""):gsub("%s+$", "")
current_favorite_test = command_alias
print(current_favorite_test)
vim.cmd("bd!")
M.open_tests_list()

if string.sub(current_favorite_test, 1, string.len("*")) == "*" then
tests_commands[wd]["current_favorite_test"] = nil
else
tests_commands[wd]["current_favorite_test"] = current_favorite_test
end
gtestler_utils.save_json_to_file(tests_commands)
end
end

--- @return string
function M.add_favorite_test()
current_favorite_test = M.add_test()

tests_commands[wd].current_favorite_test = current_favorite_test
return current_favorite_test
end

Expand Down
2 changes: 1 addition & 1 deletion lua/gtestler/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ function M.get_working_directory()
table.insert(t, str)
end

return t[#t]
return t[#t - 1] .. "/" .. t[#t]
end

function M.remove_star_if_exists(str)
Expand Down

0 comments on commit f692c18

Please sign in to comment.