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
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
opts.ignore_filename = opts.ignore_filename or true
|
||||||
pickers.new(opts, {
|
pickers.new(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_symbols(opts)
|
entry_maker = make_entry.gen_from_lsp_symbols(opts)
|
||||||
},
|
},
|
||||||
previewer = conf.qflist_previewer(opts),
|
previewer = conf.qflist_previewer(opts),
|
||||||
sorter = conf.generic_sorter(opts),
|
sorter = conf.generic_sorter(opts),
|
||||||
@@ -165,11 +166,15 @@ lsp.workspace_symbols = function(opts)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
opts.ignore_filename = utils.get_default(opts.ignore_filename, false)
|
||||||
|
opts.hide_filename = utils.get_default(opts.hide_filename, false)
|
||||||
|
|
||||||
pickers.new(opts, {
|
pickers.new(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_symbols(opts)
|
entry_maker = make_entry.gen_from_lsp_symbols(opts)
|
||||||
},
|
},
|
||||||
previewer = conf.qflist_previewer(opts),
|
previewer = conf.qflist_previewer(opts),
|
||||||
sorter = conf.generic_sorter(opts),
|
sorter = conf.generic_sorter(opts),
|
||||||
|
|||||||
@@ -7,6 +7,28 @@ local utils = require('telescope.utils')
|
|||||||
|
|
||||||
local get_default = utils.get_default
|
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 make_entry = {}
|
||||||
|
|
||||||
local transform_devicons
|
local transform_devicons
|
||||||
@@ -219,6 +241,21 @@ do
|
|||||||
end
|
end
|
||||||
|
|
||||||
function make_entry.gen_from_git_commits()
|
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)
|
return function(entry)
|
||||||
if entry == "" then
|
if entry == "" then
|
||||||
return nil
|
return nil
|
||||||
@@ -229,7 +266,8 @@ function make_entry.gen_from_git_commits()
|
|||||||
return {
|
return {
|
||||||
value = sha,
|
value = sha,
|
||||||
ordinal = sha .. ' ' .. msg,
|
ordinal = sha .. ' ' .. msg,
|
||||||
display = sha .. ' ' .. msg,
|
msg = msg,
|
||||||
|
display = make_display
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@@ -243,8 +281,8 @@ function make_entry.gen_from_quickfix(opts)
|
|||||||
items = {
|
items = {
|
||||||
{ width = 8 },
|
{ width = 8 },
|
||||||
{ width = 50 },
|
{ width = 50 },
|
||||||
{ remaining = true },
|
{ remaining = true }
|
||||||
},
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
local make_display = function(entry)
|
local make_display = function(entry)
|
||||||
@@ -290,24 +328,44 @@ function make_entry.gen_from_quickfix(opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function make_entry.gen_from_symbols(opts)
|
function make_entry.gen_from_lsp_symbols(opts)
|
||||||
opts = opts or {}
|
opts = opts or {}
|
||||||
opts.tail_path = get_default(opts.tail_path, true)
|
local bufnr = opts.bufnr or vim.api.nvim_get_current_buf()
|
||||||
|
|
||||||
|
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 {
|
local displayer = entry_display.create {
|
||||||
separator = "",
|
separator = " ",
|
||||||
items = {
|
hl_chars = { ['['] = 'TelescopeBorder', [']'] = 'TelescopeBorder' },
|
||||||
{ width = 6 },
|
items = display_items
|
||||||
{ width = 40 },
|
|
||||||
{ width = 1 },
|
|
||||||
{ remaining = true },
|
|
||||||
{ width = 1 },
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
local make_display = function(entry)
|
local make_display = function(entry)
|
||||||
local filename
|
local msg
|
||||||
if not opts.hide_filename then
|
|
||||||
|
-- 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
|
filename = entry.filename
|
||||||
if opts.tail_path then
|
if opts.tail_path then
|
||||||
filename = utils.path_tail(filename)
|
filename = utils.path_tail(filename)
|
||||||
@@ -316,26 +374,24 @@ function make_entry.gen_from_symbols(opts)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local default_type_highlight = {
|
if opts.show_line then -- show inline line info
|
||||||
["Class"] = "Function",
|
filename = filename .. " [" ..entry.lnum .. ":" .. entry.col .. "]"
|
||||||
["Constant"] = "Constant",
|
end
|
||||||
["Field"] = "Function",
|
msg = filename
|
||||||
["Function"] = "Function",
|
end
|
||||||
["Property"] = "Operator",
|
|
||||||
["Struct"] = "Struct",
|
|
||||||
["Variable"] = "SpecialChar",
|
|
||||||
}
|
|
||||||
|
|
||||||
local type_highlight = opts.symbol_highlights or default_type_highlight
|
local type_highlight = opts.symbol_highlights or lsp_type_highlight
|
||||||
|
local display_columns = {
|
||||||
return displayer {
|
|
||||||
{entry.lnum .. ":" .. entry.col, "LineNr"},
|
|
||||||
entry.symbol_name,
|
entry.symbol_name,
|
||||||
{"[", "TelescopeBorder"},
|
{entry.symbol_type:lower(), type_highlight[entry.symbol_type], type_highlight[entry.symbol_type]},
|
||||||
{entry.symbol_type, type_highlight[entry.symbol_type], type_highlight[entry.symbol_type]},
|
msg,
|
||||||
{"]", "TelescopeBorder"},
|
|
||||||
filename,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
end
|
||||||
|
|
||||||
return function(entry)
|
return function(entry)
|
||||||
@@ -343,14 +399,16 @@ function make_entry.gen_from_symbols(opts)
|
|||||||
local symbol_msg = entry.text:gsub(".* | ", "")
|
local symbol_msg = entry.text:gsub(".* | ", "")
|
||||||
local symbol_type, symbol_name = symbol_msg:match("%[(.+)%]%s+(.*)")
|
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 {
|
return {
|
||||||
valid = true,
|
valid = true,
|
||||||
|
|
||||||
value = entry,
|
value = entry,
|
||||||
ordinal = (
|
ordinal = ordinal,
|
||||||
not opts.ignore_filename and filename
|
|
||||||
or ''
|
|
||||||
) .. ' ' .. symbol_name .. ' ' .. symbol_type,
|
|
||||||
display = make_display,
|
display = make_display,
|
||||||
|
|
||||||
filename = filename,
|
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 bufnr = opts.bufnr or vim.api.nvim_get_current_buf()
|
||||||
|
|
||||||
local make_display = function(entry)
|
local display_items = {
|
||||||
|
{ width = 25 },
|
||||||
|
{ width = 10 },
|
||||||
|
{ remaining = true },
|
||||||
|
}
|
||||||
|
|
||||||
if opts.show_line then
|
if opts.show_line then
|
||||||
if not tonumber(opts.show_line) then
|
table.insert(display_items, 2, { width = 6 })
|
||||||
opts.show_line = 30
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local spacing = string.rep(" ", opts.show_line - #entry.ordinal)
|
local displayer = entry_display.create {
|
||||||
|
separator = " ",
|
||||||
|
items = display_items,
|
||||||
|
}
|
||||||
|
|
||||||
return entry.ordinal .. spacing .. ": " .. (vim.api.nvim_buf_get_lines(
|
local type_highlight = opts.symbol_highlights or treesitter_type_highlight
|
||||||
|
|
||||||
|
local make_display = function(entry)
|
||||||
|
local msg = vim.api.nvim_buf_get_lines(
|
||||||
bufnr,
|
bufnr,
|
||||||
entry.lnum - 1,
|
entry.lnum - 1,
|
||||||
entry.lnum,
|
entry.lnum,
|
||||||
false
|
false
|
||||||
)[1] or '')
|
)[1] or ''
|
||||||
else
|
msg = vim.trim(msg)
|
||||||
return entry.ordinal
|
|
||||||
|
local display_columns = {
|
||||||
|
entry.text,
|
||||||
|
{entry.kind, type_highlight[entry.kind], type_highlight[entry.kind]},
|
||||||
|
msg
|
||||||
|
}
|
||||||
|
if opts.show_line then
|
||||||
|
table.insert(display_columns, 2, {entry.lnum .. ":" .. entry.col, "LineNr"})
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return displayer(display_columns)
|
||||||
end
|
end
|
||||||
|
|
||||||
return function(entry)
|
return function(entry)
|
||||||
@@ -451,7 +528,8 @@ function make_entry.gen_from_treesitter(opts)
|
|||||||
valid = true,
|
valid = true,
|
||||||
|
|
||||||
value = entry.node,
|
value = entry.node,
|
||||||
ordinal = string.format("%s [%s]", node_text, entry.kind),
|
kind = entry.kind,
|
||||||
|
ordinal = node_text .. " " .. entry.kind,
|
||||||
display = make_display,
|
display = make_display,
|
||||||
|
|
||||||
node_text = node_text,
|
node_text = node_text,
|
||||||
@@ -764,9 +842,9 @@ function make_entry.gen_from_autocommands(_)
|
|||||||
|
|
||||||
local make_display = function(entry)
|
local make_display = function(entry)
|
||||||
return displayer {
|
return displayer {
|
||||||
entry.event,
|
{entry.event, "vimAutoEvent"},
|
||||||
entry.group,
|
{entry.group , "vimAugroup"},
|
||||||
entry.ft_pattern,
|
{entry.ft_pattern, "vimAutoCmdSfxList"},
|
||||||
entry.command
|
entry.command
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user