diff options
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 |