|
4 | 4 |
|
5 | 5 | local uv = vim.uv
|
6 | 6 |
|
7 |
| ----@return string |
8 |
| -local function get_buf_text() |
9 |
| - local bufnr = vim.api.nvim_get_current_buf() |
| 7 | +--- @param bufnr integer |
| 8 | +--- @return string |
| 9 | +local function get_buf_text(bufnr) |
10 | 10 | local lines = vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
|
11 | 11 |
|
12 | 12 | -- exclude word under the cursor
|
@@ -62,19 +62,38 @@ local function run_async(buf_text, callback)
|
62 | 62 | worker:queue(buf_text)
|
63 | 63 | end
|
64 | 64 |
|
| 65 | +--- @class blink.cmp.BufferOpts |
| 66 | +--- @field get_bufnrs fun(): integer[] |
| 67 | + |
65 | 68 | --- Public API
|
66 | 69 |
|
67 |
| ---- @class blink.cmp.Source |
68 | 70 | local buffer = {}
|
69 | 71 |
|
70 |
| -function buffer.new() return setmetatable({}, { __index = buffer }) end |
| 72 | +function buffer.new(opts) |
| 73 | + opts = opts or {} ---@type blink.cmp.BufferOpts |
| 74 | + local self = setmetatable({}, { __index = buffer }) |
| 75 | + self.get_bufnrs = opts.get_bufnrs |
| 76 | + or function() |
| 77 | + return vim |
| 78 | + .iter(vim.api.nvim_list_wins()) |
| 79 | + :map(function(win) return vim.api.nvim_win_get_buf(win) end) |
| 80 | + :filter(function(buf) return vim.bo[buf].buftype ~= 'nofile' end) |
| 81 | + :totable() |
| 82 | + end |
| 83 | + return self |
| 84 | +end |
71 | 85 |
|
72 | 86 | function buffer:get_completions(_, callback)
|
73 | 87 | local transformed_callback = function(items)
|
74 | 88 | callback({ is_incomplete_forward = false, is_incomplete_backward = false, items = items })
|
75 | 89 | end
|
76 | 90 |
|
77 |
| - local buf_text = get_buf_text() |
| 91 | + local bufnrs = require('blink.cmp.lib.utils').deduplicate(self.get_bufnrs()) |
| 92 | + local buf_texts = {} |
| 93 | + for _, buf in ipairs(bufnrs) do |
| 94 | + table.insert(buf_texts, get_buf_text(buf)) |
| 95 | + end |
| 96 | + local buf_text = table.concat(buf_texts, '\n') |
78 | 97 | -- should take less than 2ms
|
79 | 98 | if #buf_text < 20000 then
|
80 | 99 | run_sync(buf_text, transformed_callback)
|
|
0 commit comments