Repository: neovim/neovim
File: runtime/lua/vim/_defaults.lua (Lua)

Code before:
    if cmd.bang then
      vim.print(vim.inspect_pos())
    else
      vim.show_pos()
    end
  end, { desc = 'Inspect highlights and extmarks at the cursor', bang = true })

  vim.api.nvim_create_user_command('InspectTree', function(cmd)
    local opts = { lang = cmd.fargs[1] }

    if cmd.mods ~= '' or cmd.count ~= 0 then
      local count = cmd.count ~= 0 and cmd.count or ''
      local new = cmd.mods ~= '' and 'new' or 'vnew'

      opts.command = ('%s %s%s'):format(cmd.mods, count, new)
    end

    vim.treesitter.inspect_tree(opts)
  end, { desc = 'Inspect treesitter language tree for buffer', count = true, nargs = '?' })

  vim.api.nvim_create_user_command('EditQuery', function(cmd)
    vim.treesitter.query.edit(cmd.fargs[1])
  end, {
    desc = 'Edit treesitter query',
    nargs = '?',
    complete = function()
      local parsers = vim.api.nvim_get_runtime_file('parser/*', true)
      local parser_names_set = {} ---@type table<string, boolean>
      for _, parser in ipairs(parsers) do
        local parser_name = vim.fn.fnamemodify(parser, ':t:r')
        parser_names_set[parser_name] = true
      end
      return vim.tbl_keys(parser_names_set)
    end,
  })

  vim.api.nvim_create_user_command('Open', function(cmd)
    vim.ui.open(assert(cmd.fargs[1]))
  end, {
    desc = 'Open file with system default handler. See :help vim.ui.open()',
    nargs = 1,
    complete = 'file',
  })
end

--- Default mappings
do
  --- Default maps for * and # in visual mode.
  ---
  --- See |v_star-default| and |v_#-default|
  do

Review comment (suggestion):
Let's put this logic in `vim.treesitter.query._complete()`. Need to keep defaults.lua as simple as possible.

Code after:
    if cmd.bang then
      vim.print(vim.inspect_pos())
    else
      vim.show_pos()
    end
  end, { desc = 'Inspect highlights and extmarks at the cursor', bang = true })

  vim.api.nvim_create_user_command('InspectTree', function(cmd)
    local opts = { lang = cmd.fargs[1] }

    if cmd.mods ~= '' or cmd.count ~= 0 then
      local count = cmd.count ~= 0 and cmd.count or ''
      local new = cmd.mods ~= '' and 'new' or 'vnew'

      opts.command = ('%s %s%s'):format(cmd.mods, count, new)
    end

    vim.treesitter.inspect_tree(opts)
  end, { desc = 'Inspect treesitter language tree for buffer', count = true, nargs = '?' })

  vim.api.nvim_create_user_command('EditQuery', function(cmd)
    vim.treesitter.query.edit(cmd.fargs[1])
  end, {
    desc = 'Edit treesitter query',
    nargs = '?',
    complete = function()
      return vim.treesitter.language._complete()
    end,
  })

  vim.api.nvim_create_user_command('Open', function(cmd)
    vim.ui.open(assert(cmd.fargs[1]))
  end, {
    desc = 'Open file with system default handler. See :help vim.ui.open()',
    nargs = 1,
    complete = 'file',
  })
end

--- Default mappings
do
  --- Default maps for * and # in visual mode.
  ---
  --- See |v_star-default| and |v_#-default|
  do
    local function _visual_search(forward)
      assert(forward == 0 or forward == 1)
      local pos = vim.fn.getpos('.')
      local vpos = vim.fn.getpos('v')
      local mode = vim.fn.mode()
      local chunks = vim.fn.getregion(pos, vpos, { type = mode })