-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor of public plugin's api (#37)
* refactor: move all plugin functionality to init.lua * fix(commands): now it uses correct module paths * refactor(config): change way how it handles options * refactor(gotests): use correct config, change way how deps required, fix some typos * fix(healthchecker): use correct config * refactor(iferr): change api * refactor(impl): change api * refactor(installer): change api * refactor(struct_tags): change way of importting deps * refactor(struct_tags): rename M to struct_tags * run stylua * refactor(dap): make it all in one file, and make some refactoring * refactor(_utils): change way how it organizes * fix: use new _utils api * refactor(_utils.health): reorganize module * refactor(_utils.ts): some renameing, moving requires lines * run stylua
- Loading branch information
Showing
18 changed files
with
359 additions
and
341 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,26 @@ | ||
return { | ||
---@param lib string | ||
---@return boolean | ||
lualib_is_found = function(lib) | ||
local is_found, _ = pcall(require, lib) | ||
return is_found | ||
end, | ||
local h = vim.health or require "health" | ||
local health = {} | ||
|
||
---@param bin string | ||
---@return boolean | ||
binary_is_found = function(bin) | ||
if vim.fn.executable(bin) == 1 then | ||
return true | ||
end | ||
return false | ||
end, | ||
} | ||
health.start = h.start or h.report_start | ||
health.ok = h.ok or h.report_ok | ||
health.warn = h.warn or h.report_warn | ||
health.error = h.error or h.report_error | ||
health.info = h.info or h.report_info | ||
|
||
---@param module string | ||
---@return boolean | ||
function health.is_lualib_found(module) | ||
local is_found, _ = pcall(require, module) | ||
return is_found | ||
end | ||
|
||
---@param bin string | ||
---@return boolean | ||
function health.is_binary_found(bin) | ||
if vim.fn.executable(bin) == 1 then | ||
return true | ||
end | ||
return false | ||
end | ||
|
||
return health |
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,48 +1,39 @@ | ||
---@diagnostic disable: param-type-mismatch | ||
return { | ||
---@param t table | ||
---@return boolean | ||
empty = function(t) | ||
if t == nil then | ||
return true | ||
end | ||
local utils = {} | ||
|
||
return next(t) == nil | ||
end, | ||
---@param t table | ||
---@return boolean | ||
function utils.is_tbl_empty(t) | ||
if t == nil then | ||
return true | ||
end | ||
return next(t) == nil | ||
end | ||
|
||
---@param s string | ||
---@return string | ||
rtrim = function(s) | ||
local n = #s | ||
while n > 0 and s:find("^%s", n) do | ||
n = n - 1 | ||
end | ||
---@param s string | ||
---@return string | ||
function utils.rtrim(s) | ||
local n = #s | ||
while n > 0 and s:find("^%s", n) do | ||
n = n - 1 | ||
end | ||
|
||
return s:sub(1, n) | ||
end, | ||
return s:sub(1, n) | ||
end | ||
|
||
---@param msg string | ||
---@param lvl string|integer | ||
notify = function(msg, lvl) | ||
local l | ||
if lvl == "error" or lvl == 4 then | ||
l = vim.log.levels.ERROR | ||
elseif lvl == "info" or lvl == 2 then | ||
l = vim.log.levels.INFO | ||
elseif lvl == "debug" or lvl == 1 then | ||
l = vim.log.levels.DEBUG | ||
end | ||
---@param msg string | ||
---@param lvl any | ||
function utils.deferred_notify(msg, lvl) | ||
vim.defer_fn(function() | ||
vim.notify(msg, lvl) | ||
end, 0) | ||
end | ||
|
||
vim.defer_fn(function() | ||
vim.notify(msg, l) | ||
end, 0) | ||
end, | ||
-- safe require | ||
---@param module string module name | ||
function utils.sreq(module) | ||
local ok, m = pcall(require, module) | ||
assert(ok, string.format("gopher.nvim dependency error: %s not installed", module)) | ||
return m | ||
end | ||
|
||
---safe require | ||
---@param name string module name | ||
sreq = function(name) | ||
local ok, m = pcall(require, name) | ||
assert(ok, string.format("gopher.nvim dependency error: %s not installed", name)) | ||
return m | ||
end, | ||
} | ||
return utils |
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 was deleted.
Oops, something went wrong.
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,33 +1,27 @@ | ||
---@class Config | ||
---@field commands ConfigCommands | ||
---@class gopher.Config | ||
local config = {} | ||
|
||
---@class ConfigCommands | ||
---@field go string | ||
---@field gomodifytags string | ||
---@field gotests string | ||
---@field impl string | ||
---@field iferr string | ||
---@field dlv string | ||
|
||
local M = { | ||
---@type Config | ||
config = { | ||
---set custom commands for tools | ||
commands = { | ||
go = "go", | ||
gomodifytags = "gomodifytags", | ||
gotests = "gotests", | ||
impl = "impl", | ||
iferr = "iferr", | ||
dlv = "dlv", | ||
}, | ||
---@class gopher.Config | ||
---@field commands gopher.ConfigCommands | ||
local default_config = { | ||
---@class gopher.ConfigCommands | ||
commands = { | ||
go = "go", | ||
gomodifytags = "gomodifytags", | ||
gotests = "gotests", | ||
impl = "impl", | ||
iferr = "iferr", | ||
dlv = "dlv", | ||
}, | ||
} | ||
|
||
---Plugin setup function | ||
---@param opts Config user config | ||
function M.setup(opts) | ||
M.config = vim.tbl_deep_extend("force", M.config, opts or {}) | ||
---@param user_config gopher.Config|nil | ||
function config.setup(user_config) | ||
config = vim.tbl_deep_extend("force", {}, default_config, user_config or {}) | ||
end | ||
|
||
return M | ||
-- setup ifself, needs for ability to get | ||
-- default config without calling .setup() | ||
config.setup() | ||
|
||
return config |
Oops, something went wrong.