summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--script-beta/core/completion.lua27
-rw-r--r--script-beta/core/hover/table.lua54
-rw-r--r--script-beta/core/rename.lua17
-rw-r--r--script-beta/core/signature.lua2
-rw-r--r--script-beta/vm/eachDef.lua7
-rw-r--r--script-beta/vm/eachField.lua10
-rw-r--r--script-beta/vm/eachRef.lua7
-rw-r--r--script-beta/vm/getClass.lua7
-rw-r--r--script-beta/vm/getMeta.lua8
-rw-r--r--test-beta/hover/init.lua22
10 files changed, 92 insertions, 69 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua
index 6939d240..c7350b8f 100644
--- a/script-beta/core/completion.lua
+++ b/script-beta/core/completion.lua
@@ -162,7 +162,7 @@ end
local function buildFunctionSnip(source, oop)
local name = getName(source):gsub('^.-[$.:]', '')
- local defs = vm.getDefs(source)
+ local defs = vm.getDefs(source, 'deep')
local args = ''
for _, def in ipairs(defs) do
local defArgs = getArg(def, oop)
@@ -182,8 +182,8 @@ local function buildFunctionSnip(source, oop)
end
local function buildDetail(source)
- local types = vm.getInferType(source)
- local literals = vm.getInferLiteral(source)
+ local types = vm.getInferType(source, 'deep')
+ local literals = vm.getInferLiteral(source, 'deep')
if literals then
return types .. ' = ' .. literals
else
@@ -196,7 +196,7 @@ local function getSnip(source)
if context <= 0 then
return nil
end
- local defs = vm.getRefs(source)
+ local defs = vm.getRefs(source, 'deep')
for _, def in ipairs(defs) do
if def ~= source and def.type == 'function' then
local uri = guide.getUri(def)
@@ -403,27 +403,27 @@ end
local function checkField(ast, word, start, offset, parent, oop, results)
local fields = {}
- vm.eachField(parent, function (src)
+ for _, src in ipairs(vm.getFields(parent, 'deep')) do
if src.type == 'library' then
if src.name:sub(1, 1) == '@' then
- return
+ goto CONTINUE
end
end
local key = vm.getKeyName(src)
if not key or key:sub(1, 1) ~= 's' then
- return
+ goto CONTINUE
end
if isSameSource(ast, src, start) then
- return
+ goto CONTINUE
end
local name = key:sub(3)
if not matchKey(word, name) then
- return
+ goto CONTINUE
end
local last = fields[name]
if not last then
fields[name] = src
- return
+ goto CONTINUE
end
if src.type == 'tablefield'
or src.type == 'setfield'
@@ -431,9 +431,10 @@ local function checkField(ast, word, start, offset, parent, oop, results)
or src.type == 'setindex'
or src.type == 'setmethod' then
fields[name] = src
- return
+ goto CONTINUE
end
- end)
+ ::CONTINUE::
+ end
for name, src in util.sortPairs(fields) do
checkFieldThen(name, src, word, start, offset, parent, oop, results)
end
@@ -914,7 +915,7 @@ local function tryCallArg(ast, text, offset, results)
end
local myResults = {}
local argIndex, arg = getCallArgInfo(call, text, offset)
- local defs = vm.getDefs(call.node)
+ local defs = vm.getDefs(call.node, 'deep')
for _, def in ipairs(defs) do
local enums = getCallEnums(def, argIndex)
if enums then
diff --git a/script-beta/core/hover/table.lua b/script-beta/core/hover/table.lua
index f845c335..fbe765b2 100644
--- a/script-beta/core/hover/table.lua
+++ b/script-beta/core/hover/table.lua
@@ -1,6 +1,7 @@
local vm = require 'vm'
local util = require 'utility'
local guide = require 'parser.guide'
+local config = require 'config'
local function getKey(src)
if src.type == 'library' then
@@ -35,7 +36,7 @@ local function getKey(src)
return ('[%s]'):format(key)
end
-local function getField(src)
+local function getField(src, marker)
if src.type == 'table'
or src.type == 'function' then
return nil
@@ -49,9 +50,41 @@ local function getField(src)
end
end
end
- local tp = vm.getInferType(src)
- local class = vm.getClass(src)
- local literal = vm.getInferLiteral(src)
+ local value = guide.getObjectValue(src) or src
+ if not value then
+ return 'any'
+ end
+ if value.library then
+ return value.type, util.viewLiteral(value.value)
+ end
+ if value.type == 'boolean' then
+ return value.type, util.viewLiteral(value[1])
+ end
+ if value.type == 'number'
+ or value.type == 'integer' then
+ if math.tointeger(value[1]) then
+ if config.config.runtime.version == 'Lua 5.3'
+ or config.config.runtime.version == 'Lua 5.4' then
+ return 'integer', util.viewLiteral(value[1])
+ end
+ end
+ return value.type, util.viewLiteral(value[1])
+ end
+ if value.type == 'table'
+ or value.type == 'function' then
+ return value.type
+ end
+ if value.type == 'string' then
+ local literal = value[1]
+ if type(literal) == 'string' and #literal >= 50 then
+ literal = literal:sub(1, 47) .. '...'
+ end
+ return value.type, util.viewLiteral(literal)
+ end
+ marker()
+ local tp = vm.getInferType(value)
+ local class = vm.getClass(value)
+ local literal = vm.getInferLiteral(value)
if type(literal) == 'string' and #literal >= 50 then
literal = literal:sub(1, 47) .. '...'
end
@@ -174,19 +207,28 @@ return function (source)
local classes = {}
local clock = os.clock()
local timeUp
+ local mark = {}
for _, src in ipairs(vm.getFields(source, 'deep')) do
local key = getKey(src)
if not key then
goto CONTINUE
end
+ if mark[key] then
+ goto CONTINUE
+ end
if not classes[key] then
classes[key] = {}
end
if not literals[key] then
literals[key] = {}
end
- if os.clock() - clock <= 5 then
- local class, literal = getField(src)
+ if TEST or os.clock() - clock <= 5 then
+ local class, literal = getField(src, function ()
+ mark[key] = true
+ end)
+ if literal == 'nil' then
+ literal = nil
+ end
classes[key][#classes[key]+1] = class
literals[key][#literals[key]+1] = literal
else
diff --git a/script-beta/core/rename.lua b/script-beta/core/rename.lua
index ffc514c9..720d8b0c 100644
--- a/script-beta/core/rename.lua
+++ b/script-beta/core/rename.lua
@@ -233,9 +233,9 @@ end
local function ofField(source, newname, callback)
local key = guide.getKeyName(source)
- vm.eachRef(source, function (src)
+ for _, src in ipairs(vm.getRefs(source, 'deep')) do
if vm.getKeyName(src) ~= key then
- return
+ goto CONTINUE
end
if src.type == 'tablefield'
or src.type == 'getfield'
@@ -253,30 +253,31 @@ local function ofField(source, newname, callback)
local quo = src[2]
local text = util.viewString(newname, quo)
callback(src, src.start, src.finish, text)
- return
+ goto CONTINUE
elseif src.type == 'field'
or src.type == 'method' then
local suc = renameField(src, newname, callback)
if not suc then
- return false
+ goto CONTINUE
end
elseif src.type == 'setglobal'
or src.type == 'getglobal' then
local suc = renameGlobal(src, newname, callback)
if not suc then
- return false
+ goto CONTINUE
end
end
- end)
+ ::CONTINUE::
+ end
end
local function ofLabel(source, newname, callback)
if not isValidName(newname) and not askForcing(newname)then
return false
end
- vm.eachRef(source, function (src)
+ for _, src in ipairs(vm.getRefs(source, 'deep')) do
callback(src, src.start, src.finish, newname)
- end)
+ end
end
local function rename(source, newname, callback)
diff --git a/script-beta/core/signature.lua b/script-beta/core/signature.lua
index ba21ae50..af17d655 100644
--- a/script-beta/core/signature.lua
+++ b/script-beta/core/signature.lua
@@ -79,7 +79,7 @@ local function makeSignatures(call, pos)
index = 1
end
local signs = {}
- local defs = vm.getDefs(node)
+ local defs = vm.getDefs(node, 'deep')
for _, src in ipairs(defs) do
if src.type == 'function' then
signs[#signs+1] = makeOneSignature(src, oop, index)
diff --git a/script-beta/vm/eachDef.lua b/script-beta/vm/eachDef.lua
index 37ba4ec5..ab71e7c4 100644
--- a/script-beta/vm/eachDef.lua
+++ b/script-beta/vm/eachDef.lua
@@ -43,10 +43,3 @@ function vm.getDefs(source, deep)
return cache
end
end
-
-function vm.eachDef(source, callback)
- local results = vm.getDefs(source)
- for i = 1, #results do
- callback(results[i])
- end
-end
diff --git a/script-beta/vm/eachField.lua b/script-beta/vm/eachField.lua
index ac104267..12d1d908 100644
--- a/script-beta/vm/eachField.lua
+++ b/script-beta/vm/eachField.lua
@@ -64,13 +64,3 @@ function vm.getFields(source, deep)
return cache
end
end
-
-function vm.eachField(source, callback)
- local results = vm.getFields(source)
- if not results then
- return
- end
- for i = 1, #results do
- callback(results[i])
- end
-end
diff --git a/script-beta/vm/eachRef.lua b/script-beta/vm/eachRef.lua
index 95b91343..7d1f2c77 100644
--- a/script-beta/vm/eachRef.lua
+++ b/script-beta/vm/eachRef.lua
@@ -42,10 +42,3 @@ function vm.getRefs(source, deep)
return cache
end
end
-
-function vm.eachRef(source, callback)
- local results = vm.getRefs(source)
- for i = 1, #results do
- callback(results[i])
- end
-end
diff --git a/script-beta/vm/getClass.lua b/script-beta/vm/getClass.lua
index 2a507b12..1948922d 100644
--- a/script-beta/vm/getClass.lua
+++ b/script-beta/vm/getClass.lua
@@ -35,10 +35,10 @@ local function getClass(source, classes, depth, deep)
classes[#classes+1] = value[1]
end
else
- vm.eachField(value, function (src)
+ for _, src in ipairs(vm.getFields(value)) do
local key = vm.getKeyName(src)
if not key then
- return
+ goto CONTINUE
end
local lkey = key:lower()
if lkey == 's|type'
@@ -50,7 +50,8 @@ local function getClass(source, classes, depth, deep)
classes[#classes+1] = value[1]
end
end
- end)
+ ::CONTINUE::
+ end
end
if #classes ~= 0 then
return
diff --git a/script-beta/vm/getMeta.lua b/script-beta/vm/getMeta.lua
index 73d01aef..aebef1a7 100644
--- a/script-beta/vm/getMeta.lua
+++ b/script-beta/vm/getMeta.lua
@@ -34,13 +34,15 @@ end
function vm.eachMetaValue(source, callback)
vm.eachMeta(source, function (mt)
- vm.eachField(mt, function (src)
+ for _, src in ipairs(vm.getFields(mt)) do
if vm.getKeyName(src) == 's|__index' then
if src.value then
- vm.eachField(src.value, callback)
+ for _, valueSrc in ipairs(vm.getFields(src.value)) do
+ callback(valueSrc)
+ end
end
end
- end)
+ end
end)
end
diff --git a/test-beta/hover/init.lua b/test-beta/hover/init.lua
index 6efbef55..0e9a9009 100644
--- a/test-beta/hover/init.lua
+++ b/test-beta/hover/init.lua
@@ -785,24 +785,24 @@ TEST [[
]]
[[
global _G: _G {
- _G: _G,
- _VERSION: string,
- arg: arg,
+ _G: table,
+ _VERSION: string = "Lua 5.4",
+ arg: table,
assert: function,
collectgarbage: function,
- coroutine: coroutine,
- debug: debug,
+ coroutine: table,
+ debug: table,
dofile: function,
error: function,
getmetatable: function,
- io: io,
+ io: table,
ipairs: function,
load: function,
loadfile: function,
- math: math,
+ math: table,
next: function,
- os: os,
- package: package,
+ os: table,
+ package: table,
pairs: function,
pcall: function,
print: function,
@@ -813,12 +813,12 @@ global _G: _G {
require: function,
select: function,
setmetatable: function,
- string: string,
+ string: table,
table: table,
tonumber: function,
tostring: function,
type: function,
- utf8: utf8,
+ utf8: table,
warn: function,
xpcall: function,
}