summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-06-23 16:22:13 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-06-23 16:22:13 +0800
commitac1bddb7ca2f3b497085b06f310280f7d7ec0fb3 (patch)
tree2a4b5bb7fe21d258e7e31589e146e610ffbab0e1
parent366d163edf1373ca4f7c56ef44b77b818d9ee4f8 (diff)
downloadlua-language-server-ac1bddb7ca2f3b497085b06f310280f7d7ec0fb3.zip
fix #571
-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