diff options
| author | Nathan Zeng <nathan.j.zeng@gmail.com> | 2026-05-13 04:31:17 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-05-13 07:31:17 -0400 |
| commit | dbdd73e84673ae730bd719b3a4be0133ca845b8a (patch) | |
| tree | 2d1f4a44f7504b42b27edb936a35dbcae22e3f23 /runtime/lua/nvim | |
| parent | 8b11734b1838c1c99ff5bdb2895ec05d5ad41993 (diff) | |
| download | rneovim-dbdd73e84673ae730bd719b3a4be0133ca845b8a.tar.gz rneovim-dbdd73e84673ae730bd719b3a4be0133ca845b8a.tar.bz2 rneovim-dbdd73e84673ae730bd719b3a4be0133ca845b8a.zip | |
refactor(tutor): use inline comments instead of json file #39714
Problem: Expected text for interactive marks is in a separate json file
from the tutor file. When the tutor file is updated, line numbers
(potentially many) have to be updated in the json file. This is a
burden for maintenance and automatic testing.
Solution: Put the expected text inline in the tutor file, marked
with `[[]]`. Parse and remove the comments before opening the tutor
file so extmarks can be applied.
Diffstat (limited to 'runtime/lua/nvim')
| -rw-r--r-- | runtime/lua/nvim/tutor.lua | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/runtime/lua/nvim/tutor.lua b/runtime/lua/nvim/tutor.lua index 97bfbbb2d0..fb6693024c 100644 --- a/runtime/lua/nvim/tutor.lua +++ b/runtime/lua/nvim/tutor.lua @@ -16,6 +16,30 @@ local tutor_hl_ns = vim.api.nvim_create_namespace('nvim.tutor.hl') local M = {} +-- Extract inline comments into metadata. +-- Example: "This is wrong. [[This is right.]]" => { '1' = 'This is right.'} +function M.load_metadata() + ---@type table<string, string|-1> + local data = {} + local lines = vim.api.nvim_buf_get_lines(0, 0, -1, false) + + for i, line in ipairs(lines) do + local text, expected_text = line:match('^(.-)%s%[%[(.-)%]%]$') + + if text then + if expected_text == '-1' then + data[tostring(i)] = -1 + else + data[tostring(i)] = expected_text + end + lines[i] = text + end + end + + vim.b.tutor_metadata = { expect = data } + vim.api.nvim_buf_set_lines(0, 0, -1, false, lines) +end + ---@param line integer 1-based local function check_line(line) if vim.b.tutor_metadata and vim.b.tutor_metadata.expect and vim.b.tutor_extmarks then |