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