summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-01-04 18:09:27 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-01-04 18:09:27 +0800
commita9c1b4135f3467a195c72ddceb393fa850399078 (patch)
tree03cb32cf111775080161ad3c179936983ae01de7
parentbed17488513b0e7e840f4e4e8cde7b281e646e47 (diff)
downloadlua-language-server-a9c1b4135f3467a195c72ddceb393fa850399078.zip
close #149 supports "--#region"
-rw-r--r--changelog.md2
-rw-r--r--script/core/completion.lua16
-rw-r--r--script/core/folding.lua28
-rw-r--r--test/completion/init.lua14
4 files changed, 57 insertions, 3 deletions
diff --git a/changelog.md b/changelog.md
index 93ad308a..6ad9d8e4 100644
--- a/changelog.md
+++ b/changelog.md
@@ -2,7 +2,7 @@
## 1.10.0
* `NEW` workspace: supports `.dll`(`.so`) in `require`
-* `NEW` folding: `---@class` and docs of function
+* `NEW` folding: `---@class`, `--#region` and docs of function
* `CHG` supports `~` in command line
* `CHG` completion: improve workspace words
* `CHG` completion: show words in string
diff --git a/script/core/completion.lua b/script/core/completion.lua
index 7fa9855b..140bee5c 100644
--- a/script/core/completion.lua
+++ b/script/core/completion.lua
@@ -1332,7 +1332,7 @@ end
local function getComment(ast, offset)
for _, comm in ipairs(ast.comms) do
- if offset >= comm.start and offset <= comm.finish then
+ if offset >= comm.start - 2 and offset <= comm.finish then
return comm
end
end
@@ -1643,6 +1643,20 @@ local function tryComment(ast, text, offset, results)
local word = findWord(text, offset)
local doc = getLuaDoc(ast, offset)
if not word then
+ local comment = getComment(ast, offset)
+ if comment.type == 'comment.short'
+ or comment.type == 'comment.cshort' then
+ if comment.text == '' then
+ results[#results+1] = {
+ label = '#region',
+ kind = define.CompletionItemKind.Snippet,
+ }
+ results[#results+1] = {
+ label = '#endregion',
+ kind = define.CompletionItemKind.Snippet,
+ }
+ end
+ end
return
end
if doc and doc.type ~= 'doc.comment' then
diff --git a/script/core/folding.lua b/script/core/folding.lua
index f7657631..ae69d8c3 100644
--- a/script/core/folding.lua
+++ b/script/core/folding.lua
@@ -90,6 +90,31 @@ local Care = {
}
results[#results+1] = folding
end,
+ ['comment.short'] = function (source, text, results, status)
+ local ltext = source.text:lower()
+ if ltext:sub(1, #'region') == 'region'
+ or ltext:sub(1, #'#region') == '#region' then
+ if not status.regions then
+ status.regions = {}
+ end
+ status.regions[#status.regions+1] = source
+ elseif ltext:sub(1, #'endregion') == 'endregion'
+ or ltext:sub(1, #'#endregion') == '#endregion' then
+ if not status.regions then
+ status.regions = {}
+ end
+ local start = table.remove(status.regions)
+ if not start then
+ return
+ end
+ results[#results+1] = {
+ start = start.start,
+ finish = source.finish,
+ kind = 'region',
+ hideLastLine = true,
+ }
+ end
+ end,
['comment.long'] = function (source, text, results)
local folding = {
start = source.start,
@@ -124,6 +149,7 @@ return function (uri)
return nil
end
local regions = {}
+ local status = {}
guide.eachSource(ast.ast, function (source)
local tp = source.type
@@ -134,7 +160,7 @@ return function (uri)
for _, source in ipairs(ast.comms) do
local tp = source.type
if Care[tp] then
- Care[tp](source, text, regions)
+ Care[tp](source, text, regions, status)
end
end
diff --git a/test/completion/init.lua b/test/completion/init.lua
index 3e0f5cd9..e51ab808 100644
--- a/test/completion/init.lua
+++ b/test/completion/init.lua
@@ -1990,3 +1990,17 @@ ${1:comment}\
}
Cared['insertText'] = nil
+
+TEST [[
+--$
+]]
+{
+ {
+ label = '#region',
+ kind = define.CompletionItemKind.Snippet,
+ },
+ {
+ label = '#endregion',
+ kind = define.CompletionItemKind.Snippet,
+ }
+}