diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2020-05-29 18:43:41 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2020-05-29 18:43:41 +0800 |
commit | 56660210803cd9128d52007fe14b0b0f5a726ff5 (patch) | |
tree | b18f22fe382e15c99cdbc1966544b12245056edb /script-beta/core/hover | |
parent | 0c009afbc73804259e1da0cf2b7a6a69ca728cee (diff) | |
download | lua-language-server-56660210803cd9128d52007fe14b0b0f5a726ff5.zip |
整理代码
Diffstat (limited to 'script-beta/core/hover')
-rw-r--r-- | script-beta/core/hover/init.lua | 41 |
1 files changed, 23 insertions, 18 deletions
diff --git a/script-beta/core/hover/init.lua b/script-beta/core/hover/init.lua index 38f6fa88..e56b009e 100644 --- a/script-beta/core/hover/init.lua +++ b/script-beta/core/hover/init.lua @@ -1,9 +1,10 @@ -local files = require 'files' -local guide = require 'parser.guide' -local vm = require 'vm' -local getLabel = require 'core.hover.label' -local getDesc = require 'core.hover.description' -local util = require 'utility' +local files = require 'files' +local guide = require 'parser.guide' +local vm = require 'vm' +local getLabel = require 'core.hover.label' +local getDesc = require 'core.hover.description' +local util = require 'utility' +local findSource = require 'core.find-source' local function getHoverAsFunction(source) local values = vm.getValue(source) @@ -81,23 +82,27 @@ local function getHover(source) end end +local accept = { + ['local'] = true, + ['setlocal'] = true, + ['getlocal'] = true, + ['setglobal'] = true, + ['getglobal'] = true, + ['field'] = true, + ['method'] = true, + ['string'] = true, +} + local function getHoverByUri(uri, offset) local ast = files.getAst(uri) if not ast then return nil end - local hover = guide.eachSourceContain(ast.ast, offset, function (source) - if source.type == 'local' - or source.type == 'setlocal' - or source.type == 'getlocal' - or source.type == 'setglobal' - or source.type == 'getglobal' - or source.type == 'field' - or source.type == 'method' - or source.type == 'string' then - return getHover(source) - end - end) + local source = findSource(ast, offset, accept) + if not source then + return nil + end + local hover = getHover(source) return hover end |