From 250d4de718d096f092938dbcdd2e4d1a829a4c19 Mon Sep 17 00:00:00 2001 From: Smirnov Olexander Date: Wed, 22 Jun 2022 14:42:14 +0300 Subject: [PATCH] refactor: add comments & update type anotation --- lua/gopher/_utils/ts/init.lua | 10 +++++++--- lua/gopher/gogenerate.lua | 1 + lua/gopher/goget.lua | 1 + lua/gopher/gomod.lua | 1 + lua/gopher/gotests.lua | 2 ++ lua/gopher/impl.lua | 4 +--- lua/gopher/installer.lua | 1 + 7 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lua/gopher/_utils/ts/init.lua b/lua/gopher/_utils/ts/init.lua index 91455c1..8de819e 100644 --- a/lua/gopher/_utils/ts/init.lua +++ b/lua/gopher/_utils/ts/init.lua @@ -18,9 +18,9 @@ local function get_name_defaults() } end ----@param row any ----@param col any ----@param bufnr any +---@param row string +---@param col string +---@param bufnr string ---@return table|nil function M.get_struct_node_at_pos(row, col, bufnr) local query = M.querys.struct_block .. " " .. M.querys.em_struct_block @@ -33,6 +33,10 @@ function M.get_struct_node_at_pos(row, col, bufnr) end end +---@param row string +---@param col string +---@param bufnr string +---@return table|nil function M.get_func_method_node_at_pos(row, col, bufnr) local query = M.querys.func .. " " .. M.querys.method_name local bufn = bufnr or vim.api.nvim_get_current_buf() diff --git a/lua/gopher/gogenerate.lua b/lua/gopher/gogenerate.lua index 78d6e45..1820e5f 100644 --- a/lua/gopher/gogenerate.lua +++ b/lua/gopher/gogenerate.lua @@ -1,5 +1,6 @@ local Job = require "plenary.job" +---run "go generate" return function(...) local args = { ... } if #args == 1 and args[1] == "%" then diff --git a/lua/gopher/goget.lua b/lua/gopher/goget.lua index 5807e2f..2bbb73a 100644 --- a/lua/gopher/goget.lua +++ b/lua/gopher/goget.lua @@ -1,5 +1,6 @@ local Job = require "plenary.job" +---run "go get" return function(...) local args = { ... } for i, arg in ipairs(args) do diff --git a/lua/gopher/gomod.lua b/lua/gopher/gomod.lua index 8106b0c..8bd6703 100644 --- a/lua/gopher/gomod.lua +++ b/lua/gopher/gomod.lua @@ -1,5 +1,6 @@ local Job = require "plenary.job" +---run "go mod" return function(...) local args = { ... } local cmd_args = vim.list_extend({ "mod" }, args) diff --git a/lua/gopher/gotests.lua b/lua/gopher/gotests.lua index 9366fa7..49fa80c 100644 --- a/lua/gopher/gotests.lua +++ b/lua/gopher/gotests.lua @@ -45,6 +45,8 @@ function M.func_test(parallel) add_test(cmd_args) end +---generate unit tests for all functions in current file +---@param parallel boolean function M.all_tests(parallel) local cmd_args = { "-all" } if parallel then diff --git a/lua/gopher/impl.lua b/lua/gopher/impl.lua index b19c84a..1ea1bef 100644 --- a/lua/gopher/impl.lua +++ b/lua/gopher/impl.lua @@ -1,6 +1,7 @@ local Job = require "plenary.job" local ts_utils = require "gopher._utils.ts" +---@return string local function get_struct() local ns = ts_utils.get_struct_node_at_pos(unpack(vim.api.nvim_win_get_cursor(0))) if ns == nil then @@ -68,7 +69,4 @@ return function(...) local pos = vim.fn.getcurpos()[2] table.insert(res_data, 1, "") vim.fn.append(pos, res_data) - - -- table.insert(res_data, 1, "") - -- vim.fn.append(vim.fn.getcurpos()[2], res_data) end diff --git a/lua/gopher/installer.lua b/lua/gopher/installer.lua index 4b84eb5..28d0dec 100644 --- a/lua/gopher/installer.lua +++ b/lua/gopher/installer.lua @@ -5,6 +5,7 @@ local urls = { gotests = "github.com/cweill/gotests", } +---@param pkg string local function install(pkg) local url = urls[pkg] .. "@latest"