summaryrefslogtreecommitdiff
path: root/script
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 /script
parentbed17488513b0e7e840f4e4e8cde7b281e646e47 (diff)
downloadlua-language-server-a9c1b4135f3467a195c72ddceb393fa850399078.zip
close #149 supports "--#region"
Diffstat (limited to 'script')
-rw-r--r--script/core/completion.lua16
-rw-r--r--script/core/folding.lua28
2 files changed, 42 insertions, 2 deletions
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