Skip to content

Commit

Permalink
feat!: remove config.keymaps
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Jun 16, 2023
1 parent 512ed64 commit 256569c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 161 deletions.
25 changes: 2 additions & 23 deletions doc/gitsigns.txt
Original file line number Diff line number Diff line change
Expand Up @@ -531,26 +531,6 @@ signs *gitsigns-config-signs*

See |gitsigns-highlight-groups|.

keymaps *gitsigns-config-keymaps*
DEPRECATED
config.keymaps is now deprecated. Please define mappings in config.on_attach() instead.

Type: `table`, Default: `{}`

Keymaps to set up when attaching to a buffer.

Each key in the table defines the mode and key (whitespace delimited)
for the mapping and the value defines what the key maps to. The value
can be a table which can contain keys matching the options defined in
|map-arguments| which are: `expr`, `noremap`, `nowait`, `script`, `silent`
and `unique`. These options can also be used in the top level of the
table to define default options for all mappings.

Since this field is not extended (unlike |gitsigns-config-signs|),
mappings defined in this field can be disabled by setting the whole field
to `{}`, and |gitsigns-config-on_attach| can instead be used to define
mappings.

worktrees *gitsigns-config-worktrees*
Type: `table`, Default: `nil`

Expand All @@ -572,9 +552,8 @@ worktrees *gitsigns-config-worktrees*
on_attach *gitsigns-config-on_attach*
Type: `function`, Default: `nil`

Callback called when attaching to a buffer. Mainly used to setup keymaps
when `config.keymaps` is empty. The buffer number is passed as the first
argument.
Callback called when attaching to a buffer. Mainly used to setup keymaps.
The buffer number is passed as the first argument.

This callback can return `false` to prevent attaching to the buffer.

Expand Down
11 changes: 7 additions & 4 deletions gen_help.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/bin/sh
_=[[
exec luajit "$0" "$@"
exec nvim -l "$0" "$@"
]]
-- Simple script to update the help doc by reading the config schema.

local inspect = require('inspect')
local inspect = vim.inspect
local config = require('lua.gitsigns.config')

function table.slice(tbl, first, last, step)
Expand Down Expand Up @@ -184,8 +184,11 @@ local function gen_functions_doc_from_file(path)
else
if in_block then
-- First line after block
block[1] = parse_func_header(l)
blocks[#blocks+1] = block
local ok, header = pcall(parse_func_header, l)
if ok then
block[1] = header
blocks[#blocks+1] = block
end
block = {''}
end
in_block = false
Expand Down
29 changes: 2 additions & 27 deletions lua/gitsigns/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ end
--- @field yadm { enable: boolean }
--- @field worktrees {toplevel: string, gitdir: string}[]
--- @field word_diff boolean
--- @field keymaps table<string,string>
--- @field trouble boolean
--- -- Undocumented
--- @field _refresh_staged_on_update boolean
Expand Down Expand Up @@ -224,29 +223,6 @@ M.schema = {
]],
},

keymaps = {
deprecated = {
message = 'config.keymaps is now deprecated. Please define mappings in config.on_attach() instead.',
},
type = 'table',
default = {},
description = [[
Keymaps to set up when attaching to a buffer.
Each key in the table defines the mode and key (whitespace delimited)
for the mapping and the value defines what the key maps to. The value
can be a table which can contain keys matching the options defined in
|map-arguments| which are: `expr`, `noremap`, `nowait`, `script`, `silent`
and `unique`. These options can also be used in the top level of the
table to define default options for all mappings.
Since this field is not extended (unlike |gitsigns-config-signs|),
mappings defined in this field can be disabled by setting the whole field
to `{}`, and |gitsigns-config-on_attach| can instead be used to define
mappings.
]],
},

worktrees = {
type = 'table',
default = nil,
Expand Down Expand Up @@ -294,9 +270,8 @@ M.schema = {
type = 'function',
default = nil,
description = [[
Callback called when attaching to a buffer. Mainly used to setup keymaps
when `config.keymaps` is empty. The buffer number is passed as the first
argument.
Callback called when attaching to a buffer. Mainly used to setup keymaps.
The buffer number is passed as the first argument.
This callback can return `false` to prevent attaching to the buffer.
Expand Down
95 changes: 0 additions & 95 deletions lua/gitsigns/mappings.lua

This file was deleted.

26 changes: 15 additions & 11 deletions test/gs_helpers.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,13 @@ M.test_config = {
changedelete = {hl = 'DiffChange', text = '%'},
untracked = {hl = 'DiffChange', text = '#'},
},
keymaps = {
noremap = true,
buffer = true,
['n mhs'] = '<cmd>lua require"gitsigns".stage_hunk()<CR>',
['n mhu'] = '<cmd>lua require"gitsigns".undo_stage_hunk()<CR>',
['n mhr'] = '<cmd>lua require"gitsigns".reset_hunk()<CR>',
['n mhp'] = '<cmd>lua require"gitsigns".preview_hunk()<CR>',
['n mhS'] = '<cmd>lua require"gitsigns".stage_buffer()<CR>',
['n mhU'] = '<cmd>lua require"gitsigns".reset_buffer_index()<CR>',
on_attach = {
{'n', 'mhs', '<cmd>lua require"gitsigns".stage_hunk()<CR>'},
{'n', 'mhu', '<cmd>lua require"gitsigns".undo_stage_hunk()<CR>'},
{'n', 'mhr', '<cmd>lua require"gitsigns".reset_hunk()<CR>'},
{'n', 'mhp', '<cmd>lua require"gitsigns".preview_hunk()<CR>'},
{'n', 'mhS', '<cmd>lua require"gitsigns".stage_buffer()<CR>'},
{'n', 'mhU', '<cmd>lua require"gitsigns".reset_buffer_index()<CR>'},
},
update_debounce = 5,
}
Expand Down Expand Up @@ -225,12 +223,18 @@ function M.match_debug_messages(spec)
end)
end

local git_version

function M.setup_gitsigns(config, extra)
extra = extra or ''
exec_lua([[
local config = ...
if config and config.on_attach then
local maps = config.on_attach
config.on_attach = function(bufnr)
for _, map in ipairs(maps) do
vim.keymap.set(map[1], map[2], map[3], {buffer = bufnr})
end
end
end
]]..extra..[[
require('gitsigns').setup(...)
]], config)
Expand Down
2 changes: 1 addition & 1 deletion test/highlights_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ describe('highlights', function()
config.linehl = true
config._test_mode = true

exec_lua('gs.setup(...)', config)
setup_gitsigns(config)

expectf(function()
match_dag(debug_messages(), {
Expand Down

0 comments on commit 256569c

Please sign in to comment.