Repository: neovim/neovim
File: runtime/ftplugin/help.lua (Lua)

Code before:
        local lang_node = match[metadata[id].lang][1] --[[@as TSNode]]
        local lang = vim.treesitter.get_node_text(lang_node, 0)
        for i = start + 1, end_ do
          code_blocks[i] = { lang = lang, code = code }
        end
      end
    end
  end

  vim.keymap.set('n', 'g==', function()
    local pos = vim.api.nvim_win_get_cursor(0)[1]
    local code_block = code_blocks[pos]
    if not code_block then
      vim.print('No code block found')
    elseif code_block.lang == 'lua' then
      vim.cmd.lua(code_block.code)
    elseif code_block.lang == 'vim' then
      vim.cmd(code_block.code)
    end
  end, { buffer = true })
end

-- Retry once if the buffer has changed during the iteration of the code
-- blocks. See #36574.
if not pcall(runnables) then
  pcall(runnables)
end

local url_ns = vim.api.nvim_create_namespace('nvim.help.urls')
local function urls()
  local filepath = vim.fs.normalize(vim.api.nvim_buf_get_name(0))

  if vim.fs.relpath(vim.env.VIMRUNTIME, filepath) ~= nil then
    local base = 'https://neovim.io/doc/user/helptag.html?tag='
    local query = vim.treesitter.query.parse(
      'vimdoc',
      [[
    ((optionlink) @helplink)
    (taglink
      text: (_) @helplink)
    (tag
      text: (_) @helplink)
    ]]
    )

    vim.api.nvim_buf_clear_namespace(0, url_ns, 0, -1)
    local root = parser:parse()[1]:root()
    for _, match, _ in query:iter_matches(root, 0, 0, -1) do
      for id, nodes in pairs(match) do
        if query.captures[id] == 'helplink' then
          for _, node in ipairs(nodes) do

Review comment (bug):
Perhaps we should raise errors on the retry step, WDYT? Because, otherwise we may not notice when things go wrong again (or it will be hard to trace).

```suggestion
  runnables()
```

Code after:
        local lang_node = match[metadata[id].lang][1] --[[@as TSNode]]
        local lang = vim.treesitter.get_node_text(lang_node, 0)
        for i = start + 1, end_ do
          code_blocks[i] = { lang = lang, code = code }
        end
      end
    end
  end

  vim.keymap.set('n', 'g==', function()
    local pos = vim.api.nvim_win_get_cursor(0)[1]
    local code_block = code_blocks[pos]
    if not code_block then
      vim.print('No code block found')
    elseif code_block.lang == 'lua' then
      vim.cmd.lua(code_block.code)
    elseif code_block.lang == 'vim' then
      vim.cmd(code_block.code)
    end
  end, { buffer = true })
end

-- Retry once if the buffer has changed during the iteration of the code
-- blocks. See #36574.
if not pcall(runnables) then
  runnables()
end

local url_ns = vim.api.nvim_create_namespace('nvim.help.urls')
local function urls()
  local filepath = vim.fs.normalize(vim.api.nvim_buf_get_name(0))

  if vim.fs.relpath(vim.env.VIMRUNTIME, filepath) ~= nil then
    local base = 'https://neovim.io/doc/user/helptag.html?tag='
    local query = vim.treesitter.query.parse(
      'vimdoc',
      [[
    ((optionlink) @helplink)
    (taglink
      text: (_) @helplink)
    (tag
      text: (_) @helplink)
    ]]
    )

    vim.api.nvim_buf_clear_namespace(0, url_ns, 0, -1)
    local root = parser:parse()[1]:root()
    for _, match, _ in query:iter_matches(root, 0, 0, -1) do
      for id, nodes in pairs(match) do
        if query.captures[id] == 'helplink' then
          for _, node in ipairs(nodes) do