summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-12-25 17:27:01 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-12-25 17:27:01 +0800
commit856a4cb27430d6d578a1ee450e7ac4aa13a5f4f1 (patch)
tree356120ae3713e723e8dca5fdae6314b2d3b63676
parent64aab1cc575552ce2ed494790d201d3e6f170065 (diff)
downloadlua-language-server-856a4cb27430d6d578a1ee450e7ac4aa13a5f4f1.zip
更新API
-rw-r--r--script-beta/core/completion.lua26
-rw-r--r--script-beta/core/diagnostics/redundant-parameter.lua3
-rw-r--r--script-beta/core/diagnostics/undefined-env-child.lua7
-rw-r--r--script-beta/core/diagnostics/undefined-global.lua27
-rw-r--r--script-beta/core/diagnostics/unused-function.lua10
-rw-r--r--script-beta/core/highlight.lua20
-rw-r--r--script-beta/core/hover/class.lua12
-rw-r--r--script-beta/core/hover/table.lua30
-rw-r--r--script-beta/core/rename.lua9
-rw-r--r--script-beta/vm/eachMeta.lua6
-rw-r--r--script-beta/vm/getLibrary.lua6
-rw-r--r--script-beta/vm/getValue.lua3
12 files changed, 82 insertions, 77 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua
index 6f07459b..c8965808 100644
--- a/script-beta/core/completion.lua
+++ b/script-beta/core/completion.lua
@@ -125,9 +125,9 @@ end
local function buildFunctionSnip(source)
local name = getName(source):gsub('^.-[$.:]', '')
- local args = vm.eachDef(source, function (info)
- if info.source.type == 'function' then
- local args = getArg(info.source)
+ local args = vm.eachDef(source, function (src)
+ if src.type == 'function' then
+ local args = getArg(src)
if args ~= '' then
return args
end
@@ -219,12 +219,12 @@ end
local function checkField(word, start, parent, oop, results)
local used = {}
- vm.eachField(parent, function (info)
- local key = info.key
+ vm.eachField(parent, function (src)
+ local key = vm.getKeyName(src)
if not key or key:sub(1, 1) ~= 's' then
return
end
- if isSameSource(info.source, start) then
+ if isSameSource(src, start) then
return
end
local name = key:sub(3)
@@ -236,20 +236,20 @@ local function checkField(word, start, parent, oop, results)
return
end
local kind = ckind.Field
- if vm.hasType(info.source, 'function') then
+ if vm.hasType(src, 'function') then
if oop then
kind = ckind.Method
else
kind = ckind.Function
end
used[name] = true
- buildFunction(results, info.source, oop, {
+ buildFunction(results, src, oop, {
label = name,
kind = kind,
id = stack(function ()
return {
- detail = buildDetail(info.source),
- description = buildDesc(info.source),
+ detail = buildDetail(src),
+ description = buildDesc(src),
}
end),
})
@@ -258,7 +258,7 @@ local function checkField(word, start, parent, oop, results)
return
end
used[name] = true
- local literal = vm.getLiteral(info.source)
+ local literal = vm.getLiteral(src)
if literal ~= nil then
kind = ckind.Enum
end
@@ -267,8 +267,8 @@ local function checkField(word, start, parent, oop, results)
kind = kind,
id = stack(function ()
return {
- detail = buildDetail(info.source),
- description = buildDesc(info.source),
+ detail = buildDetail(src),
+ description = buildDesc(src),
}
end)
}
diff --git a/script-beta/core/diagnostics/redundant-parameter.lua b/script-beta/core/diagnostics/redundant-parameter.lua
index 8d486aea..45f8327e 100644
--- a/script-beta/core/diagnostics/redundant-parameter.lua
+++ b/script-beta/core/diagnostics/redundant-parameter.lua
@@ -62,8 +62,7 @@ return function (uri, callback)
local func = source.node
local funcArgs
- vm.eachDef(func, function (info)
- local src = info.source
+ vm.eachDef(func, function (src)
if src.type == 'function' then
local args = countFuncArgs(src)
if not funcArgs or args > funcArgs then
diff --git a/script-beta/core/diagnostics/undefined-env-child.lua b/script-beta/core/diagnostics/undefined-env-child.lua
index df096cb8..a19abb63 100644
--- a/script-beta/core/diagnostics/undefined-env-child.lua
+++ b/script-beta/core/diagnostics/undefined-env-child.lua
@@ -14,9 +14,10 @@ return function (uri, callback)
if source.node.tag == '_ENV' then
return
end
- local setInENV = vm.eachRef(source, function (info)
- if info.mode == 'set' then
- return true
+ local setInENV
+ vm.eachRef(source, function (src)
+ if vm.isSet(src) then
+ setInENV = true
end
end)
if setInENV then
diff --git a/script-beta/core/diagnostics/undefined-global.lua b/script-beta/core/diagnostics/undefined-global.lua
index ffb64582..4cb9c1ef 100644
--- a/script-beta/core/diagnostics/undefined-global.lua
+++ b/script-beta/core/diagnostics/undefined-global.lua
@@ -4,6 +4,19 @@ local lang = require 'language'
local library = require 'library'
local config = require 'config'
+local function hasSet(sources)
+ if sources.hasSet ~= nil then
+ return sources.hasSet
+ end
+ sources.hasSet = false
+ for i = 1, #sources do
+ if vm.isSet(sources[i]) then
+ sources.hasSet = true
+ end
+ end
+ return sources.hasSet
+end
+
return function (uri, callback)
local ast = files.getAst(uri)
if not ast then
@@ -12,13 +25,13 @@ return function (uri, callback)
local globalCache = {}
- -- 遍历全局变量,检查所有没有 mode['set'] 的全局变量
+ -- 遍历全局变量,检查所有没有 set 模式的全局变量
local globals = vm.getGlobals(ast.ast)
if not globals then
return
end
- for key, infos in pairs(globals) do
- if infos.mode['set'] == true then
+ for key, sources in pairs(globals) do
+ if hasSet(sources) then
goto CONTINUE
end
if globalCache[key] then
@@ -39,7 +52,7 @@ return function (uri, callback)
for i = 1, #uris do
local destAst = files.getAst(uris[i])
local destGlobals = vm.getGlobals(destAst.ast)
- if destGlobals[key] and destGlobals[key].mode['set'] then
+ if destGlobals[key] and hasSet(destGlobals[key]) then
globalCache[key] = true
goto CONTINUE
end
@@ -54,10 +67,10 @@ return function (uri, callback)
elseif customVersion then
message = ('%s(%s)'):format(message, lang.script('DIAG_DEFINED_CUSTOM', table.concat(customVersion, '/')))
end
- for _, info in ipairs(infos) do
+ for _, source in ipairs(sources) do
callback {
- start = info.source.start,
- finish = info.source.finish,
+ start = source.start,
+ finish = source.finish,
message = message,
}
end
diff --git a/script-beta/core/diagnostics/unused-function.lua b/script-beta/core/diagnostics/unused-function.lua
index f5a49610..52c7749a 100644
--- a/script-beta/core/diagnostics/unused-function.lua
+++ b/script-beta/core/diagnostics/unused-function.lua
@@ -22,12 +22,12 @@ return function (uri, callback)
return
end
local hasSet
- local hasGet = vm.eachRef(source, function (info)
- if info.mode == 'get' then
- return true
- elseif info.mode == 'set'
- or info.mode == 'declare' then
+ local hasGet
+ vm.eachRef(source, function (src)
+ if vm.isSet(src) then
hasSet = true
+ else
+ hasGet = true
end
end)
if not hasGet and hasSet then
diff --git a/script-beta/core/highlight.lua b/script-beta/core/highlight.lua
index 48f2ea9f..2d63f54e 100644
--- a/script-beta/core/highlight.lua
+++ b/script-beta/core/highlight.lua
@@ -21,26 +21,26 @@ local function ofField(source, uri, callback)
if parent.type == 'tableindex'
or parent.type == 'tablefield' then
local tbl = parent.parent
- vm.eachField(tbl, function (info)
- if info.key ~= myKey then
+ vm.eachField(tbl, function (src)
+ if vm.getKeyName(src) ~= myKey then
return
end
- local destUri = guide.getRoot(info.source).uri
+ local destUri = guide.getRoot(src).uri
if destUri ~= uri then
return
end
- callback(info.source)
+ callback(src)
end)
else
- vm.eachField(parent.node, function (info)
- if info.key ~= myKey then
+ vm.eachField(parent.node, function (src)
+ if vm.getKeyName(src) ~= myKey then
return
end
- local destUri = guide.getRoot(info.source).uri
+ local destUri = guide.getRoot(src).uri
if destUri ~= uri then
return
end
- callback(info.source)
+ callback(src)
end)
end
end
@@ -58,9 +58,7 @@ local function ofIndex(source, uri, callback)
end
local function ofLabel(source, callback)
- vm.eachRef(source, function (info)
- callback(info.source)
- end)
+ vm.eachRef(source, callback)
end
local function find(source, uri, callback)
diff --git a/script-beta/core/hover/class.lua b/script-beta/core/hover/class.lua
index be7b3995..94c8fb99 100644
--- a/script-beta/core/hover/class.lua
+++ b/script-beta/core/hover/class.lua
@@ -4,17 +4,15 @@ local function getClass(source, deep)
if deep > 3 then
return nil
end
- local class = vm.eachField(source, function (info)
- if not info.key then
- return
- end
- local lkey = info.key:lower()
+ local class = vm.eachField(source, function (src)
+ local key = vm.getKeyName(src)
+ local lkey = key:lower()
if lkey == 's|type'
or lkey == 's|__name'
or lkey == 's|name'
or lkey == 's|class' then
- if info.value and info.value.type == 'string' then
- return info.value[1]
+ if src.value and src.value.type == 'string' then
+ return src.value[1]
end
end
end)
diff --git a/script-beta/core/hover/table.lua b/script-beta/core/hover/table.lua
index 71f90b97..0cc94103 100644
--- a/script-beta/core/hover/table.lua
+++ b/script-beta/core/hover/table.lua
@@ -2,24 +2,24 @@ local vm = require 'vm'
local util = require 'utility'
local getClass = require 'core.hover.class'
-local function getKey(info)
- if not info.key or #info.key <= 2 then
- local source = info.source
- if not source.index then
+local function getKey(src)
+ local key = vm.getKeyName(src)
+ if not key or #key <= 2 then
+ if not src.index then
return '[any]'
end
- local class = getClass(source.index)
+ local class = getClass(src.index)
if class then
return ('[%s]'):format(class)
end
- local tp = vm.getType(source.index)
+ local tp = vm.getType(src.index)
if tp then
return ('[%s]'):format(tp)
end
return '[any]'
end
- local ktype = info.key:sub(1, 2)
- local key = info.key:sub(3)
+ local ktype = key:sub(1, 2)
+ key = key:sub(3)
if ktype == 's|' then
if key:match '^[%a_][%w_]*$' then
return key
@@ -30,11 +30,11 @@ local function getKey(info)
return ('[%s]'):format(key)
end
-local function getField(info)
- local tp = vm.getType(info.source)
- local class = getClass(info.source)
- local literal = vm.getLiteral(info.source)
- local key = getKey(info)
+local function getField(src)
+ local tp = vm.getType(src)
+ local class = getClass(src)
+ local literal = vm.getLiteral(src)
+ local key = getKey(src)
if type(literal) == 'string' and #literal >= 50 then
literal = literal:sub(1, 47) .. '...'
end
@@ -112,8 +112,8 @@ return function (source)
local literals = {}
local classes = {}
local intValue = true
- vm.eachField(source, function (info)
- local key, class, literal = getField(info)
+ vm.eachField(source, function (src)
+ local key, class, literal = getField(src)
classes[key] = vm.mergeTypeViews(class, classes[key])
literals[key] = mergeLiteral(literal, literals[key])
if class ~= 'integer'
diff --git a/script-beta/core/rename.lua b/script-beta/core/rename.lua
index f65bd71b..0bfaa95f 100644
--- a/script-beta/core/rename.lua
+++ b/script-beta/core/rename.lua
@@ -235,11 +235,10 @@ local function ofField(source, newname, callback)
else
tbl = source.node
end
- return vm.eachField(tbl, function (info)
- if info.key ~= key then
+ return vm.eachField(tbl, function (src)
+ if vm.getKeyName(src) ~= key then
return
end
- local src = info.source
if src.type == 'tablefield'
or src.type == 'getfield'
or src.type == 'setfield' then
@@ -279,8 +278,8 @@ local function rename(source, newname, callback)
if not isValidName(newname) and not askForcing(newname)then
return false
end
- vm.eachRef(source, function (info)
- callback(info.source, info.source.start, info.source.finish, newname)
+ vm.eachRef(source, function (src)
+ callback(src, src.start, src.finish, newname)
end)
elseif source.type == 'local' then
return ofLocal(source, newname, callback)
diff --git a/script-beta/vm/eachMeta.lua b/script-beta/vm/eachMeta.lua
index 096c0b0a..f75fa215 100644
--- a/script-beta/vm/eachMeta.lua
+++ b/script-beta/vm/eachMeta.lua
@@ -24,13 +24,11 @@ function vm.eachMeta(source, callback)
return
end
cache = {}
- vm.eachRef(source, function (info)
- local src = info.source
+ vm.eachRef(source, function (src)
vm.cache.eachMeta[src] = cache
end)
unlock()
- vm.eachRef(source, function (info)
- local src = info.source
+ vm.eachRef(source, function (src)
cache[#cache+1] = vm.cache.getMeta[src]
end)
for i = 1, #cache do
diff --git a/script-beta/vm/getLibrary.lua b/script-beta/vm/getLibrary.lua
index 69280fd9..32438805 100644
--- a/script-beta/vm/getLibrary.lua
+++ b/script-beta/vm/getLibrary.lua
@@ -73,9 +73,9 @@ end
local function getLibrary(source)
return checkNode(source)
or checkStdLibrary(source)
- or vm.eachRef(source, function (info)
- return checkStdLibrary(info.source)
- or checkNode(info.source)
+ or vm.eachRef(source, function (src)
+ return checkStdLibrary(src)
+ or checkNode(src)
end, 100)
end
diff --git a/script-beta/vm/getValue.lua b/script-beta/vm/getValue.lua
index 0df834ac..fbc630f0 100644
--- a/script-beta/vm/getValue.lua
+++ b/script-beta/vm/getValue.lua
@@ -484,8 +484,7 @@ local function inferByGetTable(results, source)
end
local function checkDef(results, source)
- vm.eachDef(source, function (info)
- local src = info.source
+ vm.eachDef(source, function (src)
local tp = vm.getValue(src)
if tp then
merge(results, tp)