refactor: make_entry more consistent (#1410)
drops `ignore_filename`, use `path_display= { "hidden" }`
Co-authored-by: Simon Hauser <Simon-Hauser@outlook.de>
This commit is contained in:
committed by
Simon Hauser
parent
3f1f5b7e52
commit
838c32d6a8
@@ -1195,9 +1195,11 @@ builtin.quickfix({opts}) *telescope.builtin.quickfix()*
|
|||||||
{opts} (table) options to pass to the picker
|
{opts} (table) options to pass to the picker
|
||||||
|
|
||||||
Options: ~
|
Options: ~
|
||||||
{ignore_filename} (boolean) dont show filenames (default: true)
|
{show_line} (boolean) show results text (default: true)
|
||||||
{trim_text} (boolean) trim results text (default: false)
|
{trim_text} (boolean) trim results text (default: false)
|
||||||
{nr} (number) specify the quickfix list number
|
{fname_width} (number) defines the width of the filename section
|
||||||
|
(default: 30)
|
||||||
|
{nr} (number) specify the quickfix list number
|
||||||
|
|
||||||
|
|
||||||
builtin.quickfixhistory({opts}) *telescope.builtin.quickfixhistory()*
|
builtin.quickfixhistory({opts}) *telescope.builtin.quickfixhistory()*
|
||||||
@@ -1219,8 +1221,10 @@ builtin.loclist({opts}) *telescope.builtin.loclist()*
|
|||||||
{opts} (table) options to pass to the picker
|
{opts} (table) options to pass to the picker
|
||||||
|
|
||||||
Options: ~
|
Options: ~
|
||||||
{ignore_filename} (boolean) dont show filenames (default: true)
|
{show_line} (boolean) show results text (default: true)
|
||||||
{trim_text} (boolean) trim results text (default: false)
|
{trim_text} (boolean) trim results text (default: false)
|
||||||
|
{fname_width} (number) defines the width of the filename section
|
||||||
|
(default: 30)
|
||||||
|
|
||||||
|
|
||||||
builtin.oldfiles({opts}) *telescope.builtin.oldfiles()*
|
builtin.oldfiles({opts}) *telescope.builtin.oldfiles()*
|
||||||
@@ -1419,8 +1423,10 @@ builtin.tagstack({opts}) *telescope.builtin.tagstack()*
|
|||||||
{opts} (table) options to pass to the picker
|
{opts} (table) options to pass to the picker
|
||||||
|
|
||||||
Options: ~
|
Options: ~
|
||||||
{ignore_filename} (boolean) dont show filenames (default: true)
|
{show_line} (boolean) show results text (default: true)
|
||||||
{trim_text} (boolean) trim results text (default: false)
|
{trim_text} (boolean) trim results text (default: false)
|
||||||
|
{fname_width} (number) defines the width of the filename section
|
||||||
|
(default: 30)
|
||||||
|
|
||||||
|
|
||||||
builtin.jumplist({opts}) *telescope.builtin.jumplist()*
|
builtin.jumplist({opts}) *telescope.builtin.jumplist()*
|
||||||
@@ -1431,8 +1437,10 @@ builtin.jumplist({opts}) *telescope.builtin.jumplist()*
|
|||||||
{opts} (table) options to pass to the picker
|
{opts} (table) options to pass to the picker
|
||||||
|
|
||||||
Options: ~
|
Options: ~
|
||||||
{ignore_filename} (boolean) dont show filenames (default: true)
|
{show_line} (boolean) show results text (default: true)
|
||||||
{trim_text} (boolean) trim results text (default: false)
|
{trim_text} (boolean) trim results text (default: false)
|
||||||
|
{fname_width} (number) defines the width of the filename section
|
||||||
|
(default: 30)
|
||||||
|
|
||||||
|
|
||||||
builtin.lsp_references({opts}) *telescope.builtin.lsp_references()*
|
builtin.lsp_references({opts}) *telescope.builtin.lsp_references()*
|
||||||
@@ -1449,6 +1457,8 @@ builtin.lsp_references({opts}) *telescope.builtin.lsp_references()*
|
|||||||
{include_current_line} (boolean) include current line (default:
|
{include_current_line} (boolean) include current line (default:
|
||||||
false)
|
false)
|
||||||
{trim_text} (boolean) trim results text (default: false)
|
{trim_text} (boolean) trim results text (default: false)
|
||||||
|
{fname_width} (number) defines the width of the filename
|
||||||
|
section (default: 30)
|
||||||
|
|
||||||
|
|
||||||
builtin.lsp_definitions({opts}) *telescope.builtin.lsp_definitions()*
|
builtin.lsp_definitions({opts}) *telescope.builtin.lsp_definitions()*
|
||||||
@@ -1460,11 +1470,12 @@ builtin.lsp_definitions({opts}) *telescope.builtin.lsp_definitions()*
|
|||||||
{opts} (table) options to pass to the picker
|
{opts} (table) options to pass to the picker
|
||||||
|
|
||||||
Options: ~
|
Options: ~
|
||||||
{jump_type} (string) how to goto definition if there is only
|
{jump_type} (string) how to goto definition if there is only one,
|
||||||
one, values: "tab", "split", "vsplit",
|
values: "tab", "split", "vsplit", "never"
|
||||||
"never"
|
{show_line} (boolean) show results text (default: true)
|
||||||
{ignore_filename} (boolean) dont show filenames (default: true)
|
{trim_text} (boolean) trim results text (default: false)
|
||||||
{trim_text} (boolean) trim results text (default: false)
|
{fname_width} (number) defines the width of the filename section
|
||||||
|
(default: 30)
|
||||||
|
|
||||||
|
|
||||||
builtin.lsp_type_definitions({opts}) *telescope.builtin.lsp_type_definitions()*
|
builtin.lsp_type_definitions({opts}) *telescope.builtin.lsp_type_definitions()*
|
||||||
@@ -1476,11 +1487,12 @@ builtin.lsp_type_definitions({opts}) *telescope.builtin.lsp_type_definitions()*
|
|||||||
{opts} (table) options to pass to the picker
|
{opts} (table) options to pass to the picker
|
||||||
|
|
||||||
Options: ~
|
Options: ~
|
||||||
{jump_type} (string) how to goto definition if there is only
|
{jump_type} (string) how to goto definition if there is only one,
|
||||||
one, values: "tab", "split", "vsplit",
|
values: "tab", "split", "vsplit", "never"
|
||||||
"never"
|
{show_line} (boolean) show results text (default: true)
|
||||||
{ignore_filename} (boolean) dont show filenames (default: true)
|
{trim_text} (boolean) trim results text (default: false)
|
||||||
{trim_text} (boolean) trim results text (default: false)
|
{fname_width} (number) defines the width of the filename section
|
||||||
|
(default: 30)
|
||||||
|
|
||||||
|
|
||||||
builtin.lsp_implementations({opts}) *telescope.builtin.lsp_implementations()*
|
builtin.lsp_implementations({opts}) *telescope.builtin.lsp_implementations()*
|
||||||
@@ -1492,11 +1504,13 @@ builtin.lsp_implementations({opts}) *telescope.builtin.lsp_implementations()*
|
|||||||
{opts} (table) options to pass to the picker
|
{opts} (table) options to pass to the picker
|
||||||
|
|
||||||
Options: ~
|
Options: ~
|
||||||
{jump_type} (string) how to goto implementation if there is
|
{jump_type} (string) how to goto implementation if there is only
|
||||||
only one, values: "tab", "split",
|
one, values: "tab", "split", "vsplit",
|
||||||
"vsplit", "never"
|
"never"
|
||||||
{ignore_filename} (boolean) dont show filenames (default: true)
|
{show_line} (boolean) show results text (default: true)
|
||||||
{trim_text} (boolean) trim results text (default: false)
|
{trim_text} (boolean) trim results text (default: false)
|
||||||
|
{fname_width} (number) defines the width of the filename section
|
||||||
|
(default: 30)
|
||||||
|
|
||||||
|
|
||||||
builtin.lsp_document_symbols({opts}) *telescope.builtin.lsp_document_symbols()*
|
builtin.lsp_document_symbols({opts}) *telescope.builtin.lsp_document_symbols()*
|
||||||
@@ -1510,8 +1524,6 @@ builtin.lsp_document_symbols({opts}) *telescope.builtin.lsp_document_symbols()*
|
|||||||
{opts} (table) options to pass to the picker
|
{opts} (table) options to pass to the picker
|
||||||
|
|
||||||
Options: ~
|
Options: ~
|
||||||
{ignore_filename} (boolean) dont show filenames (default:
|
|
||||||
true)
|
|
||||||
{show_line} (boolean) if true, shows the content of the
|
{show_line} (boolean) if true, shows the content of the
|
||||||
line the tag is found on (default:
|
line the tag is found on (default:
|
||||||
false)
|
false)
|
||||||
@@ -1534,8 +1546,6 @@ builtin.lsp_workspace_symbols({opts}) *telescope.builtin.lsp_workspace_symbols()
|
|||||||
Options: ~
|
Options: ~
|
||||||
{query} (string) for what to query the workspace
|
{query} (string) for what to query the workspace
|
||||||
(default: "")
|
(default: "")
|
||||||
{ignore_filename} (boolean) dont show filenames (default:
|
|
||||||
false)
|
|
||||||
{show_line} (boolean) if true, shows the content of the
|
{show_line} (boolean) if true, shows the content of the
|
||||||
line the tag is found on (default:
|
line the tag is found on (default:
|
||||||
false)
|
false)
|
||||||
@@ -1556,8 +1566,6 @@ builtin.lsp_dynamic_workspace_symbols({opts}) *telescope.builtin.lsp_dynamic_wor
|
|||||||
{opts} (table) options to pass to the picker
|
{opts} (table) options to pass to the picker
|
||||||
|
|
||||||
Options: ~
|
Options: ~
|
||||||
{ignore_filename} (boolean) dont show filenames (default:
|
|
||||||
false)
|
|
||||||
{show_line} (boolean) if true, shows the content of the
|
{show_line} (boolean) if true, shows the content of the
|
||||||
line the symbol is found on
|
line the symbol is found on
|
||||||
(default: false)
|
(default: false)
|
||||||
|
|||||||
@@ -245,8 +245,9 @@ builtin.commands = require_on_exported_call("telescope.builtin.internal").comman
|
|||||||
|
|
||||||
--- Lists items in the quickfix list, jumps to location on `<cr>`
|
--- Lists items in the quickfix list, jumps to location on `<cr>`
|
||||||
---@param opts table: options to pass to the picker
|
---@param opts table: options to pass to the picker
|
||||||
---@field ignore_filename boolean: dont show filenames (default: true)
|
---@field show_line boolean: show results text (default: true)
|
||||||
---@field trim_text boolean: trim results text (default: false)
|
---@field trim_text boolean: trim results text (default: false)
|
||||||
|
---@field fname_width number: defines the width of the filename section (default: 30)
|
||||||
---@field nr number: specify the quickfix list number
|
---@field nr number: specify the quickfix list number
|
||||||
builtin.quickfix = require_on_exported_call("telescope.builtin.internal").quickfix
|
builtin.quickfix = require_on_exported_call("telescope.builtin.internal").quickfix
|
||||||
|
|
||||||
@@ -257,8 +258,9 @@ builtin.quickfixhistory = require_on_exported_call("telescope.builtin.internal")
|
|||||||
|
|
||||||
--- Lists items from the current window's location list, jumps to location on `<cr>`
|
--- Lists items from the current window's location list, jumps to location on `<cr>`
|
||||||
---@param opts table: options to pass to the picker
|
---@param opts table: options to pass to the picker
|
||||||
---@field ignore_filename boolean: dont show filenames (default: true)
|
---@field show_line boolean: show results text (default: true)
|
||||||
---@field trim_text boolean: trim results text (default: false)
|
---@field trim_text boolean: trim results text (default: false)
|
||||||
|
---@field fname_width number: defines the width of the filename section (default: 30)
|
||||||
builtin.loclist = require_on_exported_call("telescope.builtin.internal").loclist
|
builtin.loclist = require_on_exported_call("telescope.builtin.internal").loclist
|
||||||
|
|
||||||
--- Lists previously open files, opens on `<cr>`
|
--- Lists previously open files, opens on `<cr>`
|
||||||
@@ -350,14 +352,16 @@ builtin.spell_suggest = require_on_exported_call("telescope.builtin.internal").s
|
|||||||
|
|
||||||
--- Lists the tag stack for the current window, jumps to tag on `<cr>`
|
--- Lists the tag stack for the current window, jumps to tag on `<cr>`
|
||||||
---@param opts table: options to pass to the picker
|
---@param opts table: options to pass to the picker
|
||||||
---@field ignore_filename boolean: dont show filenames (default: true)
|
---@field show_line boolean: show results text (default: true)
|
||||||
---@field trim_text boolean: trim results text (default: false)
|
---@field trim_text boolean: trim results text (default: false)
|
||||||
|
---@field fname_width number: defines the width of the filename section (default: 30)
|
||||||
builtin.tagstack = require_on_exported_call("telescope.builtin.internal").tagstack
|
builtin.tagstack = require_on_exported_call("telescope.builtin.internal").tagstack
|
||||||
|
|
||||||
--- Lists items from Vim's jumplist, jumps to location on `<cr>`
|
--- Lists items from Vim's jumplist, jumps to location on `<cr>`
|
||||||
---@param opts table: options to pass to the picker
|
---@param opts table: options to pass to the picker
|
||||||
---@field ignore_filename boolean: dont show filenames (default: true)
|
---@field show_line boolean: show results text (default: true)
|
||||||
---@field trim_text boolean: trim results text (default: false)
|
---@field trim_text boolean: trim results text (default: false)
|
||||||
|
---@field fname_width number: defines the width of the filename section (default: 30)
|
||||||
builtin.jumplist = require_on_exported_call("telescope.builtin.internal").jumplist
|
builtin.jumplist = require_on_exported_call("telescope.builtin.internal").jumplist
|
||||||
|
|
||||||
--
|
--
|
||||||
@@ -371,35 +375,38 @@ builtin.jumplist = require_on_exported_call("telescope.builtin.internal").jumpli
|
|||||||
---@field include_declaration boolean: include symbol declaration in the lsp references (default: true)
|
---@field include_declaration boolean: include symbol declaration in the lsp references (default: true)
|
||||||
---@field include_current_line boolean: include current line (default: false)
|
---@field include_current_line boolean: include current line (default: false)
|
||||||
---@field trim_text boolean: trim results text (default: false)
|
---@field trim_text boolean: trim results text (default: false)
|
||||||
|
---@field fname_width number: defines the width of the filename section (default: 30)
|
||||||
builtin.lsp_references = require_on_exported_call("telescope.builtin.lsp").references
|
builtin.lsp_references = require_on_exported_call("telescope.builtin.lsp").references
|
||||||
|
|
||||||
--- Goto the definition of the word under the cursor, if there's only one, otherwise show all options in Telescope
|
--- Goto the definition of the word under the cursor, if there's only one, otherwise show all options in Telescope
|
||||||
---@param opts table: options to pass to the picker
|
---@param opts table: options to pass to the picker
|
||||||
---@field jump_type string: how to goto definition if there is only one, values: "tab", "split", "vsplit", "never"
|
---@field jump_type string: how to goto definition if there is only one, values: "tab", "split", "vsplit", "never"
|
||||||
---@field ignore_filename boolean: dont show filenames (default: true)
|
---@field show_line boolean: show results text (default: true)
|
||||||
---@field trim_text boolean: trim results text (default: false)
|
---@field trim_text boolean: trim results text (default: false)
|
||||||
|
---@field fname_width number: defines the width of the filename section (default: 30)
|
||||||
builtin.lsp_definitions = require_on_exported_call("telescope.builtin.lsp").definitions
|
builtin.lsp_definitions = require_on_exported_call("telescope.builtin.lsp").definitions
|
||||||
|
|
||||||
--- Goto the definition of the type of the word under the cursor, if there's only one,
|
--- Goto the definition of the type of the word under the cursor, if there's only one,
|
||||||
--- otherwise show all options in Telescope
|
--- otherwise show all options in Telescope
|
||||||
---@param opts table: options to pass to the picker
|
---@param opts table: options to pass to the picker
|
||||||
---@field jump_type string: how to goto definition if there is only one, values: "tab", "split", "vsplit", "never"
|
---@field jump_type string: how to goto definition if there is only one, values: "tab", "split", "vsplit", "never"
|
||||||
---@field ignore_filename boolean: dont show filenames (default: true)
|
---@field show_line boolean: show results text (default: true)
|
||||||
---@field trim_text boolean: trim results text (default: false)
|
---@field trim_text boolean: trim results text (default: false)
|
||||||
|
---@field fname_width number: defines the width of the filename section (default: 30)
|
||||||
builtin.lsp_type_definitions = require("telescope.builtin.lsp").type_definitions
|
builtin.lsp_type_definitions = require("telescope.builtin.lsp").type_definitions
|
||||||
|
|
||||||
--- Goto the implementation of the word under the cursor if there's only one, otherwise show all options in Telescope
|
--- Goto the implementation of the word under the cursor if there's only one, otherwise show all options in Telescope
|
||||||
---@param opts table: options to pass to the picker
|
---@param opts table: options to pass to the picker
|
||||||
---@field jump_type string: how to goto implementation if there is only one, values: "tab", "split", "vsplit", "never"
|
---@field jump_type string: how to goto implementation if there is only one, values: "tab", "split", "vsplit", "never"
|
||||||
---@field ignore_filename boolean: dont show filenames (default: true)
|
---@field show_line boolean: show results text (default: true)
|
||||||
---@field trim_text boolean: trim results text (default: false)
|
---@field trim_text boolean: trim results text (default: false)
|
||||||
|
---@field fname_width number: defines the width of the filename section (default: 30)
|
||||||
builtin.lsp_implementations = require_on_exported_call("telescope.builtin.lsp").implementations
|
builtin.lsp_implementations = require_on_exported_call("telescope.builtin.lsp").implementations
|
||||||
|
|
||||||
--- Lists LSP document symbols in the current buffer
|
--- Lists LSP document symbols in the current buffer
|
||||||
--- - Default keymaps:
|
--- - Default keymaps:
|
||||||
--- - `<C-l>`: show autocompletion menu to prefilter your query by type of symbol you want to see (i.e. `:variable:`)
|
--- - `<C-l>`: show autocompletion menu to prefilter your query by type of symbol you want to see (i.e. `:variable:`)
|
||||||
---@param opts table: options to pass to the picker
|
---@param opts table: options to pass to the picker
|
||||||
---@field ignore_filename boolean: dont show filenames (default: true)
|
|
||||||
---@field show_line boolean: if true, shows the content of the line the tag is found on (default: false)
|
---@field show_line boolean: if true, shows the content of the line the tag is found on (default: false)
|
||||||
---@field symbols string|table: filter results by symbol kind(s)
|
---@field symbols string|table: filter results by symbol kind(s)
|
||||||
---@field ignore_symbols string|table: list of symbols to ignore
|
---@field ignore_symbols string|table: list of symbols to ignore
|
||||||
@@ -411,7 +418,6 @@ builtin.lsp_document_symbols = require_on_exported_call("telescope.builtin.lsp")
|
|||||||
--- - `<C-l>`: show autocompletion menu to prefilter your query by type of symbol you want to see (i.e. `:variable:`)
|
--- - `<C-l>`: show autocompletion menu to prefilter your query by type of symbol you want to see (i.e. `:variable:`)
|
||||||
---@param opts table: options to pass to the picker
|
---@param opts table: options to pass to the picker
|
||||||
---@field query string: for what to query the workspace (default: "")
|
---@field query string: for what to query the workspace (default: "")
|
||||||
---@field ignore_filename boolean: dont show filenames (default: false)
|
|
||||||
---@field show_line boolean: if true, shows the content of the line the tag is found on (default: false)
|
---@field show_line boolean: if true, shows the content of the line the tag is found on (default: false)
|
||||||
---@field symbols string|table: filter results by symbol kind(s)
|
---@field symbols string|table: filter results by symbol kind(s)
|
||||||
---@field ignore_symbols string|table: list of symbols to ignore
|
---@field ignore_symbols string|table: list of symbols to ignore
|
||||||
@@ -422,7 +428,6 @@ builtin.lsp_workspace_symbols = require_on_exported_call("telescope.builtin.lsp"
|
|||||||
--- - Default keymaps:
|
--- - Default keymaps:
|
||||||
--- - `<C-l>`: show autocompletion menu to prefilter your query by type of symbol you want to see (i.e. `:variable:`)
|
--- - `<C-l>`: show autocompletion menu to prefilter your query by type of symbol you want to see (i.e. `:variable:`)
|
||||||
---@param opts table: options to pass to the picker
|
---@param opts table: options to pass to the picker
|
||||||
---@field ignore_filename boolean: dont show filenames (default: false)
|
|
||||||
---@field show_line boolean: if true, shows the content of the line the symbol is found on (default: false)
|
---@field show_line boolean: if true, shows the content of the line the symbol is found on (default: false)
|
||||||
---@field symbols string|table: filter results by symbol kind(s)
|
---@field symbols string|table: filter results by symbol kind(s)
|
||||||
---@field ignore_symbols string|table: list of symbols to ignore
|
---@field ignore_symbols string|table: list of symbols to ignore
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ lsp.document_symbols = function(opts)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
opts.ignore_filename = opts.ignore_filename or true
|
opts.path_display = { "hidden" }
|
||||||
pickers.new(opts, {
|
pickers.new(opts, {
|
||||||
prompt_title = "LSP Document Symbols",
|
prompt_title = "LSP Document Symbols",
|
||||||
finder = finders.new_table {
|
finder = finders.new_table {
|
||||||
|
|||||||
@@ -26,6 +26,21 @@ local lsp_type_highlight = {
|
|||||||
["Variable"] = "TelescopeResultsVariable",
|
["Variable"] = "TelescopeResultsVariable",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
local get_filename_fn = function()
|
||||||
|
local bufnr_name_cache = {}
|
||||||
|
return function(bufnr)
|
||||||
|
bufnr = vim.F.if_nil(bufnr, 0)
|
||||||
|
local c = bufnr_name_cache[bufnr]
|
||||||
|
if c then
|
||||||
|
return c
|
||||||
|
end
|
||||||
|
|
||||||
|
local n = vim.api.nvim_buf_get_name(bufnr)
|
||||||
|
bufnr_name_cache[bufnr] = n
|
||||||
|
return n
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
local make_entry = {}
|
local make_entry = {}
|
||||||
|
|
||||||
do
|
do
|
||||||
@@ -309,40 +324,49 @@ end
|
|||||||
|
|
||||||
function make_entry.gen_from_quickfix(opts)
|
function make_entry.gen_from_quickfix(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
|
local show_line = vim.F.if_nil(opts.show_line, true)
|
||||||
|
|
||||||
local displayer = entry_display.create {
|
local hidden = utils.is_path_hidden(opts)
|
||||||
separator = "▏",
|
local items = {
|
||||||
items = {
|
{ width = vim.F.if_nil(opts.fname_width, 30) },
|
||||||
{ width = 8 },
|
{ remaining = true },
|
||||||
{ width = 0.45 },
|
|
||||||
{ remaining = true },
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
if hidden then
|
||||||
local make_display = function(entry)
|
items[1] = 8
|
||||||
local filename = utils.transform_path(opts, entry.filename)
|
end
|
||||||
|
if not show_line then
|
||||||
local line_info = { table.concat({ entry.lnum, entry.col }, ":"), "TelescopeResultsLineNr" }
|
table.remove(items, 1)
|
||||||
|
|
||||||
if opts.trim_text then
|
|
||||||
entry.text = entry.text:gsub("^%s*(.-)%s*$", "%1")
|
|
||||||
end
|
|
||||||
|
|
||||||
return displayer {
|
|
||||||
line_info,
|
|
||||||
entry.text:gsub(".* | ", ""),
|
|
||||||
filename,
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local displayer = entry_display.create { separator = "▏", items = items }
|
||||||
|
|
||||||
|
local make_display = function(entry)
|
||||||
|
local input = {}
|
||||||
|
if not hidden then
|
||||||
|
table.insert(input, string.format("%s:%d:%d", utils.transform_path(opts, entry.filename), entry.lnum, entry.col))
|
||||||
|
else
|
||||||
|
table.insert(input, string.format("%4d:%2d", entry.lnum, entry.col))
|
||||||
|
end
|
||||||
|
|
||||||
|
if show_line then
|
||||||
|
local text = entry.text
|
||||||
|
if opts.trim_text then
|
||||||
|
text = text:gsub("^%s*(.-)%s*$", "%1")
|
||||||
|
end
|
||||||
|
text = text:gsub(".* | ", "")
|
||||||
|
table.insert(input, text)
|
||||||
|
end
|
||||||
|
|
||||||
|
return displayer(input)
|
||||||
|
end
|
||||||
|
|
||||||
|
local get_filename = get_filename_fn()
|
||||||
return function(entry)
|
return function(entry)
|
||||||
local filename = entry.filename or vim.api.nvim_buf_get_name(entry.bufnr)
|
local filename = vim.F.if_nil(entry.filename, get_filename(entry.bufnr))
|
||||||
|
|
||||||
return {
|
return {
|
||||||
valid = true,
|
|
||||||
|
|
||||||
value = entry,
|
value = entry,
|
||||||
ordinal = (not opts.ignore_filename and filename or "") .. " " .. entry.text,
|
ordinal = (not hidden and filename or "") .. " " .. entry.text,
|
||||||
display = make_display,
|
display = make_display,
|
||||||
|
|
||||||
bufnr = entry.bufnr,
|
bufnr = entry.bufnr,
|
||||||
@@ -361,14 +385,22 @@ function make_entry.gen_from_lsp_symbols(opts)
|
|||||||
|
|
||||||
local bufnr = opts.bufnr or vim.api.nvim_get_current_buf()
|
local bufnr = opts.bufnr or vim.api.nvim_get_current_buf()
|
||||||
|
|
||||||
|
-- Default we have two columns, symbol and type(unbound)
|
||||||
|
-- If path is not hidden then its, filepath, symbol and type(still unbound)
|
||||||
|
-- If show_line is also set, type is bound to len 8
|
||||||
local display_items = {
|
local display_items = {
|
||||||
{ width = opts.symbol_width or 25 }, -- symbol
|
{ width = opts.symbol_width or 25 },
|
||||||
{ width = opts.symbol_type_width or 8 }, -- symbol type
|
{ remaining = true },
|
||||||
{ remaining = true }, -- filename{:optional_lnum+col} OR content preview
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.ignore_filename and opts.show_line then
|
local hidden = utils.is_path_hidden(opts)
|
||||||
table.insert(display_items, 2, { width = 6 })
|
if not hidden then
|
||||||
|
table.insert(display_items, 1, { width = vim.F.if_nil(opts.fname_width, 30) })
|
||||||
|
end
|
||||||
|
|
||||||
|
if opts.show_line then
|
||||||
|
-- bound type to len 8 or custom
|
||||||
|
table.insert(display_items, #display_items, { width = opts.symbol_type_width or 8 })
|
||||||
end
|
end
|
||||||
|
|
||||||
local displayer = entry_display.create {
|
local displayer = entry_display.create {
|
||||||
@@ -376,51 +408,43 @@ function make_entry.gen_from_lsp_symbols(opts)
|
|||||||
hl_chars = { ["["] = "TelescopeBorder", ["]"] = "TelescopeBorder" },
|
hl_chars = { ["["] = "TelescopeBorder", ["]"] = "TelescopeBorder" },
|
||||||
items = display_items,
|
items = display_items,
|
||||||
}
|
}
|
||||||
|
local type_highlight = vim.F.if_nil(opts.symbol_highlights or lsp_type_highlight)
|
||||||
|
|
||||||
local make_display = function(entry)
|
local make_display = function(entry)
|
||||||
local msg
|
local msg
|
||||||
|
|
||||||
-- what to show in the last column: filename or symbol information
|
if opts.show_line then
|
||||||
if opts.ignore_filename then -- ignore the filename and show line preview instead
|
msg = vim.trim(vim.F.if_nil(vim.api.nvim_buf_get_lines(bufnr, entry.lnum - 1, entry.lnum, false)[1], ""))
|
||||||
-- TODO: fixme - if ignore_filename is set for workspace, bufnr will be incorrect
|
end
|
||||||
msg = vim.api.nvim_buf_get_lines(bufnr, entry.lnum - 1, entry.lnum, false)[1] or ""
|
|
||||||
msg = vim.trim(msg)
|
if hidden then
|
||||||
|
return displayer {
|
||||||
|
entry.symbol_name,
|
||||||
|
{ entry.symbol_type:lower(), type_highlight[entry.symbol_type] },
|
||||||
|
msg,
|
||||||
|
}
|
||||||
else
|
else
|
||||||
local filename = utils.transform_path(opts, entry.filename)
|
return displayer {
|
||||||
|
utils.transform_path(opts, entry.filename),
|
||||||
if opts.show_line then -- show inline line info
|
entry.symbol_name,
|
||||||
filename = filename .. " [" .. entry.lnum .. ":" .. entry.col .. "]"
|
{ entry.symbol_type:lower(), type_highlight[entry.symbol_type] },
|
||||||
end
|
msg,
|
||||||
msg = filename
|
}
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
|
local get_filename = get_filename_fn()
|
||||||
return function(entry)
|
return function(entry)
|
||||||
local filename = entry.filename or vim.api.nvim_buf_get_name(entry.bufnr)
|
local filename = vim.F.if_nil(entry.filename, get_filename(entry.bufnr))
|
||||||
local symbol_msg = entry.text
|
local symbol_msg = entry.text
|
||||||
local symbol_type, symbol_name = symbol_msg:match "%[(.+)%]%s+(.*)"
|
local symbol_type, symbol_name = symbol_msg:match "%[(.+)%]%s+(.*)"
|
||||||
|
|
||||||
local ordinal = ""
|
local ordinal = ""
|
||||||
if not opts.ignore_filename and filename then
|
if not hidden and filename then
|
||||||
ordinal = filename .. " "
|
ordinal = filename .. " "
|
||||||
end
|
end
|
||||||
ordinal = ordinal .. symbol_name .. " " .. (symbol_type or "unknown")
|
ordinal = ordinal .. symbol_name .. " " .. (symbol_type or "unknown")
|
||||||
return {
|
|
||||||
valid = true,
|
|
||||||
|
|
||||||
|
return {
|
||||||
value = entry,
|
value = entry,
|
||||||
ordinal = ordinal,
|
ordinal = ordinal,
|
||||||
display = make_display,
|
display = make_display,
|
||||||
@@ -484,8 +508,6 @@ function make_entry.gen_from_buffer(opts)
|
|||||||
local line_count = vim.api.nvim_buf_line_count(entry.bufnr)
|
local line_count = vim.api.nvim_buf_line_count(entry.bufnr)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
valid = true,
|
|
||||||
|
|
||||||
value = bufname,
|
value = bufname,
|
||||||
ordinal = entry.bufnr .. " : " .. bufname,
|
ordinal = entry.bufnr .. " : " .. bufname,
|
||||||
display = make_display,
|
display = make_display,
|
||||||
@@ -537,13 +559,12 @@ function make_entry.gen_from_treesitter(opts)
|
|||||||
return displayer(display_columns)
|
return displayer(display_columns)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local get_filename = get_filename_fn()
|
||||||
return function(entry)
|
return function(entry)
|
||||||
local ts_utils = require "nvim-treesitter.ts_utils"
|
local ts_utils = require "nvim-treesitter.ts_utils"
|
||||||
local start_row, start_col, end_row, _ = ts_utils.get_node_range(entry.node)
|
local start_row, start_col, end_row, _ = ts_utils.get_node_range(entry.node)
|
||||||
local node_text = vim.treesitter.get_node_text(entry.node, bufnr)
|
local node_text = vim.treesitter.get_node_text(entry.node, bufnr)
|
||||||
return {
|
return {
|
||||||
valid = true,
|
|
||||||
|
|
||||||
value = entry.node,
|
value = entry.node,
|
||||||
kind = entry.kind,
|
kind = entry.kind,
|
||||||
ordinal = node_text .. " " .. (entry.kind or "unknown"),
|
ordinal = node_text .. " " .. (entry.kind or "unknown"),
|
||||||
@@ -551,7 +572,7 @@ function make_entry.gen_from_treesitter(opts)
|
|||||||
|
|
||||||
node_text = node_text,
|
node_text = node_text,
|
||||||
|
|
||||||
filename = vim.api.nvim_buf_get_name(bufnr),
|
filename = get_filename(bufnr),
|
||||||
-- need to add one since the previewer substacts one
|
-- need to add one since the previewer substacts one
|
||||||
lnum = start_row + 1,
|
lnum = start_row + 1,
|
||||||
col = start_col,
|
col = start_col,
|
||||||
@@ -668,7 +689,6 @@ function make_entry.gen_from_registers(_)
|
|||||||
|
|
||||||
return function(entry)
|
return function(entry)
|
||||||
return {
|
return {
|
||||||
valid = true,
|
|
||||||
value = entry,
|
value = entry,
|
||||||
ordinal = entry,
|
ordinal = entry,
|
||||||
content = vim.fn.getreg(entry),
|
content = vim.fn.getreg(entry),
|
||||||
@@ -800,7 +820,6 @@ function make_entry.gen_from_buffer_lines(opts)
|
|||||||
end
|
end
|
||||||
|
|
||||||
return {
|
return {
|
||||||
valid = true,
|
|
||||||
ordinal = entry.text,
|
ordinal = entry.text,
|
||||||
display = make_display,
|
display = make_display,
|
||||||
filename = entry.filename,
|
filename = entry.filename,
|
||||||
@@ -982,7 +1001,8 @@ function make_entry.gen_from_diagnostics(opts)
|
|||||||
{ remaining = true },
|
{ remaining = true },
|
||||||
}
|
}
|
||||||
local line_width = vim.F.if_nil(opts.line_width, 0.5)
|
local line_width = vim.F.if_nil(opts.line_width, 0.5)
|
||||||
if not utils.is_path_hidden(opts) then
|
local hidden = utils.is_path_hidden(opts)
|
||||||
|
if not hidden then
|
||||||
table.insert(display_items, 2, { width = line_width })
|
table.insert(display_items, 2, { width = line_width })
|
||||||
end
|
end
|
||||||
local displayer = entry_display.create {
|
local displayer = entry_display.create {
|
||||||
@@ -1000,10 +1020,6 @@ function make_entry.gen_from_diagnostics(opts)
|
|||||||
"Diagnostic" .. entry.type,
|
"Diagnostic" .. entry.type,
|
||||||
}
|
}
|
||||||
|
|
||||||
--TODO(conni2461): I dont like that this is symbol lnum:col | msg | filename
|
|
||||||
-- i want: symbol filename:lnum:col | msg
|
|
||||||
-- or : symbol lnum:col | msg
|
|
||||||
-- I think this is more natural
|
|
||||||
return displayer {
|
return displayer {
|
||||||
line_info,
|
line_info,
|
||||||
entry.text,
|
entry.text,
|
||||||
@@ -1014,7 +1030,7 @@ function make_entry.gen_from_diagnostics(opts)
|
|||||||
return function(entry)
|
return function(entry)
|
||||||
return {
|
return {
|
||||||
value = entry,
|
value = entry,
|
||||||
ordinal = ("%s %s"):format(not opts.ignore_filename and entry.filename or "", entry.text),
|
ordinal = ("%s %s"):format(not hidden and entry.filename or "", entry.text),
|
||||||
display = make_display,
|
display = make_display,
|
||||||
filename = entry.filename,
|
filename = entry.filename,
|
||||||
type = entry.type,
|
type = entry.type,
|
||||||
@@ -1104,7 +1120,6 @@ function make_entry.gen_from_commands(_)
|
|||||||
definition = entry.definition,
|
definition = entry.definition,
|
||||||
--
|
--
|
||||||
value = entry,
|
value = entry,
|
||||||
valid = true,
|
|
||||||
ordinal = entry.name,
|
ordinal = entry.name,
|
||||||
display = make_display,
|
display = make_display,
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user