docs: update doc file

This commit is contained in:
2024-05-15 23:23:14 +03:00
committed by Chen Asraf
parent 9c62c9cd9d
commit 16069971e9
7 changed files with 97 additions and 102 deletions

View File

@@ -7,8 +7,6 @@ local common = require("text-transform.popup.common")
local TextTransform = {}
--- Initializes user commands
--- @private
function TextTransform.init_commands()
local map = {
TtCamel = "camel_case",
@@ -56,8 +54,6 @@ function TextTransform.init_commands()
vim.api.nvim_create_user_command("TextTransform", popup.show_popup, opts("Change Case"))
end
--- Initializes user keymaps
--- @private
function TextTransform.init_keymaps()
local keymaps = _G.TextTransform.config.keymap
D.log("init_keymaps", "Initializing keymaps, config %s", vim.inspect(_G.TextTransform))

View File

@@ -5,9 +5,9 @@ local t = require("text-transform.transformers")
local TextTransform = {}
--- Finds the boundaries of the surrounding word around `start_col` within `line`.
--- @param line number
--- @param start_col number
--- @return number start_col, number end_col
---@param line number
---@param start_col number
---@return number start_col, number end_col
local function find_word_boundaries(line, start_col)
local line_text = vim.fn.getline(line)
-- dashes, underscores, and periods are considered part of a word
@@ -31,15 +31,15 @@ end
--- Replace the range between the given positions with the given transform.
--- Acts on the lines between the given positions, replacing the text between the given columns.
---
--- @param start_line number The starting line
--- @param start_col number The starting column
--- @param end_line number The ending line
--- @param end_col number The ending column
--- @param transform_name string The transformer name
---@param start_line number The starting line
---@param start_col number The starting column
---@param end_line number The ending line
---@param end_col number The ending column
---@param transform_name string The transformer name
function TextTransform.replace_range(start_line, start_col, end_line, end_col, transform_name)
D.log("replace_range", "Replacing range with %s", transform_name)
local transform = t["to_" .. transform_name]
local lines = vim.fn.getline(start_line, end_line) --- @type any
local lines = vim.fn.getline(start_line, end_line) ---@type any
local transformed = {}
if #lines == 1 then
local line = lines[1]
@@ -66,8 +66,8 @@ end
--- If `position` is provided, replace the word under the given position.
--- Otherwise, attempts to find the word under the cursor.
---
--- @param transform_name string The transformer name
--- @param position table|nil A table containing the position of the word to replace
---@param transform_name string The transformer name
---@param position table|nil A table containing the position of the word to replace
function TextTransform.replace_word(transform_name, position)
D.log("replace_word", "Replacing word with %s", transform_name)
local word, line, col, start_col, end_col
@@ -93,7 +93,7 @@ end
--- Replaces each column in visual block mode selection with the given transform.
--- Assumes that the each selection is 1 character and operates on the whole word under each cursor.
---
--- @param transform_name string The transformer name
---@param transform_name string The transformer name
function TextTransform.replace_columns(transform_name)
local selections = TextTransform.get_visual_selection_details()
D.log("replace_columns", "Replacing columns with %s", transform_name)
@@ -106,7 +106,7 @@ end
--- type based on the cursor positiono and visual selections, and passes information to relevant
--- range replacement functions.
---
--- @param transform_name string The transformer name
---@param transform_name string The transformer name
function TextTransform.replace_selection(transform_name)
D.log("replace_selection", "Replacing selection with %s", transform_name)
-- determine if cursor is a 1-width column across multiple lines or a normal selection

View File

@@ -6,8 +6,8 @@ local TextTransform = {}
TextTransform.WORD_BOUNDRY = "[%_%-%s%.]"
--- Splits a string into words.
--- @param string string
--- @return table
---@param string string
---@return table
function TextTransform.to_words(string)
local words = {}
local word = ""
@@ -60,10 +60,10 @@ end
--- The callback is called with the word, the index, and the table of words.
--- The separator is added between each word.
---
--- @param words string|table string or table of strings
--- @param with_word_cb function (word: string, index: number, words: table) -> string
--- @param separator string|nil (optional)
--- @return string
---@param words string|table string or table of strings
---@param with_word_cb function (word: string, index: number, words: table) -> string
---@param separator string|nil (optional)
---@return string
function TextTransform.transform_words(words, with_word_cb, separator)
if type(words) ~= "table" then
words = TextTransform.to_words(words)
@@ -81,8 +81,8 @@ function TextTransform.transform_words(words, with_word_cb, separator)
end
--- Transforms a string into camelCase.
--- @param string string
--- @return string
---@param string string
---@return string
function TextTransform.to_camel_case(string)
return TextTransform.transform_words(string, function(word, i)
if i == 1 then
@@ -93,8 +93,8 @@ function TextTransform.to_camel_case(string)
end
--- Transfroms a string into snake_case.
--- @param string any
--- @return string
---@param string any
---@return string
function TextTransform.to_snake_case(string)
return TextTransform.transform_words(string, function(word, i)
if i == 1 then
@@ -105,16 +105,16 @@ function TextTransform.to_snake_case(string)
end
--- Transforms a string into PascalCase.
--- @param string string
--- @return string
---@param string string
---@return string
function TextTransform.to_pascal_case(string)
local cc = TextTransform.to_camel_case(string)
return cc:sub(1, 1):upper() .. cc:sub(2)
end
--- Transforms a string into Title Case.
--- @param string string
--- @return string
---@param string string
---@return string
function TextTransform.to_title_case(string)
return TextTransform.transform_words(string, function(word)
return word:sub(1, 1):upper() .. word:sub(2):lower()
@@ -122,8 +122,8 @@ function TextTransform.to_title_case(string)
end
--- Transforms a string into kebab-case.
--- @param string string
--- @return string
---@param string string
---@return string
function TextTransform.to_kebab_case(string)
return TextTransform.transform_words(string, function(word)
return word:lower()
@@ -131,8 +131,8 @@ function TextTransform.to_kebab_case(string)
end
--- Transforms a string into dot.case.
--- @param string string
--- @return string
---@param string string
---@return string
function TextTransform.to_dot_case(string)
return TextTransform.transform_words(string, function(word)
return word:lower()
@@ -140,8 +140,8 @@ function TextTransform.to_dot_case(string)
end
--- Transforms a string into CONSTANT_CASE.
--- @param string string
--- @return string
---@param string string
---@return string
function TextTransform.to_const_case(string)
return TextTransform.transform_words(string, function(word)
return word:upper()

View File

@@ -6,12 +6,6 @@ local function is_debug()
and _G.TextTransform.config.debug
end
---prints only if debug is true.
---
---@param scope string: the scope from where this function is called.
---@param str string: the formatted string.
---@param ... any: the arguments of the formatted string.
---@private
function D.log(scope, str, ...)
if not is_debug() then
return
@@ -35,11 +29,6 @@ function D.log(scope, str, ...)
)
end
---prints the table if debug is true.
---
---@param table table: the table to print.
---@param indent number?: the default indent value, starts at 0.
---@private
function D.tprint(table, indent)
if not is_debug() then
return

View File

@@ -5,9 +5,9 @@ local TextTransform = {}
---
--- TODO accept multiple tables to merge
---
--- @param t1 table
--- @param t2 table
--- @return table
---@param t1 table
---@param t2 table
---@return table
function TextTransform.merge(t1, t2)
return vim.tbl_extend("force", t1, t2)
end