summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/core/folding.lua2
-rw-r--r--script/utility.lua37
3 files changed, 30 insertions, 10 deletions
diff --git a/changelog.md b/changelog.md
index 906cfe99..25ec001f 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,6 +1,7 @@
# changelog
## 1.20.5
+`CHG` folding: supports `-- #region`
`FIX` [#522](https://github.com/sumneko/lua-language-server/issues/522)
`FIX` [#523](https://github.com/sumneko/lua-language-server/issues/523)
diff --git a/script/core/folding.lua b/script/core/folding.lua
index 77cb39e7..15678995 100644
--- a/script/core/folding.lua
+++ b/script/core/folding.lua
@@ -1,5 +1,6 @@
local files = require "files"
local guide = require "core.guide"
+local util = require 'utility'
local Care = {
['function'] = function (source, text, results)
@@ -92,6 +93,7 @@ local Care = {
end,
['comment.short'] = function (source, text, results, status)
local ltext = source.text:lower()
+ ltext = util.trim(ltext, 'left')
if ltext:sub(1, #'region') == 'region'
or ltext:sub(1, #'#region') == '#region' then
if not status.regions then
diff --git a/script/utility.lua b/script/utility.lua
index a98bef92..04597a39 100644
--- a/script/utility.lua
+++ b/script/utility.lua
@@ -23,6 +23,14 @@ local utf8 = utf8
_ENV = nil
+local function isInteger(n)
+ if mathType then
+ return mathType(n) == 'integer'
+ else
+ return type(n) == 'number' and n % 1 == 0
+ end
+end
+
local function formatNumber(n)
if n == inf
or n == -inf
@@ -30,7 +38,7 @@ local function formatNumber(n)
or n ~= n then -- IEEE 标准中,NAN 不等于自己。但是某些实现中没有遵守这个规则
return ('%q'):format(n)
end
- if mathType(n) == 'integer' then
+ if isInteger(n) then
return tostring(n)
end
local str = ('%.10f'):format(n)
@@ -38,14 +46,6 @@ local function formatNumber(n)
return str
end
-local function isInteger(n)
- if mathType then
- return mathType(n) == 'integer'
- else
- return type(n) == 'number' and n % 1 == 0
- end
-end
-
local TAB = setmetatable({}, { __index = function (self, n)
self[n] = stringRep(' ', n)
return self[n]
@@ -204,7 +204,10 @@ function m.equal(a, b)
end
return true
elseif tp1 == 'number' then
- return mathAbs(a - b) <= 1e-10
+ if mathAbs(a - b) <= 1e-10 then
+ return true
+ end
+ return tostring(a) == tostring(b)
else
return a == b
end
@@ -617,4 +620,18 @@ function m.sortByScore(tbl, callbacks)
end)
end
+---裁剪字符串
+---@param str string
+---@param mode? '"left"'|'"right"'
+---@return string
+function m.trim(str, mode)
+ if mode == "left" then
+ return str:gsub('^%s+', '')
+ end
+ if mode == "right" then
+ return str:gsub('%s+$', '')
+ end
+ return str:match '^%s*(%S+)%s*$'
+end
+
return m