summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--changelog.md1
-rw-r--r--script/core/infer.lua11
-rw-r--r--test/type_inference/init.lua21
3 files changed, 31 insertions, 2 deletions
diff --git a/changelog.md b/changelog.md
index 8a10293e..a05b4bce 100644
--- a/changelog.md
+++ b/changelog.md
@@ -3,6 +3,7 @@
## 2.0.2
* `FIX` [#567](https://github.com/sumneko/lua-language-server/issues/567)
* `FIX` [#570](https://github.com/sumneko/lua-language-server/issues/570)
+* `FIX` [#571](https://github.com/sumneko/lua-language-server/issues/571)
## 2.0.1
`2021-6-21`
diff --git a/script/core/infer.lua b/script/core/infer.lua
index 6a795dd4..d3145a2e 100644
--- a/script/core/infer.lua
+++ b/script/core/infer.lua
@@ -2,7 +2,7 @@ local searcher = require 'core.searcher'
local config = require 'config'
local noder = require 'core.noder'
local util = require 'utility'
-local vm = require "vm.vm"
+local vm = require "vm.vm"
local STRING_OR_TABLE = {'STRING_OR_TABLE'}
local BE_RETURN = {'BE_RETURN'}
@@ -296,7 +296,14 @@ function m.viewInfers(infers)
return sa < sb
end
end)
- infers[0] = table.concat(result, '|')
+ local limit = config.config.hover.enumsLimit
+ if limit < 0 then
+ limit = 0
+ end
+ infers[0] = table.concat(result, '|', 1, math.min(count, limit))
+ if count > limit then
+ infers[0] = ('%s...(+%d)'):format(infers[0], count - limit)
+ end
return infers[0]
end
diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua
index 7d5ea44f..3ca46cda 100644
--- a/test/type_inference/init.lua
+++ b/test/type_inference/init.lua
@@ -2,6 +2,7 @@ local files = require 'files'
local vm = require 'vm'
local guide = require 'parser.guide'
local infer = require 'core.infer'
+local config = require 'config'
rawset(_G, 'TEST', true)
@@ -746,3 +747,23 @@ return test
TEST 'function' [[
string.gsub():gsub():<?gsub?>()
]]
+
+config.config.hover.enumsLimit = 5
+TEST 'a|b|c|d|e...(+5)' [[
+---@type 'a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'i'|'j'
+local <?t?>
+]]
+
+config.config.hover.enumsLimit = 1
+TEST 'a...(+9)' [[
+---@type 'a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'i'|'j'
+local <?t?>
+]]
+
+config.config.hover.enumsLimit = 0
+TEST '...(+10)' [[
+---@type 'a'|'b'|'c'|'d'|'e'|'f'|'g'|'h'|'i'|'j'
+local <?t?>
+]]
+
+config.config.hover.enumsLimit = 5