summaryrefslogtreecommitdiff
path: root/server/src/matcher
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-12 21:15:27 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-12 21:15:27 +0800
commitd76d63f7063376852ee9c8ea6795abde09149851 (patch)
tree5067140e9d592e5e401fe448186592026e59a133 /server/src/matcher
parent3ce89009f9e37193a00aa3eefb09f46eaff409c7 (diff)
downloadlua-language-server-d76d63f7063376852ee9c8ea6795abde09149851.zip
非函数的hover
Diffstat (limited to 'server/src/matcher')
-rw-r--r--server/src/matcher/hover.lua32
-rw-r--r--server/src/matcher/vm.lua11
2 files changed, 40 insertions, 3 deletions
diff --git a/server/src/matcher/hover.lua b/server/src/matcher/hover.lua
index 750cf778..d4d9d04b 100644
--- a/server/src/matcher/hover.lua
+++ b/server/src/matcher/hover.lua
@@ -270,9 +270,41 @@ local function buildValueFunctionHover(result, source)
]]):format(title)
end
+local function buildValueSimpleHover(result, source)
+ local type = result.value.type
+ if type == 'nil' then
+ type = 'any'
+ end
+ local resType = result.type
+ if resType == 'field' then
+ local field = result
+ local stack = 0
+ while field.parent do
+ field = field.parent
+ stack = stack + 1
+ end
+ if field.value.ENV then
+ if stack > 1 then
+ resType = 'global field'
+ else
+ resType = 'global'
+ end
+ else
+ resType = 'local field'
+ end
+ end
+ return ([[
+```lua
+%s: %s
+```
+]]):format(resType, type)
+end
+
local function getValueHover(result, source)
if result.value.type == 'function' then
return buildValueFunctionHover(result, source)
+ else
+ return buildValueSimpleHover(result, source)
end
end
diff --git a/server/src/matcher/vm.lua b/server/src/matcher/vm.lua
index 16034eaf..4936fc0f 100644
--- a/server/src/matcher/vm.lua
+++ b/server/src/matcher/vm.lua
@@ -539,9 +539,14 @@ function mt:getLibValue(lib, parentType, v)
end
function mt:getName(name, source)
- local var = self.scope.locals[name]
- or self:getField(self:getValue(self.scope.locals._ENV), name, source)
- return var
+ local loc = self.scope.locals[name]
+ if loc then
+ return loc
+ end
+ local ENV = self.scope.locals._ENV
+ local global = self:getField(self:getValue(ENV), name, source)
+ global.parent = ENV
+ return global
end
function mt:getIndex(obj)