-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.lua
More file actions
73 lines (64 loc) · 1.99 KB
/
Copy pathinit.lua
File metadata and controls
73 lines (64 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
local M = {}
local defaultConfig = {
httpCommand = "Http",
graphqlCommand = "Gql",
envFile = function()
return string.format("%s/%s", vim.env.PWD, "gqlenv.yml")
end,
}
M.setup = function(cfg)
cfg = vim.tbl_deep_extend("force", defaultConfig, cfg or {})
local currDir = debug.getinfo(1).source:match("@?(.*/)")
local pRootDir = currDir .. "../.."
-- local vimBufOptions = "vne | setlocal buftype=nofile | setlocal bufhidden=hide | setlocal noswapfile | set ft=json "
-- local cliExec = string.format("cd %s && go run ./main.go ", pRootDir)
local cliExec = string.format("%s/bin/http", pRootDir)
function execute(subCommand)
local win = vim.api.nvim_get_current_win()
local buf = vim.api.nvim_create_buf(true, true)
vim.api.nvim_buf_set_var(buf, "has_stderr", false)
vim.fn.jobstart({
cliExec,
subCommand,
"--file",
vim.fn.expand("%:p"),
"--envFile",
cfg.envFile(),
"--lineNo",
vim.fn.line("."),
}, {
stdout_buffered = true,
on_stdout = function(_, data)
if data then
vim.api.nvim_buf_set_lines(buf, -2, -1, false, data)
end
end,
on_stderr = function(_, data)
if data then
if #data == 1 and data[1] == "" then
return
end
if not vim.api.nvim_buf_get_var(buf, "has_stderr") then
vim.api.nvim_buf_set_var(buf, "has_stderr", true)
vim.api.nvim_buf_set_lines(buf, -1, -1, false, { "", "", "STDERR:", "" })
end
vim.api.nvim_buf_set_lines(buf, -1, -1, false, data)
end
end,
on_exit = function(status)
vim.api.nvim_set_current_win(win)
vim.cmd("80vne | setlocal buftype=nofile | setlocal bufhidden=hide | setlocal noswapfile")
vim.cmd("buffer " .. buf)
vim.cmd("set ft=markdown")
vim.cmd("norm! G")
end,
})
end
vim.api.nvim_create_user_command(cfg.graphqlCommand, function()
execute("graphql")
end, { desc = "runs http-cli for graphql" })
vim.api.nvim_create_user_command(cfg.httpCommand, function()
execute("rest")
end, { desc = "runs http-cli for rest-api" })
end
return M