diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-10-27 10:36:32 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-10-27 10:36:32 +0800 |
commit | 10ed5c9e5946b36b7d75afb3855afa0cacc42543 (patch) | |
tree | e50a4ce88368f1dc5b4febe215a12dd3c01df966 | |
parent | 95a6fd7121fab859249ac015f7bfa1e0fbb09e8e (diff) | |
download | lua-language-server-10ed5c9e5946b36b7d75afb3855afa0cacc42543.zip |
更新
-rw-r--r-- | script-beta/parser/guide.lua | 30 | ||||
-rw-r--r-- | script-beta/vm/getClass.lua | 12 | ||||
-rw-r--r-- | test-beta/hover/init.lua | 2 |
3 files changed, 32 insertions, 12 deletions
diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 8bf01fc4..cc0bcdfe 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -1434,6 +1434,21 @@ function m.checkSameSimpleByBindDocs(status, obj, start, queue, mode) results[#results+1] = res end end + elseif doc.type == 'doc.param' then + -- function (x) 的情况 + if obj.type == 'local' + and m.getName(obj) == doc.param[1] then + if obj.parent.type == 'funcargs' + or obj.parent.type == 'in' + or obj.parent.type == 'loop' then + for _, piece in ipairs(doc.extends.types) do + local pieceResult = stepRefOfDocType(status, piece, mode) + for _, res in ipairs(pieceResult) do + results[#results+1] = res + end + end + end + end end end local mark = {} @@ -2610,8 +2625,8 @@ function m.inferCheckUpDoc(status, source) if m.inferCheckUpDocOfVararg(status, source) then return true end - while source.type == 'select' or source.type == 'call' do - local parent = source.parent + local parent = source.parent + if parent then if parent.type == 'local' or parent.type == 'setlocal' or parent.type == 'setglobal' @@ -2621,8 +2636,6 @@ function m.inferCheckUpDoc(status, source) or parent.type == 'tablefield' or parent.type == 'tableindex' then source = parent - else - break end end local binds = source.bindDocs @@ -2636,6 +2649,15 @@ function m.inferCheckUpDoc(status, source) type = doc.class[1], source = doc, } + -- ---@class Class + -- local x = { field = 1 } + -- 这种情况下,将字面量表接受为Class的定义 + if source.value and source.value.type == 'table' then + status.results[#status.results+1] = { + type = source.value.type, + source = source.value, + } + end return true elseif doc.type == 'doc.type' then local results = m.getDocTypeNames(doc) diff --git a/script-beta/vm/getClass.lua b/script-beta/vm/getClass.lua index 0d6980a2..ec86e0cf 100644 --- a/script-beta/vm/getClass.lua +++ b/script-beta/vm/getClass.lua @@ -2,13 +2,11 @@ local vm = require 'vm.vm' local guide = require 'parser.guide' local function lookUpDocClass(source) - local docs = source.bindDocs - if not docs then - return - end - for _, doc in ipairs(docs) do - if doc.type == 'doc.class' then - return guide.getName(doc) + local infers = vm.getInfers(source) + for _, infer in ipairs(infers) do + if infer.source.type == 'doc.class' + or infer.source.type == 'doc.type' then + return infer.type end end end diff --git a/test-beta/hover/init.lua b/test-beta/hover/init.lua index 0ceb897a..645b9131 100644 --- a/test-beta/hover/init.lua +++ b/test-beta/hover/init.lua @@ -936,7 +936,7 @@ function f(t) end ]] [[ -local t: Class +local t: Class {} ]] TEST [[ |