<commit_before>local Files = require('ryankoval.util.files')

local function javascript(selection)
  return "console.log('" .. selection:gsub("'", "\\'") .. "', " .. selection .. ')'
end

local function lua(selection)
  return "vim.pretty_print('" .. selection:gsub("'", "\\'") .. "', " .. selection .. ')'
end

local function go(selection)
  return "log.Printf(\"" .. selection:gsub("'", "\\'") .. " %#v\", " .. selection .. ')'
end

local function python(selection)
  return "print(\"" .. selection:gsub("'", "\\'") .. "\", " .. selection .. ')'
end

local filetype_handlers = {
  ['javascript'] = javascript,
  ['typescript'] = javascript,
  ['lua'] = lua,
  ['go'] = go,
  ['python'] = python,
}

local function get_indentation()
  local line = vim.api.nvim_get_current_line()
  local start_index, end_index = line:find('^%s*')
  local indentation = string.sub(line, start_index, end_index)
  return indentation
end

local function add_log()
  local filetype = vim.bo.filetype
  local handler = filetype_handlers[filetype]
  if not handler then
    return
  end
  local selection = Files.get_selection()
  local text = handler(selection)
  local indentation = get_indentation()
  vim.fn.append('.', indentation .. text)<commit_msg>added typscript logs<commit_after>local Files = require('ryankoval.util.files')

local function javascript(selection)
  return "console.log('" .. selection:gsub("'", "\\'") .. "', " .. selection .. ')'
end

local function lua(selection)
  return "vim.pretty_print('" .. selection:gsub("'", "\\'") .. "', " .. selection .. ')'
end

local function go(selection)
  return 'log.Printf("' .. selection:gsub("'", "\\'") .. ' %#v", ' .. selection .. ')'
end

local function python(selection)
  return 'print("' .. selection:gsub("'", "\\'") .. '", ' .. selection .. ')'
end

local filetype_handlers = {
  ['javascript'] = javascript,
  ['javascriptreact'] = javascript,
  ['typescript'] = javascript,
  ['typescriptreact'] = javascript,
  ['lua'] = lua,
  ['go'] = go,
  ['python'] = python,
}

local function get_indentation()
  local line = vim.api.nvim_get_current_line()
  local start_index, end_index = line:find('^%s*')
  local indentation = string.sub(line, start_index, end_index)
  return indentation
end

local function add_log()
  local filetype = vim.bo.filetype
  local handler = filetype_handlers[filetype]
  if not handler then
    return
  end
  local selection = Files.get_selection()
  local text = handler(selection)
  local indentation = get_indentation()
  vim.fn.append('.', indentation .. text)
{'fraction_non_alphanumeric': 0.18781925343811395, 'fraction_numerical': 0.0, 'mean_word_length': 3.9055876685934487, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '914987', 'n_tokens_mistral': 850, 'n_tokens_neox': 824, 'n_words': 191}