summaryrefslogtreecommitdiff
path: root/lua/telescope/make_entry.lua
blob: bd1bf730c49286ced63f01db482ecbbe6a20a886 (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
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
local has_devicons, devicons = pcall(require, 'nvim-web-devicons')

local conf = require('telescope.config').values
local entry_display = require('telescope.pickers.entry_display')
local path = require('telescope.path')
local utils = require('telescope.utils')

local get_default = utils.get_default

local treesitter_type_highlight = {
  ["associated"] = "TSConstant",
  ["constant"]   = "TSConstant",
  ["field"]      = "TSField",
  ["function"]   = "TSFunction",
  ["method"]     = "TSMethod",
  ["parameter"]  = "TSParameter",
  ["property"]   = "TSProperty",
  ["struct"]     = "Struct",
  ["var"]        = "TSVariableBuiltin",
}

local lsp_type_highlight = {
  ["Class"]    = "TelescopeResultsClass",
  ["Constant"] = "TelescopeResultsConstant",
  ["Field"]    = "TelescopeResultsField",
  ["Function"] = "TelescopeResultsFunction",
  ["Method"]   = "TelescopeResultsMethod",
  ["Property"] = "TelescopeResultsOperator",
  ["Struct"]   = "TelescopeResultsStruct",
  ["Variable"] = "TelescopeResultsVariable",
}

local make_entry = {}

local transform_devicons
local get_devicons
if has_devicons then
  if not devicons.has_loaded() then
    devicons.setup()
  end

  transform_devicons = function(filename, display, disable_devicons)
    if disable_devicons or not filename then
      return display
    end

    local icon, icon_highlight = devicons.get_icon(filename, string.match(filename, '%a+$'), { default = true })
    local icon_display = (icon or ' ') .. ' ' .. display

    if conf.color_devicons then
      return icon_display, icon_highlight
    else
      return icon_display
    end
  end

  get_devicons = function(filename, disable_devicons)
    if disable_devicons or not filename then
      return ''
    end

    local icon, icon_highlight = devicons.get_icon(filename, string.match(filename, '%a+$'), { default = true })
    if conf.color_devicons then
      return icon, icon_highlight
    else
      return icon
    end
  end
else
  transform_devicons = function(_, display, _)
    return display
  end

  get_devicons = function(_, _)
    return ''
  end
end

do
  local lookup_keys = {
    display = 1,
    ordinal = 1,
    value = 1,
  }

  local mt_string_entry = {
    __index = function(t, k)
      return rawget(t, rawget(lookup_keys, k))
    end
  }

  function make_entry.gen_from_string()
    return function(line)
      return setmetatable({
        line,
      }, mt_string_entry)
    end
  end
end

do
  local lookup_keys = {
    ordinal = 1,
    value = 1,
    filename = 1,
    cwd = 2,
  }

  function make_entry.gen_from_file(opts)
    opts = opts or {}

    local cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd())

    local disable_devicons = opts.disable_devicons
    local shorten_path = opts.shorten_path

    local mt_file_entry = {}

    mt_file_entry.cwd = cwd
    mt_file_entry.display = function(entry)
      local hl_group
      local display = path.make_relative(entry.value, cwd)
      if shorten_path then
        display = utils.path_shorten(display)
      end

      display, hl_group = transform_devicons(entry.value, display, disable_devicons)

      if hl_group then
        return display, { { {1, 3}, hl_group } }
      else
        return display
      end
    end

    mt_file_entry.__index = function(t, k)
      local raw = rawget(mt_file_entry, k)
      if raw then return raw end

      if k == "path" then
        local retpath = t.cwd .. path.separator .. t.value
        if not vim.loop.fs_access(retpath, "R", nil) then
          retpath = t.value
        end
        return retpath
      end

      return rawget(t, rawget(lookup_keys, k))
    end

    return function(line)
      return setmetatable({line}, mt_file_entry)
    end
  end
end

do
  local lookup_keys = {
    value = 1,
    ordinal = 1,
  }

  -- Gets called only once to parse everything out for the vimgrep, after that looks up directly.
  local parse = function(t)
    local _, _, filename, lnum, col, text = string.find(t.value, [[([^:]+):(%d+):(%d+):(.*)]])

    local ok
    ok, lnum = pcall(tonumber, lnum)
    if not ok then lnum = nil end

    ok, col = pcall(tonumber, col)
    if not ok then col = nil end

    t.filename = filename
    t.lnum = lnum
    t.col = col
    t.text = text

    return {filename, lnum, col, text}
  end

  --- Special options:
  ---  - shorten_path: make the path appear short
  ---  - disable_coordinates: Don't show the line & row numbers
  ---  - only_sort_text: Only sort via the text. Ignore filename and other items
  function make_entry.gen_from_vimgrep(opts)
    local mt_vimgrep_entry

    opts = opts or {}

    local disable_devicons = opts.disable_devicons
    local shorten_path = opts.shorten_path
    local disable_coordinates = opts.disable_coordinates
    local only_sort_text = opts.only_sort_text

    local execute_keys = {
      path = function(t)
        return t.cwd .. path.separator .. t.filename, false
      end,

      filename = function(t)
        return parse(t)[1], true
      end,

      lnum = function(t)
        return parse(t)[2], true
      end,

      col = function(t)
        return parse(t)[3], true
      end,

      text = function(t)
        return parse(t)[4], true
      end,
    }

    -- For text search only, the ordinal value is actually the text.
    if only_sort_text then
      execute_keys.ordinal = function(t)
        return t.text
      end
    end

    local display_string = "%s:%s%s"

    mt_vimgrep_entry = {
      cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd()),

      display = function(entry)
        local display_filename
        if shorten_path then
          display_filename = utils.path_shorten(entry.filename)
        else
          display_filename = entry.filename
        end

        local coordinates = ""
        if not disable_coordinates then
          coordinates = string.format("%s:%s:", entry.lnum, entry.col)
        end

        local display, hl_group = transform_devicons(
          entry.filename,
          string.format(display_string, display_filename,  coordinates, entry.text),
          disable_devicons
        )

        if hl_group then
          return display, { { {1, 3}, hl_group } }
        else
          return display
        end
      end,

      __index = function(t, k)
        local raw = rawget(mt_vimgrep_entry, k)
        if raw then return raw end

        local executor = rawget(execute_keys, k)
        if executor then
          local val, save = executor(t)
          if save then rawset(t, k, val) end
          return val
        end

        return rawget(t, rawget(lookup_keys, k))
      end,
    }

    return function(line)
      return setmetatable({line}, mt_vimgrep_entry)
    end
  end
end

function make_entry.gen_from_git_commits()
  local displayer = entry_display.create {
    separator = " ",
    items = {
      { width = 8 },
      { remaining = true }
      }
    }

  local make_display = function(entry)
    return displayer {
      {entry.value, "TelescopeResultsIdentifier"},
      entry.msg
    }
  end

  return function(entry)
    if entry == "" then
      return nil
    end

    local sha, msg = string.match(entry, '([^ ]+) (.+)')

    return {
      value = sha,
      ordinal = sha .. ' ' .. msg,
      msg = msg,
      display = make_display
    }
  end
end

function make_entry.gen_from_quickfix(opts)
  opts = opts or {}
  opts.tail_path = get_default(opts.tail_path, true)

  local displayer = entry_display.create {
    separator = "▏",
    items = {
      { width = 8 },
      { width = 50 },
      { remaining = true }
    }
  }

  local make_display = function(entry)
    local filename
    if not opts.hide_filename then
      filename = entry.filename
      if opts.tail_path then
        filename = utils.path_tail(filename)
      elseif opts.shorten_path then
        filename = utils.path_shorten(filename)
      end
    end

    local line_info = {table.concat({entry.lnum, entry.col}, ":"), "TelescopeResultsLineNr"}

    return displayer {
      line_info,
      entry.text:gsub(".* | ", ""),
      filename,
    }
  end

  return function(entry)
    local filename = entry.filename or vim.api.nvim_buf_get_name(entry.bufnr)

    return {
      valid = true,

      value = entry,
      ordinal = (
        not opts.ignore_filename and filename
        or ''
        ) .. ' ' .. entry.text,
      display = make_display,

      filename = filename,
      lnum = entry.lnum,
      col = entry.col,
      text = entry.text,
      start = entry.start,
      finish = entry.finish,
    }
  end
end

function make_entry.gen_from_lsp_symbols(opts)
  opts = opts or {}
  local bufnr = opts.bufnr or vim.api.nvim_get_current_buf()

  local display_items = {
    { width = 25 },       -- symbol
    { width = 8 },        -- symbol type
    { remaining = true }, -- filename{:optional_lnum+col} OR content preview
  }

  if opts.ignore_filename and opts.show_line then
    table.insert(display_items, 2, { width = 6 })
  end

  local displayer = entry_display.create {
    separator = " ",
    hl_chars = { ['['] = 'TelescopeBorder', [']'] = 'TelescopeBorder' },
    items = display_items
  }

  local make_display = function(entry)
    local msg

    -- what to show in the last column: filename or symbol information
    if opts.ignore_filename then -- ignore the filename and show line preview instead
      -- TODO: fixme - if ignore_filename is set for workspace, bufnr will be incorrect
      msg = vim.api.nvim_buf_get_lines(
          bufnr,
          entry.lnum - 1,
          entry.lnum,
          false
        )[1] or ''
      msg = vim.trim(msg)
    else
      local filename = ""
      opts.tail_path = get_default(opts.tail_path, true)

      if not opts.hide_filename then -- hide the filename entirely
        filename = entry.filename
        if opts.tail_path then
          filename = utils.path_tail(filename)
        elseif opts.shorten_path then
          filename = utils.path_shorten(filename)
        end
      end

      if opts.show_line then -- show inline line info
        filename = filename .. " [" ..entry.lnum .. ":" .. entry.col .. "]"
      end
      msg = filename
    end

    local type_highlight = opts.symbol_highlights or lsp_type_highlight
    local display_columns = {
      entry.symbol_name,
      {entry.symbol_type:lower(), type_highlight[entry.symbol_type], type_highlight[entry.symbol_type]},
      msg,
    }

    if opts.ignore_filename and opts.show_line then
      table.insert(display_columns, 2, {entry.lnum .. ":" .. entry.col, "TelescopeResultsLineNr"})
    end

    return displayer(display_columns)
  end

  return function(entry)
    local filename = entry.filename or vim.api.nvim_buf_get_name(entry.bufnr)
    local symbol_msg = entry.text:gsub(".* | ", "")
    local symbol_type, symbol_name = symbol_msg:match("%[(.+)%]%s+(.*)")

    local ordinal = ""
    if not opts.ignore_filename and filename then
      ordinal = filename .. " "
    end
    ordinal = ordinal ..  symbol_name .. " " .. symbol_type
    return {
      valid = true,

      value = entry,
      ordinal = ordinal,
      display = make_display,

      filename = filename,
      lnum = entry.lnum,
      col = entry.col,
      symbol_name = symbol_name,
      symbol_type = symbol_type,
      start = entry.start,
      finish = entry.finish,
    }
  end
end

function make_entry.gen_from_buffer(opts)
  opts = opts or {}

  local disable_devicons = opts.disable_devicons

  local icon_width = 0
  if not disable_devicons then
    icon_width = vim.fn.strdisplaywidth(get_devicons('fname', disable_devicons))
  end

  local displayer = entry_display.create {
    separator = " ",
    items = {
      { width = opts.bufnr_width },
      { width = 4 },
      { width = icon_width },
      { remaining = true },
    },
  }

  local cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd())

  local make_display = function(entry)
    local display_bufname
    if opts.shorten_path then
      display_bufname = path.shorten(entry.filename)
    else
      display_bufname = entry.filename
    end

    local icon, hl_group = get_devicons(entry.filename, disable_devicons)

    return displayer {
      {entry.bufnr, "TelescopeResultsNumber"},
      {entry.indicator, "TelescopeResultsComment"},
      { icon, hl_group },
      display_bufname .. ":" .. entry.lnum
      }
  end

  return function(entry)
    local bufname = entry.info.name ~= "" and entry.info.name or '[No Name]'
    -- if bufname is inside the cwd, trim that part of the string
    bufname = path.normalize(bufname, cwd)

    local hidden = entry.info.hidden == 1 and 'h' or 'a'
    local readonly = vim.api.nvim_buf_get_option(entry.bufnr, 'readonly') and '=' or ' '
    local changed = entry.info.changed == 1 and '+' or ' '
    local indicator = entry.flag .. hidden .. readonly .. changed

    return {
      valid = true,

      value = bufname,
      ordinal = entry.bufnr .. " : " .. bufname,
      display = make_display,

      bufnr = entry.bufnr,
      filename = bufname,

      lnum = entry.info.lnum ~= 0 and entry.info.lnum or 1,
      indicator = indicator,
    }
  end
end

function make_entry.gen_from_treesitter(opts)
  opts = opts or {}

  local bufnr = opts.bufnr or vim.api.nvim_get_current_buf()

  local display_items = {
    { width = 25 },
    { width = 10 },
    { remaining = true },
  }

  if opts.show_line then
    table.insert(display_items, 2, { width = 6 })
  end

  local displayer = entry_display.create {
    separator = " ",
    items = display_items,
  }

  local type_highlight = opts.symbol_highlights or treesitter_type_highlight

  local make_display = function(entry)
    local msg = vim.api.nvim_buf_get_lines(
      bufnr,
      entry.lnum,
      entry.lnum,
      false
      )[1] or ''
    msg = vim.trim(msg)

    local display_columns = {
      entry.text,
      {entry.kind, type_highlight[entry.kind], type_highlight[entry.kind]},
      msg
    }
    if opts.show_line then
      table.insert(display_columns, 2, {entry.lnum .. ":" .. entry.col, "TelescopeResultsLineNr"})
    end

    return displayer(display_columns)
  end

  return function(entry)
    local ts_utils = require('nvim-treesitter.ts_utils')
    local start_row, start_col, end_row, _ = ts_utils.get_node_range(entry.node)
    local node_text = ts_utils.get_node_text(entry.node)[1]
    return {
      valid = true,

      value = entry.node,
      kind = entry.kind,
      ordinal = node_text .. " " .. entry.kind,
      display = make_display,

      node_text = node_text,

      filename = vim.api.nvim_buf_get_name(bufnr),
      -- need to add one since the previewer substacts one
      lnum = start_row + 1,
      col = start_col,
      text = node_text,
      start = start_row,
      finish = end_row
    }
  end
end

function make_entry.gen_from_packages(opts)
  opts = opts or {}

  local make_display = function(module_name)
    local p_path = package.searchpath(module_name, package.path) or ""
    local display = string.format("%-" .. opts.column_len .. "s : %s", module_name, vim.fn.fnamemodify(p_path, ":~:."))

    return display
  end

  return function(module_name)
    local entry = {
      valid = module_name ~= "",
      value = module_name,
      ordinal = module_name,
    }
    entry.display = make_display(module_name)

    return entry
  end
end

function make_entry.gen_from_apropos()
  local displayer = entry_display.create {
    separator = "",
    items = {
      { width = 30 },
      { remaining = true },
    },
  }

  local make_display = function(entry)
    return displayer {
      entry.value,
      entry.description
    }
  end

  return function(line)
    local cmd, _, desc = line:match("^(.*)%s+%((.*)%)%s+%-%s(.*)$")

    return {
      value = cmd,
      description = desc,
      ordinal = cmd,
      display = make_display,
    }
  end
end

function make_entry.gen_from_marks(_)
  return function(line)
    local split_value = utils.max_split(line, "%s+", 4)

    local mark_value = split_value[1]
    local cursor_position = vim.fn.getpos("'" .. mark_value)

    return {
      value = line,
      ordinal = line,
      display = line,
      lnum = cursor_position[2],
      col = cursor_position[3],
      start = cursor_position[2],
      filename = vim.api.nvim_buf_get_name(cursor_position[1])
    }
  end
end

function make_entry.gen_from_registers(_)
  local displayer = entry_display.create {
    separator = " ",
    hl_chars = { ['['] = 'TelescopeBorder', [']'] = 'TelescopeBorder' },
    items = {
      { width = 3 },
      { remaining = true },
    },
  }

  local make_display = function(entry)
    return displayer {
      {'[' .. entry.value .. ']', "TelescopeResultsNumber"},
      entry.content,
    }
  end

  return function(entry)
    return {
      valid = true,
      value = entry,
      ordinal = entry,
      content = vim.fn.getreg(entry),
      display = make_display
    }
  end
end

function make_entry.gen_from_highlights()
  local make_display = function(entry)
    local display = entry.value
    return display, { { { 0, #display }, display } }
  end

  return function(entry)
    return {
      value = entry,
      display = make_display,
      ordinal = entry,
    }
  end
end

function make_entry.gen_from_vimoptions()
  local process_one_opt = function(o)
    local ok, value_origin

    local option = {
      name          = "",
      description   = "",
      current_value = "",
      default_value = "",
      value_type    = "",
      set_by_user   = false,
      last_set_from = "",
    }

    local is_global = false
    for _, v in ipairs(o.scope) do
      if v == "global" then
        is_global = true
      end
    end

    if not is_global then
      return
    end

    if is_global then
      option.name = o.full_name

      ok, option.current_value = pcall(vim.api.nvim_get_option, o.full_name)
      if not ok then
        return
      end

      local str_funcname = o.short_desc()
      option.description = assert(loadstring(str_funcname))()
      -- if #option.description > opts.desc_col_length then
      --   opts.desc_col_length = #option.description
      -- end

      if o.defaults ~= nil then
        option.default_value = o.defaults.if_true.vim or o.defaults.if_true.vi
      end

      if type(option.default_value) == "function" then
        option.default_value = "Macro: " .. option.default_value()
      end

      option.value_type = (type(option.current_value) == "boolean" and "bool" or type(option.current_value))

      if option.current_value ~= option.default_value then
        option.set_by_user = true
        value_origin = vim.fn.execute("verbose set " .. o.full_name .. "?")
        if string.match(value_origin, "Last set from") then
          -- TODO: parse file and line number as separate items
          option.last_set_from = value_origin:gsub("^.*Last set from ", "")
        end
      end

      return option
    end
  end

  local displayer = entry_display.create {
    separator = "",
    hl_chars = { ['['] = 'TelescopeBorder', [']'] = 'TelescopeBorder' },
    items = {
      { width = 25 },
      { width = 12 },
      { remaining = true },
    },
  }

  local make_display = function(entry)

    return displayer {
      {entry.name, "Keyword"},
      {"["..entry.value_type.."]", "Type"},
      utils.display_termcodes(tostring(entry.current_value)),
      entry.description,
    }
  end

  return function(line)
    local entry = process_one_opt(line)
    if not entry then
      return
    end

    entry.valid   = true
    entry.display = make_display
    entry.value   = line
    entry.ordinal = line.full_name
    -- entry.raw_value = d.raw_value
    -- entry.last_set_from = d.last_set_from

    return entry
  end
end

function make_entry.gen_from_ctags(opts)
  opts = opts or {}

  local cwd = vim.fn.expand(opts.cwd or vim.fn.getcwd())
  local current_file = path.normalize(vim.fn.expand('%'), cwd)

  local display_items = {
    { width = 30 },
    { remaining = true },
  }

  if opts.show_line then
    table.insert(display_items, 2, { width = 30 })
  end

  local displayer = entry_display.create {
    separator = " │ ",
    items = display_items,
  }

  local make_display = function(entry)
    local filename
    if not opts.hide_filename then
      if opts.shorten_path then
        filename = path.shorten(entry.filename)
      else
        filename = entry.filename
      end
    end

    local scode
    if opts.show_line then
      scode = entry.scode
    end

    return displayer {
      filename,
      entry.tag,
      scode,
    }
  end

  return function(line)
    if line == '' or line:sub(1, 1) == '!' then
      return nil
    end

    local tag, file, scode, lnum
    -- ctags gives us: 'tags\tfile\tsource'
    tag, file, scode = string.match(line, '([^\t]+)\t([^\t]+)\t/^\t?(.*)/;"\t+.*')
    if not tag then
      -- hasktags gives us: 'tags\tfile\tlnum'
      tag, file, lnum  = string.match(line, '([^\t]+)\t([^\t]+)\t(%d+).*')
    end

    if opts.only_current_file and file ~= current_file then
      return nil
    end

    return {
      valid = true,

      ordinal = file .. ': ' .. tag,
      display = make_display,
      scode = scode,
      tag = tag,

      filename = file,

      col = 1,
      lnum = lnum and tonumber(lnum) or 1,
    }
  end
end

function make_entry.gen_from_autocommands(_)
  local displayer = entry_display.create {
    separator = "▏",
    items = {
      { width = 14 },
      { width = 18 },
      { width = 16 },
      { remaining = true },
    },
  }

  local make_display = function(entry)
    return displayer {
      {entry.event, "vimAutoEvent"},
      {entry.group , "vimAugroup"},
      {entry.ft_pattern, "vimAutoCmdSfxList"},
      entry.command
    }
  end

  -- TODO: <action> dump current filtered items to buffer
  return function(entry)
    return {
      event      = entry.event,
      group      = entry.group,
      ft_pattern = entry.ft_pattern,
      command    = entry.command,
      value      = string.format("+%d %s", entry.source_lnum, entry.source_file),
      source_file = entry.source_file,
      source_lnum = entry.source_lnum,
      --
      valid = true,
      ordinal = entry.event .. " "  .. entry.group .. " " .. entry.ft_pattern .. " " .. entry.command,
      display = make_display,
    }
  end
end

function make_entry.gen_from_git_status(_)
  local displayer = entry_display.create {
  separator = " ",
  items = {
      { width = 1},
      { width = 1},
      { remaining = true },
    }
  }

  local make_display = function(entry)
    local modified = "TelescopeResultsDiffChange"
    local staged = "TelescopeResultsDiffAdd"

    if entry.status == "??" then
      modified = "TelescopeResultsDiffDelete"
      staged = "TelescopeResultsDiffDelete"
    end

    return displayer {
      { string.sub(entry.status, 1, 1), staged},
      { string.sub(entry.status, -1), modified},
      entry.value,
    }
  end

  return function (entry)
    if entry == '' then return nil end
    local mod, file = string.match(entry, '(..).*%s[->%s]?(.+)')
      return {
        value = file,
        status = mod,
        ordinal = entry,
        display = make_display,
      }
  end
end


return make_entry