Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ To view these help docs and to get more detailed help information, please run `:

## Requirements

- <a href="https://neovim.io/">Neovim</a> >= v0.10
- <a href="https://go.dev/">Go</a> >= v1.25.1

## Quick Start
Expand Down
78 changes: 34 additions & 44 deletions lua/gitlab/server.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
-- This module contains the logic responsible for building and starting
-- the Golang server. The Go server is responsible for making API calls
-- to Gitlab and returning the data
local List = require("gitlab.utils.list")
local state = require("gitlab.state")
local u = require("gitlab.utils")
local job = require("gitlab.job")
Expand Down Expand Up @@ -62,58 +61,49 @@ M.start = function(callback)
state.chosen_mr_iid = 0 -- Do not let this interfere with subsequent reviewer.open() calls

local settings = vim.json.encode(go_server_settings)
if vim.fn.has("win32") then
settings = settings:gsub('"', '\\"')
end

local command = string.format('"%s" "%s"', state.settings.server.binary, settings)

local job_id = vim.fn.jobstart(command, {
on_stdout = function(_, data)
-- if port was not provided then we need to parse it from output of server
if parsed_port == nil then
for _, line in ipairs(data) do
port = line:match("Server started on port:%s+(%d+)")
if port ~= nil then
parsed_port = port
state.settings.server.port = port
break
end
end
local ok, err = pcall(vim.system, { state.settings.server.binary, settings }, {
stdout = function(_, data)
if data == nil or parsed_port ~= nil then
return
end

-- This assumes that first output of server will be parsable and port will be correctly set.
-- Make sure that this actually check if port was correctly parsed based on server output
-- because server outputs port only if it started successfully.
if parsed_port ~= nil and not callback_called then
state.go_server_running = true
callback()
callback_called = true
for line in data:gmatch("[^\r\n]+") do
local matched = line:match("Server started on port:%s+(%d+)")
if matched ~= nil then
parsed_port = matched
vim.schedule(function()
state.settings.server.port = matched
state.go_server_running = true
if not callback_called then
callback_called = true
callback()
end
end)
break
end
end
end,
on_stderr = function(_, errors)
local err_msg = List.new(errors):reduce(function(agg, err)
if err ~= "" and err ~= nil then
agg = agg .. err .. "\n"
end
return agg
end, "")

if err_msg ~= "" then
u.notify(err_msg, vim.log.levels.ERROR)
stderr = function(_, data)
if data == nil or data == "" then
return
end
vim.schedule(function()
u.notify(data, vim.log.levels.ERROR)
end)
end,
on_exit = function(job_id, exit_code)
if exit_code ~= 0 then
}, function(out)
if out.code ~= 0 then
vim.schedule(function()
u.notify(
"Golang gitlab server exited: job_id: " .. job_id .. ", exit_code: " .. exit_code,
"Golang gitlab server exited: code: " .. out.code .. ", signal: " .. (out.signal or 0),
vim.log.levels.ERROR
)
end
end,
})
if job_id <= 0 then
u.notify("Could not start gitlab.nvim binary", vim.log.levels.ERROR)
end)
end
end)

if not ok then
u.notify("Could not start gitlab.nvim binary: " .. tostring(err), vim.log.levels.ERROR)
end
end

Expand Down
Loading