Closed casonadams closed 1 year ago
I think this is due to previewers actually not opening files as buffers so the events for your autocmd doesn't actually trigger. The contents are just read and nvim_buf_set_lines'ed into the previewer buffer. This is done for performance reasons (LSPs attaching to buffers, arbitrary autocmds, etc).
I'm not sure if there's a workaround for this. I thought maybe using vim.filetype.add
with/without ftplugin
might work but it doesn't in my testing.
Seem to be running into this as well. I just managed to get a custom search going and it works great. Just no syntax highlighting.
I have txt, adoc, md, yet none show any syntax highlighting. Which for my use would be very useful. Note that live_grep does work fine. Just that I have to be a bit more lazy and retype the word....
Thanks for any eventual work around or solution!!!!
function M.manden_string()
require("utils.functions").SetCALayout()
require("telescope.builtin").grep_string {
file_ignore_patterns = {
".xhtml",
".svg",
".idx",
".dat",
".dic",
".all.txt",
".delete-sed.txt",
},
cwd = "$HOME/Documents/Jula/search",
path_display = { "hidden" },
prompt_title = "Mandenkan",
-- preview_title = false,
layout_strategy = "vertical",
layout_config = {
-- preview_cutoff = 120,
vertical = {
height = vim.o.lines,
width = vim.o.columns,
prompt_position = "top",
preview_height = 0.4,
mirror = true,
},
},
}
end
so yeah, we now changed our filetype detection on latest master from plenary.filetype
to vim.filetype
so we should be able to correctly apply highlighting if you register your filetypes using vim.filetype.add
(which is the preferred way anyway).
We will never run "BufNewFile", "BufFilePost", "BufRead"
autocommands for previewer, because these autocommands could have unwanted side effects and negative performance impact.
Also please read :help telescope.changelog-2529
I don't think we run the on_detect
function returned from vim.filetype.match
so you have to return set the returning filetype as the filetype of the syntax you want but something like this will work.
vim.filetype.add({
extension = {
brs = function(path, bufnr)
return "vb", function(bufnr) -- return ft="vb" here to get "vb" syntax highlighting in telescope previewer
vim.bo[bufnr].filetype = "brs" -- re-set filetype to "brs" if preferred
vim.bo[bufnr].syntax = "vb"
-- more settings
end
end
}
})
@boydkelly
markdown syntax highlight works for me using that custom grep_string
function
with this min config
vim.cmd([[set runtimepath=$VIMRUNTIME]])
vim.cmd([[set packpath=/tmp/nvim/site]])
local package_root = "/tmp/nvim/site/pack"
local install_path = package_root .. "/packer/start/packer.nvim"
local function load_plugins()
require("packer").startup({
{
"wbthomason/packer.nvim",
{
"nvim-telescope/telescope.nvim",
requires = {
"nvim-lua/plenary.nvim",
{ "nvim-telescope/telescope-fzf-native.nvim", run = "make" },
},
},
-- ADD PLUGINS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
},
config = {
package_root = package_root,
compile_path = install_path .. "/plugin/packer_compiled.lua",
display = { non_interactive = true },
},
})
end
_G.load_config = function()
require("telescope").setup()
require("telescope").load_extension("fzf")
-- ADD INIT.LUA SETTINGS THAT ARE _NECESSARY_ FOR REPRODUCING THE ISSUE
vim.api.nvim_create_user_command("TestGS", function()
require("telescope.builtin").grep_string({
file_ignore_patterns = {
".xhtml",
".svg",
".idx",
".dat",
".dic",
".all.txt",
".delete-sed.txt",
},
-- cwd = "$HOME/Documents/Jula/search",
path_display = { "hidden" },
prompt_title = "Mandenkan",
-- preview_title = false,
layout_strategy = "vertical",
layout_config = {
-- preview_cutoff = 120,
vertical = {
height = vim.o.lines,
width = vim.o.columns,
prompt_position = "top",
preview_height = 0.4,
mirror = true,
},
},
})
end, {})
end
if vim.fn.isdirectory(install_path) == 0 then
print("Installing Telescope and dependencies.")
vim.fn.system({
"git",
"clone",
"--depth=1",
"https://github.com/wbthomason/packer.nvim",
install_path,
})
end
load_plugins()
require("packer").sync()
vim.cmd([[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]])
I don't think we run the
on_detect
function returned fromvim.filetype.match
so you have to return set the returning filetype as the filetype of the syntax you want but something like this will work.vim.filetype.add({ extension = { brs = function(path, bufnr) return "vb", function(bufnr) -- return ft="vb" here to get "vb" syntax highlighting in telescope previewer vim.bo[bufnr].filetype = "brs" -- re-set filetype to "brs" if preferred vim.bo[bufnr].syntax = "vb" -- more settings end end } })
Thanks!
However, now when the previewer tries to display a .brs file. It says it can't display binary files. Not sure how to get around that.
.brs is not a binary it is the extension for Roku Brightscript.
You probably just have to update telescope
@boydkelly markdown syntax highlight works for me using that custom
grep_string
function with this min confighmmm. Maybe my issue is a bit different. So its not actually the 'Grep Preview window but the
Results
window where the search term is not highlighted. This example is an adoc file. First image with live_grep, second with grep_string. Is this somehow an issue with the highlight group?
Thats a completly different issue and we are currently working on that
You probably just have to update telescope
I am running the latest version
Are you sure?
I'm able to get a proper file preview with syntax highlighting using the minimal config + the vim.filetype.add
from above.
It appears there is a commit that fixes unknown file types just recently. So this is resolved.
Description
Steps to reproduce
brs.lua
:Telescope grep_string
Expected Results
No syntax highlights applied *.brs files
Actual Results
Syntax highlights SHOULD be applied to *.brs files
Notes
Syntax highlighting is correct when finding files.
Neovim version
Operating system and version
13.3.1
Telescope version / branch / rev
master
checkhealth telescope
Steps to reproduce
brs.lua
:Telescope grep_string
Expected behavior
No syntax highlights applied *.brs files
Actual behavior
Syntax highlighting is correct when finding files.
Minimal config