summaryrefslogtreecommitdiff
path: root/server-beta/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-05 20:34:17 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-05 20:34:17 +0800
commit12eecd0df7d2c577d56b5e81e393963a614dc8e7 (patch)
tree2a6d85959cf9fbe4d7feee44c552f0f868d8743d /server-beta/src
parentc844e46ae97f28ec928db6b701fdf5f2eea2664d (diff)
downloadlua-language-server-12eecd0df7d2c577d56b5e81e393963a614dc8e7.zip
更新诊断
Diffstat (limited to 'server-beta/src')
-rw-r--r--server-beta/src/core/diagnostics/redundant-parameter.lua25
-rw-r--r--server-beta/src/core/diagnostics/unused-local.lua10
-rw-r--r--server-beta/src/core/diagnostics/unused-vararg.lua32
-rw-r--r--server-beta/src/parser/compile.lua8
-rw-r--r--server-beta/src/searcher/getLibrary.lua56
-rw-r--r--server-beta/src/searcher/init.lua2
-rw-r--r--server-beta/src/searcher/isGlobal.lua15
-rw-r--r--server-beta/src/searcher/searcher.lua2
8 files changed, 142 insertions, 8 deletions
diff --git a/server-beta/src/core/diagnostics/redundant-parameter.lua b/server-beta/src/core/diagnostics/redundant-parameter.lua
index c087197c..79c259d8 100644
--- a/server-beta/src/core/diagnostics/redundant-parameter.lua
+++ b/server-beta/src/core/diagnostics/redundant-parameter.lua
@@ -3,12 +3,28 @@ local guide = require 'parser.guide'
local searcher = require 'searcher'
local lang = require 'language'
local define = require 'proto.define'
+local library = require 'library'
-local function packCallArgs(source)
- if not source.args then
+local function packLibraryArgs(source)
+ local func = searcher.getLibrary(source)
+ if not func then
return nil
end
local result = {}
+ if not func.args then
+ return result
+ end
+ for _, lib in ipairs(func.args) do
+ result[#result+1] = lib
+ end
+ return result
+end
+
+local function packCallArgs(source)
+ local result = {}
+ if not source.args then
+ return result
+ end
if source.node and source.node.type == 'getmethod' then
result[#result+1] = source.node.node
end
@@ -19,10 +35,10 @@ local function packCallArgs(source)
end
local function packFuncArgs(source)
+ local result = {}
if not source.args then
- return nil
+ return result
end
- local result = {}
if source.parent and source.parent.type == 'setmethod' then
result[#result+1] = source.parent.node
end
@@ -58,6 +74,7 @@ return function (uri, callback)
end
end)
+ funcArgs = funcArgs or packLibraryArgs(func)
if not funcArgs then
return
end
diff --git a/server-beta/src/core/diagnostics/unused-local.lua b/server-beta/src/core/diagnostics/unused-local.lua
index e6052e39..22b2e16b 100644
--- a/server-beta/src/core/diagnostics/unused-local.lua
+++ b/server-beta/src/core/diagnostics/unused-local.lua
@@ -9,7 +9,15 @@ local function hasGet(loc)
end
for _, ref in ipairs(loc.ref) do
if ref.type == 'getlocal' then
- return true
+ if not ref.next then
+ return true
+ end
+ local nextType = ref.next.type
+ if nextType ~= 'setmethod'
+ and nextType ~= 'setfield'
+ and nextType ~= 'setindex' then
+ return true
+ end
end
end
return false
diff --git a/server-beta/src/core/diagnostics/unused-vararg.lua b/server-beta/src/core/diagnostics/unused-vararg.lua
index b3d19c21..74cc08e7 100644
--- a/server-beta/src/core/diagnostics/unused-vararg.lua
+++ b/server-beta/src/core/diagnostics/unused-vararg.lua
@@ -1,3 +1,31 @@
-return function ()
-
+local files = require 'files'
+local guide = require 'parser.guide'
+local define = require 'proto.define'
+local lang = require 'language'
+
+return function (uri, callback)
+ local ast = files.getAst(uri)
+ if not ast then
+ return
+ end
+
+ guide.eachSourceType(ast.ast, 'function', function (source)
+ local args = source.args
+ if not args then
+ return
+ end
+
+ for _, arg in ipairs(args) do
+ if arg.type == '...' then
+ if not arg.ref then
+ callback {
+ start = arg.start,
+ finish = arg.finish,
+ tags = { define.DiagnosticTag.Unnecessary },
+ message = lang.script.DIAG_UNUSED_VARARG,
+ }
+ end
+ end
+ end
+ end)
end
diff --git a/server-beta/src/parser/compile.lua b/server-beta/src/parser/compile.lua
index 81a1ba4f..6479106f 100644
--- a/server-beta/src/parser/compile.lua
+++ b/server-beta/src/parser/compile.lua
@@ -53,7 +53,7 @@ local vmMap = {
['varargs'] = function (obj)
local func = guide.getParentFunction(obj)
if func then
- local index = guide.getFunctionVarArgs(func)
+ local index, vararg = guide.getFunctionVarArgs(func)
if not index then
pushError {
type = 'UNEXPECT_DOTS',
@@ -61,6 +61,12 @@ local vmMap = {
finish = obj.finish,
}
end
+ if vararg then
+ if not vararg.ref then
+ vararg.ref = {}
+ end
+ vararg.ref[#vararg.ref+1] = obj
+ end
end
end,
['paren'] = function (obj)
diff --git a/server-beta/src/searcher/getLibrary.lua b/server-beta/src/searcher/getLibrary.lua
new file mode 100644
index 00000000..3b9714a3
--- /dev/null
+++ b/server-beta/src/searcher/getLibrary.lua
@@ -0,0 +1,56 @@
+local searcher = require 'searcher.searcher'
+local guide = require 'parser.guide'
+local library = require 'library'
+
+local function getLibrary(source)
+ local name = guide.getKeyName(source)
+ if not name then
+ return
+ end
+ local sname = name:match '^s|(.+)$'
+ if not sname then
+ return
+ end
+ if searcher.isGlobal(source) then
+ return library.global[sname]
+ end
+ local node = source.node
+ if not node then
+ return
+ end
+
+ local lib
+ searcher.eachRef(node, function (info)
+ local src = info.source
+ if info.mode == 'get' and searcher.isGlobal(node) then
+ local nodeName = guide.getKeyName(src)
+ if not nodeName then
+ return
+ end
+ local sNodeName = nodeName:match '^s|(.+)$'
+ if not sNodeName then
+ return
+ end
+ local tbl = library.global[sNodeName]
+ if tbl then
+ lib = lib or tbl[sname]
+ end
+ end
+ end)
+ return lib
+end
+
+function searcher.getLibrary(source)
+ local cache = searcher.cache.getLibrary[source]
+ if cache ~= nil then
+ return cache
+ end
+ local unlock = searcher.lock('getLibrary', source)
+ if not unlock then
+ return
+ end
+ cache = getLibrary(source) or false
+ searcher.cache.getLibrary[source] = cache
+ unlock()
+ return cache
+end
diff --git a/server-beta/src/searcher/init.lua b/server-beta/src/searcher/init.lua
index 549d38cf..95d21427 100644
--- a/server-beta/src/searcher/init.lua
+++ b/server-beta/src/searcher/init.lua
@@ -2,4 +2,6 @@ local searcher = require 'searcher.searcher'
require 'searcher.eachField'
require 'searcher.eachRef'
require 'searcher.eachGlobal'
+require 'searcher.isGlobal'
+require 'searcher.getLibrary'
return searcher
diff --git a/server-beta/src/searcher/isGlobal.lua b/server-beta/src/searcher/isGlobal.lua
new file mode 100644
index 00000000..549220a9
--- /dev/null
+++ b/server-beta/src/searcher/isGlobal.lua
@@ -0,0 +1,15 @@
+local searcher = require 'searcher.searcher'
+
+function searcher.isGlobal(source)
+ local node = source.node
+ if not node then
+ return false
+ end
+ local isGlobal
+ searcher.eachRef(node, function (info)
+ if info.source.tag == '_ENV' then
+ isGlobal = true
+ end
+ end)
+ return isGlobal
+end
diff --git a/server-beta/src/searcher/searcher.lua b/server-beta/src/searcher/searcher.lua
index 361243fc..059afe8a 100644
--- a/server-beta/src/searcher/searcher.lua
+++ b/server-beta/src/searcher/searcher.lua
@@ -109,12 +109,14 @@ function m.refreshCache()
eachField = {},
eachGlobal = {},
specialName = {},
+ getLibrary = {},
specials = nil,
}
m.locked = {
eachRef = {},
eachField = {},
eachGlobal = {},
+ getLibrary = {},
}
end