diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-11-21 21:02:19 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-11-21 21:02:19 +0800 |
commit | 3bd61890073f9ff69b214e84843c71be94890edc (patch) | |
tree | 0c337baab88b6233ffac0e36daffcf0993997fc6 | |
parent | 442b2d559537ed0caeb9116bf904bd93002aaa8b (diff) | |
download | lua-language-server-3bd61890073f9ff69b214e84843c71be94890edc.zip |
检查class
-rw-r--r-- | server-beta/src/core/hover/name.lua | 23 | ||||
-rw-r--r-- | server-beta/src/vm/eachField.lua | 10 | ||||
-rw-r--r-- | server-beta/test/hover/init.lua | 50 |
3 files changed, 79 insertions, 4 deletions
diff --git a/server-beta/src/core/hover/name.lua b/server-beta/src/core/hover/name.lua index d0caf885..ef7fee02 100644 --- a/server-beta/src/core/hover/name.lua +++ b/server-beta/src/core/hover/name.lua @@ -1,5 +1,21 @@ +local guide = require 'parser.guide' +local vm = require 'vm' + local function asLocal(source) - return source[1] + return guide.getName(source) +end + +local function asMethod(source) + local class = vm.eachField(source.node, function (info) + if info.key == 's|type' or info.key == 's|__name' then + if info.value and info.value.type == 'string' then + return info.value[1] + end + end + end) + local node = class or guide.getName(source.node) or '*' + local method = guide.getName(source) + return ('%s:%s'):format(node, method) end return function (source) @@ -10,7 +26,10 @@ return function (source) if parent.type == 'local' or parent.type == 'getlocal' or parent.type == 'setlocal' then - return asLocal(parent) + return asLocal(parent) or '' + end + if parent.type == 'setmethod' then + return asMethod(parent) or '' end return '' end diff --git a/server-beta/src/vm/eachField.lua b/server-beta/src/vm/eachField.lua index 549a7dec..1d3d222d 100644 --- a/server-beta/src/vm/eachField.lua +++ b/server-beta/src/vm/eachField.lua @@ -133,7 +133,10 @@ function vm.eachField(source, callback) local cache = vm.cache.eachField[source] if cache then for i = 1, #cache do - callback(cache[i]) + local res = callback(cache[i]) + if res ~= nil then + return res + end end return end @@ -158,6 +161,9 @@ function vm.eachField(source, callback) vm.cache.eachField[src] = cache end) for i = 1, #cache do - callback(cache[i]) + local res = callback(cache[i]) + if res ~= nil then + return res + end end end diff --git a/server-beta/test/hover/init.lua b/server-beta/test/hover/init.lua index 33999342..7637120e 100644 --- a/server-beta/test/hover/init.lua +++ b/server-beta/test/hover/init.lua @@ -37,6 +37,56 @@ local mt = {} mt.__index = mt function mt:init(a, b, c) + return +end + +local obj = setmetatable({}, mt) + +obj:<?init?>(1, '测试') +]] +[[ +function mt:init(a: any, b: any, c: any) +]] + +TEST [[ +local mt = {} +mt.__index = mt +mt.type = 'Class' + +function mt:init(a, b, c) + return +end + +local obj = setmetatable({}, mt) + +obj:<?init?>(1, '测试') +]] +[[ +function Class:init(a: any, b: any, c: any) +]] + +TEST [[ +local mt = {} +mt.__index = mt +mt.__name = 'Class' + +function mt:init(a, b, c) + return +end + +local obj = setmetatable({}, mt) + +obj:<?init?>(1, '测试') +]] +[[ +function Class:init(a: any, b: any, c: any) +]] + +TEST [[ +local mt = {} +mt.__index = mt + +function mt:init(a, b, c) return {} end |