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

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

View File

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

View File

@@ -241,7 +241,7 @@ function make_entry.gen_from_quickfix(opts)
local displayer = entry_display.create { local displayer = entry_display.create {
separator = "", separator = "",
items = { items = {
{ width = 6 }, { width = 8 },
{ width = 50 }, { width = 50 },
{ remaining = true }, { remaining = true },
}, },
@@ -258,8 +258,10 @@ function make_entry.gen_from_quickfix(opts)
end end
end end
local line_info = {table.concat({entry.lnum, entry.col}, ":"), "LineNr"}
return displayer { return displayer {
entry.lnum .. ":" .. entry.col, line_info,
entry.text:gsub(".* | ", ""), entry.text:gsub(".* | ", ""),
filename, filename,
} }
@@ -288,6 +290,80 @@ function make_entry.gen_from_quickfix(opts)
end end
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) function make_entry.gen_from_buffer(opts)
opts = opts or {} opts = opts or {}
@@ -311,10 +387,10 @@ function make_entry.gen_from_buffer(opts)
end end
return displayer { return displayer {
entry.bufnr, {entry.bufnr, "Number"},
entry.indicator, {entry.indicator, "Comment"},
display_bufname .. ":" .. entry.lnum, display_bufname .. ":" .. entry.lnum
} }
end end
return function(entry) return function(entry)
@@ -414,13 +490,29 @@ function make_entry.gen_from_packages(opts)
end end
function make_entry.gen_from_apropos() 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) return function(line)
local cmd, _, desc = line:match("^(.*)%s+%((.*)%)%s+%-%s(.*)$") local cmd, _, desc = line:match("^(.*)%s+%((.*)%)%s+%-%s(.*)$")
return { return {
value = cmd, value = cmd,
description = desc,
ordinal = cmd, ordinal = cmd,
display = string.format("%-30s : %s", cmd, desc) display = make_display,
} }
end end
end end
@@ -446,17 +538,21 @@ end
function make_entry.gen_from_registers(_) function make_entry.gen_from_registers(_)
local displayer = entry_display.create { local displayer = entry_display.create {
separator = ":", separator = "",
items = { items = {
{ width = 4 }, { width = 1 },
{ width = 1 },
{ width = 2 },
{ remaining = true }, { remaining = true },
}, },
} }
local make_display = function(entry) local make_display = function(entry)
return displayer { return displayer {
string.format("[%s]", entry.value), {"[", "TelescopeBorder"},
entry.content {entry.value, "Number"},
{"]", "TelescopeBorder"},
entry.content,
} }
end end