diff options
Diffstat (limited to 'runtime')
-rw-r--r-- | runtime/doc/api.txt | 6 | ||||
-rw-r--r-- | runtime/doc/options.txt | 6 | ||||
-rw-r--r-- | runtime/lua/vim/treesitter/highlighter.lua | 25 | ||||
-rw-r--r-- | runtime/queries/c/highlights.scm | 2 | ||||
-rw-r--r-- | runtime/queries/lua/highlights.scm | 2 | ||||
-rw-r--r-- | runtime/queries/vim/highlights.scm | 2 |
6 files changed, 37 insertions, 6 deletions
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt index ea562e60b6..00a3759936 100644 --- a/runtime/doc/api.txt +++ b/runtime/doc/api.txt @@ -2646,6 +2646,8 @@ nvim_buf_set_extmark({buffer}, {ns_id}, {line}, {col}, {*opts}) When a character is supplied it is used as |:syn-cchar|. "hl_group" is used as highlight for the cchar if provided, otherwise it defaults to |hl-Conceal|. + • spell: boolean indicating that spell checking should be + performed within this extmark • ui_watched: boolean that indicates the mark should be drawn by a UI. When set, the UI will receive win_extmark events. Note: the mark is positioned by virt_text @@ -2677,7 +2679,7 @@ nvim_get_namespaces() *nvim_get_namespaces()* dict that maps from names to namespace ids. *nvim_set_decoration_provider()* -nvim_set_decoration_provider({ns_id}, {opts}) +nvim_set_decoration_provider({ns_id}, {*opts}) Set or change decoration provider for a namespace This is a very general purpose interface for having lua callbacks being @@ -2709,7 +2711,7 @@ nvim_set_decoration_provider({ns_id}, {opts}) Parameters: ~ {ns_id} Namespace id from |nvim_create_namespace()| - {opts} Callbacks invoked during redraw: + {opts} Table of callbacks: • on_start: called first on each screen redraw ["start", tick] • on_buf: called for each buffer being redrawn (before window diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt index 316b7ae3f1..b84a41eabc 100644 --- a/runtime/doc/options.txt +++ b/runtime/doc/options.txt @@ -5871,10 +5871,14 @@ A jump table for the options with a short description can be found at |Q_op|. 'spelloptions' 'spo' string (default "") local to buffer A comma-separated list of options for spell checking: - camel When a word is CamelCased, assume "Cased" is a + camel When a word is CamelCased, assume "Cased" is a separate word: every upper-case character in a word that comes after a lower case character indicates the start of a new word. + noplainbuffer Only spellcheck a buffer when 'syntax' is enabled, or + or when extmarks are set within the buffer. Only + designated regions of the buffer are spellchecked in + this case. *'spellsuggest'* *'sps'* 'spellsuggest' 'sps' string (default "best") diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua index 1f242b0fdd..9e95af98db 100644 --- a/runtime/lua/vim/treesitter/highlighter.lua +++ b/runtime/lua/vim/treesitter/highlighter.lua @@ -97,6 +97,7 @@ function TSHighlighter.new(tree, opts) if vim.g.syntax_on ~= 1 then vim.api.nvim_command('runtime! syntax/synload.vim') end + vim.bo[self.bufnr].spelloptions = 'noplainbuffer' self.tree:parse() @@ -156,7 +157,7 @@ function TSHighlighter:get_query(lang) end ---@private -local function on_line_impl(self, buf, line) +local function on_line_impl(self, buf, line, spell) self.tree:for_each_tree(function(tstree, tree) if not tstree then return @@ -193,7 +194,9 @@ local function on_line_impl(self, buf, line) local start_row, start_col, end_row, end_col = node:range() local hl = highlighter_query.hl_cache[capture] - if hl and end_row >= line then + local is_spell = highlighter_query:query().captures[capture] == 'spell' + + if hl and end_row >= line and (not spell or is_spell) then a.nvim_buf_set_extmark(buf, ns, start_row, start_col, { end_line = end_row, end_col = end_col, @@ -201,6 +204,7 @@ local function on_line_impl(self, buf, line) ephemeral = true, priority = tonumber(metadata.priority) or 100, -- Low but leaves room below conceal = metadata.conceal, + spell = is_spell, }) end if start_row > line then @@ -217,7 +221,21 @@ function TSHighlighter._on_line(_, _win, buf, line, _) return end - on_line_impl(self, buf, line) + on_line_impl(self, buf, line, false) +end + +---@private +function TSHighlighter._on_spell_nav(_, _, buf, srow, _, erow, _) + local self = TSHighlighter.active[buf] + if not self then + return + end + + self:reset_highlight_state() + + for row = srow, erow do + on_line_impl(self, buf, row, true) + end end ---@private @@ -244,6 +262,7 @@ a.nvim_set_decoration_provider(ns, { on_buf = TSHighlighter._on_buf, on_win = TSHighlighter._on_win, on_line = TSHighlighter._on_line, + _on_spell_nav = TSHighlighter._on_spell_nav, }) return TSHighlighter diff --git a/runtime/queries/c/highlights.scm b/runtime/queries/c/highlights.scm index 260750a85b..33e6df74ab 100644 --- a/runtime/queries/c/highlights.scm +++ b/runtime/queries/c/highlights.scm @@ -101,6 +101,7 @@ [ "(" ")" "[" "]" "{" "}"] @punctuation.bracket (string_literal) @string +(string_literal) @spell (system_lib_string) @string (null) @constant.builtin @@ -148,6 +149,7 @@ (comment) @comment +(comment) @spell ;; Parameters (parameter_declaration diff --git a/runtime/queries/lua/highlights.scm b/runtime/queries/lua/highlights.scm index 92baba0f39..054d787932 100644 --- a/runtime/queries/lua/highlights.scm +++ b/runtime/queries/lua/highlights.scm @@ -181,12 +181,14 @@ ;; Others (comment) @comment +(comment) @spell (hash_bang_line) @comment (number) @number (string) @string +(string) @spell ;; Error (ERROR) @error diff --git a/runtime/queries/vim/highlights.scm b/runtime/queries/vim/highlights.scm index c02e226b66..1bbaebef01 100644 --- a/runtime/queries/vim/highlights.scm +++ b/runtime/queries/vim/highlights.scm @@ -162,9 +162,11 @@ ;; Literals (string_literal) @string +(string_literal) @spell (integer_literal) @number (float_literal) @float (comment) @comment +(comment) @spell (pattern) @string.special (pattern_multi) @string.regex (filename) @string |