Skip to content

Commit

Permalink
perf: dont set filetype for highlights. Use vim.treesitter.start inst…
Browse files Browse the repository at this point in the history
…ead. Fixes #104
  • Loading branch information
folke committed Oct 23, 2022
1 parent f7c093c commit df02aa2
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 15 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ Check the [wiki](https://github.com/folke/noice.nvim/wiki/Configuration-Recipes)
cmdline = {
enabled = true, -- enables the Noice cmdline UI
view = "cmdline_popup", -- view for rendering the cmdline. Change to `cmdline` to get a classic cmdline at the bottom
opts = { buf_options = { filetype = "vim" } }, -- enable syntax highlighting in the cmdline
opts = { lang = "vim" }, -- enable syntax highlighting in the cmdline
---@type table<string, CmdlineFormat>
format = {
-- conceal: (default=true) This will hide the text in the cmdline that matches the pattern.
-- view: (default is cmdline view)
-- opts: any options passed to the view
-- icon_hl_group: optional hl_group for the icon
cmdline = { pattern = "^:", icon = "" },
search_down = { kind = "search", pattern = "^/", icon = " ", ft = "regex" },
search_up = { kind = "search", pattern = "^%?", icon = " ", ft = "regex" },
filter = { pattern = "^:%s*!", icon = "$", ft = "sh" },
lua = { pattern = "^:%s*lua%s+", icon = "", ft = "lua" },
search_down = { kind = "search", pattern = "^/", icon = " ", lang = "regex" },
search_up = { kind = "search", pattern = "^%?", icon = " ", lang = "regex" },
filter = { pattern = "^:%s*!", icon = "$", lang = "sh" },
lua = { pattern = "^:%s*lua%s+", icon = "", lang = "lua" },
-- lua = false, -- to disable a format, set to `false`
},
},
Expand Down
5 changes: 2 additions & 3 deletions lua/noice/config/cmdline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,8 @@ function M.setup()
icon_hl_group = "Noice" .. hl_group_icon,
view = Config.options.cmdline.view,
opts = {
buf_options = {
filetype = format.ft,
},
---@diagnostic disable-next-line: undefined-field
lang = format.lang or format.ft,
border = {
text = {
top = " " .. kind_cc .. " ",
Expand Down
10 changes: 5 additions & 5 deletions lua/noice/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ M.defaults = {
cmdline = {
enabled = true, -- enables the Noice cmdline UI
view = "cmdline_popup", -- view for rendering the cmdline. Change to `cmdline` to get a classic cmdline at the bottom
opts = { buf_options = { filetype = "vim" } }, -- enable syntax highlighting in the cmdline
opts = { lang = "vim" }, -- enable syntax highlighting in the cmdline
---@type table<string, CmdlineFormat>
format = {
-- conceal: (default=true) This will hide the text in the cmdline that matches the pattern.
-- view: (default is cmdline view)
-- opts: any options passed to the view
-- icon_hl_group: optional hl_group for the icon
cmdline = { pattern = "^:", icon = "" },
search_down = { kind = "search", pattern = "^/", icon = " ", ft = "regex" },
search_up = { kind = "search", pattern = "^%?", icon = " ", ft = "regex" },
filter = { pattern = "^:%s*!", icon = "$", ft = "sh" },
lua = { pattern = "^:%s*lua%s+", icon = "", ft = "lua" },
search_down = { kind = "search", pattern = "^/", icon = " ", lang = "regex" },
search_up = { kind = "search", pattern = "^%?", icon = " ", lang = "regex" },
filter = { pattern = "^:%s*!", icon = "$", lang = "bash" },
lua = { pattern = "^:%s*lua%s+", icon = "", lang = "lua" },
-- lua = false, -- to disable a format, set to `false`
},
},
Expand Down
2 changes: 1 addition & 1 deletion lua/noice/config/routes.lua
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ function M.defaults()
event = "noice",
kind = { "stats", "debug" },
},
opts = { buf_options = { filetype = "lua" }, replace = true, title = "Noice" },
opts = { lang = "lua", replace = true, title = "Noice" },
},
{
view = Config.options.lsp_progress.view,
Expand Down
2 changes: 1 addition & 1 deletion lua/noice/ui/cmdline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ M.events = {
---@field icon? string
---@field icon_hl_group? string
---@field opts? NoiceViewOptions
---@field ft? string
---@field lang? string

---@class NoiceCmdline
---@field state CmdlineState
Expand Down
5 changes: 5 additions & 0 deletions lua/noice/view/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ local Format = require("noice.text.format")
---@field fallback string Fallback view in case the backend could not be loaded
---@field format? NoiceFormat|string
---@field align? NoiceAlign
---@field lang? string
---@field view string

---@alias NoiceViewOptions NoiceViewBaseOptions|NoiceNuiOptions|NoiceNotifyOptions
Expand Down Expand Up @@ -199,6 +200,10 @@ function View:render(buf, opts)
require("nui.utils")._.set_buf_options(buf, self._opts.buf_options)
end

if self._opts.lang and not vim.b[buf].ts_highlight then
vim.treesitter.start(buf, self._opts.lang)
end

vim.api.nvim_buf_clear_namespace(buf, Config.ns, linenr - 1, -1)

if not opts.highlight then
Expand Down

0 comments on commit df02aa2

Please sign in to comment.