From df02aa2d4d805e1a87cd39b858f602be23147851 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Sun, 23 Oct 2022 22:38:57 +0200 Subject: [PATCH] perf: dont set filetype for highlights. Use vim.treesitter.start instead. Fixes #104 --- README.md | 10 +++++----- lua/noice/config/cmdline.lua | 5 ++--- lua/noice/config/init.lua | 10 +++++----- lua/noice/config/routes.lua | 2 +- lua/noice/ui/cmdline.lua | 2 +- lua/noice/view/init.lua | 5 +++++ 6 files changed, 19 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 3b48ccae..48f82bb2 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ 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 format = { -- conceal: (default=true) This will hide the text in the cmdline that matches the pattern. @@ -67,10 +67,10 @@ Check the [wiki](https://github.com/folke/noice.nvim/wiki/Configuration-Recipes) -- 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` }, }, diff --git a/lua/noice/config/cmdline.lua b/lua/noice/config/cmdline.lua index 3782e57f..ba5ebb73 100644 --- a/lua/noice/config/cmdline.lua +++ b/lua/noice/config/cmdline.lua @@ -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 .. " ", diff --git a/lua/noice/config/init.lua b/lua/noice/config/init.lua index a8295dfd..3350d059 100644 --- a/lua/noice/config/init.lua +++ b/lua/noice/config/init.lua @@ -11,7 +11,7 @@ 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 format = { -- conceal: (default=true) This will hide the text in the cmdline that matches the pattern. @@ -19,10 +19,10 @@ M.defaults = { -- 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` }, }, diff --git a/lua/noice/config/routes.lua b/lua/noice/config/routes.lua index 14c0c573..b1110dfa 100644 --- a/lua/noice/config/routes.lua +++ b/lua/noice/config/routes.lua @@ -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, diff --git a/lua/noice/ui/cmdline.lua b/lua/noice/ui/cmdline.lua index 9b53af1a..a796348f 100644 --- a/lua/noice/ui/cmdline.lua +++ b/lua/noice/ui/cmdline.lua @@ -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 diff --git a/lua/noice/view/init.lua b/lua/noice/view/init.lua index 030ff1cc..0e73a6bf 100644 --- a/lua/noice/view/init.lua +++ b/lua/noice/view/init.lua @@ -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 @@ -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