feat: qol oss improvements
This commit is contained in:
parent
0b9a914f7e
commit
52bc53e4b5
7 changed files with 151 additions and 44 deletions
|
|
@ -1,21 +1,6 @@
|
|||
local M = {}
|
||||
|
||||
local debug_enabled = false
|
||||
|
||||
---@param enabled boolean
|
||||
function M.set_debug(enabled)
|
||||
debug_enabled = enabled
|
||||
end
|
||||
|
||||
---@param msg string
|
||||
---@param ... any
|
||||
local function dbg(msg, ...)
|
||||
if not debug_enabled then
|
||||
return
|
||||
end
|
||||
local formatted = string.format(msg, ...)
|
||||
vim.notify('[fugitive-ts] ' .. formatted, vim.log.levels.DEBUG)
|
||||
end
|
||||
local dbg = require('fugitive-ts.log').dbg
|
||||
|
||||
---@param bufnr integer
|
||||
---@param ns integer
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@
|
|||
local M = {}
|
||||
|
||||
local highlight = require('fugitive-ts.highlight')
|
||||
local log = require('fugitive-ts.log')
|
||||
local parser = require('fugitive-ts.parser')
|
||||
|
||||
local ns = vim.api.nvim_create_namespace('fugitive_ts')
|
||||
|
|
@ -104,15 +105,7 @@ function M.is_fugitive_buffer(bufnr)
|
|||
return vim.api.nvim_buf_get_name(bufnr):match('^fugitive://') ~= nil
|
||||
end
|
||||
|
||||
---@param msg string
|
||||
---@param ... any
|
||||
local function dbg(msg, ...)
|
||||
if not config.debug then
|
||||
return
|
||||
end
|
||||
local formatted = string.format(msg, ...)
|
||||
vim.notify('[fugitive-ts] ' .. formatted, vim.log.levels.DEBUG)
|
||||
end
|
||||
local dbg = log.dbg
|
||||
|
||||
---@param bufnr integer
|
||||
local function highlight_buffer(bufnr)
|
||||
|
|
@ -338,9 +331,18 @@ function M.setup(opts)
|
|||
})
|
||||
end
|
||||
|
||||
if opts.debounce_ms and opts.debounce_ms < 0 then
|
||||
error('fugitive-ts: debounce_ms must be >= 0')
|
||||
end
|
||||
if opts.treesitter and opts.treesitter.max_lines and opts.treesitter.max_lines < 1 then
|
||||
error('fugitive-ts: treesitter.max_lines must be >= 1')
|
||||
end
|
||||
if opts.vim and opts.vim.max_lines and opts.vim.max_lines < 1 then
|
||||
error('fugitive-ts: vim.max_lines must be >= 1')
|
||||
end
|
||||
|
||||
config = vim.tbl_deep_extend('force', default_config, opts)
|
||||
parser.set_debug(config.debug)
|
||||
highlight.set_debug(config.debug)
|
||||
log.set_enabled(config.debug)
|
||||
|
||||
compute_highlight_groups()
|
||||
|
||||
|
|
|
|||
19
lua/fugitive-ts/log.lua
Normal file
19
lua/fugitive-ts/log.lua
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
local M = {}
|
||||
|
||||
local enabled = false
|
||||
|
||||
---@param val boolean
|
||||
function M.set_enabled(val)
|
||||
enabled = val
|
||||
end
|
||||
|
||||
---@param msg string
|
||||
---@param ... any
|
||||
function M.dbg(msg, ...)
|
||||
if not enabled then
|
||||
return
|
||||
end
|
||||
vim.notify('[fugitive-ts] ' .. string.format(msg, ...), vim.log.levels.DEBUG)
|
||||
end
|
||||
|
||||
return M
|
||||
|
|
@ -9,22 +9,7 @@
|
|||
|
||||
local M = {}
|
||||
|
||||
local debug_enabled = false
|
||||
|
||||
---@param enabled boolean
|
||||
function M.set_debug(enabled)
|
||||
debug_enabled = enabled
|
||||
end
|
||||
|
||||
---@param msg string
|
||||
---@param ... any
|
||||
local function dbg(msg, ...)
|
||||
if not debug_enabled then
|
||||
return
|
||||
end
|
||||
local formatted = string.format(msg, ...)
|
||||
vim.notify('[fugitive-ts] ' .. formatted, vim.log.levels.DEBUG)
|
||||
end
|
||||
local dbg = require('fugitive-ts.log').dbg
|
||||
|
||||
---@param filename string
|
||||
---@return string?
|
||||
|
|
@ -116,7 +101,13 @@ function M.parse_buffer(bufnr)
|
|||
local prefix = line:sub(1, 1)
|
||||
if prefix == ' ' or prefix == '+' or prefix == '-' then
|
||||
table.insert(hunk_lines, line)
|
||||
elseif line == '' or line:match('^[MADRC%?!]%s+') or line:match('^%a') then
|
||||
elseif
|
||||
line == ''
|
||||
or line:match('^[MADRC%?!]%s+')
|
||||
or line:match('^diff ')
|
||||
or line:match('^index ')
|
||||
or line:match('^Binary ')
|
||||
then
|
||||
flush_hunk()
|
||||
current_filename = nil
|
||||
current_ft = nil
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue