Skip to content

Commit a9c1b41

Browse files
committed
close LuaLS#149 supports "--#region"
1 parent bed1748 commit a9c1b41

File tree

4 files changed

+57
-3
lines changed

4 files changed

+57
-3
lines changed

changelog.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## 1.10.0
44
* `NEW` workspace: supports `.dll`(`.so`) in `require`
5-
* `NEW` folding: `---@class` and docs of function
5+
* `NEW` folding: `---@class`, `--#region` and docs of function
66
* `CHG` supports `~` in command line
77
* `CHG` completion: improve workspace words
88
* `CHG` completion: show words in string

script/core/completion.lua

+15-1
Original file line numberDiff line numberDiff line change
@@ -1332,7 +1332,7 @@ end
13321332

13331333
local function getComment(ast, offset)
13341334
for _, comm in ipairs(ast.comms) do
1335-
if offset >= comm.start and offset <= comm.finish then
1335+
if offset >= comm.start - 2 and offset <= comm.finish then
13361336
return comm
13371337
end
13381338
end
@@ -1643,6 +1643,20 @@ local function tryComment(ast, text, offset, results)
16431643
local word = findWord(text, offset)
16441644
local doc = getLuaDoc(ast, offset)
16451645
if not word then
1646+
local comment = getComment(ast, offset)
1647+
if comment.type == 'comment.short'
1648+
or comment.type == 'comment.cshort' then
1649+
if comment.text == '' then
1650+
results[#results+1] = {
1651+
label = '#region',
1652+
kind = define.CompletionItemKind.Snippet,
1653+
}
1654+
results[#results+1] = {
1655+
label = '#endregion',
1656+
kind = define.CompletionItemKind.Snippet,
1657+
}
1658+
end
1659+
end
16461660
return
16471661
end
16481662
if doc and doc.type ~= 'doc.comment' then

script/core/folding.lua

+27-1
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,31 @@ local Care = {
9090
}
9191
results[#results+1] = folding
9292
end,
93+
['comment.short'] = function (source, text, results, status)
94+
local ltext = source.text:lower()
95+
if ltext:sub(1, #'region') == 'region'
96+
or ltext:sub(1, #'#region') == '#region' then
97+
if not status.regions then
98+
status.regions = {}
99+
end
100+
status.regions[#status.regions+1] = source
101+
elseif ltext:sub(1, #'endregion') == 'endregion'
102+
or ltext:sub(1, #'#endregion') == '#endregion' then
103+
if not status.regions then
104+
status.regions = {}
105+
end
106+
local start = table.remove(status.regions)
107+
if not start then
108+
return
109+
end
110+
results[#results+1] = {
111+
start = start.start,
112+
finish = source.finish,
113+
kind = 'region',
114+
hideLastLine = true,
115+
}
116+
end
117+
end,
93118
['comment.long'] = function (source, text, results)
94119
local folding = {
95120
start = source.start,
@@ -124,6 +149,7 @@ return function (uri)
124149
return nil
125150
end
126151
local regions = {}
152+
local status = {}
127153

128154
guide.eachSource(ast.ast, function (source)
129155
local tp = source.type
@@ -134,7 +160,7 @@ return function (uri)
134160
for _, source in ipairs(ast.comms) do
135161
local tp = source.type
136162
if Care[tp] then
137-
Care[tp](source, text, regions)
163+
Care[tp](source, text, regions, status)
138164
end
139165
end
140166

test/completion/init.lua

+14
Original file line numberDiff line numberDiff line change
@@ -1990,3 +1990,17 @@ ${1:comment}\
19901990
}
19911991

19921992
Cared['insertText'] = nil
1993+
1994+
TEST [[
1995+
--$
1996+
]]
1997+
{
1998+
{
1999+
label = '#region',
2000+
kind = define.CompletionItemKind.Snippet,
2001+
},
2002+
{
2003+
label = '#endregion',
2004+
kind = define.CompletionItemKind.Snippet,
2005+
}
2006+
}

0 commit comments

Comments
 (0)