mirror of
https://codeberg.org/FelipeLema/cmp-async-path
synced 2025-05-12 12:48:31 +00:00
misc
This commit is contained in:
parent
868f1206ff
commit
f3de33728e
@ -5,6 +5,10 @@ local PATH_REGEX = ([[\%(/PAT\+\)*\ze/PAT*]]):gsub('PAT', NAME_REGEX)
|
|||||||
|
|
||||||
local source = {}
|
local source = {}
|
||||||
|
|
||||||
|
local defaults = {
|
||||||
|
max_lines = 10,
|
||||||
|
}
|
||||||
|
|
||||||
source.new = function()
|
source.new = function()
|
||||||
return setmetatable({}, { __index = source })
|
return setmetatable({}, { __index = source })
|
||||||
end
|
end
|
||||||
@ -82,13 +86,14 @@ source._stat = function(_, path)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local function lines_from(file, count)
|
local function lines_from(file, count)
|
||||||
lines = {}
|
lines = {'```'}
|
||||||
for line in io.lines(file) do
|
for line in io.lines(file) do
|
||||||
lines[#lines + 1] = line
|
lines[#lines + 1] = line
|
||||||
if count ~= nil and #lines >= count then
|
if count ~= nil and #lines >= count then
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
lines[#lines + 1] = '```'
|
||||||
return lines
|
return lines
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -149,7 +154,7 @@ source._candidates = function(_, context, dirname, offset, callback)
|
|||||||
filterText = '/' .. name,
|
filterText = '/' .. name,
|
||||||
insertText = '/' .. name,
|
insertText = '/' .. name,
|
||||||
kind = cmp.lsp.CompletionItemKind.File,
|
kind = cmp.lsp.CompletionItemKind.File,
|
||||||
path = dirname .. '/' .. name,
|
data = {path = dirname .. '/' .. name},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -159,7 +164,7 @@ source._candidates = function(_, context, dirname, offset, callback)
|
|||||||
filterText = '/' .. name,
|
filterText = '/' .. name,
|
||||||
insertText = '/' .. name,
|
insertText = '/' .. name,
|
||||||
kind = cmp.lsp.CompletionItemKind.File,
|
kind = cmp.lsp.CompletionItemKind.File,
|
||||||
path = dirname .. '/' .. name,
|
data = {path = dirname .. '/' .. name},
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -178,7 +183,7 @@ end
|
|||||||
|
|
||||||
function source:resolve(completion_item, callback)
|
function source:resolve(completion_item, callback)
|
||||||
if completion_item.kind == cmp.lsp.CompletionItemKind.File then
|
if completion_item.kind == cmp.lsp.CompletionItemKind.File then
|
||||||
completion_item.documentation = try_get_lines(completion_item.path, 10)
|
completion_item.documentation = try_get_lines(completion_item.data.path, 10)
|
||||||
end
|
end
|
||||||
callback(completion_item)
|
callback(completion_item)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user