diff options
-rw-r--r-- | script-beta/core/completion.lua | 2 | ||||
-rw-r--r-- | script-beta/core/diagnostics/redundant-parameter.lua | 9 | ||||
-rw-r--r-- | script-beta/core/hover/arg.lua | 4 | ||||
-rw-r--r-- | script-beta/core/hover/init.lua | 2 | ||||
-rw-r--r-- | script-beta/core/hover/label.lua | 6 | ||||
-rw-r--r-- | script-beta/core/hover/table.lua | 6 | ||||
-rw-r--r-- | script-beta/vm/getInfer.lua | 17 | ||||
-rw-r--r-- | test-beta/type_inference/init.lua | 2 |
8 files changed, 31 insertions, 17 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua index f04f11c9..e4310673 100644 --- a/script-beta/core/completion.lua +++ b/script-beta/core/completion.lua @@ -152,7 +152,7 @@ local function buildFunctionSnip(source) end local function buildDetail(source) - local types = vm.getType(source) + local types = vm.getInferType(source) return types end diff --git a/script-beta/core/diagnostics/redundant-parameter.lua b/script-beta/core/diagnostics/redundant-parameter.lua index b424c2bf..acb6f63c 100644 --- a/script-beta/core/diagnostics/redundant-parameter.lua +++ b/script-beta/core/diagnostics/redundant-parameter.lua @@ -65,10 +65,11 @@ return function (uri, callback) if not vm.hasType(func, 'function') then return end - local values = vm.getInfers(func) - for _, value in ipairs(values) do - if value.type and value.source.type == 'function' then - local args = countFuncArgs(value.source) + local defs = vm.getDefs(func) + for _, def in ipairs(defs) do + local value = guide.getObjectValue(def) or def + if value.type == 'function' then + local args = countFuncArgs(value) if not funcArgs or args > funcArgs then funcArgs = args end diff --git a/script-beta/core/hover/arg.lua b/script-beta/core/hover/arg.lua index dc8db16c..37c5e6ad 100644 --- a/script-beta/core/hover/arg.lua +++ b/script-beta/core/hover/arg.lua @@ -10,9 +10,9 @@ local function asFunction(source, oop) local arg = source.args[i] local name = arg.name or guide.getName(arg) if name then - args[i] = ('%s: %s'):format(name, vm.getType(arg)) + args[i] = ('%s: %s'):format(name, vm.getInferType(arg)) else - args[i] = ('%s'):format(vm.getType(arg)) + args[i] = ('%s'):format(vm.getInferType(arg)) end end local methodDef diff --git a/script-beta/core/hover/init.lua b/script-beta/core/hover/init.lua index e123bb06..82cc310d 100644 --- a/script-beta/core/hover/init.lua +++ b/script-beta/core/hover/init.lua @@ -75,7 +75,7 @@ end local function getHover(source) vm.setSearchLevel(5) - local isFunction = vm.hasType(source, 'function') + local isFunction = vm.hasInferType(source, 'function') if isFunction then return getHoverAsFunction(source) else diff --git a/script-beta/core/hover/label.lua b/script-beta/core/hover/label.lua index 6b3d0988..6e5b284c 100644 --- a/script-beta/core/hover/label.lua +++ b/script-beta/core/hover/label.lua @@ -19,11 +19,11 @@ end local function asValue(source, title) local name = buildName(source) local infers = vm.getInfers(source) - local type = vm.getType(source) + local type = vm.getInferType(source) local class = vm.getClass(source) - local literal = vm.getLiteral(source) + local literal = vm.getInferLiteral(source) local cont - if vm.hasType(source, 'table') then + if vm.hasInferType(source, 'table') then cont = buildTable(source) end local pack = {} diff --git a/script-beta/core/hover/table.lua b/script-beta/core/hover/table.lua index 97209a4f..f16eed9b 100644 --- a/script-beta/core/hover/table.lua +++ b/script-beta/core/hover/table.lua @@ -12,7 +12,7 @@ local function getKey(src) if class then return ('[%s]'):format(class) end - local tp = vm.getType(src.index) + local tp = vm.getInferType(src.index) if tp then return ('[%s]'):format(tp) end @@ -36,9 +36,9 @@ local function getField(src) or src.parent.type == 'getindex' then src = src.parent end - local tp = vm.getType(src) + local tp = vm.getInferType(src) local class = vm.getClass(src) - local literal = vm.getLiteral(src) + local literal = vm.getInferLiteral(src) local key = getKey(src) if type(literal) == 'string' and #literal >= 50 then literal = literal:sub(1, 47) .. '...' diff --git a/script-beta/vm/getInfer.lua b/script-beta/vm/getInfer.lua index 194f78b4..077ec982 100644 --- a/script-beta/vm/getInfer.lua +++ b/script-beta/vm/getInfer.lua @@ -6,6 +6,19 @@ NIL = setmetatable({'<nil>'}, { __tostring = function () return 'nil' end }) --- 是否包含某种类型 function vm.hasType(source, type) + local defs = vm.getDefs(source) + for i = 1, #defs do + local def = defs[i] + local value = guide.getObjectValue(def) or def + if value.type == type then + return true + end + end + return false +end + +--- 是否包含某种类型 +function vm.hasInferType(source, type) local infers = vm.getInfers(source) for i = 1, #infers do local infer = infers[i] @@ -16,12 +29,12 @@ function vm.hasType(source, type) return false end -function vm.getType(source) +function vm.getInferType(source) local infers = vm.getInfers(source) return guide.viewInferType(infers) end -function vm.getLiteral(source) +function vm.getInferLiteral(source) local infers = vm.getInfers(source) local literals = {} local mark = {} diff --git a/test-beta/type_inference/init.lua b/test-beta/type_inference/init.lua index 6bac5976..5a532b27 100644 --- a/test-beta/type_inference/init.lua +++ b/test-beta/type_inference/init.lua @@ -30,7 +30,7 @@ function TEST(wanted) files.setText('', newScript) local source = getSource(pos) assert(source) - local result = vm.getType(source) + local result = vm.getInferType(source) assert(wanted == result) end end |