-
Notifications
You must be signed in to change notification settings - Fork 29
/
Copy pathsatellite.lua
91 lines (70 loc) · 2.12 KB
/
satellite.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
---@mod lean.satellite satellite.nvim integration
---@brief [[
--- A satellite.nvim progress handler.
---
--- See https://github.com/lewis6991/satellite.nvim/blob/main/HANDLERS.md
---@brief ]]
local has_satellite, satellite = pcall(require, 'satellite.handlers')
if not has_satellite then
return false
end
local async = require 'satellite.async'
local row_to_barpos = require('satellite.util').row_to_barpos
local progress = require 'lean.progress'
local SYMBOL = '│'
local HIGHLIGHT = 'leanProgressBar'
---@type Satellite.Handler
local handler = {
name = 'lean.nvim',
}
---@class Lean.SatelliteConfig: Satellite.Handlers.BaseConfig
local config = {
enable = true,
overlap = true,
priority = 20, -- cursor looks like 100
}
handler.config = config
local function setup_hl()
vim.api.nvim_set_hl(0, HIGHLIGHT, {
default = true,
fg = vim.api.nvim_get_hl(0, { name = 'NonText' }).fg,
})
end
---@param user_config Satellite.Handlers.CursorConfig
---@param update fun()
function handler.setup(user_config, update)
config = vim.tbl_deep_extend('force', config, user_config)
handler.config = config
local group = vim.api.nvim_create_augroup('LeanSatellite', {})
vim.api.nvim_create_autocmd('ColorScheme', {
group = group,
callback = setup_hl,
})
setup_hl()
vim.api.nvim_create_autocmd('User', {
pattern = progress.AUTOCMD,
group = group,
callback = update,
})
end
function handler.update(bufnr, winid)
local marks = {} ---@type Satellite.Mark[]
local infos = progress.proc_infos[vim.uri_from_bufnr(bufnr)] or {}
local pred = async.winbuf_pred(bufnr, winid)
for _, info in async.ipairs(infos or {}, pred) do
local min_lnum = math.max(1, info.range.start.line)
local min_pos = row_to_barpos(winid, min_lnum - 1)
local max_lnum = math.max(1, info.range['end'].line + math.max(0, info.range.start.line - 1))
local max_pos = row_to_barpos(winid, max_lnum - 1)
for pos = min_pos, max_pos do
marks[#marks + 1] = {
pos = pos,
symbol = SYMBOL,
highlight = HIGHLIGHT,
}
end
end
return marks
end
satellite.register(handler)
return true