summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-05-07 14:28:50 +0800
committersumneko <sumneko@hotmail.com>2019-05-07 14:28:50 +0800
commit717729c33ce10067aac8afddd2fc2a5da9d801b5 (patch)
tree9abcc4b9f809372aa9c031f4f9f0087a2c567d91
parenta2c3b5915949daf39ddf6f044dbc1a5a64ae9847 (diff)
downloadlua-language-server-717729c33ce10067aac8afddd2fc2a5da9d801b5.zip
外部判空
-rw-r--r--server/src/core/completion.lua4
-rw-r--r--server/src/method/textDocument/publishDiagnostics.lua34
-rw-r--r--server/src/vm/emmy.lua2
-rw-r--r--server/src/vm/function.lua2
-rw-r--r--server/src/vm/ipairs.lua8
5 files changed, 26 insertions, 24 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index 7cddcaf5..22ee8167 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -257,7 +257,7 @@ local function searchCloseGlobal(vm, start, finish, word, callback)
end
local function searchParams(vm, source, func, word, callback)
- ---@type function
+ ---@type emmyFunction
local emmyParams = func:getEmmyParams()
if not emmyParams then
return
@@ -609,7 +609,7 @@ local function searchCallArg(vm, source, word, callback, pos)
return
end
- ---@type function
+ ---@type emmyFunction
local func = value:getFunction()
if func then
searchEnumAsEmmyParams(vm, source, word, callback, pos, args, func)
diff --git a/server/src/method/textDocument/publishDiagnostics.lua b/server/src/method/textDocument/publishDiagnostics.lua
index 3a4e4658..0698baea 100644
--- a/server/src/method/textDocument/publishDiagnostics.lua
+++ b/server/src/method/textDocument/publishDiagnostics.lua
@@ -53,25 +53,27 @@ local function createInfo(lsp, data, lines)
}
if data.related then
local related = {}
- for i, info in ipairs(data.related) do
+ for _, info in ipairs(data.related) do
local _, lines = lsp:getVM(info.uri)
- local message = info.message
- if not message then
- local start_line = lines:rowcol(info.start)
- local finish_line = lines:rowcol(info.finish)
- local chars = {}
- for n = start_line, finish_line do
- chars[#chars+1] = lines:line(n)
+ if lines then
+ local message = info.message
+ if not message then
+ local start_line = lines:rowcol(info.start)
+ local finish_line = lines:rowcol(info.finish)
+ local chars = {}
+ for n = start_line, finish_line do
+ chars[#chars+1] = lines:line(n)
+ end
+ message = table.concat(chars, '\n')
end
- message = table.concat(chars, '\n')
- end
- related[i] = {
- message = message,
- location = {
- uri = info.uri,
- range = getRange(info.start, info.finish, lines),
+ related[#related+1] = {
+ message = message,
+ location = {
+ uri = info.uri,
+ range = getRange(info.start, info.finish, lines),
+ }
}
- }
+ end
end
diagnostic.relatedInformation = related
end
diff --git a/server/src/vm/emmy.lua b/server/src/vm/emmy.lua
index 4ecef4d3..32c21e45 100644
--- a/server/src/vm/emmy.lua
+++ b/server/src/vm/emmy.lua
@@ -271,7 +271,7 @@ function mt:doEmmyFunctionType(action)
local emmyMgr = self.emmyMgr
self:instantSource(action)
local funcObj = emmyMgr:addFunctionType(action)
- ---@type function
+ ---@type emmyFunction
local func = functionMgr.create(action)
for i = 1, #action // 2 do
local nameSource = action[i*2-1]
diff --git a/server/src/vm/function.lua b/server/src/vm/function.lua
index 593d40dd..1ba49f9c 100644
--- a/server/src/vm/function.lua
+++ b/server/src/vm/function.lua
@@ -6,7 +6,7 @@ local listMgr = require 'vm.list'
local Watch = setmetatable({}, {__mode = 'kv'})
----@class function
+---@class emmyFunction
local mt = {}
mt.__index = mt
mt.type = 'function'
diff --git a/server/src/vm/ipairs.lua b/server/src/vm/ipairs.lua
index b8d821ef..58c7d827 100644
--- a/server/src/vm/ipairs.lua
+++ b/server/src/vm/ipairs.lua
@@ -1,12 +1,12 @@
local mt = require 'vm.manager'
----@param func function
+---@param func emmyFunction
function mt:callIpairs(func, values, source)
local tbl = values[1]
func:setReturn(2, tbl)
end
----@param func function
+---@param func emmyFunction
function mt:callAtIpairs(func, values, source)
local tbl = values[1]
if tbl then
@@ -20,13 +20,13 @@ function mt:callAtIpairs(func, values, source)
end
end
----@param func function
+---@param func emmyFunction
function mt:callPairs(func, values, source)
local tbl = values[1]
func:setReturn(2, tbl)
end
----@param func function
+---@param func emmyFunction
function mt:callNext(func, values, source)
local tbl = values[1]
if tbl then