More colours (#351)
* add vim hl_groups for autocmds finder * spacing * add displayer/colouring for git_commits * LSP colouring and restore filename for workspace symbols * resolve review issues. * fix: handle 'show_line', 'ignore_filename', 'hide_filename' * fix lsp workspace defaults * allow for setting show_line when ignore filename is true * move lsp_doc_symbol lineinfo to 2nd column * reformat treesitter display to match LSP * use utility functions for setting opts defaults * add fix-me note for unlikely configuration permutation * use hl_chars format for inline lineinfo
This commit is contained in:
@@ -55,11 +55,12 @@ lsp.document_symbols = function(opts)
|
||||
return
|
||||
end
|
||||
|
||||
opts.ignore_filename = opts.ignore_filename or true
|
||||
pickers.new(opts, {
|
||||
prompt_title = 'LSP Document Symbols',
|
||||
finder = finders.new_table {
|
||||
results = locations,
|
||||
entry_maker = make_entry.gen_from_symbols(opts)
|
||||
entry_maker = make_entry.gen_from_lsp_symbols(opts)
|
||||
},
|
||||
previewer = conf.qflist_previewer(opts),
|
||||
sorter = conf.generic_sorter(opts),
|
||||
@@ -165,11 +166,15 @@ lsp.workspace_symbols = function(opts)
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
opts.ignore_filename = utils.get_default(opts.ignore_filename, false)
|
||||
opts.hide_filename = utils.get_default(opts.hide_filename, false)
|
||||
|
||||
pickers.new(opts, {
|
||||
prompt_title = 'LSP Workspace Symbols',
|
||||
finder = finders.new_table {
|
||||
results = locations,
|
||||
entry_maker = make_entry.gen_from_symbols(opts)
|
||||
entry_maker = make_entry.gen_from_lsp_symbols(opts)
|
||||
},
|
||||
previewer = conf.qflist_previewer(opts),
|
||||
sorter = conf.generic_sorter(opts),
|
||||
|
||||
@@ -7,6 +7,28 @@ 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"] = "Function",
|
||||
["Constant"] = "Constant",
|
||||
["Field"] = "Function",
|
||||
["Function"] = "Function",
|
||||
["Property"] = "Operator",
|
||||
["Struct"] = "Struct",
|
||||
["Variable"] = "SpecialChar",
|
||||
}
|
||||
|
||||
local make_entry = {}
|
||||
|
||||
local transform_devicons
|
||||
@@ -219,6 +241,21 @@ do
|
||||
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, "Number"},
|
||||
entry.msg
|
||||
}
|
||||
end
|
||||
|
||||
return function(entry)
|
||||
if entry == "" then
|
||||
return nil
|
||||
@@ -229,7 +266,8 @@ function make_entry.gen_from_git_commits()
|
||||
return {
|
||||
value = sha,
|
||||
ordinal = sha .. ' ' .. msg,
|
||||
display = sha .. ' ' .. msg,
|
||||
msg = msg,
|
||||
display = make_display
|
||||
}
|
||||
end
|
||||
end
|
||||
@@ -238,13 +276,13 @@ function make_entry.gen_from_quickfix(opts)
|
||||
opts = opts or {}
|
||||
opts.tail_path = get_default(opts.tail_path, true)
|
||||
|
||||
local displayer = entry_display.create {
|
||||
local displayer = entry_display.create {
|
||||
separator = "▏",
|
||||
items = {
|
||||
{ width = 8 },
|
||||
{ width = 50 },
|
||||
{ remaining = true },
|
||||
},
|
||||
{ remaining = true }
|
||||
}
|
||||
}
|
||||
|
||||
local make_display = function(entry)
|
||||
@@ -290,52 +328,70 @@ function make_entry.gen_from_quickfix(opts)
|
||||
end
|
||||
end
|
||||
|
||||
function make_entry.gen_from_symbols(opts)
|
||||
function make_entry.gen_from_lsp_symbols(opts)
|
||||
opts = opts or {}
|
||||
opts.tail_path = get_default(opts.tail_path, true)
|
||||
local bufnr = opts.bufnr or vim.api.nvim_get_current_buf()
|
||||
|
||||
local displayer = entry_display.create {
|
||||
separator = "",
|
||||
items = {
|
||||
{ width = 6 },
|
||||
{ width = 40 },
|
||||
{ width = 1 },
|
||||
{ remaining = true },
|
||||
{ width = 1 },
|
||||
},
|
||||
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 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)
|
||||
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 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"},
|
||||
local type_highlight = opts.symbol_highlights or lsp_type_highlight
|
||||
local display_columns = {
|
||||
entry.symbol_name,
|
||||
{"[", "TelescopeBorder"},
|
||||
{entry.symbol_type, type_highlight[entry.symbol_type], type_highlight[entry.symbol_type]},
|
||||
{"]", "TelescopeBorder"},
|
||||
filename,
|
||||
{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, "LineNr"})
|
||||
end
|
||||
|
||||
return displayer(display_columns)
|
||||
end
|
||||
|
||||
return function(entry)
|
||||
@@ -343,14 +399,16 @@ function make_entry.gen_from_symbols(opts)
|
||||
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 = (
|
||||
not opts.ignore_filename and filename
|
||||
or ''
|
||||
) .. ' ' .. symbol_name .. ' ' .. symbol_type,
|
||||
ordinal = ordinal,
|
||||
display = make_display,
|
||||
|
||||
filename = filename,
|
||||
@@ -424,23 +482,42 @@ function make_entry.gen_from_treesitter(opts)
|
||||
|
||||
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 - 1,
|
||||
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
|
||||
if not tonumber(opts.show_line) then
|
||||
opts.show_line = 30
|
||||
end
|
||||
|
||||
local spacing = string.rep(" ", opts.show_line - #entry.ordinal)
|
||||
|
||||
return entry.ordinal .. spacing .. ": " .. (vim.api.nvim_buf_get_lines(
|
||||
bufnr,
|
||||
entry.lnum - 1,
|
||||
entry.lnum,
|
||||
false
|
||||
)[1] or '')
|
||||
else
|
||||
return entry.ordinal
|
||||
table.insert(display_columns, 2, {entry.lnum .. ":" .. entry.col, "LineNr"})
|
||||
end
|
||||
|
||||
return displayer(display_columns)
|
||||
end
|
||||
|
||||
return function(entry)
|
||||
@@ -451,7 +528,8 @@ function make_entry.gen_from_treesitter(opts)
|
||||
valid = true,
|
||||
|
||||
value = entry.node,
|
||||
ordinal = string.format("%s [%s]", node_text, entry.kind),
|
||||
kind = entry.kind,
|
||||
ordinal = node_text .. " " .. entry.kind,
|
||||
display = make_display,
|
||||
|
||||
node_text = node_text,
|
||||
@@ -764,9 +842,9 @@ function make_entry.gen_from_autocommands(_)
|
||||
|
||||
local make_display = function(entry)
|
||||
return displayer {
|
||||
entry.event,
|
||||
entry.group,
|
||||
entry.ft_pattern,
|
||||
{entry.event, "vimAutoEvent"},
|
||||
{entry.group , "vimAugroup"},
|
||||
{entry.ft_pattern, "vimAutoCmdSfxList"},
|
||||
entry.command
|
||||
}
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user