diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-10-26 14:55:45 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-10-26 14:55:45 +0800 |
commit | a12fec5c00f8b6f77aac845977c6c8aab36518bb (patch) | |
tree | 97fc16ec3e7321cd3dd065866a25749646cf2e25 | |
parent | b899ea541c6186ed9c4a3f2cefbb502eb22b083a (diff) | |
download | lua-language-server-a12fec5c00f8b6f77aac845977c6c8aab36518bb.zip |
param.return
-rw-r--r-- | script-beta/core/diagnostics/undefined-doc-class.lua | 1 | ||||
-rw-r--r-- | script-beta/core/diagnostics/undefined-doc-name.lua | 1 | ||||
-rw-r--r-- | script-beta/core/hover/return.lua | 35 | ||||
-rw-r--r-- | script-beta/parser/guide.lua | 22 | ||||
-rw-r--r-- | test-beta/hover/init.lua | 5 |
5 files changed, 59 insertions, 5 deletions
diff --git a/script-beta/core/diagnostics/undefined-doc-class.lua b/script-beta/core/diagnostics/undefined-doc-class.lua index f3381039..db68c74e 100644 --- a/script-beta/core/diagnostics/undefined-doc-class.lua +++ b/script-beta/core/diagnostics/undefined-doc-class.lua @@ -14,6 +14,7 @@ local builtin = { ['table'] = true, ['file'] = true, ['string'] = true, + ['userdata'] = true, ['function'] = true, } diff --git a/script-beta/core/diagnostics/undefined-doc-name.lua b/script-beta/core/diagnostics/undefined-doc-name.lua index 454d6c65..65d3a8ab 100644 --- a/script-beta/core/diagnostics/undefined-doc-name.lua +++ b/script-beta/core/diagnostics/undefined-doc-name.lua @@ -14,6 +14,7 @@ local builtin = { ['table'] = true, ['file'] = true, ['string'] = true, + ['userdata'] = true, ['function'] = true, } diff --git a/script-beta/core/hover/return.lua b/script-beta/core/hover/return.lua index 0fd11c57..d42ee5b2 100644 --- a/script-beta/core/hover/return.lua +++ b/script-beta/core/hover/return.lua @@ -43,12 +43,34 @@ local function asLibrary(source) return table.concat(returns, '\n') end -local function asFunction(source) +local function getReturnDualByDoc(source) + local docs = source.bindDocs + if not docs then + return + end + local dual + for _, doc in ipairs(docs) do + if doc.type == 'doc.return' then + for _, rtn in ipairs(doc.returns) do + if not dual then + dual = {} + end + dual[#dual+1] = { rtn } + end + end + end + return dual +end + +local function getReturnDualByGrammar(source) if not source.returns then return nil end - local dual = {} + local dual for _, rtn in ipairs(source.returns) do + if not dual then + dual = {} + end for n = 1, #rtn do if not dual[n] then dual[n] = {} @@ -56,6 +78,15 @@ local function asFunction(source) dual[n][#dual[n]+1] = rtn[n] end end + return dual +end + +local function asFunction(source) + local dual = getReturnDualByDoc(source) + or getReturnDualByGrammar(source) + if not dual then + return + end local returns = {} for i, rtn in ipairs(dual) do local line = {} diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 98146386..f4bf65f2 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -2514,6 +2514,23 @@ function m.getDocTypeNames(doc) end function m.inferCheckDoc(status, source) + if source.type == 'doc.class' then + status.results[#status.results+1] = { + type = source.class[1], + source = source, + } + return true + end + if source.type == 'doc.type' then + local results = m.getDocTypeNames(source) + for _, res in ipairs(results) do + status.results[#status.results+1] = res + end + return true + end +end + +function m.inferCheckUpDoc(status, source) while source.type == 'select' or source.type == 'call' do local parent = source.parent if parent.type == 'local' @@ -2540,11 +2557,13 @@ function m.inferCheckDoc(status, source) type = doc.class[1], source = doc, } + return true elseif doc.type == 'doc.type' then local results = m.getDocTypeNames(doc) for _, res in ipairs(results) do status.results[#status.results+1] = res end + return true elseif doc.type == 'doc.param' then -- function (x) 的情况 if source.type == 'local' @@ -2556,11 +2575,11 @@ function m.inferCheckDoc(status, source) type = m.viewInferType(m.getDocTypeNames(doc.extends)), source = doc, } + return true end end end end - return true end function m.inferCheckUnary(status, source) @@ -3252,6 +3271,7 @@ function m.searchInfer(status, obj) end local checked = m.inferCheckDoc(status, obj) + or m.inferCheckUpDoc(status, obj) or m.inferCheckLibrary(status, obj) or m.inferCheckLiteral(status, obj) or m.inferCheckUnary(status, obj) diff --git a/test-beta/hover/init.lua b/test-beta/hover/init.lua index 119e1ee1..b3b6719d 100644 --- a/test-beta/hover/init.lua +++ b/test-beta/hover/init.lua @@ -961,7 +961,6 @@ end local v: Class ]] -do return end TEST [[ ---@return A|B ---@return C @@ -970,9 +969,11 @@ end ]] [[ function f() - -> A|B, C + -> A|B + 2. C ]] +do return end TEST [[ ---@generic T ---@param x T |