Skip to content

Commit

Permalink
refactor: move trim to strings module
Browse files Browse the repository at this point in the history
  • Loading branch information
mrcjkb committed Aug 20, 2023
1 parent 5e32f16 commit 90471aa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
4 changes: 2 additions & 2 deletions lua/haskell-tools/project/stack.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
-- local ht_util = require('haskell-tools.util')
-- local Path = require('plenary.path')

local HtUtil = require('haskell-tools.util')
local Strings = require('haskell-tools.strings')
local HtParser = require('haskell-tools.parser')
local Dap = require('haskell-tools.dap.internal')
local OS = require('haskell-tools.os')
Expand All @@ -23,7 +23,7 @@ local StackProjectHelper = {}
---@param str string
---@return boolean is_yaml_comment
local function is_yaml_comment(str)
return vim.startswith(HtUtil.trim(str), '#')
return vim.startswith(Strings.trim(str), '#')
end

---@class StackEntryPointParserData
Expand Down
4 changes: 2 additions & 2 deletions lua/haskell-tools/project/util.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

local log = require('haskell-tools.log')
local deps = require('haskell-tools.deps')
local HtUtil = require('haskell-tools.util')
local Strings = require('haskell-tools.strings')
local OS = require('haskell-tools.os')
local cabal = require('haskell-tools.project.cabal')
local stack = require('haskell-tools.project.stack')
Expand Down Expand Up @@ -214,7 +214,7 @@ function HtProjectUtil.parse_package_paths(project_file)
end
end
if packages_start then
local trimmed = HtUtil.trim(line)
local trimmed = Strings.trim(line)
local pkg_rel_path = trimmed:match('/(.+)')
local pkg_path = Path:new(project_dir, pkg_rel_path).filename
if vim.fn.isdirectory(pkg_path) == 1 then
Expand Down
11 changes: 5 additions & 6 deletions lua/haskell-tools/util.lua → lua/haskell-tools/strings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,17 @@
---WARNING: This is not part of the public API.
---Breaking changes to this module will not be reflected in the semantic versioning of this plugin.

--- General utility functions that may need to be moved somewhere else
--- Helper functions for working with strings
---@brief ]]

---@class HtUtil
local HtUtil = {}
---@class StringsUtil
local Strings = {}

---TODO: Move this to a "strings" module?
---Trim leading and trailing whitespace.
---@param str string
---@return string trimmed
HtUtil.trim = function(str)
Strings.trim = function(str)
return (str:match('^%s*(.*)') or str):gsub('%s*$', '')
end

return HtUtil
return Strings

0 comments on commit 90471aa

Please sign in to comment.