-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add history menu & cache, gradle support, luacheck
- Loading branch information
Showing
19 changed files
with
742 additions
and
66 deletions.
There are no files selected for viewing
File renamed without changes.
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 @@ | ||
--- | ||
name: luacheck | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
jobs: | ||
luacheck: | ||
name: luacheck | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: checkout | ||
uses: actions/checkout@v4 | ||
- name: lint | ||
uses: lunarmodules/luacheck@v1 |
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,8 @@ | ||
std = "min+busted" | ||
globals = { | ||
"vim", | ||
"T_Type", | ||
"_Toggle_term", | ||
"A", | ||
} | ||
|
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,4 @@ | ||
{ | ||
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json", | ||
"Lua.workspace.checkThirdParty": false | ||
} |
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,151 @@ | ||
local M = {} | ||
|
||
---@class CommandHistoryItem | ||
---@field command? string | ||
---@field component? string | ||
---@field type? string | ||
|
||
local config = require("java_test_util.config") | ||
local util = require("java_test_util.util") | ||
|
||
---@type CommandHistoryItem[]|nil | ||
M.cmd_history = {} | ||
|
||
|
||
local max_size = config.max_history_size or 10 | ||
local CACHE_PATH = "/java-test-util/" | ||
local CACHE_SUFFIX = "_history.lua" | ||
|
||
---@param command string | ||
---@param component string | ||
---@return boolean | ||
function M.check_for_duplicate(command, component, type) | ||
for _, item in ipairs(M.cmd_history) do | ||
if item.command == command and item.component == component and item.type == type then | ||
return true | ||
end | ||
end | ||
return false | ||
end | ||
|
||
---@return string|nil | ||
local function get_cache_path() | ||
local project_root | ||
|
||
if util.root_dir then | ||
project_root = util.root_dir | ||
else | ||
project_root = util.get_project_root() | ||
end | ||
|
||
if project_root then | ||
local cache_path = vim.fn.stdpath("cache") .. CACHE_PATH .. vim.fn.fnamemodify(project_root, ":t") .. CACHE_SUFFIX | ||
return cache_path | ||
end | ||
vim.notify("no project root found!", vim.log.levels.ERROR) | ||
return nil | ||
end | ||
|
||
function M.load_cached_history() | ||
local cache_path = get_cache_path() | ||
|
||
if not cache_path then | ||
vim.notify("no cache found", vim.log.levels.WARN) | ||
return nil | ||
end | ||
|
||
if cache_path and vim.fn.filereadable(cache_path) == 1 then | ||
local chunk = loadfile(cache_path) | ||
if chunk then | ||
local loaded_history = chunk() | ||
if type(loaded_history) == "table" then | ||
M.cmd_history = loaded_history | ||
end | ||
end | ||
end | ||
end | ||
|
||
function M.write_history_to_cache() | ||
local cache_path = get_cache_path() | ||
if not cache_path then | ||
vim.notify("no cache_path") | ||
return | ||
end | ||
|
||
if cache_path then | ||
vim.fn.mkdir(vim.fn.fnamemodify(cache_path, ":h"), "p") | ||
local serialized_history = "return " .. vim.inspect(M.cmd_history) | ||
vim.fn.writefile(vim.split(serialized_history, "\n"), cache_path) | ||
end | ||
end | ||
|
||
function M.remove_cache_file() | ||
local cache_path = get_cache_path() | ||
if cache_path and vim.fn.filereadable(cache_path) == 1 then | ||
vim.fn.delete(cache_path) | ||
M.cmd_history = {} | ||
vim.notify("history file removed from: " .. cache_path) | ||
else | ||
vim.notify("no history file found for the current project", vim.log.levels.WARN) | ||
end | ||
end | ||
|
||
---@param command string | ||
---@param component string | ||
---@param type string | ||
function M.save_to_history(command, component, type) | ||
if M.check_for_duplicate(command, component, type) then | ||
return | ||
end | ||
|
||
if #M.cmd_history >= max_size then | ||
table.remove(M.cmd_history, 1) | ||
end | ||
|
||
table.insert(M.cmd_history, { command = command, component = component, type = type }) | ||
M.write_history_to_cache() | ||
end | ||
|
||
---@param component string | ||
function M.remove_from_history(component) | ||
for i, item in ipairs(M.cmd_history) do | ||
if item.component == component then | ||
table.remove(M.cmd_history, i) | ||
M.write_history_to_cache() | ||
break | ||
end | ||
end | ||
end | ||
|
||
---@return table<string> | ||
function M.get_all_descriptions() | ||
local descriptions = {} | ||
for _, item in ipairs(M.cmd_history) do | ||
table.insert(descriptions, item.component) | ||
end | ||
return descriptions | ||
end | ||
|
||
---@param component string | ||
---@return string|nil | ||
function M.get_command_by_component(component) | ||
for _, item in ipairs(M.cmd_history) do | ||
if item.component == component then | ||
return item.command | ||
end | ||
end | ||
return nil | ||
end | ||
|
||
---@param component string | ||
---@return string | ||
function M.get_type_by_component(component) | ||
for _, item in ipairs(M.cmd_history) do | ||
if item.component == component then | ||
return item.type | ||
end | ||
end | ||
return "" | ||
end | ||
|
||
return M |
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 |
---|---|---|
@@ -1,19 +1,35 @@ | ||
local default_config = require("java_test_util.config") | ||
local core = require("java_test_util.core") | ||
local term = require("java_test_util.terminal") | ||
local menu = require("java_test_util.menu") | ||
local util = require("java_test_util.util") | ||
local history = require("java_test_util.history") | ||
|
||
local M = {} | ||
|
||
function M.setup(opts) | ||
---@type Config | ||
M.config = vim.tbl_deep_extend("force", default_config, opts or {}) | ||
core.config = M.config | ||
term.config = M.config | ||
history.config = M.config | ||
menu.config = M.config | ||
util.config = M.config | ||
|
||
util.root_dir = util.get_project_root() | ||
|
||
if util.root_dir then | ||
util.build_tool = util.detect_build_tool() | ||
history.load_cached_history() | ||
end | ||
end | ||
|
||
M.run_mvn_test_for_current_method = core.run_mvn_test_for_current_method | ||
M.run_mvn_test_for_current_class = core.run_mvn_test_for_current_class | ||
M.run_mvn_test_for_current_package = core.run_mvn_test_for_current_package | ||
M.run_mvn_previous_test = core.run_mvn_previous_test | ||
M.run_mvn_test_for_all = core.run_mvn_test_for_all | ||
M.create_history_menu = menu.create_history_menu | ||
M.detect_build_tool = util.detect_build_tool | ||
|
||
return M |
Oops, something went wrong.