This commit is contained in:
Rob Pilling 2024-04-28 16:00:44 +01:00 committed by GitHub
commit 9feaab78f5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View File

@ -377,4 +377,16 @@ function buffer.get_words_distances(self, cursor_row)
return self.words_distances
end
--@return name of buffer (maybe shortened), if file, otherwise buffer number
function buffer.description(self, short)
local name = vim.fn.bufname(self.bufnr)
if name then
if short then
return name:match("[^/]*$")
end
return name
end
return ("<buf %d>"):format(self.bufnr)
end
return buffer

View File

@ -7,6 +7,7 @@ local buffer = require('cmp_buffer.buffer')
---@field public indexing_batch_size number
---@field public indexing_interval number
---@field public max_indexed_line_length number
---@field public show_source boolean
---@type cmp_buffer.Options
local defaults = {
@ -18,6 +19,7 @@ local defaults = {
indexing_batch_size = 1000,
indexing_interval = 100,
max_indexed_line_length = 1024 * 40,
show_source = false,
}
local source = {}
@ -37,6 +39,7 @@ source._validate_options = function(_, params)
get_bufnrs = { opts.get_bufnrs, 'function' },
indexing_batch_size = { opts.indexing_batch_size, 'number' },
indexing_interval = { opts.indexing_interval, 'number' },
show_source = { opts.show_source, 'boolean' },
})
return opts
end
@ -70,6 +73,10 @@ source.complete = function(self, params, callback)
table.insert(items, {
label = word,
dup = 0,
labelDetails = opts.show_source and {
description = buf:description(true),
},
detail = opts.show_source and buf:description(),
})
end
end