Feat: displayer hl_chars and TelescopeResults hlgroups (#349)
This commit is contained in:
@@ -34,14 +34,16 @@ internal.builtin = function(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
|
||||
},
|
||||
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(_)
|
||||
|
||||
@@ -20,13 +20,14 @@ local treesitter_type_highlight = {
|
||||
}
|
||||
|
||||
local lsp_type_highlight = {
|
||||
["Class"] = "Function",
|
||||
["Constant"] = "Constant",
|
||||
["Field"] = "Function",
|
||||
["Function"] = "Function",
|
||||
["Property"] = "Operator",
|
||||
["Struct"] = "Struct",
|
||||
["Variable"] = "SpecialChar",
|
||||
["Class"] = "TelescopeResultsClass",
|
||||
["Constant"] = "TelescopeResultsConstant",
|
||||
["Field"] = "TelescopeResultsField",
|
||||
["Function"] = "TelescopeResultsFunction",
|
||||
["Method"] = "TelescopeResultsMethod",
|
||||
["Property"] = "TelescopeResultsOperator",
|
||||
["Struct"] = "TelescopeResultsStruct",
|
||||
["Variable"] = "TelescopeResultsVariable",
|
||||
}
|
||||
|
||||
local make_entry = {}
|
||||
@@ -251,7 +252,7 @@ function make_entry.gen_from_git_commits()
|
||||
|
||||
local make_display = function(entry)
|
||||
return displayer {
|
||||
{entry.value, "Number"},
|
||||
{entry.value, "TelescopeResultsNumber"},
|
||||
entry.msg
|
||||
}
|
||||
end
|
||||
@@ -296,7 +297,7 @@ function make_entry.gen_from_quickfix(opts)
|
||||
end
|
||||
end
|
||||
|
||||
local line_info = {table.concat({entry.lnum, entry.col}, ":"), "LineNr"}
|
||||
local line_info = {table.concat({entry.lnum, entry.col}, ":"), "TelescopeResultsLineNr"}
|
||||
|
||||
return displayer {
|
||||
line_info,
|
||||
@@ -388,7 +389,7 @@ function make_entry.gen_from_lsp_symbols(opts)
|
||||
}
|
||||
|
||||
if opts.ignore_filename and opts.show_line then
|
||||
table.insert(display_columns, 2, {entry.lnum .. ":" .. entry.col, "LineNr"})
|
||||
table.insert(display_columns, 2, {entry.lnum .. ":" .. entry.col, "TelescopeResultsLineNr"})
|
||||
end
|
||||
|
||||
return displayer(display_columns)
|
||||
@@ -445,8 +446,8 @@ function make_entry.gen_from_buffer(opts)
|
||||
end
|
||||
|
||||
return displayer {
|
||||
{entry.bufnr, "Number"},
|
||||
{entry.indicator, "Comment"},
|
||||
{entry.bufnr, "TelescopeResultsNumber"},
|
||||
{entry.indicator, "TelescopeResultsComment"},
|
||||
display_bufname .. ":" .. entry.lnum
|
||||
}
|
||||
end
|
||||
@@ -514,7 +515,7 @@ function make_entry.gen_from_treesitter(opts)
|
||||
msg
|
||||
}
|
||||
if opts.show_line then
|
||||
table.insert(display_columns, 2, {entry.lnum .. ":" .. entry.col, "LineNr"})
|
||||
table.insert(display_columns, 2, {entry.lnum .. ":" .. entry.col, "TelescopeResultsLineNr"})
|
||||
end
|
||||
|
||||
return displayer(display_columns)
|
||||
@@ -616,20 +617,17 @@ end
|
||||
|
||||
function make_entry.gen_from_registers(_)
|
||||
local displayer = entry_display.create {
|
||||
separator = "",
|
||||
separator = " ",
|
||||
hl_chars = { ['['] = 'TelescopeBorder', [']'] = 'TelescopeBorder' },
|
||||
items = {
|
||||
{ width = 1 },
|
||||
{ width = 1 },
|
||||
{ width = 2 },
|
||||
{ width = 3 },
|
||||
{ remaining = true },
|
||||
},
|
||||
}
|
||||
|
||||
local make_display = function(entry)
|
||||
return displayer {
|
||||
{"[", "TelescopeBorder"},
|
||||
{entry.value, "Number"},
|
||||
{"]", "TelescopeBorder"},
|
||||
{'[' .. entry.value .. ']', "TelescopeResultsNumber"},
|
||||
entry.content,
|
||||
}
|
||||
end
|
||||
|
||||
@@ -62,8 +62,18 @@ entry_display.create = function(configuration)
|
||||
table.insert(highlights, { { hl_start, hl_end }, configuration.separator_hl })
|
||||
end
|
||||
end
|
||||
local final_str = table.concat(results, configuration.separator or "│")
|
||||
if configuration.hl_chars then
|
||||
for i = 1, #final_str do
|
||||
local c = final_str:sub(i,i)
|
||||
local hl = configuration.hl_chars[c]
|
||||
if hl then
|
||||
table.insert(highlights, { { i - 1, i }, hl })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return table.concat(results, configuration.separator or "│"), highlights
|
||||
return final_str, highlights
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -24,6 +24,20 @@ highlight default link TelescopePromptPrefix Identifier
|
||||
highlight default link TelescopePreviewLine Visual
|
||||
highlight default link TelescopePreviewMatch Search
|
||||
|
||||
" Used for Picker specific Results highlighting
|
||||
highlight default link TelescopeResultsClass Function
|
||||
highlight default link TelescopeResultsConstant Constant
|
||||
highlight default link TelescopeResultsField Function
|
||||
highlight default link TelescopeResultsFunction Function
|
||||
highlight default link TelescopeResultsMethod Method
|
||||
highlight default link TelescopeResultsOperator Operator
|
||||
highlight default link TelescopeResultsStruct Struct
|
||||
highlight default link TelescopeResultsVariable SpecialChar
|
||||
|
||||
highlight default link TelescopeResultsLineNr LineNr
|
||||
highlight default link TelescopeResultsNumber Number
|
||||
highlight default link TelescopeResultsComment Comment
|
||||
|
||||
" This is like "<C-R>" in your terminal.
|
||||
" To use it, do `cmap <C-R> <Plug>(TelescopeFuzzyCommandSearch)
|
||||
cnoremap <silent> <Plug>(TelescopeFuzzyCommandSearch) <C-\>e
|
||||
|
||||
Reference in New Issue
Block a user