summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-07 18:06:17 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-07 18:06:17 +0800
commit76dd555e146fdd4250daea262d1d84fd7734c547 (patch)
tree0a12f3bbc4ab1054b137d22afe16493ac5544e52 /server
parent08ad622130ad703a7fcb4120559ebcf9cc163185 (diff)
downloadlua-language-server-76dd555e146fdd4250daea262d1d84fd7734c547.zip
检查以括号开始的一行
Diffstat (limited to 'server')
-rw-r--r--server/src/matcher/compile.lua14
-rw-r--r--server/src/matcher/diagnostics.lua23
-rw-r--r--server/src/method/textDocument/publishDiagnostics.lua4
3 files changed, 36 insertions, 5 deletions
diff --git a/server/src/matcher/compile.lua b/server/src/matcher/compile.lua
index 65755821..43b68acf 100644
--- a/server/src/matcher/compile.lua
+++ b/server/src/matcher/compile.lua
@@ -169,12 +169,19 @@ function mt:fixCallAsRequire(results)
return self:createLib(libname.string)
end
-function mt:searchCall(call, func)
+function mt:searchCall(call, func, lastobj)
local results = {}
for i, exp in ipairs(call) do
results[i] = self:searchExp(exp)
end
+ if lastobj then
+ table.insert(self.results.calls, {
+ call = call,
+ lastobj = lastobj,
+ })
+ end
+
local api = self:getApi(func)
if api == 'setmetatable' then
@@ -202,7 +209,7 @@ function mt:searchSimple(simple)
local obj = simple[i]
local tp = obj.type
if tp == 'call' then
- var = self:searchCall(obj, var)
+ var = self:searchCall(obj, var, simple[i-1])
elseif tp == ':' then
elseif tp == 'name' then
if obj.index then
@@ -325,7 +332,7 @@ function mt:markSimple(simple)
local obj = simple[i]
local tp = obj.type
if tp == 'call' then
- var = self:searchCall(obj, var)
+ var = self:searchCall(obj, var, simple[i-1])
elseif tp == ':' then
var = self:createLocal('self', simple[i-1], self:getVar(simple[i-1][1]))
var.disableRename = true
@@ -583,6 +590,7 @@ return function (ast)
labels = {},
vars = {},
dots = {},
+ calls = {},
}
}, mt)
searcher.env.label = {}
diff --git a/server/src/matcher/diagnostics.lua b/server/src/matcher/diagnostics.lua
index 74066283..89a1ecfb 100644
--- a/server/src/matcher/diagnostics.lua
+++ b/server/src/matcher/diagnostics.lua
@@ -116,6 +116,20 @@ local function searchRedefinition(results, uri, callback)
end
end
+local function searchNewLineCall(results, lines, callback)
+ for _, call in ipairs(results.calls) do
+ if not call.lastobj.start then
+ goto NEXT_CALL
+ end
+ local callline = lines:rowcol(call.call.start, 'utf8')
+ local lastline = lines:rowcol(call.lastobj.start, 'utf8')
+ if callline > lastline then
+ callback(call.call.start, call.call.finish)
+ end
+ ::NEXT_CALL::
+ end
+end
+
return function (ast, results, lines, uri)
local datas = {}
-- 未使用的局部变量
@@ -164,5 +178,14 @@ return function (ast, results, lines, uri)
related = related,
}
end)
+ -- 以括号开始的一行(可能被误解析为了上一行的call)
+ searchNewLineCall(results, lines, function (start, finish)
+ datas[#datas+1] = {
+ start = start,
+ finish = finish,
+ level = 'Warning',
+ message = 'Parsed as function call for the previous line. It may be necessary to add a `;` before.',
+ }
+ end)
return datas
end
diff --git a/server/src/method/textDocument/publishDiagnostics.lua b/server/src/method/textDocument/publishDiagnostics.lua
index bfca0621..d9a21c8b 100644
--- a/server/src/method/textDocument/publishDiagnostics.lua
+++ b/server/src/method/textDocument/publishDiagnostics.lua
@@ -54,8 +54,8 @@ local function createInfo(data, lines)
for i, info in ipairs(data.related) do
local message = info.message
if not message then
- local start_line = lines:rowcol(info.start)
- local finish_line = lines:rowcol(info.finish)
+ local start_line = lines:rowcol(info.start, 'utf8')
+ local finish_line = lines:rowcol(info.finish, 'utf8')
local chars = {}
for n = start_line, finish_line do
chars[#chars+1] = lines:line(n)