diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-12 20:19:44 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-12 20:19:44 +0800 |
commit | e4357d4cd7ee9018372b8e8231686888304a05d1 (patch) | |
tree | 283b38b8185a4261ea90752ea2c159bdf29e6310 /server/test | |
parent | ee7ddabf22768c57952e89098db9ffea84475ff7 (diff) | |
download | lua-language-server-e4357d4cd7ee9018372b8e8231686888304a05d1.zip |
hover支持自定义函数
Diffstat (limited to 'server/test')
-rw-r--r-- | server/test/hover/init.lua | 65 | ||||
-rw-r--r-- | server/test/main.lua | 1 | ||||
-rw-r--r-- | server/test/type_inference/init.lua | 7 |
3 files changed, 73 insertions, 0 deletions
diff --git a/server/test/hover/init.lua b/server/test/hover/init.lua new file mode 100644 index 00000000..55931339 --- /dev/null +++ b/server/test/hover/init.lua @@ -0,0 +1,65 @@ +local parser = require 'parser' +local matcher = require 'matcher' + +rawset(_G, 'TEST', true) + +function TEST(script) + local start = script:find('<?', 1, true) + local finish = script:find('?>', 1, true) + local pos = (start + finish) // 2 + 1 + local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ') + local ast = parser:ast(new_script) + local vm = matcher.vm(ast) + assert(vm) + local result = matcher.hover(vm, pos) + assert(result) +end + +TEST [[ +local function <?x?>(a, b) +end +]] + +TEST [[ +local function x(a, b) +end +<?x?>() +]] + +TEST [[ +local mt = {} +mt.__index = mt + +function mt:init(a, b, c) + return {} +end + +local obj = setmetatable({}, mt) + +obj:<?init?>(1, '测试') +]] + +TEST [[ +local mt = {} +mt.__index = mt + +function mt:init(a, b, c) + return {} +end + +local obj = setmetatable({}, mt) + +obj:init(1, '测试') +obj.<?init?>(obj, 1, '测试') +]] + +TEST [[ +function obj.xxx() +end + +obj.<?xxx?>() +]] + +TEST [[ +obj.<?xxx?>() +]] diff --git a/server/test/main.lua b/server/test/main.lua index 67e2da0a..82828714 100644 --- a/server/test/main.lua +++ b/server/test/main.lua @@ -28,6 +28,7 @@ local function main() test 'diagnostics' test 'type_inference' test 'find_lib' + test 'hover' print('测试完成') end diff --git a/server/test/type_inference/init.lua b/server/test/type_inference/init.lua index c906fdd4..36e28aec 100644 --- a/server/test/type_inference/init.lua +++ b/server/test/type_inference/init.lua @@ -127,3 +127,10 @@ local function x() end <?y?> = x() ]] + +TEST 'number' [[ +local function x(a) + return <?a?> +end +x(1) +]] |