gopher.nvim/lua/gopher/_utils/init.lua
Oleksandr Smirnov 1e7af1b212
feat(comment): add support for: interface methods, struct fields, variables (#123)
* refactor(comment): dont use unnecessary function

* chore: quick way to open vim in dev mode

* feat(comment): add comment on on interface method

* feat(comment): add comment on a struct field

* feat(comment): add comment on a variable

* docs: add note about the generate function

* docs: gopher.TsResult

* fix(utils): handle case when indentation is wrong
2025-09-04 16:52:18 +03:00

53 lines
1.1 KiB
Lua

local c = require "gopher.config"
local log = require "gopher._utils.log"
local utils = {}
---@param msg string
---@param lvl? integer by default `vim.log.levels.INFO`
function utils.notify(msg, lvl)
lvl = lvl or vim.log.levels.INFO
vim.notify(msg, lvl, {
---@diagnostic disable-next-line:undefined-field
title = c.___plugin_name,
})
log.debug(msg)
end
---@param path string
---@return string
function utils.readfile_joined(path)
return table.concat(vim.fn.readfile(path), "\n")
end
---@param t string[]
---@return string[]
function utils.remove_empty_lines(t)
local res = {}
for _, line in ipairs(t) do
if line ~= "" then
table.insert(res, line)
end
end
return res
end
---@param s string
---@return string
function utils.trimend(s)
local r, _ = string.gsub(s, "%s+$", "")
return r
end
-- Since indentation can be spaces or tabs, that's my hack around it
---@param line string
---@param indent integer
---@return string
function utils.indent(line, indent)
local char = string.sub(line, 1, 1)
if char ~= " " and char ~= "\t" then
char = " "
end
return string.rep(char, indent)
end
return utils