Update Impl
This commit is contained in:
parent
76c950b01a
commit
b566782f4a
17
README.md
17
README.md
@ -146,6 +146,23 @@ goimport)
|
||||
| Gofmt | goline + gofumpt |
|
||||
| Goimport | goline + goimport + gofumpt |
|
||||
|
||||
## GoImpl
|
||||
|
||||
generate method stubs for implementing an interface
|
||||
|
||||
Usage:
|
||||
|
||||
|
||||
```
|
||||
:GoImpl {receiver} {interface}
|
||||
```
|
||||
|
||||
e.g:
|
||||
|
||||
```
|
||||
:GoImpl f *File io.Reader
|
||||
```
|
||||
|
||||
## Debug
|
||||
|
||||
| command | Description |
|
||||
|
@ -61,7 +61,7 @@ function go.setup(cfg)
|
||||
|
||||
vim.cmd([[command! -nargs=* GoAddTag lua require("go.tags").add(<f-args>)]])
|
||||
vim.cmd([[command! -nargs=* GoRmTag lua require("go.tags").rm(<f-args>)]])
|
||||
-- vim.cmd([[command! -nargs=* GoImpl lua require("go.impl").run(<f-args>)]])
|
||||
vim.cmd([[command! -nargs=* GoImpl lua require("go.impl").run(<f-args>)]])
|
||||
vim.cmd([[command! GoClearTag lua require("go.tags").clear()]])
|
||||
vim.cmd([[command! GoCmt lua require("go.comment").gen()]])
|
||||
vim.cmd([[command! GoRename lua require("go.rename").run()]])
|
||||
|
@ -17,7 +17,6 @@ local run = function(...)
|
||||
return
|
||||
end
|
||||
|
||||
require('go.utils').log(data)
|
||||
local pos = vim.fn.getcurpos()[2]
|
||||
vim.fn.append(pos, data)
|
||||
|
||||
|
37
lua/go/impl.lua
Normal file
37
lua/go/impl.lua
Normal file
@ -0,0 +1,37 @@
|
||||
-- local ts_utils = require 'nvim-treesitter.ts_utils'
|
||||
local utils = require("go.utils")
|
||||
|
||||
local impl = "impl"
|
||||
-- GoImpl f *Foo io.Writer
|
||||
local run = function(...)
|
||||
require("go.install").install(impl)
|
||||
local setup = "impl"
|
||||
|
||||
local arg = {...}
|
||||
if #arg < 3 then
|
||||
print("Usage: GoImpl f *File io.Reader")
|
||||
end
|
||||
|
||||
local rec1 = select(1, ...)
|
||||
local rec2 = select(2, ...)
|
||||
local interface = select(3, ...)
|
||||
|
||||
setup = setup .. " '" .. rec1 .. " " .. rec2 .. "' " .. interface
|
||||
local data = vim.fn.systemlist(setup, vim.fn.bufnr('%'))
|
||||
|
||||
data = utils.handle_job_data(data)
|
||||
if not data then
|
||||
return
|
||||
end
|
||||
|
||||
utils.log(data)
|
||||
local pos = vim.fn.getcurpos()[2]
|
||||
vim.fn.append(pos, data)
|
||||
|
||||
vim.cmd('silent normal! j=2j')
|
||||
vim.fn.setpos('.', pos)
|
||||
vim.cmd('silent normal! 4j')
|
||||
--
|
||||
|
||||
end
|
||||
return {run = run}
|
@ -1,28 +1,29 @@
|
||||
local uv = vim.loop
|
||||
local DIR_SEP = package.config:sub(1,1)
|
||||
local DIR_SEP = package.config:sub(1, 1)
|
||||
|
||||
local url = {
|
||||
gofumpt = "mvdan.cc/gofumpt",
|
||||
gofumports = "mvdan.cc/gofumpt",
|
||||
golines = "github.com/segmentio/golines",
|
||||
gofumpt = "mvdan.cc/gofumpt",
|
||||
gofumports = "mvdan.cc/gofumpt",
|
||||
golines = "github.com/segmentio/golines",
|
||||
gomodifytags = "github.com/fatih/gomodifytags",
|
||||
gotsts = "github.com/cweill/gotests",
|
||||
iferr = 'github.com/koron/iferr',
|
||||
fillstruct = 'github.com/davidrjenni/reftools/cmd/fillstruct',
|
||||
fixplurals = 'github.com/davidrjenni/reftools/cmd/fixplurals',
|
||||
fillswitch = 'github.com/davidrjenni/reftools/cmd/fillswitch',
|
||||
gotsts = "github.com/cweill/gotests",
|
||||
iferr = 'github.com/koron/iferr',
|
||||
impl = 'github.com/josharian/impl',
|
||||
fillstruct = 'github.com/davidrjenni/reftools/cmd/fillstruct',
|
||||
fixplurals = 'github.com/davidrjenni/reftools/cmd/fixplurals',
|
||||
fillswitch = 'github.com/davidrjenni/reftools/cmd/fillswitch'
|
||||
}
|
||||
|
||||
local function is_installed(bin)
|
||||
local env_path = os.getenv("PATH")
|
||||
local base_paths = vim.split(env_path, ":", true)
|
||||
local env_path = os.getenv("PATH")
|
||||
local base_paths = vim.split(env_path, ":", true)
|
||||
|
||||
for key, value in pairs(base_paths) do
|
||||
if uv.fs_stat(value .. DIR_SEP .. bin) then
|
||||
return true
|
||||
end
|
||||
for key, value in pairs(base_paths) do
|
||||
if uv.fs_stat(value .. DIR_SEP .. bin) then
|
||||
return true
|
||||
end
|
||||
return false
|
||||
end
|
||||
return false
|
||||
end
|
||||
|
||||
local function go_install(pkg)
|
||||
@ -35,14 +36,11 @@ local function go_install(pkg)
|
||||
u = u .. "@latest"
|
||||
local setup = {"go", "install", u}
|
||||
|
||||
vim.fn.jobstart(
|
||||
setup,
|
||||
{
|
||||
on_stdout = function(c, data, name)
|
||||
print(data)
|
||||
end
|
||||
}
|
||||
)
|
||||
vim.fn.jobstart(setup, {
|
||||
on_stdout = function(c, data, name)
|
||||
print(data)
|
||||
end
|
||||
})
|
||||
end
|
||||
|
||||
local function install(bin)
|
||||
@ -53,7 +51,7 @@ local function install(bin)
|
||||
end
|
||||
|
||||
local function update(bin)
|
||||
go_install(bin)
|
||||
go_install(bin)
|
||||
end
|
||||
|
||||
local function install_all()
|
||||
|
Loading…
Reference in New Issue
Block a user