feat: add comments to generated lua files
This commit is contained in:
parent
2ec47b437b
commit
8ad98db42a
16
Makefile
16
Makefile
|
@ -1,6 +1,9 @@
|
|||
|
||||
export PJ_ROOT=$(PWD)
|
||||
|
||||
# Suppress built in rules. This reduces clutter when running with -d
|
||||
MAKEFLAGS += --no-builtin-rules
|
||||
|
||||
FILTER ?= .*
|
||||
|
||||
LUA_VERSION := 5.1
|
||||
|
@ -29,15 +32,21 @@ $(NVIM_DIR):
|
|||
TL := $(LUAROCKS_TREE)/bin/tl
|
||||
|
||||
$(TL):
|
||||
@mkdir -p $@
|
||||
@mkdir -p $$(dirname $@)
|
||||
$(LUAROCKS) --tree $(LUAROCKS_TREE) install tl $(TL_VERSION)
|
||||
|
||||
INSPECT := $(LUAROCKS_LPATH)/inspect.lua
|
||||
|
||||
$(INSPECT):
|
||||
@mkdir -p $@
|
||||
@mkdir -p $$(dirname $@)
|
||||
$(LUAROCKS) --tree $(LUAROCKS_TREE) install inspect
|
||||
|
||||
LUV := $(LUAROCKS_TREE)/lib/lua/$(LUA_VERSION)/luv.so
|
||||
|
||||
$(LUV):
|
||||
@mkdir -p $$(dirname $@)
|
||||
$(LUAROCKS) --tree $(LUAROCKS_TREE) install luv
|
||||
|
||||
.PHONY: lua_deps
|
||||
lua_deps: $(TL) $(INSPECT)
|
||||
|
||||
|
@ -72,8 +81,9 @@ tl-check: $(TL)
|
|||
$(TL) check teal/*.tl teal/**/*.tl
|
||||
|
||||
.PHONY: tl-build
|
||||
tl-build: tlconfig.lua $(TL)
|
||||
tl-build: tlconfig.lua $(TL) $(LUV)
|
||||
@$(TL) build
|
||||
@$(LUAROCKS_INIT) ./etc/add_comments.lua
|
||||
@echo Updated lua files
|
||||
|
||||
.PHONY: gen_help
|
||||
|
|
|
@ -1170,3 +1170,4 @@ like so: >lua
|
|||
|
||||
------------------------------------------------------------------------------
|
||||
vim:tw=78:ts=8:ft=help:norl:
|
||||
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
#!/bin/sh
|
||||
_=[[
|
||||
exec luajit "$0" "$@"
|
||||
]]
|
||||
|
||||
local uv = require'luv'
|
||||
|
||||
local function read_file(path)
|
||||
local f = assert(io.open(path, 'r'))
|
||||
local t = f:read("*all")
|
||||
f:close()
|
||||
return t
|
||||
end
|
||||
|
||||
local function join_paths(...)
|
||||
return table.concat({ ... }, '/'):gsub('//+', '/')
|
||||
end
|
||||
|
||||
local function dir(path)
|
||||
--- @async
|
||||
return coroutine.wrap(function()
|
||||
local dirs = { { path, 1 } }
|
||||
while #dirs > 0 do
|
||||
local dir0, level = unpack(table.remove(dirs, 1))
|
||||
local dir1 = level == 1 and dir0 or join_paths(path, dir0)
|
||||
local fs = uv.fs_scandir(dir1)
|
||||
while fs do
|
||||
local name, t = uv.fs_scandir_next(fs)
|
||||
if not name then
|
||||
break
|
||||
end
|
||||
local f = level == 1 and name or join_paths(dir0, name)
|
||||
if t == 'directory' then
|
||||
dirs[#dirs + 1] = { f, level + 1 }
|
||||
else
|
||||
coroutine.yield(f, t)
|
||||
end
|
||||
end
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local function write_file(path, lines)
|
||||
local f = assert(io.open(path, 'w'))
|
||||
f:write(table.concat(lines, '\n'))
|
||||
f:close()
|
||||
end
|
||||
|
||||
local function read_file_lines(path)
|
||||
local lines = {}
|
||||
for l in read_file(path):gmatch("([^\n]*)\n?") do
|
||||
table.insert(lines, l)
|
||||
end
|
||||
return lines
|
||||
end
|
||||
|
||||
for p in dir('teal') do
|
||||
local path = join_paths('teal', p)
|
||||
local op = p:gsub('%.tl$', '.lua')
|
||||
local opath = join_paths('lua', op)
|
||||
|
||||
local lines = read_file_lines(path)
|
||||
|
||||
local comments = {}
|
||||
for i, l in ipairs(lines) do
|
||||
local comment = l:match('%s+%-%-.*')
|
||||
if comment then
|
||||
comments[i] = comment:gsub(' ', ' ')
|
||||
end
|
||||
end
|
||||
|
||||
local olines = read_file_lines(opath)
|
||||
|
||||
for i, l in pairs(comments) do
|
||||
if not olines[i]:match('%-%-.*') then
|
||||
olines[i] = olines[i]..l
|
||||
end
|
||||
end
|
||||
write_file(opath, olines)
|
||||
end
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
#!/bin/sh
|
||||
_=[[
|
||||
exec lua "$0" "$@"
|
||||
exec luajit "$0" "$@"
|
||||
]]
|
||||
-- Simple script to update the help doc by reading the config schema.
|
||||
|
||||
|
|
|
@ -58,12 +58,12 @@ end
|
|||
|
||||
|
||||
function M.detach(bufnr, _keep_signs)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- When this is called interactively (with no arguments) we want to remove all
|
||||
-- the signs, however if called via a detach event (due to nvim_buf_attach)
|
||||
-- then we don't want to clear the signs in case the buffer is just being
|
||||
-- updated due to the file externally changing. When this happens a detach and
|
||||
-- attach event happen in sequence and so we keep the old signs to stop the
|
||||
-- sign column width moving about between updates.
|
||||
bufnr = bufnr or current_buf()
|
||||
dprint('Detached')
|
||||
local bcache = cache[bufnr]
|
||||
|
@ -74,7 +74,7 @@ function M.detach(bufnr, _keep_signs)
|
|||
|
||||
manager.detach(bufnr, _keep_signs)
|
||||
|
||||
|
||||
-- Clear status variables
|
||||
Status:clear(bufnr)
|
||||
|
||||
cache:destroy(bufnr)
|
||||
|
@ -90,18 +90,18 @@ local function parse_fugitive_uri(name)
|
|||
local path = vim.fn.FugitiveReal(name)
|
||||
local commit = vim.fn.FugitiveParse(name)[1]:match('([^:]+):.*')
|
||||
if commit == '0' then
|
||||
|
||||
-- '0' means the index so clear commit so we attach normally
|
||||
commit = nil
|
||||
end
|
||||
return path, commit
|
||||
end
|
||||
|
||||
local function parse_gitsigns_uri(name)
|
||||
|
||||
-- TODO(lewis6991): Support submodules
|
||||
local _, _, root_path, commit, rel_path =
|
||||
name:find([[^gitsigns://(.*)/%.git/(.*):(.*)]])
|
||||
if commit == ':0' then
|
||||
|
||||
-- ':0' means the index so clear commit so we attach normally
|
||||
commit = nil
|
||||
end
|
||||
if root_path then
|
||||
|
@ -145,8 +145,8 @@ local vimgrep_running = false
|
|||
|
||||
local function on_lines(_, bufnr, _, first, last_orig, last_new, byte_count)
|
||||
if first == last_orig and last_orig == last_new and byte_count == 0 then
|
||||
|
||||
|
||||
-- on_lines can be called twice for undo events; ignore the second
|
||||
-- call which indicates no changes.
|
||||
return
|
||||
end
|
||||
return manager.on_lines(bufnr, first, last_orig, last_new)
|
||||
|
@ -295,8 +295,8 @@ local attach_throttled = throttle_by_id(function(cbuf, ctx, aucmd)
|
|||
return
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- On windows os.tmpname() crashes in callback threads so initialise this
|
||||
-- variable on the main thread.
|
||||
scheduler()
|
||||
|
||||
if config.on_attach and config.on_attach(cbuf) == false then
|
||||
|
@ -317,15 +317,15 @@ local attach_throttled = throttle_by_id(function(cbuf, ctx, aucmd)
|
|||
return
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- Make sure to attach before the first update (which is async) so we pick up
|
||||
-- changes from BufReadCmd.
|
||||
api.nvim_buf_attach(cbuf, false, {
|
||||
on_lines = on_lines,
|
||||
on_reload = on_reload,
|
||||
on_detach = on_detach,
|
||||
})
|
||||
|
||||
|
||||
-- Initial update
|
||||
manager.update(cbuf, cache[cbuf])
|
||||
|
||||
if config.keymaps and not vim.tbl_isempty(config.keymaps) then
|
||||
|
@ -436,9 +436,9 @@ M.setup = void(function(cfg)
|
|||
|
||||
Status.formatter = config.status_formatter
|
||||
|
||||
|
||||
|
||||
|
||||
-- Make sure highlights are setup on or after VimEnter so the colorscheme is
|
||||
-- loaded. Do not set them up with vim.schedule as this removes the intro
|
||||
-- message.
|
||||
on_or_after_vimenter(hl.setup_highlights)
|
||||
|
||||
setup_cli()
|
||||
|
@ -447,7 +447,7 @@ M.setup = void(function(cfg)
|
|||
git.set_version(config._git_version)
|
||||
scheduler()
|
||||
|
||||
|
||||
-- Attach to all open buffers
|
||||
for _, buf in ipairs(api.nvim_list_bufs()) do
|
||||
if api.nvim_buf_is_loaded(buf) and
|
||||
api.nvim_buf_get_name(buf) ~= '' then
|
||||
|
@ -471,8 +471,8 @@ M.setup = void(function(cfg)
|
|||
end, })
|
||||
|
||||
|
||||
|
||||
|
||||
-- vimpgrep creates and deletes lots of buffers so attaching to each one will
|
||||
-- waste lots of resource and even slow down vimgrep.
|
||||
autocmd('QuickFixCmdPre', {
|
||||
pattern = '*vimgrep*',
|
||||
callback = function()
|
||||
|
@ -491,8 +491,8 @@ M.setup = void(function(cfg)
|
|||
|
||||
scheduler()
|
||||
manager.update_cwd_head()
|
||||
|
||||
|
||||
-- Need to debounce in case some plugin changes the cwd too often
|
||||
-- (like vim-grepper)
|
||||
autocmd('DirChanged', debounce_trailing(100, manager.update_cwd_head))
|
||||
end)
|
||||
|
||||
|
|
|
@ -179,7 +179,7 @@ M.toggle_word_diff = function(value)
|
|||
else
|
||||
config.word_diff = not config.word_diff
|
||||
end
|
||||
|
||||
-- Don't use refresh() to avoid flicker
|
||||
api.nvim__buf_redraw_range(0, vim.fn.line('w0') - 1, vim.fn.line('w$'))
|
||||
return config.word_diff
|
||||
end
|
||||
|
@ -253,7 +253,7 @@ local function get_hunks(bufnr, bcache, greedy, staged)
|
|||
local hunks
|
||||
|
||||
if greedy then
|
||||
|
||||
-- Re-run the diff without linematch
|
||||
local buftext = util.buf_lines(bufnr)
|
||||
local text
|
||||
if staged then
|
||||
|
@ -445,7 +445,7 @@ M.stage_buffer = void(function()
|
|||
return
|
||||
end
|
||||
|
||||
|
||||
-- Only process files with existing hunks
|
||||
local hunks = bcache.hunks
|
||||
if #hunks == 0 then
|
||||
print("No unstaged changes in file to stage")
|
||||
|
@ -480,12 +480,12 @@ M.reset_buffer_index = void(function()
|
|||
return
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- `bcache.staged_diffs` won't contain staged changes outside of current
|
||||
-- neovim session so signs added from this unstage won't be complete They will
|
||||
-- however be fixed by gitdir watcher and properly updated We should implement
|
||||
-- some sort of initial population from git diff, after that this function can
|
||||
-- be improved to check if any staged hunks exists and it can undo changes
|
||||
-- using git apply line by line instead of resetting whole file
|
||||
bcache.staged_diffs = {}
|
||||
|
||||
bcache.git_obj:unstage_file()
|
||||
|
@ -495,12 +495,12 @@ M.reset_buffer_index = void(function()
|
|||
end)
|
||||
|
||||
local function process_nav_opts(opts)
|
||||
|
||||
-- show navigation message
|
||||
if opts.navigation_message == nil then
|
||||
opts.navigation_message = not vim.opt.shortmess:get().S
|
||||
end
|
||||
|
||||
|
||||
-- wrap around
|
||||
if opts.wrap == nil then
|
||||
opts.wrap = vim.opt.wrapscan:get()
|
||||
end
|
||||
|
@ -559,21 +559,21 @@ local nav_hunk = void(function(opts)
|
|||
|
||||
local row = opts.forwards and hunk.added.start or hunk.vend
|
||||
if row then
|
||||
|
||||
-- Handle topdelete
|
||||
if row == 0 then
|
||||
row = 1
|
||||
end
|
||||
vim.cmd([[ normal! m' ]])
|
||||
vim.cmd([[ normal! m' ]]) -- add current cursor position to the jump list
|
||||
api.nvim_win_set_cursor(0, { row, 0 })
|
||||
if opts.foldopen then
|
||||
vim.cmd('silent! foldopen!')
|
||||
end
|
||||
if opts.preview or popup.is_open('hunk') ~= nil then
|
||||
|
||||
|
||||
-- Use defer so the cursor change can settle, otherwise the popup might
|
||||
-- appear in the old position
|
||||
defer(function()
|
||||
|
||||
|
||||
-- Close the popup in case one is open which will cause it to focus the
|
||||
-- popup
|
||||
popup.close('hunk')
|
||||
M.preview_hunk()
|
||||
end)
|
||||
|
@ -717,7 +717,7 @@ end
|
|||
|
||||
|
||||
M.preview_hunk = noautocmd(function()
|
||||
|
||||
-- Wrap in noautocmd so vim-repeat continues to work
|
||||
|
||||
if popup.focus_open('hunk') then
|
||||
return
|
||||
|
@ -775,8 +775,8 @@ M.preview_hunk_inline = function()
|
|||
once = true,
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- Virtual lines will be hidden if cursor is on the top row, so automatically
|
||||
-- scroll the viewport.
|
||||
if api.nvim_win_get_cursor(0)[1] == 1 then
|
||||
local keys = hunk.removed.count .. '<C-y>'
|
||||
local cy = api.nvim_replace_termcodes(keys, true, false, true)
|
||||
|
@ -817,7 +817,7 @@ M.get_hunks = function(bufnr)
|
|||
bufnr = bufnr or current_buf()
|
||||
if not cache[bufnr] then return end
|
||||
local ret = {}
|
||||
|
||||
-- TODO(lewis6991): allow this to accept a greedy option
|
||||
for _, h in ipairs(cache[bufnr].hunks or {}) do
|
||||
ret[#ret + 1] = {
|
||||
head = h.head,
|
||||
|
@ -832,7 +832,7 @@ end
|
|||
|
||||
local function get_blame_hunk(repo, info)
|
||||
local a = {}
|
||||
|
||||
-- If no previous so sha of blame added the file
|
||||
if info.previous then
|
||||
a = repo:get_show_text(info.previous_sha .. ':' .. info.previous_filename)
|
||||
end
|
||||
|
@ -1040,7 +1040,7 @@ end
|
|||
|
||||
|
||||
M.diffthis = function(base, opts)
|
||||
|
||||
-- TODO(lewis6991): can't pass numbers as strings from the command line
|
||||
if base ~= nil then
|
||||
base = tostring(base)
|
||||
end
|
||||
|
@ -1053,7 +1053,7 @@ M.diffthis = function(base, opts)
|
|||
end
|
||||
|
||||
C.diffthis = function(args, params)
|
||||
|
||||
-- TODO(lewis6991): validate these
|
||||
local opts = {
|
||||
vertical = args.vertical,
|
||||
split = args.split,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
|
||||
|
||||
-- Order by highest number of return types
|
||||
|
||||
|
||||
|
||||
|
@ -26,12 +26,12 @@ local M = {}
|
|||
|
||||
local Async_T = {}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- Handle for an object currently running on the event loop.
|
||||
-- The coroutine is paused while this is active.
|
||||
-- Must provide methods cancel() and is_cancelled()
|
||||
--
|
||||
-- Handle gets updated on each call to a wrapped functions, so provide access
|
||||
-- to it via a proxy
|
||||
|
||||
|
||||
|
||||
|
@ -75,7 +75,7 @@ end
|
|||
|
||||
|
||||
function Async_T:cancel(cb)
|
||||
|
||||
-- Cancel anything running on the event loop
|
||||
if self._current and not self._current:is_cancelled() then
|
||||
self._current:cancel(cb)
|
||||
end
|
||||
|
@ -131,8 +131,8 @@ local function run(func, callback, ...)
|
|||
end
|
||||
|
||||
function M.wait(argc, func, ...)
|
||||
|
||||
|
||||
-- Always run the wrapped functions in xpcall and re-raise the error in the
|
||||
-- coroutine. This makes pcall work as normal.
|
||||
local function pfunc(...)
|
||||
local args = { ... }
|
||||
local cb = args[argc]
|
||||
|
|
|
@ -14,7 +14,7 @@ local M = {CacheEntry = {}, CacheObj = {}, }
|
|||
|
||||
|
||||
|
||||
|
||||
-- Timer object watching the gitdir
|
||||
|
||||
|
||||
|
||||
|
@ -44,7 +44,7 @@ function CacheEntry:get_compare_rev(base)
|
|||
end
|
||||
|
||||
if self.commit then
|
||||
|
||||
-- Buffer is a fugitive commit so compare against the parent of the commit
|
||||
if config._signs_staged_enable then
|
||||
return self.commit
|
||||
else
|
||||
|
|
|
@ -39,14 +39,14 @@ function M.complete(funcs, arglead, line)
|
|||
for _, m in ipairs({ actions, funcs }) do
|
||||
for func, _ in pairs(m) do
|
||||
if not func:match('^[a-z]') then
|
||||
|
||||
-- exclude
|
||||
elseif vim.startswith(func, arglead) then
|
||||
table.insert(matches, func)
|
||||
end
|
||||
end
|
||||
end
|
||||
elseif n > 2 then
|
||||
|
||||
-- Subcommand completion
|
||||
local cmp_func = actions._get_cmp_func(words[2])
|
||||
if cmp_func then
|
||||
return cmp_func(arglead)
|
||||
|
@ -75,8 +75,8 @@ M.run = void(function(funcs, params)
|
|||
|
||||
local cmd_func = actions._get_cmd_func(func)
|
||||
if cmd_func then
|
||||
|
||||
|
||||
-- Action has a specialised mapping function from command form to lua
|
||||
-- function
|
||||
cmd_func(args, params)
|
||||
return
|
||||
end
|
||||
|
@ -87,7 +87,7 @@ M.run = void(function(funcs, params)
|
|||
end
|
||||
|
||||
if type(funcs[func]) == 'function' then
|
||||
|
||||
-- Note functions here do not have named arguments
|
||||
funcs[func](unpack(pos_args))
|
||||
return
|
||||
end
|
||||
|
|
|
@ -30,7 +30,7 @@ function M.parse_args(x)
|
|||
local i = 1
|
||||
while i <= #x do
|
||||
local ch = x:sub(i, i)
|
||||
|
||||
-- dprintf('L(%d)(%s): cur_arg="%s" ch="%s"', i, state, cur_arg, ch)
|
||||
|
||||
if state == 'in_arg' then
|
||||
if is_char(ch) then
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
local warn
|
||||
do
|
||||
|
||||
-- this is included in gen_help.lua so don't error if requires fail
|
||||
local ok, ret = pcall(require, 'gitsigns.message')
|
||||
if ok then
|
||||
warn = ret.warn
|
||||
|
@ -120,7 +120,7 @@ local M = {Config = {DiffOpts = {}, SignConfig = {}, watch_gitdir = {}, current_
|
|||
|
||||
|
||||
|
||||
|
||||
-- Undocumented
|
||||
|
||||
|
||||
|
||||
|
@ -442,16 +442,16 @@ M.schema = {
|
|||
count_chars = {
|
||||
type = 'table',
|
||||
default = {
|
||||
[1] = '1',
|
||||
[2] = '2',
|
||||
[3] = '3',
|
||||
[4] = '4',
|
||||
[5] = '5',
|
||||
[6] = '6',
|
||||
[7] = '7',
|
||||
[8] = '8',
|
||||
[9] = '9',
|
||||
['+'] = '>',
|
||||
[1] = '1', -- '₁',
|
||||
[2] = '2', -- '₂',
|
||||
[3] = '3', -- '₃',
|
||||
[4] = '4', -- '₄',
|
||||
[5] = '5', -- '₅',
|
||||
[6] = '6', -- '₆',
|
||||
[7] = '7', -- '₇',
|
||||
[8] = '8', -- '₈',
|
||||
[9] = '9', -- '₉',
|
||||
['+'] = '>', -- '₊',
|
||||
},
|
||||
description = [[
|
||||
The count characters used when `signs.*.show_count` is enabled. The
|
||||
|
@ -815,12 +815,12 @@ local function handle_deprecated(cfg)
|
|||
if dep.new_field then
|
||||
local opts_key, field = dep.new_field:match('(.*)%.(.*)')
|
||||
if opts_key and field then
|
||||
|
||||
-- Field moved to an options table
|
||||
local opts = (cfg[opts_key] or {})
|
||||
opts[field] = cfg[k]
|
||||
cfg[opts_key] = opts
|
||||
else
|
||||
|
||||
-- Field renamed
|
||||
cfg[dep.new_field] = cfg[k]
|
||||
end
|
||||
end
|
||||
|
|
|
@ -69,7 +69,7 @@ end
|
|||
function BlameCache:get(bufnr, lnum)
|
||||
if not config._blame_cache then return end
|
||||
|
||||
|
||||
-- init and invalidate
|
||||
local tick = vim.b[bufnr].changedtick
|
||||
if not self.contents[bufnr] or self.contents[bufnr].tick ~= tick then
|
||||
self.contents[bufnr] = { tick = tick, cache = {}, size = 0 }
|
||||
|
@ -100,7 +100,7 @@ local update = void(function()
|
|||
|
||||
local old_lnum = get_extmark(bufnr)
|
||||
if old_lnum and lnum == old_lnum and BlameCache:get(bufnr, lnum) then
|
||||
|
||||
-- Don't update if on the same line and we already have results
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -109,23 +109,23 @@ local update = void(function()
|
|||
return
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- Set an empty extmark to save the line number.
|
||||
-- This will also clear virt_text.
|
||||
-- Only do this if there was already an extmark to avoid clearing the intro
|
||||
-- text.
|
||||
if get_extmark(bufnr) then
|
||||
reset(bufnr)
|
||||
set_extmark(bufnr, lnum)
|
||||
end
|
||||
|
||||
|
||||
-- Can't show extmarks on folded lines so skip
|
||||
if vim.fn.foldclosed(lnum) ~= -1 then
|
||||
return
|
||||
end
|
||||
|
||||
local opts = config.current_line_blame_opts
|
||||
|
||||
|
||||
-- Note because the same timer is re-used, this call has a debouncing effect.
|
||||
wait_timer(timer, opts.delay, 0)
|
||||
scheduler()
|
||||
|
||||
|
@ -144,12 +144,12 @@ local update = void(function()
|
|||
|
||||
local lnum1 = api.nvim_win_get_cursor(0)[1]
|
||||
if bufnr == current_buf() and lnum ~= lnum1 then
|
||||
|
||||
-- Cursor has moved during events; abort
|
||||
return
|
||||
end
|
||||
|
||||
if not api.nvim_buf_is_loaded(bufnr) then
|
||||
|
||||
-- Buffer is no longer loaded; abort
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -165,7 +165,7 @@ local update = void(function()
|
|||
expand_blame_format(clb_formatter, bcache.git_obj.repo.username, result),
|
||||
'GitSignsCurrentLineBlame',
|
||||
}, }
|
||||
else
|
||||
else -- function
|
||||
virt_text = clb_formatter(
|
||||
bcache.git_obj.repo.username,
|
||||
result,
|
||||
|
@ -202,8 +202,8 @@ M.setup = function()
|
|||
group = group, callback = function() reset() end,
|
||||
})
|
||||
|
||||
|
||||
|
||||
-- Call via vim.schedule to avoid the debounce timer killing the async
|
||||
-- coroutine
|
||||
vim.schedule(update)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -61,7 +61,7 @@ function M.throttle_by_id(fn, schedule)
|
|||
local running = {}
|
||||
return function(id, ...)
|
||||
if scheduled[id] then
|
||||
|
||||
-- If fn is already scheduled, then drop
|
||||
return
|
||||
end
|
||||
if not running[id] or schedule then
|
||||
|
|
|
@ -9,7 +9,7 @@ local function getvarvalue(name, lvl)
|
|||
local value
|
||||
local found
|
||||
|
||||
|
||||
-- try local variables
|
||||
local i = 1
|
||||
while true do
|
||||
local n, v = debug.getlocal(lvl, i)
|
||||
|
@ -22,7 +22,7 @@ local function getvarvalue(name, lvl)
|
|||
end
|
||||
if found then return value end
|
||||
|
||||
|
||||
-- try upvalues
|
||||
local func = debug.getinfo(lvl).func
|
||||
i = 1
|
||||
while true do
|
||||
|
@ -32,7 +32,7 @@ local function getvarvalue(name, lvl)
|
|||
i = i + 1
|
||||
end
|
||||
|
||||
|
||||
-- not found; get global
|
||||
return getfenv(func)[name]
|
||||
end
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@ local util = require('gitsigns.util')
|
|||
local scheduler = require('gitsigns.async').scheduler
|
||||
|
||||
local M = {}
|
||||
|
||||
-- Async function
|
||||
|
||||
|
||||
|
||||
|
@ -30,7 +30,7 @@ M.run_diff = function(
|
|||
|
||||
local results = {}
|
||||
|
||||
|
||||
-- tmpname must not be called in a callback
|
||||
if vim.in_fast_event() then
|
||||
scheduler()
|
||||
end
|
||||
|
@ -41,21 +41,21 @@ M.run_diff = function(
|
|||
write_to_file(file_buf, text_buf)
|
||||
write_to_file(file_cmp, text_cmp)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- Taken from gitgutter, diff.vim:
|
||||
--
|
||||
-- If a file has CRLF line endings and git's core.autocrlf is true, the file
|
||||
-- in git's object store will have LF line endings. Writing it out via
|
||||
-- git-show will produce a file with LF line endings.
|
||||
--
|
||||
-- If this last file is one of the files passed to git-diff, git-diff will
|
||||
-- convert its line endings to CRLF before diffing -- which is what we want
|
||||
-- but also by default outputs a warning on stderr.
|
||||
--
|
||||
-- warning: LF will be replace by CRLF in <temp file>.
|
||||
-- The file will have its original line endings in your working directory.
|
||||
--
|
||||
-- We can safely ignore the warning, we turn it off by passing the '-c
|
||||
-- "core.safecrlf=false"' argument to git-diff.
|
||||
|
||||
local out = git_diff(file_cmp, file_buf, indent_heuristic, diff_algo)
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ end)
|
|||
local gaps_between_regions = 5
|
||||
|
||||
local function denoise_hunks(hunks)
|
||||
|
||||
-- Denoise the hunks
|
||||
local ret = { hunks[1] }
|
||||
for j = 2, #hunks do
|
||||
local h, n = ret[#ret], hunks[j]
|
||||
|
@ -122,14 +122,14 @@ function M.run_word_diff(removed, added)
|
|||
end
|
||||
|
||||
for i = 1, #removed do
|
||||
|
||||
-- pair lines by position
|
||||
local a, b = vim.split(removed[i], ''), vim.split(added[i], '')
|
||||
|
||||
local hunks = {}
|
||||
for _, r in ipairs(run_diff_xdl(a, b)) do
|
||||
local rs, rc, as, ac = unpack(r)
|
||||
|
||||
|
||||
-- Balance of the unknown offset done in hunk_func
|
||||
if rc == 0 then rs = rs + 1 end
|
||||
if ac == 0 then as = as + 1 end
|
||||
|
||||
|
|
|
@ -59,8 +59,8 @@ local bufwrite = void(function(bufnr, dbufnr, base, bcache)
|
|||
bcache.git_obj:stage_lines(buftext)
|
||||
scheduler()
|
||||
vim.bo[dbufnr].modified = false
|
||||
|
||||
|
||||
-- If diff buffer base matches the bcache base then also update the
|
||||
-- signs.
|
||||
if util.calc_base(base) == util.calc_base(bcache.base) then
|
||||
bcache.compare_text = buftext
|
||||
manager.update(bufnr, bcache)
|
||||
|
@ -178,8 +178,8 @@ M.update = throttle_by_id(void(function(bufnr)
|
|||
|
||||
local bcache = cache[bufnr]
|
||||
|
||||
|
||||
|
||||
-- Note this will be the bufname for the currently set base
|
||||
-- which are the only ones we want to update
|
||||
local bufname = bcache:get_rev_bufname()
|
||||
|
||||
for _, w in ipairs(api.nvim_list_wins()) do
|
||||
|
|
|
@ -21,17 +21,19 @@ local err = require('gitsigns.message').error
|
|||
|
||||
|
||||
|
||||
|
||||
-- local extensions
|
||||
|
||||
|
||||
|
||||
local M = {BlameInfo = {}, Version = {}, RepoInfo = {}, Repo = {}, FileProps = {}, Obj = {}, }
|
||||
|
||||
-- Info in header
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- Porcelain fields
|
||||
|
||||
|
||||
|
||||
|
@ -85,26 +87,24 @@ local M = {BlameInfo = {}, Version = {}, RepoInfo = {}, Repo = {}, FileProps = {
|
|||
|
||||
|
||||
|
||||
-- Use for tracking moved files
|
||||
|
||||
|
||||
|
||||
-- Object has crlf
|
||||
-- Working copy has crlf
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- Use for tracking moved files
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- Object has crlf
|
||||
-- Working copy has crlf
|
||||
|
||||
|
||||
|
||||
|
@ -174,7 +174,7 @@ local git_command = async.create(function(args, spec)
|
|||
spec.args = spec.command == 'git' and {
|
||||
'--no-pager',
|
||||
'--literal-pathspecs',
|
||||
'-c', 'gc.auto=0',
|
||||
'-c', 'gc.auto=0', -- Disable auto-packing which emits messages to stderr
|
||||
unpack(args),
|
||||
} or args
|
||||
|
||||
|
@ -193,8 +193,8 @@ local git_command = async.create(function(args, spec)
|
|||
|
||||
local stdout_lines = vim.split(stdout or '', '\n', true)
|
||||
|
||||
|
||||
|
||||
-- If stdout ends with a newline, then remove the final empty string after
|
||||
-- the split
|
||||
if stdout_lines[#stdout_lines] == '' then
|
||||
stdout_lines[#stdout_lines] = nil
|
||||
end
|
||||
|
@ -260,8 +260,8 @@ end
|
|||
|
||||
local function normalize_path(path)
|
||||
if path and has_cygpath and not uv.fs_stat(path) then
|
||||
|
||||
|
||||
-- If on windows and path isn't recognizable as a file, try passing it
|
||||
-- through cygpath
|
||||
path = cygpath_convert(path)
|
||||
end
|
||||
return path
|
||||
|
@ -269,13 +269,13 @@ end
|
|||
|
||||
|
||||
function M.get_repo_info(path, cmd, gitdir, toplevel)
|
||||
|
||||
|
||||
-- Does git rev-parse have --absolute-git-dir, added in 2.13:
|
||||
-- https://public-inbox.org/git/20170203024829.8071-16-szeder.dev@gmail.com/
|
||||
local has_abs_gd = check_version({ 2, 13 })
|
||||
local git_dir_opt = has_abs_gd and '--absolute-git-dir' or '--git-dir'
|
||||
|
||||
|
||||
|
||||
-- Wait for internal scheduler to settle before running command
|
||||
-- https://github.com/lewis6991/gitsigns.nvim/pull/215
|
||||
scheduler()
|
||||
|
||||
local args = {}
|
||||
|
@ -394,7 +394,7 @@ local function strip_bom(x, encoding)
|
|||
end
|
||||
|
||||
local function iconv_supported(encoding)
|
||||
|
||||
-- TODO(lewis6991): needs https://github.com/neovim/neovim/pull/21924
|
||||
if vim.startswith(encoding, 'utf-16') then
|
||||
return false
|
||||
elseif vim.startswith(encoding, 'utf-32') then
|
||||
|
@ -417,7 +417,7 @@ function Repo:get_show_text(object, encoding)
|
|||
else
|
||||
scheduler()
|
||||
for i, l in ipairs(stdout) do
|
||||
|
||||
-- vimscript will interpret strings containing NUL as blob type
|
||||
if vim.fn.type(l) == vim.v.t_string then
|
||||
stdout[i] = vim.fn.iconv(l, encoding, 'utf-8')
|
||||
end
|
||||
|
@ -443,7 +443,7 @@ function Repo.new(dir, gitdir, toplevel)
|
|||
(self)[k] = v
|
||||
end
|
||||
|
||||
|
||||
-- Try yadm
|
||||
if M.enable_yadm and not self.gitdir then
|
||||
if vim.startswith(dir, os.getenv('HOME')) and
|
||||
#git_command({ 'ls-files', dir }, { command = 'yadm' }) ~= 0 then
|
||||
|
@ -498,8 +498,8 @@ function Obj:file_info(file, silent)
|
|||
}, { suppress_stderr = true })
|
||||
|
||||
if stderr and not silent then
|
||||
|
||||
|
||||
-- Suppress_stderr for the cases when we run:
|
||||
-- git ls-files --others exists/nonexist
|
||||
if not stderr:match('^warning: could not open directory .*: No such file or directory') then
|
||||
gsd.eprint(stderr)
|
||||
end
|
||||
|
@ -508,7 +508,7 @@ function Obj:file_info(file, silent)
|
|||
local result = {}
|
||||
for _, line in ipairs(results) do
|
||||
local parts = vim.split(line, '\t')
|
||||
if #parts > 2 then
|
||||
if #parts > 2 then -- tracked file
|
||||
local eol = vim.split(parts[2], '%s+')
|
||||
result.i_crlf = eol[1] == 'i/crlf'
|
||||
result.w_crlf = eol[2] == 'w/crlf'
|
||||
|
@ -521,7 +521,7 @@ function Obj:file_info(file, silent)
|
|||
else
|
||||
result.has_conflicts = true
|
||||
end
|
||||
else
|
||||
else -- untracked file
|
||||
result.relpath = parts[2]
|
||||
end
|
||||
end
|
||||
|
@ -537,7 +537,7 @@ function Obj:get_show_text(revision)
|
|||
local stdout, stderr = self.repo:get_show_text(revision .. ':' .. self.relpath, self.encoding)
|
||||
|
||||
if not self.i_crlf and self.w_crlf then
|
||||
|
||||
-- Add cr
|
||||
for i = 1, #stdout do
|
||||
stdout[i] = stdout[i] .. '\r'
|
||||
end
|
||||
|
@ -554,9 +554,9 @@ end
|
|||
|
||||
function Obj:run_blame(lines, lnum, ignore_whitespace)
|
||||
if not self.object_name or self.repo.abbrev_head == '' then
|
||||
|
||||
|
||||
|
||||
-- As we support attaching to untracked files we need to return something if
|
||||
-- the file isn't isn't tracked in git.
|
||||
-- If abbrev_head is empty, then assume the repo has no commits
|
||||
return {
|
||||
author = 'Not Committed Yet',
|
||||
['author_mail'] = '<not.committed.yet>',
|
||||
|
@ -614,11 +614,11 @@ local function ensure_file_in_index(obj)
|
|||
end
|
||||
|
||||
if not obj.object_name then
|
||||
|
||||
-- If there is no object_name then it is not yet in the index so add it
|
||||
obj:command({ 'add', '--intent-to-add', obj.file })
|
||||
else
|
||||
|
||||
|
||||
-- Update the index with the common ancestor (stage 1) which is what bcache
|
||||
-- stores
|
||||
local info = string.format('%s,%s,%s', obj.mode_bits, obj.object_name, obj.relpath)
|
||||
obj:command({ 'update-index', '--add', '--cacheinfo', info })
|
||||
end
|
||||
|
@ -648,7 +648,7 @@ Obj.stage_hunks = function(self, hunks, invert)
|
|||
local patch = gs_hunks.create_patch(self.relpath, hunks, self.mode_bits, invert)
|
||||
|
||||
if not self.i_crlf and self.w_crlf then
|
||||
|
||||
-- Remove cr
|
||||
for i = 1, #patch do
|
||||
patch[i] = patch[i]:gsub('\r$', '')
|
||||
end
|
||||
|
@ -696,7 +696,7 @@ function Obj.new(file, encoding, gitdir, toplevel)
|
|||
return nil
|
||||
end
|
||||
|
||||
|
||||
-- When passing gitdir and toplevel, suppress stderr when resolving the file
|
||||
local silent = gitdir ~= nil and toplevel ~= nil
|
||||
|
||||
self:update_file_info(true, silent)
|
||||
|
|
|
@ -78,8 +78,8 @@ desc = "Used for buffer line (when `config.linehl == true`) of 'changedelete' si
|
|||
desc = "Used for buffer line (when `config.linehl == true`) of 'untracked' signs.",
|
||||
}, },
|
||||
|
||||
|
||||
|
||||
-- Don't set GitSignsDeleteLn by default
|
||||
-- {GitSignsDeleteLn = {}},
|
||||
|
||||
{ GitSignsStagedAdd = { 'GitSignsAdd', fg_factor = 0.5, hidden = true } },
|
||||
{ GitSignsStagedChange = { 'GitSignsChange', fg_factor = 0.5, hidden = true } },
|
||||
|
@ -133,11 +133,11 @@ desc = "Used for changed word diff regions when `config.word_diff == true`.",
|
|||
desc = "Used for deleted word diff regions when `config.word_diff == true`.",
|
||||
}, },
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- Currently unused
|
||||
-- {GitSignsAddLnVirtLn = {'GitSignsAddLn'}},
|
||||
-- {GitSignsChangeVirtLn = {'GitSignsChangeLn'}},
|
||||
-- {GitSignsAddLnVirtLnInLine = {'GitSignsAddLnInline', }},
|
||||
-- {GitSignsChangeVirtLnInLine = {'GitSignsChangeLnInline', }},
|
||||
|
||||
{ GitSignsDeleteVirtLn = { 'GitGutterDeleteLine', 'SignifyLineDelete', 'DiffDelete',
|
||||
desc = "Used for deleted lines shown by inline `preview_hunk_inline()` or `show_deleted()`.",
|
||||
|
@ -150,7 +150,7 @@ desc = "Used for word diff regions in lines shown by inline `preview_hunk_inline
|
|||
}
|
||||
|
||||
local function is_hl_set(hl_name)
|
||||
|
||||
-- TODO: this only works with `set termguicolors`
|
||||
local exists, hl = pcall(vim.api.nvim_get_hl_by_name, hl_name, true)
|
||||
local color = hl.foreground or hl.background or hl.reverse
|
||||
return exists and color ~= nil
|
||||
|
@ -189,8 +189,8 @@ local function derive(hl, hldef)
|
|||
end
|
||||
end
|
||||
if hldef[1] and not hldef.bg_factor and not hldef.fg_factor then
|
||||
|
||||
|
||||
-- No fallback found which is set. Just link to the first fallback
|
||||
-- if there are no modifiers
|
||||
dprintf('Deriving %s from %s', hl, hldef[1])
|
||||
vim.api.nvim_set_hl(0, hl, { default = true, link = hldef[1] })
|
||||
else
|
||||
|
@ -205,7 +205,7 @@ M.setup_highlights = function()
|
|||
for _, hlg in ipairs(M.hls) do
|
||||
for hl, hldef in pairs(hlg) do
|
||||
if is_hl_set(hl) then
|
||||
|
||||
-- Already defined
|
||||
dprintf('Highlight %s is already defined', hl)
|
||||
else
|
||||
derive(hl, hldef)
|
||||
|
|
|
@ -18,7 +18,7 @@ local M = {Node = {}, Hunk = {}, Hunk_Public = {}, }
|
|||
|
||||
|
||||
|
||||
|
||||
-- For internal use
|
||||
|
||||
|
||||
|
||||
|
@ -60,21 +60,21 @@ function M.create_partial_hunk(hunks, top, bot)
|
|||
|
||||
local added_in_range = 0
|
||||
if h.added.start >= top and h.vend <= bot then
|
||||
|
||||
-- Range contains hunk
|
||||
added_in_range = added_in_hunk
|
||||
else
|
||||
local added_above_bot = max(0, bot + 1 - (h.added.start + h.removed.count))
|
||||
local added_above_top = max(0, top - (h.added.start + h.removed.count))
|
||||
|
||||
if h.added.start >= top and h.added.start <= bot then
|
||||
|
||||
-- Range top intersects hunk
|
||||
added_in_range = added_above_bot
|
||||
elseif h.vend >= top and h.vend <= bot then
|
||||
|
||||
-- Range bottom intersects hunk
|
||||
added_in_range = added_in_hunk - added_above_top
|
||||
pretop = pretop - added_above_top
|
||||
elseif h.added.start <= top and h.vend >= bot then
|
||||
|
||||
-- Range within hunk
|
||||
added_in_range = added_above_bot - added_above_top
|
||||
pretop = pretop - added_above_top
|
||||
end
|
||||
|
@ -112,8 +112,8 @@ end
|
|||
function M.parse_diff_line(line)
|
||||
local diffkey = vim.trim(vim.split(line, '@@', true)[2])
|
||||
|
||||
|
||||
|
||||
-- diffKey: "-xx,n +yy"
|
||||
-- pre: {xx, n}, now: {yy}
|
||||
local pre, now = unpack(vim.tbl_map(function(s)
|
||||
return vim.split(string.sub(s, 2), ',')
|
||||
end, vim.split(diffkey, ' ')))
|
||||
|
@ -129,13 +129,13 @@ end
|
|||
|
||||
local function change_end(hunk)
|
||||
if hunk.added.count == 0 then
|
||||
|
||||
-- delete
|
||||
return hunk.added.start
|
||||
elseif hunk.removed.count == 0 then
|
||||
|
||||
-- add
|
||||
return hunk.added.start + hunk.added.count - 1
|
||||
else
|
||||
|
||||
-- change
|
||||
return hunk.added.start + min(hunk.added.count, hunk.removed.count) - 1
|
||||
end
|
||||
end
|
||||
|
@ -149,7 +149,7 @@ function M.calc_signs(hunk, min_lnum, max_lnum, untracked)
|
|||
|
||||
if hunk.type == 'delete' and start == 0 then
|
||||
if min_lnum <= 1 then
|
||||
|
||||
-- topdelete signs get placed one row lower
|
||||
return { { type = 'topdelete', count = removed, lnum = 1 } }
|
||||
else
|
||||
return {}
|
||||
|
@ -364,12 +364,12 @@ function M.filter_common(a, b)
|
|||
local a_h, b_h = a[a_i], b[b_i]
|
||||
|
||||
if not a_h then
|
||||
|
||||
-- Reached the end of a
|
||||
break
|
||||
end
|
||||
|
||||
if not b_h then
|
||||
|
||||
-- Reached the end of b, add remainder of a
|
||||
for i = a_i, #a do
|
||||
ret[#ret + 1] = a[i]
|
||||
end
|
||||
|
@ -377,17 +377,17 @@ function M.filter_common(a, b)
|
|||
end
|
||||
|
||||
if a_h.added.start > b_h.added.start then
|
||||
|
||||
-- a pointer is ahead of b; increment b pointer
|
||||
b_i = b_i + 1
|
||||
elseif a_h.added.start < b_h.added.start then
|
||||
|
||||
-- b pointer is ahead of a; add a_h to ret and increment a pointer
|
||||
ret[#ret + 1] = a_h
|
||||
a_i = a_i + 1
|
||||
else
|
||||
|
||||
|
||||
|
||||
|
||||
else -- a_h.start == b_h.start
|
||||
-- a_h and b_h start on the same line, if hunks have the same changes then
|
||||
-- skip (filtered) otherwise add a_h to ret. Increment both hunk
|
||||
-- pointers
|
||||
-- TODO(lewis6991): Be smarter; if bh intercepts then break down ah.
|
||||
if not compare_new(a_h, b_h) then
|
||||
ret[#ret + 1] = a_h
|
||||
end
|
||||
|
|
|
@ -54,14 +54,14 @@ end, 2)
|
|||
|
||||
local function apply_win_signs0(bufnr, signs, hunks, top, bot, clear, untracked)
|
||||
if clear then
|
||||
signs:remove(bufnr)
|
||||
signs:remove(bufnr) -- Remove all signs
|
||||
end
|
||||
|
||||
for i, hunk in ipairs(hunks or {}) do
|
||||
|
||||
|
||||
|
||||
|
||||
-- To stop the sign column width changing too much, if there are signs to be
|
||||
-- added but none of them are visible in the window, then make sure to add at
|
||||
-- least one sign. Only do this on the first call after an update when we all
|
||||
-- the signs have been cleared.
|
||||
if clear and i == 1 then
|
||||
signs:add(bufnr, gs_hunks.calc_signs(hunk, hunk.added.start, hunk.added.start, untracked))
|
||||
end
|
||||
|
@ -98,16 +98,16 @@ M.on_lines = function(buf, first, last_orig, last_new)
|
|||
signs_staged:on_lines(buf, first, last_orig, last_new)
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- Signs in changed regions get invalidated so we need to force a redraw if
|
||||
-- any signs get removed.
|
||||
if bcache.hunks and signs_normal:contains(buf, first, last_new) then
|
||||
|
||||
-- Force a sign redraw on the next update (fixes #521)
|
||||
bcache.force_next_update = true
|
||||
end
|
||||
|
||||
if signs_staged then
|
||||
if bcache.hunks_staged and signs_staged:contains(buf, first, last_new) then
|
||||
|
||||
-- Force a sign redraw on the next update (fixes #521)
|
||||
bcache.force_next_update = true
|
||||
end
|
||||
end
|
||||
|
@ -118,7 +118,7 @@ end
|
|||
local ns = api.nvim_create_namespace('gitsigns')
|
||||
|
||||
local function apply_word_diff(bufnr, row)
|
||||
|
||||
-- Don't run on folded lines
|
||||
if vim.fn.foldclosed(row + 1) ~= -1 then
|
||||
return
|
||||
end
|
||||
|
@ -131,7 +131,7 @@ local function apply_word_diff(bufnr, row)
|
|||
|
||||
local line = api.nvim_buf_get_lines(bufnr, row, row + 1, false)[1]
|
||||
if not line then
|
||||
|
||||
-- Invalid line
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -139,12 +139,12 @@ local function apply_word_diff(bufnr, row)
|
|||
|
||||
local hunk = gs_hunks.find_hunk(lnum, bcache.hunks)
|
||||
if not hunk then
|
||||
|
||||
-- No hunk at line
|
||||
return
|
||||
end
|
||||
|
||||
if hunk.added.count ~= hunk.removed.count then
|
||||
|
||||
-- Only word diff if added count == removed
|
||||
return
|
||||
end
|
||||
|
||||
|
@ -160,7 +160,7 @@ local function apply_word_diff(bufnr, row)
|
|||
for _, region in ipairs(added_regions) do
|
||||
local rtype, scol, ecol = region[2], region[3] - 1, region[4] - 1
|
||||
if ecol == scol then
|
||||
|
||||
-- Make sure region is at least 1 column wide so deletes can be shown
|
||||
ecol = scol + 1
|
||||
end
|
||||
|
||||
|
@ -174,7 +174,7 @@ local function apply_word_diff(bufnr, row)
|
|||
}
|
||||
|
||||
if ecol > cols and ecol == scol + 1 then
|
||||
|
||||
-- delete on last column, use virtual text instead
|
||||
opts.virt_text = { { ' ', hl_group } }
|
||||
opts.virt_text_pos = 'overlay'
|
||||
else
|
||||
|
@ -224,7 +224,7 @@ function M.show_deleted(bufnr, nsd, hunk)
|
|||
vline[#vline + 1] = { line:sub(last_ecol, -1), 'GitSignsDeleteVirtLn' }
|
||||
end
|
||||
|
||||
|
||||
-- Add extra padding so the entire line is highlighted
|
||||
local padding = string.rep(' ', VIRT_LINE_LEN - #line)
|
||||
vline[#vline + 1] = { padding, 'GitSignsDeleteVirtLn' }
|
||||
|
||||
|
@ -236,7 +236,7 @@ function M.show_deleted(bufnr, nsd, hunk)
|
|||
local row = topdelete and 0 or hunk.added.start - 1
|
||||
api.nvim_buf_set_extmark(bufnr, nsd, row, -1, {
|
||||
virt_lines = virt_lines,
|
||||
|
||||
-- TODO(lewis6991): Note virt_lines_above doesn't work on row 0 neovim/neovim#16166
|
||||
virt_lines_above = hunk.type ~= 'delete' or topdelete,
|
||||
})
|
||||
end
|
||||
|
@ -315,12 +315,12 @@ M.update = throttle_by_id(function(bufnr, bcache)
|
|||
|
||||
scheduler_if_buf_valid(bufnr)
|
||||
|
||||
|
||||
|
||||
-- Note the decoration provider may have invalidated bcache.hunks at this
|
||||
-- point
|
||||
if bcache.force_next_update or gs_hunks.compare_heads(bcache.hunks, old_hunks) or
|
||||
gs_hunks.compare_heads(bcache.hunks_staged, old_hunks_staged) then
|
||||
|
||||
|
||||
-- Apply signs to the window. Other signs will be added by the decoration
|
||||
-- provider as they are drawn.
|
||||
apply_win_signs(bufnr, vim.fn.line('w0'), vim.fn.line('w$'), true, git_obj.object_name == nil)
|
||||
|
||||
update_show_deleted(bufnr)
|
||||
|
@ -343,7 +343,7 @@ end, true)
|
|||
|
||||
M.detach = function(bufnr, keep_signs)
|
||||
if not keep_signs then
|
||||
|
||||
-- Remove all signs
|
||||
signs_normal:remove(bufnr)
|
||||
if signs_staged then
|
||||
signs_staged:remove(bufnr)
|
||||
|
@ -372,7 +372,7 @@ local function handle_moved(bufnr, bcache, old_relpath)
|
|||
do_update = true
|
||||
end
|
||||
else
|
||||
|
||||
-- File removed from index, do nothing
|
||||
end
|
||||
|
||||
if do_update then
|
||||
|
@ -412,9 +412,9 @@ function M.watch_gitdir(bufnr, gitdir)
|
|||
local bcache = cache[bufnr]
|
||||
|
||||
if not bcache then
|
||||
|
||||
|
||||
|
||||
-- Very occasionally an external git operation may cause the buffer to
|
||||
-- detach and update the git dir simultaneously. When this happens this
|
||||
-- handler will trigger but there will be no cache.
|
||||
dprint('Has detached, aborting')
|
||||
return
|
||||
end
|
||||
|
@ -432,8 +432,8 @@ function M.watch_gitdir(bufnr, gitdir)
|
|||
git_obj:update_file_info()
|
||||
|
||||
if config.watch_gitdir.follow_files and was_tracked and not git_obj.object_name then
|
||||
|
||||
|
||||
-- File was tracked but is no longer tracked. Must of been removed or
|
||||
-- moved. Check if it was moved and switch to it.
|
||||
handle_moved(bufnr, bcache, old_relpath)
|
||||
end
|
||||
|
||||
|
@ -456,7 +456,7 @@ M.update_cwd_head = void(function()
|
|||
local cwd = vim.loop.cwd()
|
||||
local gitdir, head
|
||||
|
||||
|
||||
-- Look in the cache first
|
||||
for _, bcache in pairs(cache) do
|
||||
local repo = bcache.git_obj.repo
|
||||
if repo.toplevel == cwd then
|
||||
|
@ -482,11 +482,11 @@ M.update_cwd_head = void(function()
|
|||
local towatch = gitdir .. '/HEAD'
|
||||
|
||||
if cwd_watcher:getpath() == towatch then
|
||||
|
||||
-- Already watching
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
-- Watch .git/HEAD to detect branch changes
|
||||
cwd_watcher:start(
|
||||
towatch,
|
||||
config.watch_gitdir.interval,
|
||||
|
@ -506,7 +506,7 @@ M.update_cwd_head = void(function()
|
|||
end)
|
||||
|
||||
function M.reset_signs()
|
||||
|
||||
-- Remove all signs
|
||||
signs_normal:reset()
|
||||
if signs_staged then
|
||||
signs_staged:reset()
|
||||
|
@ -534,8 +534,8 @@ local function on_line(_, _, bufnr, row)
|
|||
end
|
||||
|
||||
function M.setup()
|
||||
|
||||
|
||||
-- Calling this before any await calls will stop nvim's intro messages being
|
||||
-- displayed
|
||||
api.nvim_set_decoration_provider(ns, {
|
||||
on_win = on_win,
|
||||
on_line = on_line,
|
||||
|
|
|
@ -6,7 +6,7 @@ local api = vim.api
|
|||
|
||||
local valid_modes = {
|
||||
n = 'n', v = 'v', x = 'x', i = 'i', o = 'o', t = 't', c = 'c', s = 's',
|
||||
|
||||
-- :map! and :map
|
||||
['!'] = '!', [' '] = '',
|
||||
}
|
||||
|
||||
|
@ -38,7 +38,7 @@ local function apply_mappings(mappings, bufnr)
|
|||
|
||||
local default_options = {}
|
||||
for key, val in pairs(mappings) do
|
||||
|
||||
-- Skip any inline default keywords.
|
||||
if valid_options[key] then
|
||||
default_options[key] = val
|
||||
end
|
||||
|
@ -46,7 +46,7 @@ local function apply_mappings(mappings, bufnr)
|
|||
|
||||
for key, opts in pairs(mappings) do
|
||||
repeat
|
||||
|
||||
-- Skip any inline default keywords.
|
||||
if valid_options[key] then
|
||||
break
|
||||
end
|
||||
|
@ -76,7 +76,7 @@ local function apply_mappings(mappings, bufnr)
|
|||
error("Invalid mode specified for keymapping. mode=" .. mode)
|
||||
end
|
||||
|
||||
|
||||
-- In case users haven't updated their config.
|
||||
options.buffer = nil
|
||||
|
||||
api.nvim_buf_set_keymap(bufnr, mode, mapping, rhs, options)
|
||||
|
|
|
@ -24,7 +24,7 @@ local function bufnr_calc_width(bufnr, lines)
|
|||
end
|
||||
end
|
||||
end
|
||||
return width + 1
|
||||
return width + 1 -- Add 1 for some miinor padding
|
||||
end)
|
||||
end
|
||||
|
||||
|
@ -34,7 +34,7 @@ local function expand_height(winid, nlines)
|
|||
for _ = 0, 50 do
|
||||
local winheight = api.nvim_win_get_height(winid)
|
||||
if newheight > winheight then
|
||||
|
||||
-- Window must be max height
|
||||
break
|
||||
end
|
||||
local wd = api.nvim_win_call(winid, function()
|
||||
|
@ -93,7 +93,7 @@ local function process_linesspec(fmt)
|
|||
start_col = scol,
|
||||
end_col = pos,
|
||||
}
|
||||
else
|
||||
else -- hl is {HlMark}
|
||||
offset_hlmarks(hl, srow)
|
||||
vim.list_extend(hls, hl)
|
||||
end
|
||||
|
@ -125,24 +125,24 @@ function popup.close(id)
|
|||
end
|
||||
|
||||
function popup.create0(lines, opts, id)
|
||||
|
||||
-- Close any popups not matching id
|
||||
close_all_but(id)
|
||||
|
||||
local ts = vim.bo.tabstop
|
||||
local bufnr = api.nvim_create_buf(false, true)
|
||||
assert(bufnr, "Failed to create buffer")
|
||||
|
||||
|
||||
-- In case nvim was opened with '-M'
|
||||
vim.bo[bufnr].modifiable = true
|
||||
api.nvim_buf_set_lines(bufnr, 0, -1, true, lines)
|
||||
vim.bo[bufnr].modifiable = false
|
||||
|
||||
|
||||
|
||||
-- Set tabstop before calculating the buffer width so that the correct width
|
||||
-- is calculated
|
||||
vim.bo[bufnr].tabstop = ts
|
||||
|
||||
local opts1 = vim.deepcopy(opts or {})
|
||||
opts1.height = opts1.height or #lines
|
||||
opts1.height = opts1.height or #lines -- Guess, adjust later
|
||||
opts1.width = opts1.width or bufnr_calc_width(bufnr, lines)
|
||||
|
||||
local winid = api.nvim_open_win(bufnr, false, opts1)
|
||||
|
@ -154,13 +154,13 @@ function popup.create0(lines, opts, id)
|
|||
end
|
||||
|
||||
if opts1.style == 'minimal' then
|
||||
|
||||
|
||||
-- If 'signcolumn' = auto:1-2, then a empty signcolumn will appear and cause
|
||||
-- line wrapping.
|
||||
vim.wo[winid].signcolumn = 'no'
|
||||
end
|
||||
|
||||
|
||||
|
||||
-- Close the popup when navigating to any window which is not the preview
|
||||
-- itself.
|
||||
local group = 'gitsigns_popup'
|
||||
local group_id = api.nvim_create_augroup(group, {})
|
||||
local old_cursor = api.nvim_win_get_cursor(0)
|
||||
|
@ -169,10 +169,10 @@ function popup.create0(lines, opts, id)
|
|||
group = group_id,
|
||||
callback = function()
|
||||
local cursor = api.nvim_win_get_cursor(0)
|
||||
|
||||
-- Did the cursor REALLY change (neovim/neovim#12923)
|
||||
if (old_cursor[1] ~= cursor[1] or old_cursor[2] ~= cursor[2]) and
|
||||
api.nvim_get_current_win() ~= winid then
|
||||
|
||||
-- Clear the augroup
|
||||
api.nvim_create_augroup(group, {})
|
||||
pcall(api.nvim_win_close, winid, true)
|
||||
return
|
||||
|
@ -185,12 +185,12 @@ function popup.create0(lines, opts, id)
|
|||
pattern = tostring(winid),
|
||||
group = group_id,
|
||||
callback = function()
|
||||
|
||||
-- Clear the augroup
|
||||
api.nvim_create_augroup(group, {})
|
||||
end,
|
||||
})
|
||||
|
||||
|
||||
-- update window position to follow the cursor when scrolling
|
||||
api.nvim_create_autocmd('WinScrolled', {
|
||||
buffer = api.nvim_get_current_buf(),
|
||||
group = group_id,
|
||||
|
|
|
@ -21,22 +21,22 @@ function B.new(cfg, name)
|
|||
end
|
||||
|
||||
local hls = (name == 'staged' and config._signs_staged or config.signs)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
-- Add when config.signs.*.[hl,numhl,linehl] are removed
|
||||
-- for _, t in ipairs {
|
||||
-- 'add',
|
||||
-- 'change',
|
||||
-- 'delete',
|
||||
-- 'topdelete',
|
||||
-- 'changedelete',
|
||||
-- 'untracked',
|
||||
-- } do
|
||||
-- local hl = string.format('GitSigns%s%s', name, capitalise_word(t))
|
||||
-- obj.hls[t] = {
|
||||
-- hl = hl,
|
||||
-- numhl = hl..'Nr',
|
||||
-- linehl = hl..'Ln',
|
||||
-- }
|
||||
-- end
|
||||
return C._new(cfg, hls, name)
|
||||
end
|
||||
|
||||
|
|
|
@ -28,10 +28,10 @@ local M = {Sign = {}, HlDef = {}, }
|
|||
|
||||
|
||||
|
||||
-- Used by signs/extmarks.tl
|
||||
|
||||
|
||||
|
||||
|
||||
-- Used by signs/vimfn.tl
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -19,8 +19,8 @@ function M._new(cfg, hls, name)
|
|||
end
|
||||
|
||||
function M:on_lines(buf, _, last_orig, last_new)
|
||||
|
||||
|
||||
-- Remove extmarks on line deletions to mimic
|
||||
-- the behaviour of vim signs.
|
||||
if last_orig > last_new then
|
||||
self:remove(buf, last_new + 1, last_orig)
|
||||
end
|
||||
|
@ -36,7 +36,7 @@ end
|
|||
|
||||
function M:add(bufnr, signs)
|
||||
if not config.signcolumn and not config.numhl and not config.linehl then
|
||||
|
||||
-- Don't place signs if it won't show anything
|
||||
return
|
||||
end
|
||||
|
||||
|
|
|
@ -54,7 +54,7 @@ local function define_sign(name, opts, redefine)
|
|||
end
|
||||
|
||||
local function define_signs(obj, redefine)
|
||||
|
||||
-- Define signs
|
||||
for stype, cs in pairs(obj.config) do
|
||||
local hls = obj.hls[stype]
|
||||
define_sign(get_sign_name(stype), {
|
||||
|
@ -100,7 +100,7 @@ end
|
|||
|
||||
function M:add(bufnr, signs)
|
||||
if not config.signcolumn and not config.numhl and not config.linehl then
|
||||
|
||||
-- Don't place signs if it won't show anything
|
||||
return
|
||||
end
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ local function handle_writer(pipe, x)
|
|||
end
|
||||
end
|
||||
elseif x then
|
||||
|
||||
-- write is string
|
||||
pipe:write(x, function()
|
||||
try_close(pipe)
|
||||
end)
|
||||
|
|
|
@ -37,7 +37,7 @@ end
|
|||
M.path_sep = package.config:sub(1, 1)
|
||||
|
||||
function M.buf_lines(bufnr)
|
||||
|
||||
-- nvim_buf_get_lines strips carriage returns if fileformat==dos
|
||||
local buftext = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
||||
if vim.bo[bufnr].fileformat == 'dos' then
|
||||
for i = 1, #buftext do
|
||||
|
@ -127,11 +127,11 @@ end
|
|||
function M.strip_cr(xs0)
|
||||
for i = 1, #xs0 do
|
||||
if xs0[i]:sub(-1) ~= '\r' then
|
||||
|
||||
-- don't strip, return early
|
||||
return xs0
|
||||
end
|
||||
end
|
||||
|
||||
-- all lines end with '\r', need to strip
|
||||
local xs = vim.deepcopy(xs0)
|
||||
for i = 1, #xs do
|
||||
xs[i] = xs[i]:sub(1, -2)
|
||||
|
@ -166,8 +166,8 @@ end
|
|||
function M.expand_format(fmt, info, reltime)
|
||||
local ret = {}
|
||||
|
||||
for _ = 1, 20 do
|
||||
|
||||
for _ = 1, 20 do -- loop protection
|
||||
-- Capture <name> or <name:format>
|
||||
local scol, ecol, match, key, time_fmt = fmt:find('(<([^:>]+):?([^>]*)>)')
|
||||
if not match then
|
||||
break
|
||||
|
|
Loading…
Reference in New Issue