Skip to content

Commit

Permalink
Use single editor
Browse files Browse the repository at this point in the history
  • Loading branch information
CKolkey committed Dec 17, 2023
1 parent d68fbac commit ac76a43
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 60 deletions.
40 changes: 24 additions & 16 deletions lua/neogit/buffers/editor/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 7,10 @@ local pad = util.pad_right

local M = {}

local filetypes = {
["COMMIT_EDITMSG"] = "NeogitCommitMessage",
["MERGE_MSG"] = "NeogitMergeMessage",
["TAG_EDITMSG"] = "NeogitTagMessage",
["EDIT_DESCRIPTION"] = "NeogitBranchDescription",
}

local kind = {
["COMMIT_EDITMSG"] = config.values.commit_editor.kind,
["MERGE_MSG"] = config.values.merge_editor.kind,
["TAG_EDITMSG"] = config.values.tag_editor.kind,
["EDIT_DESCRIPTION"] = config.values.description_editor.kind,
}

---@class EditorBuffer
---@field filename string filename of buffer
---@field kind string Type of buffer to open, eg. tab, replace, split, vsplit
---@field filetype string neogit filetype for editor
---@field on_unload function callback invoked when buffer is unloaded
---@field buffer Buffer
---@see Buffer
Expand All @@ -32,7 20,27 @@ local kind = {
---@param on_unload function the event dispatched on buffer unload
---@return EditorBuffer
function M.new(filename, on_unload)
local kind, filetype
if filename:find("COMMIT_EDITMSG$") then
kind = config.values.commit_editor.kind
filetype = "NeogitCommitMessage"
elseif filename:find("MERGE_MSG$") then
kind = config.values.merge_editor.kind
filetype = "NeogitMergeMessage"
elseif filename:find("TAG_EDITMSG$") then
kind = config.values.tag_editor.kind
filetype = "NeogitTagMessage"
elseif filename:find("EDIT_DESCRIPTION$") then
kind = config.values.description_editor.kind
filetype = "NeogitBranchDescription"
end

assert(kind, "Editor kind must be specified")
assert(filetype, "Editor filetype must be specified")

local instance = {
kind = kind,
filetype = filetype,
filename = filename,
on_unload = on_unload,
buffer = nil,
Expand All @@ -49,10 57,10 @@ function M:open()

self.buffer = Buffer.create {
name = self.filename,
filetype = filetypes[self.filename],
filetype = self.filetype,
load = true,
buftype = "",
kind = kind[self.filename],
kind = self.kind,
modifiable = true,
readonly = false,
after = function(buffer)
Expand Down
34 changes: 19 additions & 15 deletions lua/neogit/client.lua
Original file line number Diff line number Diff line change
@@ -1,4 1,6 @@
local RPC = require("neogit.lib.rpc")
local logger = require("neogit.logger")

local fn = vim.fn
local fmt = string.format

Expand Down Expand Up @@ -57,14 59,17 @@ function M.client()
end

--- Invoked by the `client` and starts the appropriate file editor
---@param target string Filename to open
---@param client string Address returned from vim.fn.serverstart()
function M.editor(target, client)
logger.debug("[CLIENT] Here")
require("neogit.process").hide_preview_buffers()

local editor = require("neogit.editor")

local rpc_client = RPC.create_connection(client)

---on_unload callback when closing editor
---@param status integer Status code to close remote nvim instance with. 0 for success, 1 for failure
local function send_client_quit(status)
status = status or 0
if status == 0 then
rpc_client:send_cmd_async("qall")
elseif status == 1 then
Expand All @@ -75,19 80,18 @@ function M.editor(target, client)
end

if target:find("git%-rebase%-todo$") then
editor.rebase_editor(target, send_client_quit)
elseif target:find("COMMIT_EDITMSG$") then
editor.commit_editor(target, send_client_quit)
elseif target:find("MERGE_MSG$") then
editor.merge_editor(target, send_client_quit)
elseif target:find("TAG_EDITMSG$") then
editor.tag_editor(target, send_client_quit)
elseif target:find("EDIT_DESCRIPTION$") then
editor.description_editor(target, send_client_quit)
require("neogit.buffers.rebase_editor").new(target, send_client_quit):open()
elseif
target:find("COMMIT_EDITMSG$")
or target:find("MERGE_MSG$")
or target:find("TAG_EDITMSG$")
or target:find("TAG_EDITMSG$")
or target:find("EDIT_DESCRIPTION$")
then
require("neogit.buffers.editor").new(target, send_client_quit):open()
else
local notification = require("neogit.lib.notification")
notification.warn(target .. " has not been implemented yet")
send_client_quit()
require("neogit.lib.notification").warn(target .. " has not been implemented yet")
send_client_quit(1)
end
end

Expand Down
29 changes: 0 additions & 29 deletions lua/neogit/editor.lua

This file was deleted.

0 comments on commit ac76a43

Please sign in to comment.