summaryrefslogtreecommitdiff
path: root/config/essentials/vis/vis-go.lua
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-08-15 18:53:47 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-08-15 18:53:47 +0200
commit4073294204effdf65e1182d1769120a5fcd9d348 (patch)
treea1a961e382a74a032dfe48ace0cb53bd89234a29 /config/essentials/vis/vis-go.lua
parent93bdfbb5d7b16a44cb23e6ee2bffd3eef368f8fc (diff)
checkpoint
Diffstat (limited to 'config/essentials/vis/vis-go.lua')
-rw-r--r--config/essentials/vis/vis-go.lua104
1 files changed, 0 insertions, 104 deletions
diff --git a/config/essentials/vis/vis-go.lua b/config/essentials/vis/vis-go.lua
deleted file mode 100644
index c4788cc..0000000
--- a/config/essentials/vis/vis-go.lua
+++ /dev/null
@@ -1,104 +0,0 @@
---[[
-Based on https://gitlab.com/timoha/vis-go
-Changes made:
-- stylua format
-- check if line, col in godef()
-- no formatting because already handled by format.lua
-- removed the goimports option
-- set env variable for godef that fixes "no definition found"
-- removed syntax checks
-- gorename is a keybind
---]]
-
-local function jump_to(path, line, col)
- if path then
- vis:command(string.format("e %s", path))
- end
- vis.win.selection:to(line, col)
-end
-
-local Gostack = { s = {}, i = 1 }
-
-function Gostack:push(v)
- self.s[self.i] = v
- self.i = self.i + 1
-end
-
-function Gostack:pop()
- if self.i == 1 then
- return nil
- end
- self.i = self.i - 1
- return self.s[self.i]
-end
-
-local function godef()
- local win = vis.win
-
- local file = win.file
- local pos = win.selection.pos
- local cmd = string.format("GO111MODULE=off godef -i -o %d", pos)
- local status, out, err = vis:pipe(file, { start = 0, finish = file.size }, cmd)
- if status ~= 0 or not out then
- if err then
- vis:info(err)
- end
- return status
- end
-
- Gostack:push({ path = file.path, line = win.selection.line, col = win.selection.col })
-
- local path, line, col = string.match(out, "([^:]+):([^:]+):([^:]+)")
- if not path then
- -- same file
- line, col = string.match(out, "([^:]+):([^:]+)")
- end
- if line and col then
- jump_to(path, line, col)
- end
-end
-
-local function godef_back()
- local pos = Gostack:pop()
- if pos then
- jump_to(pos.path, pos.line, pos.col)
- end
-end
-
-local function gorename(argv, force, win, selection)
- local name = argv[1]
- if not name then
- vis:info("empty new name provided")
- return false
- end
-
- local forceFlag = ""
- if force then
- forceFlag = "-force"
- end
-
- local pos = selection.pos
- local f =
- io.popen(string.format("gorename -offset %s:#%d -to %s %s 2>&1", win.file.path, pos, name, forceFlag), "r")
- local out = f:read("*all")
- local success, _, _ = f:close()
- if not success then
- vis:message(out)
- return false
- end
-
- -- refresh current file
- vis:command("e")
- win.selection.pos = pos
-
- vis:info(out)
- return true
-end
-
-vis:map(vis.modes.NORMAL, "gd", godef, "Jump to Go symbol/definition")
-vis:map(vis.modes.NORMAL, "gD", godef_back, "Jump back to previous Go symbol/definition")
-vis:command_register(
- "gorename",
- gorename,
- "Perform precise type-safe renaming of identifiers in Go source code: :gorename newName"
-)