summaryrefslogtreecommitdiff
path: root/script-beta/core/hover
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2020-05-29 18:43:41 +0800
committer最萌小汐 <sumneko@hotmail.com>2020-05-29 18:43:41 +0800
commit56660210803cd9128d52007fe14b0b0f5a726ff5 (patch)
treeb18f22fe382e15c99cdbc1966544b12245056edb /script-beta/core/hover
parent0c009afbc73804259e1da0cf2b7a6a69ca728cee (diff)
downloadlua-language-server-56660210803cd9128d52007fe14b0b0f5a726ff5.zip
整理代码
Diffstat (limited to 'script-beta/core/hover')
-rw-r--r--script-beta/core/hover/init.lua41
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