summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-14 11:35:52 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-14 11:35:52 +0800
commit6b51351ecf215a09609e63a17209ac8757cc3844 (patch)
treecc014b6beb7438be735168a3eecf2792bf393627 /server
parenta1a5e4da0d5b1f994117d8e51ea7e105cca7d049 (diff)
downloadlua-language-server-6b51351ecf215a09609e63a17209ac8757cc3844.zip
多行注释支持折行
Diffstat (limited to 'server')
-rw-r--r--server/src/core/folding_range.lua11
-rw-r--r--server/src/files/file.lua4
-rw-r--r--server/src/method/textDocument/foldingRange.lua3
-rw-r--r--server/src/parser/ast.lua6
-rw-r--r--server/src/parser/grammar.lua2
-rw-r--r--server/src/parser/parse.lua3
-rw-r--r--server/src/service.lua11
7 files changed, 34 insertions, 6 deletions
diff --git a/server/src/core/folding_range.lua b/server/src/core/folding_range.lua
index ec8029f8..db0b0bdf 100644
--- a/server/src/core/folding_range.lua
+++ b/server/src/core/folding_range.lua
@@ -10,7 +10,7 @@ local foldingType = {
['table'] = {'region', '}', },
}
-return function (vm)
+return function (vm, comments)
local result = {}
vm:eachSource(function (source)
local tp = source.type
@@ -50,6 +50,15 @@ return function (vm)
}
end
end)
+ if comments then
+ for _, comment in ipairs(comments) do
+ result[#result+1] = {
+ start = comment.start,
+ finish = comment.finish,
+ kind = 'comment',
+ }
+ end
+ end
if #result == 0 then
return nil
end
diff --git a/server/src/files/file.lua b/server/src/files/file.lua
index 61f62a00..81aabba5 100644
--- a/server/src/files/file.lua
+++ b/server/src/files/file.lua
@@ -100,6 +100,10 @@ function mt:getLines()
return self._lines
end
+function mt:getComments()
+ return self.comments
+end
+
---@return file
function mt:getParent()
return self._parent
diff --git a/server/src/method/textDocument/foldingRange.lua b/server/src/method/textDocument/foldingRange.lua
index 47e9cb33..33346285 100644
--- a/server/src/method/textDocument/foldingRange.lua
+++ b/server/src/method/textDocument/foldingRange.lua
@@ -36,7 +36,8 @@ return function (lsp, params)
t:remove()
timerCache[uri] = nil
- local ranges = core.foldingRange(vm)
+ local comments = lsp:getComments(uri)
+ local ranges = core.foldingRange(vm, comments)
if not ranges then
response(nil)
return
diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua
index 3d8b8ed8..38cd8576 100644
--- a/server/src/parser/ast.lua
+++ b/server/src/parser/ast.lua
@@ -271,7 +271,11 @@ local Defs = {
[1] = false,
}
end,
- LongComment = function (beforeEq, afterEq, str, missPos)
+ LongComment = function (beforeEq, afterEq, str, finish, missPos)
+ State.Comments[#State.Comments+1] = {
+ start = beforeEq,
+ finish = finish,
+ }
if missPos then
local endSymbol = ']' .. ('='):rep(afterEq-beforeEq) .. ']'
local s, _, w = str:find('(%][%=]*%])[%c%s]*$')
diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua
index 3525677a..568b8544 100644
--- a/server/src/parser/grammar.lua
+++ b/server/src/parser/grammar.lua
@@ -83,7 +83,7 @@ grammar 'Comment' [[
Comment <- LongComment / '--' ShortComment
LongComment <- ('--[' {} {:eq: '='* :} {} '['
{(!CommentClose .)*}
- (CommentClose / {}))
+ (CommentClose {} / {} {}))
-> LongComment
/ (
{} '/*' {}
diff --git a/server/src/parser/parse.lua b/server/src/parser/parse.lua
index 65464724..6ad79d9b 100644
--- a/server/src/parser/parse.lua
+++ b/server/src/parser/parse.lua
@@ -25,6 +25,7 @@ return function (self, lua, mode, version)
Label = {{}},
Dots = {true},
Version = version,
+ Comments = {},
Lua = lua,
}
ast.init(State, Errs)
@@ -36,5 +37,5 @@ return function (self, lua, mode, version)
pushError(err)
return nil, Errs
end
- return res, Errs
+ return res, Errs, State.Comments
end
diff --git a/server/src/service.lua b/server/src/service.lua
index 0e0f459a..2d8a3e64 100644
--- a/server/src/service.lua
+++ b/server/src/service.lua
@@ -413,7 +413,8 @@ end
---@param file file
---@return table
function mt:compileAst(file)
- local ast, err = parser:parse(file:getText(), 'lua', config.config.runtime.version)
+ local ast, err, comments = parser:parse(file:getText(), 'lua', config.config.runtime.version)
+ file.comments = comments
if ast then
file:setAstErr(err)
else
@@ -620,6 +621,14 @@ function mt:getText(uri)
return file:getText(), file:getOldText()
end
+function mt:getComments(uri)
+ local file = self._files:get(uri)
+ if not file then
+ return nil
+ end
+ return file:getComments()
+end
+
---@param uri uri
---@return table
function mt:getAstErrors(uri)