diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-05-24 20:37:15 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-05-24 20:37:15 +0800 |
commit | 721d6fe207fe0fb4eaa16252e451814e61011c4a (patch) | |
tree | 9908c0633f382446d4c36eb2f67e6457675e5a4e /script/core/infer.lua | |
parent | 934ab8bf64a29d44da10dee3b6f68b7b49931b3e (diff) | |
download | lua-language-server-721d6fe207fe0fb4eaa16252e451814e61011c4a.zip |
update
Diffstat (limited to 'script/core/infer.lua')
-rw-r--r-- | script/core/infer.lua | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/script/core/infer.lua b/script/core/infer.lua index 770b48f9..17935aa5 100644 --- a/script/core/infer.lua +++ b/script/core/infer.lua @@ -1,6 +1,8 @@ local searcher = require 'core.searcher' local config = require 'config' local noder = require 'core.noder' +local vm = require "vm.vm" +local guide = require "parser.guide" local STRING_OR_TABLE = {'STRING_OR_TABLE'} local BE_RETURN = {'BE_RETURN'} @@ -484,4 +486,40 @@ function m.searchAndViewInfers(source) return view end +function m.searchAndViewLiterals(source) + if not source then + return nil + end + local result = {} + local defs = vm.getDefs(source) + for _, def in ipairs(defs) do + if guide.isLiteral(def) and def[1] ~= nil then + result[#result+1] = ('%q'):format(def[1]) + end + end + table.sort(result) + return table.concat(result, '|') +end + +---搜索并显示推断的class +---@param source parser.guide.object +---@return string? +function m.getClass(source) + if not source then + return nil + end + local infers = {} + local defs = searcher.requestDefinition(source) + for _, def in ipairs(defs) do + if def.type == 'doc.class.name' then + infers[def[1]] = true + end + end + local view = m.viewInfers(infers) + if view == 'any' then + return nil + end + return view +end + return m |