diff options
-rw-r--r-- | script-beta/core/completion.lua | 0 | ||||
-rw-r--r-- | script-beta/define/CompletionItemKind.lua | 27 | ||||
-rw-r--r-- | script-beta/vm/getValue.lua | 2 | ||||
-rw-r--r-- | test-beta/completion/init.lua | 44 | ||||
-rw-r--r-- | test-beta/crossfile/hover.lua | 26 |
5 files changed, 62 insertions, 37 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua new file mode 100644 index 00000000..e69de29b --- /dev/null +++ b/script-beta/core/completion.lua diff --git a/script-beta/define/CompletionItemKind.lua b/script-beta/define/CompletionItemKind.lua new file mode 100644 index 00000000..45cee789 --- /dev/null +++ b/script-beta/define/CompletionItemKind.lua @@ -0,0 +1,27 @@ +return { + Text = 1, + Method = 2, + Function = 3, + Constructor = 4, + Field = 5, + Variable = 6, + Class = 7, + Interface = 8, + Module = 9, + Property = 10, + Unit = 11, + Value = 12, + Enum = 13, + Keyword = 14, + Snippet = 15, + Color = 16, + File = 17, + Reference = 18, + Folder = 19, + EnumMember = 20, + Constant = 21, + Struct = 22, + Event = 23, + Operator = 24, + TypeParameter = 25, +} diff --git a/script-beta/vm/getValue.lua b/script-beta/vm/getValue.lua index a93ed6e9..a1f42da1 100644 --- a/script-beta/vm/getValue.lua +++ b/script-beta/vm/getValue.lua @@ -870,7 +870,7 @@ function vm.viewType(values) local types = {} for i = 1, #values do local tp = values[i].type - if not types[tp] and tp ~= 'any' then + if tp and not types[tp] and tp ~= 'any' then types[tp] = true types[#types+1] = tp end diff --git a/test-beta/completion/init.lua b/test-beta/completion/init.lua index 12600e58..18920704 100644 --- a/test-beta/completion/init.lua +++ b/test-beta/completion/init.lua @@ -1,34 +1,6 @@ -local core = require 'core' -local parser = require 'parser' -local buildVM = require 'vm' - -local CompletionItemKind = { - Text = 1, - Method = 2, - Function = 3, - Constructor = 4, - Field = 5, - Variable = 6, - Class = 7, - Interface = 8, - Module = 9, - Property = 10, - Unit = 11, - Value = 12, - Enum = 13, - Keyword = 14, - Snippet = 15, - Color = 16, - File = 17, - Reference = 18, - Folder = 19, - EnumMember = 20, - Constant = 21, - Struct = 22, - Event = 23, - Operator = 24, - TypeParameter = 25, -} +local core = require 'core.completion' +local files = require 'files' +local CompletionItemKind = require 'define.CompletionItemKind' local EXISTS = {'EXISTS'} @@ -62,12 +34,12 @@ rawset(_G, 'TEST', true) function TEST(script) return function (expect) - local pos = script:find('$', 1, true) - 1 + files.removeAll() + local pos = script:find('$', 1, true) local new_script = script:gsub('%$', '') - local ast = parser:parse(new_script, 'lua', 'Lua 5.4') - local vm = buildVM(ast) - assert(vm) - local result = core.completion(vm, new_script, pos) + + files.setText('', new_script) + local result = core('', pos) if expect then assert(result) assert(eq(expect, result)) diff --git a/test-beta/crossfile/hover.lua b/test-beta/crossfile/hover.lua index ad2133b9..5030edf4 100644 --- a/test-beta/crossfile/hover.lua +++ b/test-beta/crossfile/hover.lua @@ -212,6 +212,32 @@ global t: { }, } +TEST { + { + path = 'a.lua', + content = [[ + return { + a = 1, + b = 2, + } + ]], + }, + { + path = 'b.lua', + content = [[ + local <?t?> = require 'a' + ]] + }, + hover = { + label = [[ +local t: { + a: integer = 1, + b: integer = 2, +}]], + name = 't', + }, +} + -- 先屏蔽掉 emmy do return end TEST { |