From 68c587034588b114687e26a940f7d22334879363 Mon Sep 17 00:00:00 2001 From: Senghan Bright Date: Fri, 18 Dec 2020 15:41:55 +0100 Subject: [PATCH] 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 --- lua/telescope/builtin/internal.lua | 20 +++-- lua/telescope/builtin/lsp.lua | 4 +- lua/telescope/make_entry.lua | 118 ++++++++++++++++++++++++++--- 3 files changed, 118 insertions(+), 24 deletions(-) diff --git a/lua/telescope/builtin/internal.lua b/lua/telescope/builtin/internal.lua index 7132bad..4557bd2 100644 --- a/lua/telescope/builtin/internal.lua +++ b/lua/telescope/builtin/internal.lua @@ -33,17 +33,15 @@ internal.builtin = function(opts) pickers.new(opts, { prompt_title = 'Telescope Builtin', finder = finders.new_table { - results = objs, - entry_maker = function(entry) - return { - value = entry, - text = entry.text, - display = entry.text, - ordinal = entry.text, - filename = entry.filename, - } - end - }, + results = objs, + entry_maker = function(entry)return { + value = entry, + text = entry.text, + display = entry.text, + ordinal = entry.text, + filename = entry.filename + }end + }, previewer = previewers.builtin.new(opts), sorter = conf.generic_sorter(opts), attach_mappings = function(_) diff --git a/lua/telescope/builtin/lsp.lua b/lua/telescope/builtin/lsp.lua index 6ddb417..386e09f 100644 --- a/lua/telescope/builtin/lsp.lua +++ b/lua/telescope/builtin/lsp.lua @@ -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), diff --git a/lua/telescope/make_entry.lua b/lua/telescope/make_entry.lua index 5d31632..3071c57 100644 --- a/lua/telescope/make_entry.lua +++ b/lua/telescope/make_entry.lua @@ -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,10 +387,10 @@ 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 return function(entry) @@ -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