diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-07-08 17:38:44 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-07-08 17:38:44 +0800 |
commit | db4ae9c48b7d2f97823469e8a32aff170ecba12f (patch) | |
tree | d167f6430773ebd3fd93b31611b1ad98bec60aaa | |
parent | 103aee69bf717936432e2739695305ce2058786e (diff) | |
download | lua-language-server-db4ae9c48b7d2f97823469e8a32aff170ecba12f.zip |
resolve #993 supports multi-types
-rw-r--r-- | changelog.md | 5 | ||||
-rw-r--r-- | script/core/diagnostics/undefined-doc-name.lua | 2 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 10 | ||||
-rw-r--r-- | script/vm/global.lua | 3 | ||||
-rw-r--r-- | test/type_inference/init.lua | 28 |
5 files changed, 30 insertions, 18 deletions
diff --git a/changelog.md b/changelog.md index 4a16c17b..8f76c0f6 100644 --- a/changelog.md +++ b/changelog.md @@ -15,6 +15,11 @@ * `unknown-operator` * `NEW` settings: * `diagnostics.unusedLocalExclude` +* `CHG` support multi-type: + ```lua + ---@type number, _, boolean + local a, b, c -- `a` is `number`, `b` is `unknown`, `c` is `boolean` + ``` * `FIX` [#880](https://github.com/sumneko/lua-language-server/issues/880) * `FIX` [#1284](https://github.com/sumneko/lua-language-server/issues/1284) * `FIX` [#1292](https://github.com/sumneko/lua-language-server/issues/1292) diff --git a/script/core/diagnostics/undefined-doc-name.lua b/script/core/diagnostics/undefined-doc-name.lua index 69edb380..bacd4288 100644 --- a/script/core/diagnostics/undefined-doc-name.lua +++ b/script/core/diagnostics/undefined-doc-name.lua @@ -32,7 +32,7 @@ return function (uri, callback) return end local name = source[1] - if name == '...' then + if name == '...' or name == '_' then return end if #vm.getDocSets(uri, name) > 0 diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index d0c06ea6..1385d5ce 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -864,7 +864,6 @@ local docSwitch = util.switch() if not first then return nil end - first.docIndex = 1 local rests while checkToken('symbol', ',', 1) do nextToken() @@ -873,7 +872,6 @@ local docSwitch = util.switch() rests = {} end rests[#rests+1] = rest - rest.docIndex = #rests + 1 end return first, rests end) @@ -1601,7 +1599,6 @@ local function bindDoc(source, binded) goto CONTINUE end if doc.type == 'doc.class' - or doc.type == 'doc.type' or doc.type == 'doc.deprecated' or doc.type == 'doc.version' or doc.type == 'doc.module' then @@ -1609,6 +1606,13 @@ local function bindDoc(source, binded) or isParam then goto CONTINUE end + elseif doc.type == 'doc.type' then + if source.type == 'function' + or isParam + or source._bindedDocType then + goto CONTINUE + end + source._bindedDocType = true elseif doc.type == 'doc.overload' then if not source.bindDocs then source.bindDocs = {} diff --git a/script/vm/global.lua b/script/vm/global.lua index d1bd798f..fe798c0d 100644 --- a/script/vm/global.lua +++ b/script/vm/global.lua @@ -323,6 +323,9 @@ local compilerGlobalSwitch = util.switch() : call(function (source) local uri = guide.getUri(source) local name = source[1] + if name == '_' then + return + end local type = vm.declareGlobal('type', name, uri) type:addGet(uri, source) source._globalNode = type diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 6c8afcea..3e871499 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -3652,17 +3652,17 @@ end local <?n?> = test(1) ]] ---TEST 'boolean' [[ ------@type boolean, number ---local <?x?>, y ---]] --- ---TEST 'number' [[ ------@type boolean, number ---local x, <?y?> ---]] --- ---TEST 'unknown' [[ ------@type _, number ---local <?x?>, y ---]] +TEST 'boolean' [[ +---@type boolean, number +local <?x?>, y +]] + +TEST 'number' [[ +---@type boolean, number +local x, <?y?> +]] + +TEST 'unknown' [[ +---@type _, number +local <?x?>, y +]] |