From 76dd555e146fdd4250daea262d1d84fd7734c547 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 7 Dec 2018 18:06:17 +0800 Subject: =?UTF-8?q?=E6=A3=80=E6=9F=A5=E4=BB=A5=E6=8B=AC=E5=8F=B7=E5=BC=80?= =?UTF-8?q?=E5=A7=8B=E7=9A=84=E4=B8=80=E8=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/matcher/compile.lua | 14 ++++++++++--- server/src/matcher/diagnostics.lua | 23 ++++++++++++++++++++++ .../src/method/textDocument/publishDiagnostics.lua | 4 ++-- 3 files changed, 36 insertions(+), 5 deletions(-) (limited to 'server/src') 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) -- cgit v1.2.3