diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-06-17 16:02:39 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-06-17 16:02:39 +0800 |
commit | 1bcadf492c4ccc19d137ffac80b0e9ca181a9ad7 (patch) | |
tree | db21c17b1b6f18d3fb60920a5d0783aaf50e8d0a | |
parent | cbb4bea9cabfa3073b39e067ea2114946c1d1690 (diff) | |
parent | 6fbe324f7130c94046ce14eee2235b663b47eafc (diff) | |
download | lua-language-server-1bcadf492c4ccc19d137ffac80b0e9ca181a9ad7.zip |
Merge branch 'master' into type-check
-rw-r--r-- | changelog.md | 3 | ||||
-rw-r--r-- | script/config/template.lua | 14 | ||||
-rw-r--r-- | script/core/diagnostics/missing-parameter.lua | 19 | ||||
-rw-r--r-- | test/crossfile/completion.lua | 29 | ||||
-rw-r--r-- | test/diagnostics/common.lua | 12 |
5 files changed, 43 insertions, 34 deletions
diff --git a/changelog.md b/changelog.md index 2b9f5b00..99c845d1 100644 --- a/changelog.md +++ b/changelog.md @@ -8,10 +8,13 @@ ``` ## 3.3.1 +`2022-6-17` * `FIX` [#1213](https://github.com/sumneko/lua-language-server/issues/1213) * `FIX` [#1215](https://github.com/sumneko/lua-language-server/issues/1215) * `FIX` [#1217](https://github.com/sumneko/lua-language-server/issues/1217) * `FIX` [#1218](https://github.com/sumneko/lua-language-server/issues/1218) +* `FIX` [#1220](https://github.com/sumneko/lua-language-server/issues/1220) +* `FIX` [#1223](https://github.com/sumneko/lua-language-server/issues/1223) ## 3.3.0 `2022-6-15` diff --git a/script/config/template.lua b/script/config/template.lua index 41913991..b1aee3fb 100644 --- a/script/config/template.lua +++ b/script/config/template.lua @@ -87,9 +87,17 @@ register('Array', {}, function (self, value) return type(value) == 'table' end, function (self, value) local t = {} - for _, v in ipairs(value) do - if self.sub:checker(v) then - t[#t+1] = self.sub:loader(v) + if #value == 0 then + for k in pairs(value) do + if self.sub:checker(k) then + t[#t+1] = self.sub:loader(k) + end + end + else + for _, v in ipairs(value) do + if self.sub:checker(v) then + t[#t+1] = self.sub:loader(v) + end end end return t diff --git a/script/core/diagnostics/missing-parameter.lua b/script/core/diagnostics/missing-parameter.lua index a475673f..9844046f 100644 --- a/script/core/diagnostics/missing-parameter.lua +++ b/script/core/diagnostics/missing-parameter.lua @@ -5,7 +5,7 @@ local lang = require 'language' ---@param source parser.object ---@return integer -local function countReturns(source) +local function countReturnsOfFunction(source) local n = 0 local docs = source.bindDocs @@ -33,14 +33,25 @@ local function countReturns(source) return n end +---@param source parser.object +---@return integer +local function countReturnsOfDocFunction(source) + return #source.returns +end + local function countMaxReturns(source) local hasFounded local n = 0 for _, def in ipairs(vm.getDefs(source)) do - if def.type == 'doc.type.function' - or def.type == 'function' then + if def.type == 'function' then + hasFounded = true + local rets = countReturnsOfFunction(def) + if rets > n then + n = rets + end + elseif def.type == 'doc.type.function' then hasFounded = true - local rets = countReturns(def) + local rets = countReturnsOfDocFunction(def) if rets > n then n = rets end diff --git a/test/crossfile/completion.lua b/test/crossfile/completion.lua index 79762646..4e573c0e 100644 --- a/test/crossfile/completion.lua +++ b/test/crossfile/completion.lua @@ -5,36 +5,11 @@ local platform = require 'bee.platform' local util = require 'utility' local config = require 'config' local catch = require 'catch' +local define = require 'proto.define' rawset(_G, 'TEST', true) -local CompletionItemKind = { - Text = 1, - Method = 2, - Function = 3, - Constructor = 4, - Field = 5, - Variable = 6, - Class = 7, - Interface = 8, - Module = 9, - Property = 10, - Unit = 11, - Value = 12, - Enum = 13, - Keyword = 14, - Snippet = 15, - Color = 16, - File = 17, - Reference = 18, - Folder = 19, - EnumMember = 20, - Constant = 21, - Struct = 22, - Event = 23, - Operator = 24, - TypeParameter = 25, -} +local CompletionItemKind = define.CompletionItemKind local EXISTS = {} diff --git a/test/diagnostics/common.lua b/test/diagnostics/common.lua index f80aee0a..39839c2a 100644 --- a/test/diagnostics/common.lua +++ b/test/diagnostics/common.lua @@ -1603,6 +1603,18 @@ f1(f2()) ]] TEST [[ +---@meta + +---@type fun():integer +local f + +---@param x integer +local function foo(x) end + +foo(f()) +]] + +TEST [[ ---@diagnostic disable: unused-local local x = 0 |