From 910f81f8e11232da868ccf2822aba5c6b0deadc2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 26 Oct 2021 14:43:18 +0800 Subject: update test --- test/crossfile/hover.lua | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) (limited to 'test/crossfile') diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua index b1c4c804..fee0f068 100644 --- a/test/crossfile/hover.lua +++ b/test/crossfile/hover.lua @@ -40,7 +40,7 @@ end function TEST(expect) files.removeAll() - local targetScript = expect[1].content + local targetScript, targetList = catch(expect[1].content, '?') local targetUri = furi.encode(expect[1].path) local sourceScript, sourceList = catch(expect[2].content, '?') @@ -49,7 +49,9 @@ function TEST(expect) files.setText(targetUri, targetScript) files.setText(sourceUri, sourceScript) - local sourcePos = (sourceList['?'][1][1] + sourceList['?'][1][2]) // 2 + local cachedList = targetList['?'] + sourceList['?'] + + local sourcePos = (cachedList[1][1] + cachedList[1][2]) // 2 local hover = core.byUri(sourceUri, sourcePos) assert(hover) hover = tostring(hover):gsub('\r\n', '\n') @@ -1018,3 +1020,32 @@ function fn() line1 line2]]} + +TEST { + { + path = 'a.lua', + content = [[ + + + +for _, x in ipairs({} and {}) do + print() -- `x` is infered as `string` +end +]], + }, + { + path = 'b.lua', + content = [[ +---@type string[] +local ss + +for _, s in ipairs(ss) do + print(s) +end +]], + }, + hover = [[ +```lua +local x: any +```]] +} -- cgit v1.2.3 From 1ed66a5e5ca3e26e82c64e9040784496a0396d3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 26 Oct 2021 15:02:12 +0800 Subject: update test --- test/crossfile/completion.lua | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'test/crossfile') diff --git a/test/crossfile/completion.lua b/test/crossfile/completion.lua index 455f0600..172f9d6f 100644 --- a/test/crossfile/completion.lua +++ b/test/crossfile/completion.lua @@ -108,9 +108,11 @@ function TEST(data) result.enableCommon = nil removeMetas(result) for _, item in ipairs(result) do - local r = core.resolve(item.id) - for k, v in pairs(r or {}) do - item[k] = v + if item.id then + local r = core.resolve(item.id) + for k, v in pairs(r or {}) do + item[k] = v + end end for k in pairs(item) do if not Cared[k] then -- cgit v1.2.3 From 088f65ea422b6a7727a3e8a20f379d2ecddc633c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 26 Oct 2021 16:19:52 +0800 Subject: update test --- test/crossfile/hover.lua | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'test/crossfile') diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua index fee0f068..35528446 100644 --- a/test/crossfile/hover.lua +++ b/test/crossfile/hover.lua @@ -49,9 +49,11 @@ function TEST(expect) files.setText(targetUri, targetScript) files.setText(sourceUri, sourceScript) - local cachedList = targetList['?'] + sourceList['?'] - - local sourcePos = (cachedList[1][1] + cachedList[1][2]) // 2 + if targetList['?'] then + local targetPos = (targetList['?'][1][1] + targetList['?'][1][2]) // 2 + core.byUri(targetUri, targetPos) + end + local sourcePos = (sourceList['?'][1][1] + sourceList['?'][1][2]) // 2 local hover = core.byUri(sourceUri, sourcePos) assert(hover) hover = tostring(hover):gsub('\r\n', '\n') @@ -1025,22 +1027,22 @@ TEST { { path = 'a.lua', content = [[ +---@type string[] +local ss - - -for _, x in ipairs({} and {}) do - print() -- `x` is infered as `string` +for _, s in ipairs(ss) do + print() end ]], }, { path = 'b.lua', content = [[ ----@type string[] -local ss -for _, s in ipairs(ss) do - print(s) + + +for _, x in ipairs({} and {}) do + print() -- `x` is infered as `string` end ]], }, -- cgit v1.2.3 From f859ed45793a7a6be015de45c1e17cdaab27a1af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 28 Oct 2021 16:47:37 +0800 Subject: resolve #691 --- test/crossfile/completion.lua | 108 +++++++++++++++++++++++++++++++++++++++++- test/crossfile/definition.lua | 25 ++++++++++ 2 files changed, 132 insertions(+), 1 deletion(-) (limited to 'test/crossfile') diff --git a/test/crossfile/completion.lua b/test/crossfile/completion.lua index 172f9d6f..27acb15d 100644 --- a/test/crossfile/completion.lua +++ b/test/crossfile/completion.lua @@ -87,7 +87,7 @@ function TEST(data) local pos for _, info in ipairs(data) do local uri = furi.encode(info.path) - local script = info.content + local script = info.content or '' if info.main then local newScript, catched = catch(script, '?') pos = catched['?'][1][1] @@ -565,8 +565,114 @@ TEST { ]], main = true, }, + completion = nil, } +TEST { + { path = 'f/a.lua' }, + { path = 'f/b.lua' }, + { + path = 'c.lua', + content = [[ + require '' + ]], + main = true, + }, + completion = { + { + label = 'a', + kind = CompletionItemKind.Reference, + textEdit = EXISTS, + }, + { + label = 'b', + kind = CompletionItemKind.Reference, + textEdit = EXISTS, + }, + { + label = 'f.a', + kind = CompletionItemKind.Reference, + textEdit = EXISTS, + }, + { + label = 'f.b', + kind = CompletionItemKind.Reference, + textEdit = EXISTS, + }, + } +} + +TEST { + { path = 'f/a.lua' }, + { path = 'f/b.lua' }, + { + path = 'c.lua', + content = [[ + require 'a' + ]], + main = true, + }, + completion = { + { + label = 'a', + kind = CompletionItemKind.Reference, + textEdit = EXISTS, + }, + { + label = 'f.a', + kind = CompletionItemKind.Reference, + textEdit = EXISTS, + }, + } +} + +config.set('Lua.runtime.pathStrict', true) + +TEST { + { path = 'f/a.lua' }, + { path = 'f/b.lua' }, + { + path = 'c.lua', + content = [[ + require '' + ]], + main = true, + }, + completion = { + { + label = 'f.a', + kind = CompletionItemKind.Reference, + textEdit = EXISTS, + }, + { + label = 'f.b', + kind = CompletionItemKind.Reference, + textEdit = EXISTS, + }, + } +} + +TEST { + { path = 'f/a.lua' }, + { path = 'f/b.lua' }, + { + path = 'c.lua', + content = [[ + require 'a' + ]], + main = true, + }, + completion = { + { + label = 'f.a', + kind = CompletionItemKind.Reference, + textEdit = EXISTS, + }, + } +} + +config.set('Lua.runtime.pathStrict', false) + TEST { { path = 'xxx.lua', diff --git a/test/crossfile/definition.lua b/test/crossfile/definition.lua index 37c10db6..862d95e8 100644 --- a/test/crossfile/definition.lua +++ b/test/crossfile/definition.lua @@ -117,6 +117,31 @@ TEST { }, } +config.set('Lua.runtime.pathStrict', true) +TEST { + { + path = 'aaa/bbb.lua', + content = '', + }, + { + path = 'b.lua', + content = 'require ""', + }, +} + +TEST { + { + path = 'aaa/bbb.lua', + content = '', + }, + { + path = 'b.lua', + content = 'require ""', + }, +} + +config.set('Lua.runtime.pathStrict', false) + TEST { { path = 'a.lua', -- cgit v1.2.3