Add more colour (#346)

* add colour to buffers finder

* new display function for LSP workspace/doc symbols

* add more hl_groups and opts paramter

* use make_display() for man_pages finder.

* use make_display for registers finder and add color

* don't use quickfix make_entry() for builtin finder

* make_entry() for builtin finder

* remove debug output

* revert change to internal.builtin finder

* fix_spacing
This commit is contained in:
Senghan Bright
2020-12-18 15:41:55 +01:00
committed by GitHub
parent e5155a4aa3
commit 68c5870345
3 changed files with 118 additions and 24 deletions

View File

@@ -34,15 +34,13 @@ internal.builtin = function(opts)
prompt_title = 'Telescope Builtin',
finder = finders.new_table {
results = objs,
entry_maker = function(entry)
return {
entry_maker = function(entry)return {
value = entry,
text = entry.text,
display = entry.text,
ordinal = entry.text,
filename = entry.filename,
}
end
filename = entry.filename
}end
},
previewer = previewers.builtin.new(opts),
sorter = conf.generic_sorter(opts),

View File

@@ -59,7 +59,7 @@ lsp.document_symbols = function(opts)
prompt_title = 'LSP Document Symbols',
finder = finders.new_table {
results = locations,
entry_maker = make_entry.gen_from_quickfix(opts)
entry_maker = make_entry.gen_from_symbols(opts)
},
previewer = conf.qflist_previewer(opts),
sorter = conf.generic_sorter(opts),
@@ -169,7 +169,7 @@ lsp.workspace_symbols = function(opts)
prompt_title = 'LSP Workspace Symbols',
finder = finders.new_table {
results = locations,
entry_maker = make_entry.gen_from_quickfix(opts)
entry_maker = make_entry.gen_from_symbols(opts)
},
previewer = conf.qflist_previewer(opts),
sorter = conf.generic_sorter(opts),

View File

@@ -241,7 +241,7 @@ function make_entry.gen_from_quickfix(opts)
local displayer = entry_display.create {
separator = "",
items = {
{ width = 6 },
{ width = 8 },
{ width = 50 },
{ remaining = true },
},
@@ -258,8 +258,10 @@ function make_entry.gen_from_quickfix(opts)
end
end
local line_info = {table.concat({entry.lnum, entry.col}, ":"), "LineNr"}
return displayer {
entry.lnum .. ":" .. entry.col,
line_info,
entry.text:gsub(".* | ", ""),
filename,
}
@@ -288,6 +290,80 @@ function make_entry.gen_from_quickfix(opts)
end
end
function make_entry.gen_from_symbols(opts)
opts = opts or {}
opts.tail_path = get_default(opts.tail_path, true)
local displayer = entry_display.create {
separator = "",
items = {
{ width = 6 },
{ width = 40 },
{ width = 1 },
{ remaining = true },
{ width = 1 },
},
}
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 default_type_highlight = {
["Class"] = "Function",
["Constant"] = "Constant",
["Field"] = "Function",
["Function"] = "Function",
["Property"] = "Operator",
["Struct"] = "Struct",
["Variable"] = "SpecialChar",
}
local type_highlight = opts.symbol_highlights or default_type_highlight
return displayer {
{entry.lnum .. ":" .. entry.col, "LineNr"},
entry.symbol_name,
{"[", "TelescopeBorder"},
{entry.symbol_type, type_highlight[entry.symbol_type], type_highlight[entry.symbol_type]},
{"]", "TelescopeBorder"},
filename,
}
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+(.*)")
return {
valid = true,
value = entry,
ordinal = (
not opts.ignore_filename and filename
or ''
) .. ' ' .. symbol_name .. ' ' .. symbol_type,
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 {}
@@ -311,9 +387,9 @@ function make_entry.gen_from_buffer(opts)
end
return displayer {
entry.bufnr,
entry.indicator,
display_bufname .. ":" .. entry.lnum,
{entry.bufnr, "Number"},
{entry.indicator, "Comment"},
display_bufname .. ":" .. entry.lnum
}
end
@@ -414,13 +490,29 @@ function make_entry.gen_from_packages(opts)
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 = string.format("%-30s : %s", cmd, desc)
display = make_display,
}
end
end
@@ -446,17 +538,21 @@ end
function make_entry.gen_from_registers(_)
local displayer = entry_display.create {
separator = ":",
separator = "",
items = {
{ width = 4 },
{ width = 1 },
{ width = 1 },
{ width = 2 },
{ remaining = true },
},
}
local make_display = function(entry)
return displayer {
string.format("[%s]", entry.value),
entry.content
{"[", "TelescopeBorder"},
{entry.value, "Number"},
{"]", "TelescopeBorder"},
entry.content,
}
end