Skip to content

Commit

Permalink
fix: better typing of setup()
Browse files Browse the repository at this point in the history
  • Loading branch information
lewis6991 committed Sep 25, 2023
1 parent 6edf360 commit 6795de0
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lua/treesitter-context.lua
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ end

local did_init = false

---@param options? TSContext.Config
---@param options? TSContext.UserConfig
function M.setup(options)
if options then
config.update(options)
Expand Down
39 changes: 35 additions & 4 deletions lua/treesitter-context/config.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

--- @class TSContext.Config
--- @class (exact) TSContext.Config
--- @field enable boolean
--- @field max_lines integer
--- @field min_window_height integer
Expand All @@ -11,23 +11,54 @@
--- @field separator? string
--- @field on_attach? fun(buf: integer): boolean

--- @class (exact) TSContext.UserConfig : TSContext.Config
---
--- Enable this plugin (Can be enabled/disabled later via commands)
--- @field enable? boolean
---
--- How many lines the window should span. Values <= 0 mean no limit.
--- @field max_lines? integer
---
--- Minimum editor window height to enable context. Values <= 0 mean no limit.
--- @field min_window_height? integer
---
--- @field line_numbers? boolean
---
--- Maximum number of lines to show for a single context
--- @field multiline_threshold? integer
---
--- Which context lines to discard if `max_lines` is exceeded.
--- @field trim_scope? 'outer'|'inner'
---
--- @field zindex? integer
---
--- Line used to calculate context.
--- @field mode? 'cursor'|'topline'
---
--- Separator between context and content. Should be a single character string, like '-'.
--- When separator is set, the context will only show up when there are at least 2 lines above cursorline.
--- @field separator? string
---
--- Callback when attaching. Return false to disable attaching
--- @field on_attach? fun(buf: integer): boolean

--- @type TSContext.Config
local default_config = {
enable = true,
max_lines = 0, -- no limit
min_window_height = 0,
line_numbers = true,
multiline_threshold = 20, -- Maximum number of lines to show for a single context
trim_scope = 'outer', -- Which context lines to discard if `max_lines` is exceeded. Choices: 'inner', 'outer'
multiline_threshold = 20,
trim_scope = 'outer',
zindex = 20,
mode = 'cursor',
}

--- @type TSContext.Config
local config = vim.deepcopy(default_config)

local M = {}

--- @param cfg TSContext.UserConfig
function M.update(cfg)
config = vim.tbl_deep_extend('force', config, cfg)
end
Expand Down

0 comments on commit 6795de0

Please sign in to comment.