diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-12-02 09:59:09 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-12-02 09:59:09 +0800 |
commit | baf8bdfc5535e27ba2ce431e62c7bff5bceef3fb (patch) | |
tree | 2a8c17cc69e1963b3b3cfddbaa0e4ef6570172b4 /script | |
parent | 8cc79c86f0e339afcaa15bbbc3176df212d93c0c (diff) | |
download | lua-language-server-baf8bdfc5535e27ba2ce431e62c7bff5bceef3fb.zip |
close #275 hover.previewFields
Diffstat (limited to 'script')
-rw-r--r-- | script/config.lua | 1 | ||||
-rw-r--r-- | script/core/hover/table.lua | 21 |
2 files changed, 17 insertions, 5 deletions
diff --git a/script/config.lua b/script/config.lua index 92ed0491..59dc75cc 100644 --- a/script/config.lua +++ b/script/config.lua @@ -141,6 +141,7 @@ local ConfigTemplate = { viewStringMax = {1000, Integer}, viewNumber = {true, Boolean}, fieldInfer = {3000, Integer}, + previewFields = {100, Integer}, }, color = { mode = {'Semantic', String}, diff --git a/script/core/hover/table.lua b/script/core/hover/table.lua index 704a7452..9e850c3e 100644 --- a/script/core/hover/table.lua +++ b/script/core/hover/table.lua @@ -111,7 +111,7 @@ local function getField(src, timeUp, mark, key) return nil end -local function buildAsHash(classes, literals) +local function buildAsHash(classes, literals, reachMax) local keys = {} for k in pairs(classes) do keys[#keys+1] = k @@ -128,11 +128,14 @@ local function buildAsHash(classes, literals) lines[#lines+1] = (' %s: %s,'):format(key, class) end end + if reachMax then + lines[#lines+1] = ' ...' + end lines[#lines+1] = '}' return table.concat(lines, '\n') end -local function buildAsConst(classes, literals) +local function buildAsConst(classes, literals, reachMax) local keys = {} for k in pairs(classes) do keys[#keys+1] = k @@ -151,6 +154,9 @@ local function buildAsConst(classes, literals) lines[#lines+1] = (' %s: %s,'):format(key, class) end end + if reachMax then + lines[#lines+1] = ' ...' + end lines[#lines+1] = '}' return table.concat(lines, '\n') end @@ -195,6 +201,9 @@ local function clearClasses(classes) end return function (source) + if config.config.hover.previewFields <= 0 then + return 'table' + end local literals = {} local classes = {} local clock = os.clock() @@ -202,6 +211,7 @@ return function (source) local mark = {} local fields = vm.getFields(source, 0) local keyCount = 0 + local reachMax for _, src in ipairs(fields) do local key = getKey(src) if not key then @@ -223,7 +233,8 @@ return function (source) end classes[key][#classes[key]+1] = class literals[key][#literals[key]+1] = literal - if keyCount >= 1000 then + if keyCount >= config.config.hover.previewFields then + reachMax = true break end ::CONTINUE:: @@ -249,9 +260,9 @@ return function (source) end local result if intValue then - result = buildAsConst(classes, literals) + result = buildAsConst(classes, literals, reachMax) else - result = buildAsHash(classes, literals) + result = buildAsHash(classes, literals, reachMax) end if timeUp then result = ('\n--%s\n%s'):format(lang.script.HOVER_TABLE_TIME_UP, result) |