summaryrefslogtreecommitdiff
path: root/lua/telescope/from_entry.lua
blob: 572a244d4d8fd4e3d90d49b34fe52c69a4a89b02 (plain)
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
--[[ =============================================================================

Get metadata from entries.

This file is still WIP, so expect some changes if you're trying to consume these APIs.

This will provide standard mechanism for accessing information from an entry.

--============================================================================= ]]

local from_entry = {}

function from_entry.path(entry, validate, escape)
  escape = vim.F.if_nil(escape, true)
  local path
  if escape then
    path = entry.path and vim.fn.fnameescape(entry.path) or nil
  else
    path = entry.path
  end

  if path == nil then
    path = entry.filename
  end
  if path == nil then
    path = entry.value
  end
  if path == nil then
    require("telescope.log").error(string.format("Invalid Entry: '%s'", vim.inspect(entry)))
    return
  end

  if validate and not vim.fn.filereadable(path) then
    return
  end

  return path
end

return from_entry