From 4d1b606cc875803cc07031c63cde351300ea664a 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, 14 Sep 2021 19:32:31 +0800 Subject: update --- test/basic/noder.lua | 24 ++++++++++------------ test/catch.lua | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+), 13 deletions(-) create mode 100644 test/catch.lua (limited to 'test') diff --git a/test/basic/noder.lua b/test/basic/noder.lua index bc572a4c..4c0a1620 100644 --- a/test/basic/noder.lua +++ b/test/basic/noder.lua @@ -2,6 +2,7 @@ local noder = require 'core.noder' local files = require 'files' local util = require 'utility' local guide = require 'parser.guide' +local catch = require 'catch' local function getSource(pos) local ast = files.getState('') @@ -30,12 +31,9 @@ local CARE = {} local function TEST(script) return function (expect) files.removeAll() - local start = script:find('', 1, true) - local pos = (start + finish) // 2 + 1 - local newScript = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ') + local newScript, catched = catch(script, '?') files.setText('', newScript) - local source = getSource(pos) + local source = getSource(catched[1][1]) assert(source) local result = { id = noder.getID(source), @@ -53,21 +51,21 @@ CARE['id'] = true TEST [[ local ]] { - id = 'l:9', + id = 'l:6', } TEST [[ local x print() ]] { - id = 'l:7', + id = 'l:6', } TEST [[ local x = 1 ]] { - id = 'l:7', + id = 'l:6', } TEST [[ @@ -86,14 +84,14 @@ TEST [[ local x print(x.y.) ]] { - id = 'l:7|.y|.z', + id = 'l:6|.y|.z', } TEST [[ local x function x:() end ]] { - id = 'l:7|.f', + id = 'l:6|.f', } TEST [[ @@ -113,7 +111,7 @@ TEST [[ = 1, } ]] { - id = 't:1|.x', + id = 't:0|.x', } TEST [[ @@ -134,12 +132,12 @@ TEST [[ :::: goto label ]] { - id = 'l:5', + id = 'l:2', } TEST [[ ::label:: goto ]] { - id = 'l:3', + id = 'l:2', } diff --git a/test/catch.lua b/test/catch.lua new file mode 100644 index 00000000..910c368f --- /dev/null +++ b/test/catch.lua @@ -0,0 +1,58 @@ + +local function getLine(offset, lns) + for i = 0, #lns do + if offset >= lns[i] + and offset < lns[i+1] then + return i + end + end +end + +local function getPosition(offset, lns) + for i = 0, #lns do + if offset >= lns[i] + and offset < lns[i+1] then + return 10000 * i + offset - lns[i] + end + end +end + +---@param script string +---@param sep string +return function (script, sep) + local pattern = ('()<%%%s.-%%%s>()'):format(sep, sep) + local lns = {} + lns[0] = 0 + for pos in script:gmatch '()\n' do + lns[#lns+1] = pos + end + lns[#lns+1] = math.maxinteger + local codes = {} + local pos = 1 + ---@type integer[] + local list = {} + local cuted = 0 + local lastLine = 0 + for a, b in script:gmatch(pattern) do + codes[#codes+1] = script:sub(pos, a - 1) + codes[#codes+1] = script:sub(a + 2, b - 3) + pos = b + local line1 = getLine(a + 1, lns) + if line1 ~= lastLine then + cuted = 0 + lastLine = line1 + end + cuted = cuted + 2 + local left = getPosition(a + 1, lns) - cuted + local line2 = getLine(b - 3, lns) + if line2 ~= lastLine then + cuted = 0 + lastLine = line2 + end + local right = getPosition(b - 3, lns) - cuted + cuted = cuted + 2 + list[#list+1] = { left, right } + end + codes[#codes+1] = script:sub(pos) + return table.concat(codes), list +end -- cgit v1.2.3 From 5a072004414ff1f8de416c62a4067774f72e7097 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, 14 Sep 2021 20:43:33 +0800 Subject: cleanup --- test/basic/noder.lua | 2 +- test/catch.lua | 28 +++++++++++++++++++++++++--- test/references/init.lua | 27 ++++++--------------------- 3 files changed, 32 insertions(+), 25 deletions(-) (limited to 'test') diff --git a/test/basic/noder.lua b/test/basic/noder.lua index 4c0a1620..87b34e12 100644 --- a/test/basic/noder.lua +++ b/test/basic/noder.lua @@ -33,7 +33,7 @@ local function TEST(script) files.removeAll() local newScript, catched = catch(script, '?') files.setText('', newScript) - local source = getSource(catched[1][1]) + local source = getSource(catched['?'][1][1]) assert(source) local result = { id = noder.getID(source), diff --git a/test/catch.lua b/test/catch.lua index 910c368f..09b55929 100644 --- a/test/catch.lua +++ b/test/catch.lua @@ -1,3 +1,22 @@ +local mt = {} + +local function catchedTable() + return setmetatable({}, mt) +end + +function mt.__add(a, b) + if not a or not b then + return a or b + end + local t = catchedTable() + for _, v in ipairs(a) do + t[#t+1] = v + end + for _, v in ipairs(b) do + t[#t+1] = v + end + return t +end local function getLine(offset, lns) for i = 0, #lns do @@ -20,7 +39,7 @@ end ---@param script string ---@param sep string return function (script, sep) - local pattern = ('()<%%%s.-%%%s>()'):format(sep, sep) + local pattern = ('()<(%s).-%s>()'):format(sep, sep) local lns = {} lns[0] = 0 for pos in script:gmatch '()\n' do @@ -33,7 +52,7 @@ return function (script, sep) local list = {} local cuted = 0 local lastLine = 0 - for a, b in script:gmatch(pattern) do + for a, char, b in script:gmatch(pattern) do codes[#codes+1] = script:sub(pos, a - 1) codes[#codes+1] = script:sub(a + 2, b - 3) pos = b @@ -51,7 +70,10 @@ return function (script, sep) end local right = getPosition(b - 3, lns) - cuted cuted = cuted + 2 - list[#list+1] = { left, right } + if not list[char] then + list[char] = catchedTable() + end + list[char][#list[char]+1] = { left, right } end codes[#codes+1] = script:sub(pos) return table.concat(codes), list diff --git a/test/references/init.lua b/test/references/init.lua index 2fba92e5..a14f0a02 100644 --- a/test/references/init.lua +++ b/test/references/init.lua @@ -1,19 +1,6 @@ local core = require 'core.reference' local files = require 'files' - -local function catch_target(script) - local list = {} - local cur = 1 - while true do - local start, finish = script:find('<[!?].-[!?]>', cur) - if not start then - break - end - list[#list+1] = { start + 2, finish - 2 } - cur = finish + 1 - end - return list -end +local catch = require 'catch' local function founded(targets, results) if #targets ~= #results then @@ -33,14 +20,12 @@ end function TEST(script) files.removeAll() - local expect = catch_target(script) - local start = script:find('<[?~]') - local finish = script:find('[?~]>') - local pos = (start + finish) // 2 + 1 - local new_script = script:gsub('<[!?~]', ' '):gsub('[!?~]>', ' ') - files.setText('', new_script) + local newScript, catched = catch(script, '[!?~]') + files.setText('', newScript) - local results = core('', pos) + local input = catched['?'] + catched['~'] + local expect = catched['!'] + catched['?'] + catched['~'] + local results = core('', input[1][1]) if results then local positions = {} for i, result in ipairs(results) do -- cgit v1.2.3 From 8880b7d63931469c0b7bfb69004f342236ce2811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 15 Sep 2021 16:11:30 +0800 Subject: cleanup --- test/example/guide.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/example/guide.txt b/test/example/guide.txt index da8d5c32..cff05faf 100644 --- a/test/example/guide.txt +++ b/test/example/guide.txt @@ -586,7 +586,7 @@ end ---@param lines table ---@return integer {name = 'row'} ---@return integer {name = 'col'} -function m.positionOf(lines, offset) +function m.rowColOf(lines, offset) if offset < 1 then return 0, 0 end @@ -619,7 +619,7 @@ end ---@param row integer ---@param col integer ---@return integer {name = 'offset'} -function m.offsetOf(lines, row, col) +function m.positionOf(lines, row, col) if row < 1 then return 0 end -- cgit v1.2.3 From 281031ba5c41ebe34bd6c8634f1436fe1341fcaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 15 Sep 2021 20:01:34 +0800 Subject: update --- test/catch.lua | 108 ++++++++++++++++++++++++----------------------- test/references/init.lua | 2 +- 2 files changed, 57 insertions(+), 53 deletions(-) (limited to 'test') diff --git a/test/catch.lua b/test/catch.lua index 09b55929..849be09d 100644 --- a/test/catch.lua +++ b/test/catch.lua @@ -1,3 +1,5 @@ +local m = require 'lpeglabel' + local mt = {} local function catchedTable() @@ -18,63 +20,65 @@ function mt.__add(a, b) return t end -local function getLine(offset, lns) - for i = 0, #lns do - if offset >= lns[i] - and offset < lns[i+1] then - return i - end - end -end - -local function getPosition(offset, lns) - for i = 0, #lns do - if offset >= lns[i] - and offset < lns[i+1] then - return 10000 * i + offset - lns[i] - end - end +local function parseTokens(script, seps) + local parser = m.P { + m.Ct(m.V 'Token'^0), + Token = m.Cp() * (m.V 'Mark' + m.V 'Nl' + m.V 'Text'), + Mark = m.Cc 'ML' * m.P '<' * m.C(m.S(seps)) + + m.Cc 'MR' * m.C(m.S(seps)) * m.P '>', + Nl = m.Cc 'NL' * m.C(m.P '\r\n' + m.S '\r\n'), + Text = m.Cc 'TX' * m.C((1 - m.V 'Nl' - m.V 'Mark')^1), + } + local results = parser:match(script) + return results end ---@param script string ----@param sep string -return function (script, sep) - local pattern = ('()<(%s).-%s>()'):format(sep, sep) - local lns = {} - lns[0] = 0 - for pos in script:gmatch '()\n' do - lns[#lns+1] = pos - end - lns[#lns+1] = math.maxinteger - local codes = {} - local pos = 1 - ---@type integer[] - local list = {} - local cuted = 0 - local lastLine = 0 - for a, char, b in script:gmatch(pattern) do - codes[#codes+1] = script:sub(pos, a - 1) - codes[#codes+1] = script:sub(a + 2, b - 3) - pos = b - local line1 = getLine(a + 1, lns) - if line1 ~= lastLine then - cuted = 0 - lastLine = line1 +---@param seps string +return function (script, seps) + local tokens = parseTokens(script, seps) + local newBuf = {} + local result = {} + local marks = {} + + local lineOffset = 1 + local line = 0 + local skipOffset = 0 + for i = 1, #tokens, 3 do + local offset = tokens[i + 0] + local mode = tokens[i + 1] + local text = tokens[i + 2] + if mode == 'TX' then + newBuf[#newBuf+1] = text end - cuted = cuted + 2 - local left = getPosition(a + 1, lns) - cuted - local line2 = getLine(b - 3, lns) - if line2 ~= lastLine then - cuted = 0 - lastLine = line2 + if mode == 'NL' then + newBuf[#newBuf+1] = text + line = line + 1 + lineOffset = offset + #text - skipOffset end - local right = getPosition(b - 3, lns) - cuted - cuted = cuted + 2 - if not list[char] then - list[char] = catchedTable() + if mode == 'ML' then + marks[#marks+1] = { + char = text, + position = line * 10000 + offset - skipOffset - lineOffset, + } + skipOffset = skipOffset + 1 + #text + end + if mode == 'MR' then + for j = #marks, 1, -1 do + local mark = marks[j] + if mark.char == text then + local position = line * 10000 + offset - skipOffset - lineOffset + if not result[text] then + result[text] = catchedTable() + end + result[text][#result[text]+1] = { mark.position, position } + table.remove(marks, j) + break + end + end + skipOffset = skipOffset + 1 + #text end - list[char][#list[char]+1] = { left, right } end - codes[#codes+1] = script:sub(pos) - return table.concat(codes), list + + return table.concat(newBuf), result end diff --git a/test/references/init.lua b/test/references/init.lua index a14f0a02..78e9aabf 100644 --- a/test/references/init.lua +++ b/test/references/init.lua @@ -20,7 +20,7 @@ end function TEST(script) files.removeAll() - local newScript, catched = catch(script, '[!?~]') + local newScript, catched = catch(script, '!?~') files.setText('', newScript) local input = catched['?'] + catched['~'] -- cgit v1.2.3 From e70f82c0534c8973b3ad809a5ad72919412a832b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 15 Sep 2021 20:24:38 +0800 Subject: update --- test/references/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/references/init.lua b/test/references/init.lua index 78e9aabf..351c80b6 100644 --- a/test/references/init.lua +++ b/test/references/init.lua @@ -24,7 +24,7 @@ function TEST(script) files.setText('', newScript) local input = catched['?'] + catched['~'] - local expect = catched['!'] + catched['?'] + catched['~'] + local expect = catched['!'] + catched['?'] local results = core('', input[1][1]) if results then local positions = {} -- cgit v1.2.3 From c3fc3c4631c8f69cb7250d8e2accd9ac0d8a0fb4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 15 Sep 2021 20:31:07 +0800 Subject: update --- test/definition/init.lua | 37 +++++++------------------------------ 1 file changed, 7 insertions(+), 30 deletions(-) (limited to 'test') diff --git a/test/definition/init.lua b/test/definition/init.lua index 85bcd5d5..992744d5 100644 --- a/test/definition/init.lua +++ b/test/definition/init.lua @@ -1,23 +1,10 @@ local core = require 'core.definition' local files = require 'files' local vm = require 'vm' +local catch = require 'catch' rawset(_G, 'TEST', true) -local function catch_target(script) - local list = {} - local cur = 1 - while true do - local start, finish = script:find('', cur) - if not start then - break - end - list[#list+1] = { start + 2, finish - 2 } - cur = finish + 1 - end - return list -end - local function founded(targets, results) if #targets ~= #results then return false @@ -36,15 +23,11 @@ end function TEST(script) files.removeAll() - script = script:gsub('\n', '\r\n') - local target = catch_target(script) - local start = script:find('', 1, true) - local pos = (start + finish) // 2 + 1 - local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ') - files.setText('', new_script) + local newScript, catched = catch(script, '!?') - local results = core('', pos) + files.setText('', newScript) + + local results = core('', catched['?'][1][1]) if results then local positions = {} for i, result in ipairs(results) do @@ -52,15 +35,9 @@ function TEST(script) positions[i] = { result.target.start, result.target.finish } end end - if not founded(target, positions) then - core('', pos) - end - assert(founded(target, positions)) + assert(founded(catched['!'], positions)) else - if #target ~= 0 then - core('', pos) - end - assert(#target == 0) + assert(#catched['!'] == 0) end end -- cgit v1.2.3 From 03444fe030383163b35fcd8c557bccd31aeebe5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 15 Sep 2021 21:40:16 +0800 Subject: update --- test/definition/init.lua | 4 ++-- test/definition/table.lua | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'test') diff --git a/test/definition/init.lua b/test/definition/init.lua index 992744d5..2e87b0c2 100644 --- a/test/definition/init.lua +++ b/test/definition/init.lua @@ -35,9 +35,9 @@ function TEST(script) positions[i] = { result.target.start, result.target.finish } end end - assert(founded(catched['!'], positions)) + assert(founded(catched['!'] or {}, positions)) else - assert(#catched['!'] == 0) + assert(catched['!'] == nil) end end diff --git a/test/definition/table.lua b/test/definition/table.lua index d63cc655..61e8746d 100644 --- a/test/definition/table.lua +++ b/test/definition/table.lua @@ -54,7 +54,7 @@ t[]() TEST [[ local t t[] = 1 -t[]() +t[ ]() ]] TEST [[ -- cgit v1.2.3 From 31e9a5235cd17c8a61d2a0a732212cd68135bed5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 17 Sep 2021 15:13:50 +0800 Subject: update --- test/hover/init.lua | 12 ++++-------- test/type_inference/init.lua | 9 +++------ 2 files changed, 7 insertions(+), 14 deletions(-) (limited to 'test') diff --git a/test/hover/init.lua b/test/hover/init.lua index 3f07ea30..c16e466d 100644 --- a/test/hover/init.lua +++ b/test/hover/init.lua @@ -1,7 +1,6 @@ local core = require 'core.hover' -local findSource = require 'core.find-source' -local getLabel = require 'core.hover.label' local files = require 'files' +local catch = require 'catch' rawset(_G, 'TEST', true) @@ -23,12 +22,9 @@ local accept = { function TEST(script) return function (expect) files.removeAll() - local start = script:find('', 1, true) - local pos = (start + finish) // 2 + 1 - local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ') - files.setText('', new_script) - local hover = core.byUri('', pos) + local newScript, catched = catch(script, '?') + files.setText('', newScript) + local hover = core.byUri('', catched['?'][1][1]) assert(hover) expect = expect:gsub('^[\r\n]*(.-)[\r\n]*$', '%1'):gsub('\r\n', '\n') local label = tostring(hover):match('```lua[\r\n]*(.-)[\r\n]*```'):gsub('\r\n', '\n') diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index a20a96e9..286d47cb 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -1,8 +1,8 @@ local files = require 'files' -local vm = require 'vm' local guide = require 'parser.guide' local infer = require 'core.infer' local config = require 'config' +local catch = require 'catch' rawset(_G, 'TEST', true) @@ -24,12 +24,9 @@ end function TEST(wanted) return function (script) files.removeAll() - local start = script:find('', 1, true) - local pos = (start + finish) // 2 + 1 - local newScript = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ') + local newScript, catched = catch(script, '?') files.setText('', newScript) - local source = getSource(pos) + local source = getSource(catched['?'][1][1]) assert(source) local result = infer.searchAndViewInfers(source) if wanted ~= result then -- cgit v1.2.3 From b944681c831b47c93b5b1f9a398f26ad3ca03c21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 17 Sep 2021 15:17:55 +0800 Subject: update test --- test/completion/common.lua | 384 +++++++++++++++++++++---------------------- test/completion/continue.lua | 10 +- test/completion/init.lua | 15 +- 3 files changed, 205 insertions(+), 204 deletions(-) (limited to 'test') diff --git a/test/completion/common.lua b/test/completion/common.lua index 2efa63ad..66cc6fe4 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -8,7 +8,7 @@ config.set('Lua.completion.showWord', 'Enable') TEST [[ local zabcde -za$ +za ]] { { @@ -20,7 +20,7 @@ za$ TEST [[ local zabcdefg local zabcde -zabcde$ +zabcde ]] { { @@ -35,7 +35,7 @@ zabcde$ TEST [[ local zabcdefg -za$ +za local zabcde ]] { @@ -51,7 +51,7 @@ local zabcde TEST [[ local zabcde -zace$ +zace ]] { { @@ -63,7 +63,7 @@ zace$ TEST [[ ZABC = x local zabc -zac$ +zac ]] { { @@ -77,7 +77,7 @@ zac$ } TEST [[ -ass$ +ass ]] { { @@ -92,7 +92,7 @@ ass$ TEST [[ local assert = 1 -ass$ +ass ]] { { @@ -103,7 +103,7 @@ ass$ TEST [[ local assert = 1 -_G.ass$ +_G.ass ]] { { @@ -119,7 +119,7 @@ _G.ass$ TEST [[ local function ffff(a, b) end -ff$ +ff ]] { { @@ -134,7 +134,7 @@ ff$ TEST [[ local zabc = 1 -z$ +z ]] { { @@ -145,7 +145,7 @@ z$ TEST [[ local zabc = 1.0 -z$ +z ]] { { @@ -158,7 +158,7 @@ TEST [[ local t = { abc = 1, } -t.ab$ +t.ab ]] { { @@ -172,7 +172,7 @@ local t = { abc = 1, } local n = t.abc -t.ab$ +t.ab ]] { { @@ -187,7 +187,7 @@ mt.ggg = 1 function mt:get(a, b) return 1 end -mt:g$ +mt:g ]] { { @@ -205,7 +205,7 @@ mt:g$ } TEST [[ -loc$ +loc ]] { { @@ -220,7 +220,7 @@ loc$ IgnoreFunction = true TEST [[ -do$ +do ]] { { @@ -234,7 +234,7 @@ do$ } TEST [[ -while true d$ +while true d ]] { { @@ -248,18 +248,18 @@ while true d$ } TEST [[ -results$ +results ]] (nil) TEST [[ -result$ +result local results ]] (EXISTS) TEST [[ -local a$ +local a local function f(fff) fff = ast @@ -280,7 +280,7 @@ end TEST [[ t.a = {} t.b = {} -t.$ +t. ]] { { @@ -296,7 +296,7 @@ t.$ TEST [[ t.a = {} t.b = {} -t. $ +t. ]] { { @@ -314,7 +314,7 @@ TEST [[ t.a = {} function t:b() end -t:$ +t: ]] { { @@ -331,7 +331,7 @@ TEST [[ local t = { a = {}, } -t.$ +t. xxx() ]] { @@ -342,14 +342,14 @@ xxx() } TEST [[ -(''):$ +(''): ]] (EXISTS) TEST [[ local zzz -return 'aa' .. zz$ +return 'aa' .. zz ]] { { @@ -358,9 +358,9 @@ return 'aa' .. zz$ }, } -TEST 'local s = "a:$"' (nil) +TEST 'local s = "a:"' (nil) -TEST 'debug.$' +TEST 'debug.' (EXISTS) IgnoreFunction = true @@ -371,7 +371,7 @@ local xxxx = { } local t = { - x$ + x } ]] { @@ -392,7 +392,7 @@ local t = { TEST [[ print(ff2) local faa -local f$ +local f print(fff) ]] { @@ -419,7 +419,7 @@ print(fff) } TEST [[ -local function f(ff$) +local function f(ff) print(fff) end ]] @@ -431,12 +431,12 @@ end } TEST [[ -collectgarbage($) +collectgarbage() ]] (EXISTS) TEST [[ -collectgarbage('$') +collectgarbage('') ]] { { @@ -514,7 +514,7 @@ collectgarbage('$') } TEST [[ -io.read($) +io.read() ]] { { @@ -536,18 +536,18 @@ io.read($) } TEST [[ -io.open('', $) +io.open('', ) ]] (EXISTS) TEST [[ -local function f(a, $) +local function f(a, ) end ]] (nil) TEST [[ -self.results.list[#$] +self.results.list[#] ]] { { @@ -562,7 +562,7 @@ self.results.list[#$] } TEST [[ -self.results.list[#$] +self.results.list[#] local n = 1 ]] { @@ -578,7 +578,7 @@ local n = 1 } TEST [[ -self.results.list[#$] = 1 +self.results.list[#] = 1 ]] { { @@ -593,7 +593,7 @@ self.results.list[#$] = 1 } TEST [[ -self.results.list[#self.re$] +self.results.list[#self.re] ]] { { @@ -612,7 +612,7 @@ self.results.list[#self.re$] } TEST [[ -fff[#ff$] +fff[#ff] ]] { { @@ -631,7 +631,7 @@ fff[#ff$] } TEST [[ -local _ = fff.kkk[#$] +local _ = fff.kkk[#] ]] { { @@ -646,7 +646,7 @@ local _ = fff.kkk[#$] } TEST [[ -fff.kkk[#$].yy +fff.kkk[#].yy ]] { { @@ -665,7 +665,7 @@ local t = { a = 1, } -t . $ +t . ]] (EXISTS) @@ -674,7 +674,7 @@ local t = { a = 1, } -t . $ b +t . b ]] (EXISTS) @@ -683,7 +683,7 @@ local t = { a = 1, } -t $ +t ]] (nil) @@ -692,13 +692,13 @@ local t = { a = 1, } -t $. +t . ]] (nil) TEST [[ local xxxx -xxxx$ +xxxx ]] { { @@ -710,7 +710,7 @@ xxxx$ TEST [[ local xxxx local XXXX -xxxx$ +xxxx ]] { { @@ -727,7 +727,7 @@ TEST [[ local t = { xxxxx = 1, } -xx$ +xx ]] { { @@ -738,7 +738,7 @@ xx$ TEST [[ local index -tbl[inde$] +tbl[inde] ]] { { @@ -753,7 +753,7 @@ return function () a = {}, b = {}, } - t.$ + t. end ]] { @@ -769,7 +769,7 @@ end TEST [[ local ast = 1 -local t = 'as$' +local t = 'as' local ask = 1 ]] (EXISTS) @@ -777,7 +777,7 @@ local ask = 1 TEST [[ local add -function f(ad$) +function f(ad) local _ = add end ]] @@ -789,25 +789,25 @@ end } TEST [[ -function table.i$ +function table.i ]] (EXISTS) TEST [[ do - xx.$ + xx. end ]] (nil) TEST [[ -print(io.$) +print(io.) ]] (EXISTS) require 'config'.set('Lua.runtime.version', 'Lua 5.4') --TEST [[ ---local $ +--local --]] --{ -- { @@ -821,7 +821,7 @@ require 'config'.set('Lua.runtime.version', 'Lua 5.4') --} -- --TEST [[ ---local --]] --{ -- { @@ -835,7 +835,7 @@ local mt = {} mt.__index = mt local t = setmetatable({}, mt) -t.$ +t. ]] { { @@ -848,7 +848,7 @@ TEST [[ local elseaaa ELSE = 1 if a then -else$ +else ]] { { @@ -877,7 +877,7 @@ Cared['insertText'] = true IgnoreFunction = false TEST [[ local xpcal -xpcal$ +xpcal ]] { { @@ -900,7 +900,7 @@ TEST [[ function mt:f(a, b, c) end -mt:f$ +mt:f ]] { { @@ -911,12 +911,12 @@ mt:f$ { label = 'f(a, b, c)', kind = define.CompletionItemKind.Snippet, - insertText = 'f(${1:a: any}, ${2:b: any}, ${3:c: any})', + insertText = 'f({1:a: any}, {2:b: any}, {3:c: any})', }, } TEST [[ -function$ +function ]] { { @@ -927,14 +927,14 @@ function$ label = 'function ()', kind = define.CompletionItemKind.Snippet, insertText = "\z -function $1($2)\ -\t$0\ +function 1(2)\ +\t0\ end", }, } TEST [[ -local t = function$ +local t = function ]] { { @@ -945,8 +945,8 @@ local t = function$ label = 'function ()', kind = define.CompletionItemKind.Snippet, insertText = "\z -function ($1)\ -\t$0\ +function (1)\ +\t0\ end", }, } @@ -956,7 +956,7 @@ IgnoreFunction = true TEST [[ local function f() if a then - else$ + else end ]] { @@ -979,7 +979,7 @@ local t = { ['a.b.c'] = {} } -t.$ +t. ]] { { @@ -1005,7 +1005,7 @@ local t = { ['a.b.c'] = {} } -t. $ +t. ]] { { @@ -1031,7 +1031,7 @@ local t = { ['a.b.c'] = {} } -t['$'] +t[''] ]] { { @@ -1048,7 +1048,7 @@ t['$'] TEST [[ _ENV['z.b.c'] = {} -z$ +z ]] { { @@ -1063,18 +1063,18 @@ z$ } TEST [[ -io.close(1, $) +io.close(1, ) ]] (nil) TEST [[ -io$ +io ]] (EXISTS) IgnoreFunction = false TEST [[ -loadstring$ +loadstring ]] { { @@ -1090,7 +1090,7 @@ loadstring$ } --TEST [[ ---bit32$ +--bit32 --]] --{ -- { @@ -1103,7 +1103,7 @@ loadstring$ TEST [[ function loadstring() end -loadstring$ +loadstring ]] { { @@ -1127,7 +1127,7 @@ loadstring$ } TEST [[ -debug.setcsta$ +debug.setcsta ]] { { @@ -1143,12 +1143,12 @@ debug.setcsta$ } TEST [[ ----@$ +---@ ]] (EXISTS) TEST [[ ----@cl$ +---@cl ]] { { @@ -1159,7 +1159,7 @@ TEST [[ TEST [[ ---@class ZABC ----@class ZBBC : Z$ +---@class ZBBC : Z ]] { { @@ -1170,14 +1170,14 @@ TEST [[ TEST [[ ---@class ZABC ----@class ZBBC : $ +---@class ZBBC : ]] (EXISTS) TEST [[ ---@class zabc local abcd ----@type za$ +---@type za ]] { { @@ -1189,14 +1189,14 @@ local abcd TEST [[ ---@class abc local abcd ----@type $ +---@type ]] (EXISTS) TEST [[ ---@class zabc local abcd ----@type zxxx|z$ +---@type zxxx|z ]] { { @@ -1207,7 +1207,7 @@ local abcd TEST [[ ---@alias zabc zabb ----@type za$ +---@type za ]] { { @@ -1218,7 +1218,7 @@ TEST [[ TEST [[ ---@class ZClass ----@param x ZC$ +---@param x ZC ]] { { @@ -1229,7 +1229,7 @@ TEST [[ Cared['insertText'] = true TEST [[ ----@param $ +---@param function f(a, b, c) end ]] @@ -1238,9 +1238,9 @@ end label = 'a, b, c', kind = define.CompletionItemKind.Snippet, insertText = [[ -a ${1:any} ----@param b ${2:any} ----@param c ${3:any}]] +a {1:any} +---@param b {2:any} +---@param c {3:any}]] }, { label = 'a', @@ -1257,7 +1257,7 @@ a ${1:any} } TEST [[ ----@param $ +---@param function f(a, b, c) end function f2(a) end @@ -1267,9 +1267,9 @@ function f2(a) end label = 'a, b, c', kind = define.CompletionItemKind.Snippet, insertText = [[ -a ${1:any} ----@param b ${2:any} ----@param c ${3:any}]] +a {1:any} +---@param b {2:any} +---@param c {3:any}]] }, { label = 'a', @@ -1286,7 +1286,7 @@ a ${1:any} } TEST [[ ----@param aa$ +---@param aa function f(aaa, bbb, ccc) end ]] @@ -1299,7 +1299,7 @@ end TEST [[ local function f() - ---@param $ + ---@param function f(a, b, c) end end @@ -1309,9 +1309,9 @@ end label = 'a, b, c', kind = define.CompletionItemKind.Snippet, insertText = [[ -a ${1:any} ----@param b ${2:any} ----@param c ${3:any}]] +a {1:any} +---@param b {2:any} +---@param c {3:any}]] }, { label = 'a', @@ -1328,7 +1328,7 @@ a ${1:any} } TEST [[ ----@param $ +---@param function mt:f(a, b, c, ...) end ]] @@ -1337,9 +1337,9 @@ end label = 'a, b, c', kind = define.CompletionItemKind.Snippet, insertText = [[ -a ${1:any} ----@param b ${2:any} ----@param c ${3:any}]], +a {1:any} +---@param b {2:any} +---@param c {3:any}]], }, { label = 'self', @@ -1360,7 +1360,7 @@ a ${1:any} } TEST [[ ----@param aaa $ +---@param aaa function f(aaa, bbb, ccc) end ]] @@ -1369,7 +1369,7 @@ end TEST [[ ---@param xyz Class ---@param xxx Class -function f(x$) +function f(x) ]] { { @@ -1389,7 +1389,7 @@ function f(x$) TEST [[ ---@param xyz Class ---@param xxx Class -function f($ +function f( ]] { { @@ -1409,7 +1409,7 @@ function f($ TEST [[ ---@param xyz Class ---@param xxx Class -function f($) +function f() ]] { { @@ -1428,7 +1428,7 @@ function f($) TEST [[ local function f() - ---@t$ + ---@t end ]] { @@ -1443,7 +1443,7 @@ TEST [[ ---@field name string ---@field id integer local mt = {} -mt.$ +mt. ]] { { @@ -1461,7 +1461,7 @@ TEST [[ function f(y, x) end -f(1, $) +f(1, ) ]] { { @@ -1483,7 +1483,7 @@ TEST [[ function f(y, x) end -f(1,$) +f(1,) ]] { { @@ -1505,7 +1505,7 @@ TEST [[ function f(x) end -f($) +f() ]] { { @@ -1528,7 +1528,7 @@ TEST [[ function f(x) end -f($) +f() ]] { { @@ -1550,7 +1550,7 @@ TEST [[ function f(x) end -f('$') +f('') ]] { { @@ -1586,7 +1586,7 @@ TEST [[ local function f(x) end -f($) +f() ]] { { @@ -1619,7 +1619,7 @@ end ---comment 3 ---| '3' -f($) +f() ]] { { @@ -1638,7 +1638,7 @@ function f(x) end f(function () - $ + end) ]] (nil) @@ -1652,7 +1652,7 @@ TEST [[ ---@return string local function zzzzz(list, sep, i, j) end -zzz$ +zzz ]] { { @@ -1672,7 +1672,7 @@ Cared['description'] = true TEST [[ --- abc zzz = 1 -zz$ +zz ]] { { @@ -1695,7 +1695,7 @@ TEST [[ ---| "'选项2'" # 注释2 function f(x) end -f($) +f() ]] { { @@ -1711,7 +1711,7 @@ f($) } TEST [[ -utf8.charpatter$ +utf8.charpatter ]] { { @@ -1726,7 +1726,7 @@ TEST [[ ---@type "'a'"|"'b'"|"'c'" local x -print(x == $) +print(x == ) ]] { { @@ -1747,7 +1747,7 @@ TEST [[ ---@type "'a'"|"'b'"|"'c'" local x -x = $ +x = ]] { { @@ -1768,7 +1768,7 @@ TEST [[ ---@type "'a'"|"'b'"|"'c'" local x -print(x == '$') +print(x == '') ]] { { @@ -1792,7 +1792,7 @@ TEST [[ ---@type "'a'"|"'b'"|"'c'" local x -x = '$' +x = '' ]] { { @@ -1815,24 +1815,24 @@ x = '$' TEST [[ local t = type() -print(t == $) +print(t == ) ]] (EXISTS) TEST [[ -if type(arg) == '$' +if type(arg) == '' ]] (EXISTS) TEST [[ -if type(arg) == $ +if type(arg) == ]] (EXISTS) TEST [[ ---@type string local s -s.$ +s. ]] (EXISTS) @@ -1841,7 +1841,7 @@ TEST [[ local t local vvv = assert(t) -vvv$ +vvv ]] { { @@ -1857,21 +1857,21 @@ TEST [[ ---@param callback fun(x: number, y: number):string local function f(callback) end -f($) +f() ]] { { label = 'fun(x: number, y: number):string', kind = define.CompletionItemKind.Function, insertText = "\z -function (${1:x}, ${2:y})\ -\t$0\ +function ({1:x}, {2:y})\ +\t0\ end", }, } TEST [[ ----$ +--- local function f(a, b, c) return a + 1, b .. '', c[1] end @@ -1881,20 +1881,20 @@ end label = '@param;@return', kind = define.CompletionItemKind.Snippet, insertText = "\z -${1:comment}\ ----@param a ${2:number}\ ----@param b ${3:string}\ ----@param c ${4:table}\ ----@return ${5:number}\ ----@return ${6:string}\ ----@return ${7:any}", +{1:comment}\ +---@param a {2:number}\ +---@param b {3:string}\ +---@param c {4:table}\ +---@return {5:number}\ +---@return {6:string}\ +---@return {7:any}", }, } Cared['insertText'] = nil TEST [[ ---$ +-- ]] { { @@ -1918,7 +1918,7 @@ TEST [[ local function f(x) end f({ - $ + }) ]] { @@ -1942,7 +1942,7 @@ local function f(x) end f({ aaa = 1, - $ + }) ]] { @@ -1960,7 +1960,7 @@ TEST [[ ---@param x cc local function f(x) end -f({aaa = 1,$}) +f({aaa = 1,}) ]] { { @@ -1977,7 +1977,7 @@ TEST [[ ---@param x cc local function f(x) end -f({aaa $}) +f({aaa }) ]] (nil) @@ -1988,7 +1988,7 @@ TEST [[ ---@param x cc local function f(x) end -f({if$}) +f({if}) ]] { include = true, @@ -2008,7 +2008,7 @@ local function f(x) end f({ { - $ + } }) ]] @@ -2020,7 +2020,7 @@ local function f() end local s = f() -s.$ +s. ]] (EXISTS) @@ -2032,7 +2032,7 @@ TEST [[ ---@type cc local t -print(t.aa$) +print(t.aa) ]] { { @@ -2050,7 +2050,7 @@ TEST [[ ---@type table local x -x.a = $ +x.a = ]] { { @@ -2071,7 +2071,7 @@ TEST [[ ---@type table local x -x['a'] = $ +x['a'] = ]] { { @@ -2091,7 +2091,7 @@ x['a'] = $ TEST [[ ---@type table local x = { - a = $ + a = } ]] { @@ -2112,7 +2112,7 @@ local x = { TEST [[ ---@type table local x = { - ['a'] = $ + ['a'] = } ]] { @@ -2138,7 +2138,7 @@ local m function m.f() end -m.f$ +m.f ]]{ { label = "f()", @@ -2154,7 +2154,7 @@ m.f$ Cared['insertText'] = nil TEST [[ -if true then$ +if true then ]] { { @@ -2168,7 +2168,7 @@ if true then$ } TEST [[ -if true then$ +if true then end ]] { @@ -2179,7 +2179,7 @@ end } TEST [[ -if true then$ +if true then else ]] { @@ -2190,7 +2190,7 @@ else } TEST [[ -if true then$ +if true then elseif ]] { @@ -2202,7 +2202,7 @@ elseif TEST [[ do - if true then$ + if true then end ]] { @@ -2226,7 +2226,7 @@ local function f(x, ...) end f(1, { - $ + }) ]] { @@ -2250,7 +2250,7 @@ local function f(x, ...) end f(1, {}, {}, { - $ + }) ]] { @@ -2271,7 +2271,7 @@ TEST [[ ---@type C local t = { - $ + } ]] @@ -2293,7 +2293,7 @@ TEST [[ ---@type C local t = { - x$ + x } ]] @@ -2306,19 +2306,19 @@ local t = { } TEST [[ -if $ then +if then ]] (nil) TEST [[ -elseif $ then +elseif then ]] (nil) TEST [[ ---@type iolib local t = { - $ + ]] (EXISTS) @@ -2329,7 +2329,7 @@ TEST [[ ---@param t A function api(t) end -api({$}) +api({}) ]] (EXISTS) @@ -2340,14 +2340,14 @@ TEST [[ ---@param t A function m:api(t) end -m:api({$}) +m:api({}) ]] (EXISTS) TEST [[ ---@class AAA.BBB ----@type AAA.$ +---@type AAA. ]] { { @@ -2365,7 +2365,7 @@ Cared['insertText'] = true TEST [[ ---@overload fun(a: any, b: any) local function zzzz(a) end -zzzz$ +zzzz ]] { { @@ -2376,7 +2376,7 @@ zzzz$ { label = 'zzzz(a)', kind = define.CompletionItemKind.Snippet, - insertText = 'zzzz(${1:a: any})', + insertText = 'zzzz({1:a: any})', }, { label = 'zzzz(a, b)', @@ -2386,7 +2386,7 @@ zzzz$ { label = 'zzzz(a, b)', kind = define.CompletionItemKind.Snippet, - insertText = 'zzzz(${1:a: any}, ${2:b: any})', + insertText = 'zzzz({1:a: any}, {2:b: any})', }, } Cared['insertText'] = false @@ -2406,13 +2406,13 @@ local tarray local b = tdirect -- type . here, shows "world" -- Inferred by index -local c = tarray[1].$ -- type . here, no auto completion +local c = tarray[1]. -- type . here, no auto completion ]] (EXISTS) TEST [[ local function f() - if type() == '$' then + if type() == '' then end end ]] @@ -2425,7 +2425,7 @@ GGG = 1 GGG = function () end -GGG$ +GGG ]] { { @@ -2446,7 +2446,7 @@ local t = {} t.GGG = function () end -t.GGG$ +t.GGG ]] { { @@ -2463,14 +2463,14 @@ TEST [[ ---@param f fun(a: any, b: any):boolean local function f(f) end -f(fun$) +f(fun) ]] { { label = 'fun(a: any, b: any):boolean', kind = define.CompletionItemKind.Function, textEdit = { - newText = 'function (${1:a}, ${2:b})\n\t$0\nend', + newText = 'function ({1:a}, {2:b})\n\t0\nend', start = 68, finish = 70, } @@ -2489,7 +2489,7 @@ TEST [[ ---@type {[1]: number} local t -t.$ +t. ]] { { @@ -2514,7 +2514,7 @@ TEST [[ ---@type {[1]: number} local t -t.$ +t. ]] { { @@ -2543,7 +2543,7 @@ TEST [[ local function f(x) end -local r = f('$') +local r = f('') ]] { { @@ -2570,7 +2570,7 @@ TEST [[ ---@type fun(x: "'aaa'"|"'bbb'") local f -f('$') +f('') ]] { { @@ -2598,7 +2598,7 @@ TEST [[ ---@field on fun() local c -c:$ +c: ]] { { @@ -2612,7 +2612,7 @@ TEST [[ ---@field on fun(x: "'aaa'"|"'bbb'") local c -c:on($) +c:on() ]] (EXISTS) @@ -2621,7 +2621,7 @@ TEST [[ ---@field on fun(x: "'aaa'"|"'bbb'") local c -c:on('$') +c:on('') ]] (EXISTS) @@ -2632,7 +2632,7 @@ function m.f() end m.f() -m.$ +m. ]] { [1] = EXISTS, @@ -2647,7 +2647,7 @@ function class1:method1() end ---@class class2 : class1 class2 = {} -class2:$ +class2: ]] { diff --git a/test/completion/continue.lua b/test/completion/continue.lua index 4159ea7a..63f970e9 100644 --- a/test/completion/continue.lua +++ b/test/completion/continue.lua @@ -9,7 +9,7 @@ ContinueTyping = true TEST [[ local zabcde -za$ +za ]] { { @@ -20,7 +20,7 @@ za$ TEST [[ -- zabcde -io.z$ +io.z ]] { { @@ -32,7 +32,7 @@ io.z$ TEST [[ -- provider -pro$ +pro ]] { { @@ -45,7 +45,7 @@ TEST [[ ---@param n '"abcdefg"' local function f(n) end -f 'abc$' +f 'abc' ]] { { @@ -59,7 +59,7 @@ TEST [[ ---@type '"abcdefg"' local t -if t == 'abc$' +if t == 'abc' ]] { { diff --git a/test/completion/init.lua b/test/completion/init.lua index 24c8932f..051c288c 100644 --- a/test/completion/init.lua +++ b/test/completion/init.lua @@ -1,5 +1,6 @@ local core = require 'core.completion' local files = require 'files' +local catch = require 'catch' EXISTS = {'EXISTS'} @@ -64,17 +65,17 @@ ContinueTyping = false function TEST(script) return function (expect) files.removeAll() - local pos = script:find('$', 1, true) - 1 - local new_script = script:gsub('%$', '') + local newScript, catched = catch(script, '?') - files.setText('', new_script) + files.setText('', newScript) core.clearCache() + local inputPos = catched['?'][1][1] if ContinueTyping then - local triggerCharacter = script:sub(pos - 1, pos - 1) - core.completion('', pos - 1, triggerCharacter) + local triggerCharacter = script:sub(inputPos - 1, inputPos - 1) + core.completion('', inputPos, triggerCharacter) end - local triggerCharacter = script:sub(pos, pos) - local result = core.completion('', pos, triggerCharacter) + local triggerCharacter = script:sub(inputPos, inputPos) + local result = core.completion('', inputPos, triggerCharacter) if not expect then assert(result == nil) return -- cgit v1.2.3 From a7fcbe21fa6e06c46875fd8abb6d2eacb1db844e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sat, 18 Sep 2021 16:04:24 +0800 Subject: update --- test/completion/common.lua | 64 +++++++++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 32 deletions(-) (limited to 'test') diff --git a/test/completion/common.lua b/test/completion/common.lua index 66cc6fe4..ff36ee0a 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -443,7 +443,7 @@ collectgarbage('') label = "'collect'", kind = define.CompletionItemKind.EnumMember, textEdit = { - start = 16, + start = 15, finish = 17, newText = "'collect'", }, @@ -452,7 +452,7 @@ collectgarbage('') label = "'stop'", kind = define.CompletionItemKind.EnumMember, textEdit = { - start = 16, + start = 15, finish = 17, newText = "'stop'", }, @@ -461,7 +461,7 @@ collectgarbage('') label = "'restart'", kind = define.CompletionItemKind.EnumMember, textEdit = { - start = 16, + start = 15, finish = 17, newText = "'restart'", }, @@ -470,7 +470,7 @@ collectgarbage('') label = "'count'", kind = define.CompletionItemKind.EnumMember, textEdit = { - start = 16, + start = 15, finish = 17, newText = "'count'", }, @@ -479,7 +479,7 @@ collectgarbage('') label = "'step'", kind = define.CompletionItemKind.EnumMember, textEdit = { - start = 16, + start = 15, finish = 17, newText = "'step'", }, @@ -488,7 +488,7 @@ collectgarbage('') label = "'isrunning'", kind = define.CompletionItemKind.EnumMember, textEdit = { - start = 16, + start = 15, finish = 17, newText = "'isrunning'", }, @@ -497,7 +497,7 @@ collectgarbage('') label = "'incremental'", kind = define.CompletionItemKind.EnumMember, textEdit = { - start = 16, + start = 15, finish = 17, newText = "'incremental'", }, @@ -506,7 +506,7 @@ collectgarbage('') label = "'generational'", kind = define.CompletionItemKind.EnumMember, textEdit = { - start = 16, + start = 15, finish = 17, newText = "'generational'", }, @@ -554,7 +554,7 @@ self.results.list[#] label = '#self.results.list+1', kind = define.CompletionItemKind.Snippet, textEdit = { - start = 19, + start = 18, finish = 20, newText = '#self.results.list+1] = ', }, @@ -570,7 +570,7 @@ local n = 1 label = '#self.results.list+1', kind = define.CompletionItemKind.Snippet, textEdit = { - start = 19, + start = 18, finish = 20, newText = '#self.results.list+1] = ', }, @@ -585,7 +585,7 @@ self.results.list[#] = 1 label = '#self.results.list+1', kind = define.CompletionItemKind.Snippet, textEdit = { - start = 19, + start = 18, finish = 20, newText = '#self.results.list+1]', }, @@ -600,7 +600,7 @@ self.results.list[#self.re] label = '#self.results.list+1', kind = define.CompletionItemKind.Snippet, textEdit = { - start = 19, + start = 18, finish = 27, newText = '#self.results.list+1] = ', }, @@ -619,7 +619,7 @@ fff[#ff] label = '#fff+1', kind = define.CompletionItemKind.Snippet, textEdit = { - start = 5, + start = 4, finish = 8, newText = '#fff+1] = ', }, @@ -638,7 +638,7 @@ local _ = fff.kkk[#] label = '#fff.kkk', kind = define.CompletionItemKind.Snippet, textEdit = { - start = 19, + start = 18, finish = 20, newText = '#fff.kkk]', }, @@ -653,7 +653,7 @@ fff.kkk[#].yy label = '#fff.kkk', kind = define.CompletionItemKind.Snippet, textEdit = { - start = 9, + start = 8, finish = 10, newText = '#fff.kkk]', }, @@ -911,7 +911,7 @@ mt:f { label = 'f(a, b, c)', kind = define.CompletionItemKind.Snippet, - insertText = 'f({1:a: any}, {2:b: any}, {3:c: any})', + insertText = 'f(${1:a: any}, ${2:b: any}, ${3:c: any})', }, } @@ -927,8 +927,8 @@ function label = 'function ()', kind = define.CompletionItemKind.Snippet, insertText = "\z -function 1(2)\ -\t0\ +function $1($2)\ +\t$0\ end", }, } @@ -945,8 +945,8 @@ local t = function label = 'function ()', kind = define.CompletionItemKind.Snippet, insertText = "\z -function (1)\ -\t0\ +function ($1)\ +\t$0\ end", }, } @@ -986,14 +986,14 @@ t. label = 'a.b.c', kind = define.CompletionItemKind.Field, textEdit = { - start = 37, - finish = 36, + start = 40002, + finish = 40002, newText = '["a.b.c"]', }, additionalTextEdits = { { - start = 36, - finish = 36, + start = 40001, + finish = 40002, newText = '', }, }, @@ -1012,14 +1012,14 @@ t. label = 'a.b.c', kind = define.CompletionItemKind.Field, textEdit = { - start = 40, - finish = 39, + start = 40005, + finish = 40005, newText = '["a.b.c"]', }, additionalTextEdits = { { - start = 36, - finish = 36, + start = 40001, + finish = 40002, newText = '', }, }, @@ -1038,8 +1038,8 @@ t[''] label = 'a.b.c', kind = define.CompletionItemKind.Field, textEdit = { - start = 38, - finish = 37, + start = 40003, + finish = 40003, newText = 'a.b.c', } } @@ -1055,8 +1055,8 @@ z label = 'z.b.c', kind = define.CompletionItemKind.Field, textEdit = { - start = 21, - finish = 21, + start = 20001, + finish = 20001, newText = '_ENV["z.b.c"]', }, }, -- cgit v1.2.3 From b45a90132438bb2d84b7376066e5ff409833a13f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sat, 18 Sep 2021 17:28:21 +0800 Subject: update --- test/completion/common.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/completion/common.lua b/test/completion/common.lua index ff36ee0a..f800fa9d 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -1055,7 +1055,7 @@ z label = 'z.b.c', kind = define.CompletionItemKind.Field, textEdit = { - start = 20001, + start = 20000, finish = 20001, newText = '_ENV["z.b.c"]', }, -- cgit v1.2.3 From bae4fa96a08158668d8b005f7885a774ad1c98fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sat, 18 Sep 2021 17:51:43 +0800 Subject: update --- test/completion/common.lua | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) (limited to 'test') diff --git a/test/completion/common.lua b/test/completion/common.lua index f800fa9d..d0ca92da 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -1238,9 +1238,9 @@ end label = 'a, b, c', kind = define.CompletionItemKind.Snippet, insertText = [[ -a {1:any} ----@param b {2:any} ----@param c {3:any}]] +a ${1:any} +---@param b ${2:any} +---@param c ${3:any}]] }, { label = 'a', @@ -1267,9 +1267,9 @@ function f2(a) end label = 'a, b, c', kind = define.CompletionItemKind.Snippet, insertText = [[ -a {1:any} ----@param b {2:any} ----@param c {3:any}]] +a ${1:any} +---@param b ${2:any} +---@param c ${3:any}]] }, { label = 'a', @@ -1309,9 +1309,9 @@ end label = 'a, b, c', kind = define.CompletionItemKind.Snippet, insertText = [[ -a {1:any} ----@param b {2:any} ----@param c {3:any}]] +a ${1:any} +---@param b ${2:any} +---@param c ${3:any}]] }, { label = 'a', @@ -1337,9 +1337,9 @@ end label = 'a, b, c', kind = define.CompletionItemKind.Snippet, insertText = [[ -a {1:any} ----@param b {2:any} ----@param c {3:any}]], +a ${1:any} +---@param b ${2:any} +---@param c ${3:any}]], }, { label = 'self', @@ -1864,7 +1864,7 @@ f() label = 'fun(x: number, y: number):string', kind = define.CompletionItemKind.Function, insertText = "\z -function ({1:x}, {2:y})\ +function (${1:x}, ${2:y})\ \t0\ end", }, @@ -1881,13 +1881,13 @@ end label = '@param;@return', kind = define.CompletionItemKind.Snippet, insertText = "\z -{1:comment}\ ----@param a {2:number}\ ----@param b {3:string}\ ----@param c {4:table}\ ----@return {5:number}\ ----@return {6:string}\ ----@return {7:any}", +${1:comment}\ +---@param a ${2:number}\ +---@param b ${3:string}\ +---@param c ${4:table}\ +---@return ${5:number}\ +---@return ${6:string}\ +---@return ${7:any}", }, } @@ -2376,7 +2376,7 @@ zzzz { label = 'zzzz(a)', kind = define.CompletionItemKind.Snippet, - insertText = 'zzzz({1:a: any})', + insertText = 'zzzz(${1:a: any})', }, { label = 'zzzz(a, b)', @@ -2386,7 +2386,7 @@ zzzz { label = 'zzzz(a, b)', kind = define.CompletionItemKind.Snippet, - insertText = 'zzzz({1:a: any}, {2:b: any})', + insertText = 'zzzz(${1:a: any}, ${2:b: any})', }, } Cared['insertText'] = false @@ -2470,7 +2470,7 @@ f(fun) label = 'fun(a: any, b: any):boolean', kind = define.CompletionItemKind.Function, textEdit = { - newText = 'function ({1:a}, {2:b})\n\t0\nend', + newText = 'function (${1:a}, ${2:b})\n\t0\nend', start = 68, finish = 70, } -- cgit v1.2.3 From a847377582e5f22244aa587f9d79a07f9db03780 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 22 Sep 2021 11:30:39 +0800 Subject: update --- test/completion/common.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/completion/common.lua b/test/completion/common.lua index d0ca92da..2f37ef38 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -1865,7 +1865,7 @@ f() kind = define.CompletionItemKind.Function, insertText = "\z function (${1:x}, ${2:y})\ -\t0\ +\t$0\ end", }, } -- cgit v1.2.3 From 1ab04aca1e0a3ad9d76aa11fa4e8eefe9781624b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 22 Sep 2021 14:31:13 +0800 Subject: update --- test/completion/common.lua | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'test') diff --git a/test/completion/common.lua b/test/completion/common.lua index 2f37ef38..33cbdf4d 100644 --- a/test/completion/common.lua +++ b/test/completion/common.lua @@ -2354,8 +2354,8 @@ TEST [[ label = 'AAA.BBB', kind = define.CompletionItemKind.Class, textEdit = { - start = 29, - finish = 32, + start = 20009, + finish = 20013, newText = 'AAA.BBB', }, } @@ -2470,9 +2470,9 @@ f(fun) label = 'fun(a: any, b: any):boolean', kind = define.CompletionItemKind.Function, textEdit = { - newText = 'function (${1:a}, ${2:b})\n\t0\nend', - start = 68, - finish = 70, + newText = 'function (${1:a}, ${2:b})\n\t$0\nend', + start = 30002, + finish = 30005, } }, { @@ -2497,13 +2497,13 @@ t. kind = define.CompletionItemKind.Field, textEdit = { newText = '[1]', - start = 35, - finish = 34, + start = 30002, + finish = 30002, }, additionalTextEdits = { { - start = 34, - finish = 34, + start = 30001, + finish = 30002, newText = '', }, }, @@ -2522,13 +2522,13 @@ t. kind = define.CompletionItemKind.Field, textEdit = { newText = '[1]', - start = 35, - finish = 34, + start = 30002, + finish = 30002, }, additionalTextEdits = { { - start = 34, - finish = 34, + start = 30001, + finish = 30002, newText = '', }, }, @@ -2551,8 +2551,8 @@ local r = f('') kind = define.CompletionItemKind.EnumMember, textEdit = { newText = "'aaa'", - start = 103, - finish = 104, + start = 70012, + finish = 70014, }, }, { @@ -2560,8 +2560,8 @@ local r = f('') kind = define.CompletionItemKind.EnumMember, textEdit = { newText = "'bbb'", - start = 103, - finish = 104, + start = 70012, + finish = 70014, }, }, } @@ -2578,8 +2578,8 @@ f('') kind = define.CompletionItemKind.EnumMember, textEdit = { newText = "'aaa'", - start = 45, - finish = 46, + start = 30002, + finish = 30004, }, }, { @@ -2587,8 +2587,8 @@ f('') kind = define.CompletionItemKind.EnumMember, textEdit = { newText = "'bbb'", - start = 45, - finish = 46, + start = 30002, + finish = 30004, }, }, } -- cgit v1.2.3 From a11c1e47a1bbe1004333143431f901ab8ecde4dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 22 Sep 2021 15:23:04 +0800 Subject: cleanup --- test/crossfile/allreferences.lua | 5 +-- test/crossfile/definition.lua | 79 +++++++++++++--------------------------- test/crossfile/references.lua | 66 +++++++-------------------------- 3 files changed, 41 insertions(+), 109 deletions(-) (limited to 'test') diff --git a/test/crossfile/allreferences.lua b/test/crossfile/allreferences.lua index 056fa416..67eb893c 100644 --- a/test/crossfile/allreferences.lua +++ b/test/crossfile/allreferences.lua @@ -9,10 +9,9 @@ TEST { { path = 'lib.lua', content = [[ - return <~function~> () - end + return () + end!> ]], - target = {22, 50}, }, } diff --git a/test/crossfile/definition.lua b/test/crossfile/definition.lua index 66e9b269..01bf0202 100644 --- a/test/crossfile/definition.lua +++ b/test/crossfile/definition.lua @@ -3,26 +3,10 @@ local furi = require 'file-uri' local core = require 'core.definition' local config = require 'config' local platform = require 'bee.platform' +local catch = require 'catch' rawset(_G, 'TEST', true) -local function catch_target(script, sep) - local list = {} - local cur = 1 - local cut = 0 - while true do - local start, finish = script:find(('<%%%s.-%%%s>'):format(sep, sep), cur) - if not start then - break - end - list[#list+1] = { start - cut, finish - 4 - cut } - cur = finish + 1 - cut = cut + 4 - end - local new_script = script:gsub(('<%%%s(.-)%%%s>'):format(sep, sep), '%1') - return new_script, list -end - local function founded(targets, results) if #targets ~= #results then return false @@ -50,32 +34,26 @@ function TEST(datas) local sourceUri for i, data in ipairs(datas) do local uri = furi.encode(data.path) - local new, list = catch_target(data.content, '!') - if new ~= data.content or data.target then - if data.target then - targetList[#targetList+1] = { - data.target[1], - data.target[2], - uri, - } - else - for _, position in ipairs(list) do - targetList[#targetList+1] = { - position[1], - position[2], - uri, - } - end - end - data.content = new + local newScript, catched = catch(data.content, '!?~') + for _, position in ipairs(catched['!'] or {}) do + targetList[#targetList+1] = { + position[1], + position[2], + uri, + } + end + for _, position in ipairs(catched['~'] or {}) do + targetList[#targetList+1] = { + position[1], + position[2], + uri, + } end - new, list = catch_target(data.content, '?') - if new ~= data.content then - sourceList = list + if catched['?'] or catched['~'] then + sourceList = catched['?'] or catched['~'] sourceUri = uri - data.content = new end - files.setText(uri, data.content) + files.setText(uri, newScript) end local sourcePos = (sourceList[1][1] + sourceList[1][2]) // 2 @@ -98,8 +76,7 @@ end TEST { { path = 'a.lua', - content = '', - target = {0, 0}, + content = '', }, { path = 'b.lua', @@ -110,8 +87,7 @@ TEST { TEST { { path = 'aaa/bbb.lua', - content = '', - target = {0, 0}, + content = '', }, { path = 'b.lua', @@ -122,8 +98,7 @@ TEST { TEST { { path = '@bbb.lua', - content = '', - target = {0, 0}, + content = '', }, { path = 'b.lua', @@ -134,8 +109,7 @@ TEST { TEST { { path = 'aaa/bbb.lua', - content = '', - target = {0, 0}, + content = '', }, { path = 'b.lua', @@ -150,8 +124,7 @@ TEST { }, { path = 'b.lua', - content = 'local = require "a"', - target = {7, 7}, + content = 'local <~t~> = require "a"', }, } @@ -176,8 +149,7 @@ TEST { }, { path = 'b.lua', - content = 'local = require "a"', - target = {7, 7}, + content = 'local <~t~> = require "a"', }, } @@ -245,9 +217,8 @@ TEST { { path = 'b.lua', content = [[ - local = require 'a' + local <~t~> = require 'a' ]], - target = {19, 19}, }, } diff --git a/test/crossfile/references.lua b/test/crossfile/references.lua index 6c28b34b..145792b5 100644 --- a/test/crossfile/references.lua +++ b/test/crossfile/references.lua @@ -1,6 +1,7 @@ local files = require 'files' local furi = require 'file-uri' local core = require 'core.reference' +local catch = require 'catch' rawset(_G, 'TEST', true) @@ -32,21 +33,6 @@ local function eq(a, b) return a == b end -local function catch_target(script, sep) - local list = {} - local cur = 1 - while true do - local start, finish = script:find(('<%%%s.-%%%s>'):format(sep, sep), cur) - if not start then - break - end - list[#list+1] = { start + 2, finish - 2 } - cur = finish + 1 - end - local new_script = script:gsub(('<%%%s(.-)%%%s>'):format(sep, sep), ' %1 ') - return new_script, list -end - local function founded(targets, results) if #targets ~= #results then return false @@ -74,37 +60,9 @@ function TEST(datas) local sourceUri for i, data in ipairs(datas) do local uri = furi.encode(data.path) - local new, list = catch_target(data.content, '!') - if new ~= data.content or data.target then - if data.target then - targetList[#targetList+1] = { - data.target[1], - data.target[2], - uri, - } - else - for _, position in ipairs(list) do - targetList[#targetList+1] = { - position[1], - position[2], - uri, - } - end - end - data.content = new - end - new, list = catch_target(data.content, '~') - if new ~= data.content then - sourceList = list - sourceUri = uri - data.content = new - end - new, list = catch_target(data.content, '?') - if new ~= data.content then - sourceList = list - sourceUri = uri - data.content = new - for _, position in ipairs(list) do + local newScript, catched = catch(data.content, '!?~') + if catched['!'] or catched['~'] then + for _, position in ipairs(catched['!'] + catched['~']) do targetList[#targetList+1] = { position[1], position[2], @@ -112,7 +70,11 @@ function TEST(datas) } end end - files.setText(uri, data.content) + if catched['?'] or catched['~'] then + sourceList = catched['?'] + catched['~'] + sourceUri = uri + end + files.setText(uri, newScript) end local sourcePos = (sourceList[1][1] + sourceList[1][2]) // 2 @@ -143,7 +105,7 @@ TEST { { path = 'a.lua', content = [[ - local = require 'lib' + local <~f~> = require 'lib' ]], }, } @@ -158,7 +120,7 @@ TEST { { path = 'b.lua', content = [[ - print() + print(<~ROOT~>) ]], }, } @@ -167,7 +129,7 @@ TEST { { path = 'a.lua', content = [[ - = 1 + <~ROOT~> = 1 ]], }, { @@ -183,7 +145,7 @@ TEST { path = 'a.lua', content = [[ local f = require 'lib' - local = f() + local <~o~> = f() ]], }, { @@ -212,7 +174,7 @@ TEST { ---@class A local mt - function mt.() + function mt.<~f~>() end ]] } -- cgit v1.2.3 From b7f7789e46ab8c67d25704be696a1523762b1d80 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 22 Sep 2021 15:54:44 +0800 Subject: update --- test/crossfile/allreferences.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/crossfile/allreferences.lua b/test/crossfile/allreferences.lua index 67eb893c..bddc159d 100644 --- a/test/crossfile/allreferences.lua +++ b/test/crossfile/allreferences.lua @@ -20,7 +20,7 @@ TEST { path = 'a.lua', content = [[ local m = {} - function m.() + function m.<~func~>() end return m ]], @@ -38,7 +38,7 @@ TEST { { path = 'a.lua', content = [[ - return + return <~function () end~> ]], }, { @@ -71,7 +71,7 @@ TEST { { path = 'a.lua', content = [[ - local function () + local function <~f~>() end return { @@ -125,7 +125,7 @@ TEST { local t = require 'a' local = t. - () + <~f~>() return { = , @@ -138,7 +138,7 @@ TEST { { path = 'a.lua', content = [[ - local function () + local function <~f~>() end return { @@ -201,7 +201,7 @@ TEST { { path = 'a.lua', content = [[ - local = require 'b' + local <~t~> = require 'b' return ]] }, -- cgit v1.2.3 From b66a9c9340d63e1a22ba7d5ccad8d9df244240d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 22 Sep 2021 16:37:54 +0800 Subject: update --- test/crossfile/hover.lua | 22 +++------------------- 1 file changed, 3 insertions(+), 19 deletions(-) (limited to 'test') diff --git a/test/crossfile/hover.lua b/test/crossfile/hover.lua index a877d226..1c46214c 100644 --- a/test/crossfile/hover.lua +++ b/test/crossfile/hover.lua @@ -2,6 +2,7 @@ local files = require 'files' local furi = require 'file-uri' local core = require 'core.hover' local config = require 'config' +local catch = require 'catch' rawset(_G, 'TEST', true) @@ -36,36 +37,19 @@ local function eq(a, b) return a == b end -local function catch_target(script, sep) - local list = {} - local cur = 1 - local cut = 0 - while true do - local start, finish = script:find(('<%%%s.-%%%s>'):format(sep, sep), cur) - if not start then - break - end - list[#list+1] = { start - cut, finish - 4 - cut } - cur = finish + 1 - cut = cut + 4 - end - local new_script = script:gsub(('<%%%s(.-)%%%s>'):format(sep, sep), '%1') - return new_script, list -end - function TEST(expect) files.removeAll() local targetScript = expect[1].content local targetUri = furi.encode(expect[1].path) - local sourceScript, sourceList = catch_target(expect[2].content, '?') + local sourceScript, sourceList = catch(expect[2].content, '?') local sourceUri = furi.encode(expect[2].path) files.setText(targetUri, targetScript) files.setText(sourceUri, sourceScript) - local sourcePos = (sourceList[1][1] + sourceList[1][2]) // 2 + local sourcePos = (sourceList['?'][1][1] + sourceList['?'][1][2]) // 2 local hover = core.byUri(sourceUri, sourcePos) assert(hover) hover = tostring(hover):gsub('\r\n', '\n') -- cgit v1.2.3 From a45e980f0d51c47229d18d0f859e718d203b472f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 22 Sep 2021 16:54:15 +0800 Subject: update --- test/crossfile/completion.lua | 58 ++++++++++++++++++++++--------------------- test/crossfile/diagnostic.lua | 27 ++++---------------- 2 files changed, 35 insertions(+), 50 deletions(-) (limited to 'test') diff --git a/test/crossfile/completion.lua b/test/crossfile/completion.lua index d26398ca..9c5ed96e 100644 --- a/test/crossfile/completion.lua +++ b/test/crossfile/completion.lua @@ -4,6 +4,7 @@ local furi = require 'file-uri' local platform = require 'bee.platform' local util = require 'utility' local config = require 'config' +local catch = require 'catch' rawset(_G, 'TEST', true) @@ -88,8 +89,9 @@ function TEST(data) local uri = furi.encode(info.path) local script = info.content if info.main then - pos = script:find('$', 1, true) - 1 - script = script:gsub('%$', '') + local newScript, catched = catch(script, '?') + pos = catched['?'][1][1] + script = newScript mainUri = uri end files.setText(uri, script) @@ -139,7 +141,7 @@ TEST { }, { path = 'test.lua', - content = 'require "a$"', + content = 'require "a"', main = true, }, completion = { @@ -178,7 +180,7 @@ TEST { }, { path = 'test.lua', - content = 'require "A$"', + content = 'require "A"', main = true, }, completion = { @@ -201,7 +203,7 @@ TEST { }, { path = 'test.lua', - content = 'require "a$"', + content = 'require "a"', main = true, }, completion = { @@ -229,7 +231,7 @@ TEST { }, { path = 'test.lua', - content = 'require "abc$"', + content = 'require "abc"', main = true, }, completion = { @@ -257,7 +259,7 @@ TEST { }, { path = 'test.lua', - content = 'require "abc$"', + content = 'require "abc"', main = true, }, completion = { @@ -290,7 +292,7 @@ TEST { }, { path = 'test.lua', - content = 'require "abc.i$"', + content = 'require "abc.i"', main = true, }, completion = { @@ -315,7 +317,7 @@ TEST { }, { path = 'test.lua', - content = 'require "abc/i$"', + content = 'require "abc/i"', main = true, }, completion = { @@ -339,7 +341,7 @@ TEST { }, { path = 'test.lua', - content = 'require "core.co$"', + content = 'require "core.co"', main = true, }, completion = { @@ -362,7 +364,7 @@ TEST { }, { path = 'abc/test.lua', - content = 'require "x$"', + content = 'require "x"', main = true, }, completion = { @@ -397,7 +399,7 @@ TEST { }, { path = 'main.lua', - content = 'require "x$"', + content = 'require "x"', main = true, }, completion = { @@ -428,7 +430,7 @@ TEST { }, { path = 'main.lua', - content = 'require "x$"', + content = 'require "x"', main = true, }, completion = { @@ -457,7 +459,7 @@ TEST { path = 'b.lua', content = [[ local t = require 'a' - t.$ + t. ]], main = true, }, @@ -499,7 +501,7 @@ TEST { { path = 'b.lua', content = [[ - zab$ + zab ]], main = true, }, @@ -533,7 +535,7 @@ TEST { { path = 'b.lua', content = [[ - zab$ + zab ]], main = true, }, @@ -557,7 +559,7 @@ TEST { path = 'a.lua', content = [[ local japi = require 'jass.japi' - japi.xxxaaaax$ + japi.xxxaaaax ]], main = true, }, @@ -571,7 +573,7 @@ TEST { { path = 'xxxx.lua', content = [[ - require 'xx$' + require 'xx' ]], main = true, }, @@ -592,7 +594,7 @@ TEST { { path = 'main.lua', content = [[ - require 'xx$' + require 'xx' ]], main = true, }, @@ -613,7 +615,7 @@ TEST { { path = 'main.lua', content = [[ - require [=[xx$]=]' + require [=[xx]=]' ]], main = true, }, @@ -635,7 +637,7 @@ TEST { { path = 'main.lua', content = [[ - dofile 'ab$' + dofile 'ab' ]], main = true, }, @@ -656,7 +658,7 @@ TEST { { path = 'main.lua', content = [[ - dofile 'ab$' + dofile 'ab' ]], main = true, }, @@ -686,7 +688,7 @@ TEST { content = [[ local t = require 'a' local v = setmetatable({}, {__index = t}) - v.$ + v. ]] }, completion = { @@ -712,7 +714,7 @@ TEST { content = [[ local z = require 'a' - z$ + z ]], main = true, }, @@ -743,7 +745,7 @@ TEST { path = 'main.lua', main = true, content = [[ - myfun$ + myfun ]], }, completion = { @@ -774,7 +776,7 @@ TEST { path = 'main.lua', main = true, content = [[ - myfun$ + myfun ]], }, completion = { @@ -807,7 +809,7 @@ TEST { path = 'main.lua', main = true, content = [[ - A.$ + A. ]], }, completion = EXISTS, @@ -819,7 +821,7 @@ TEST { path = 'main.lua', main = true, content = [[ - require'$ + require' ]] }, completion = EXISTS diff --git a/test/crossfile/diagnostic.lua b/test/crossfile/diagnostic.lua index a430cb4e..adc2961f 100644 --- a/test/crossfile/diagnostic.lua +++ b/test/crossfile/diagnostic.lua @@ -3,28 +3,12 @@ local furi = require 'file-uri' local core = require 'core.diagnostics' local config = require 'config' local platform = require 'bee.platform' +local catch = require 'catch' config.get 'Lua.diagnostics.neededFileStatus'['deprecated'] = 'Any' rawset(_G, 'TEST', true) -local function catch_target(script, sep) - local list = {} - local cur = 1 - local cut = 0 - while true do - local start, finish = script:find(('<%%%s.-%%%s>'):format(sep, sep), cur) - if not start then - break - end - list[#list+1] = { start - cut, finish - 4 - cut } - cur = finish + 1 - cut = cut + 4 - end - local new_script = script:gsub(('<%%%s(.-)%%%s>'):format(sep, sep), '%1') - return new_script, list -end - local function founded(targets, results) if #targets ~= #results then return false @@ -48,19 +32,18 @@ function TEST(datas) files.removeAll() local targetList = {} - local sourceUri for _, data in ipairs(datas) do local uri = furi.encode(data.path) - local new, list = catch_target(data.content, '!') - for _, position in ipairs(list) do + local newScript, catched = catch(data.content, '!') + for _, position in ipairs(catched['!'] or {}) do targetList[#targetList+1] = { position[1], position[2], uri, } end - data.content = new - files.setText(uri, new) + data.content = newScript + files.setText(uri, newScript) end local result = {} -- cgit v1.2.3 From 32aa2dac835a0c74b82b19d83d9fd06be7a947ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 22 Sep 2021 17:24:44 +0800 Subject: cleanup --- test/diagnostics/init.lua | 63 ++++++++++++----------------------------------- 1 file changed, 16 insertions(+), 47 deletions(-) (limited to 'test') diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua index 54ac73ef..840be836 100644 --- a/test/diagnostics/init.lua +++ b/test/diagnostics/init.lua @@ -2,36 +2,12 @@ local core = require 'core.diagnostics' local files = require 'files' local config = require 'config' local util = require 'utility' +local catch = require 'catch' config.get 'Lua.diagnostics.neededFileStatus'['deprecated'] = 'Any' rawset(_G, 'TEST', true) -local function catch_target(script, ...) - local list = {} - local function catch(buf) - local cur = 1 - local cut = 0 - while true do - local start, finish = buf:find('', cur) - if not start then - break - end - list[#list+1] = { start - cut, finish - 4 - cut } - cur = finish + 1 - cut = cut + 4 - end - end - catch(script) - if ... then - for _, buf in ipairs {...} do - catch(buf) - end - end - local new_script = script:gsub('', '%1') - return new_script, list -end - local function founded(targets, results) if #targets ~= #results then return false @@ -50,8 +26,8 @@ end function TEST(script, ...) files.removeAll() - local new_script, target = catch_target(script, ...) - files.setText('', new_script) + local newScript, catched = catch(script, '!') + files.setText('', newScript) files.open('') local datas = {} core('', function (results) @@ -65,11 +41,11 @@ function TEST(script, ...) end if results[1] then - if not founded(target, results) then - error(('%s\n%s'):format(util.dump(target), util.dump(results))) + if not founded(catched['!'], results) then + error(('%s\n%s'):format(util.dump(catched['!']), util.dump(results))) end else - assert(#target == 0) + assert(catched['!'] == nil) end end @@ -99,15 +75,11 @@ local = {} .a = 1 ]] -TEST([[ -local () end!> -]], -[[ -local function () -end ]] -) + TEST [[ local = @@ -118,21 +90,13 @@ local = ]] -TEST([[ +TEST [[ local -local () x() end!> -]], -[[ -local function x() -end -local function () - x() -end ]] -) TEST [[ local print, _G @@ -154,6 +118,11 @@ TEST [[ ]] +TEST [[ + + +]] + TEST [[ X = 1 ]] -- cgit v1.2.3 From c951f3472628bdccdbf13a6bd95bc36cc93523fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 22 Sep 2021 17:41:25 +0800 Subject: update --- test/diagnostics/init.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test') diff --git a/test/diagnostics/init.lua b/test/diagnostics/init.lua index 840be836..5f69bdc9 100644 --- a/test/diagnostics/init.lua +++ b/test/diagnostics/init.lua @@ -41,7 +41,7 @@ function TEST(script, ...) end if results[1] then - if not founded(catched['!'], results) then + if not founded(catched['!'] or {}, results) then error(('%s\n%s'):format(util.dump(catched['!']), util.dump(results))) end else -- cgit v1.2.3 From eda1918a82894137c58e19a7fdb1301e3c2bbf30 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 22 Sep 2021 20:03:07 +0800 Subject: update --- test/highlight/init.lua | 38 ++++++++++---------------------------- 1 file changed, 10 insertions(+), 28 deletions(-) (limited to 'test') diff --git a/test/highlight/init.lua b/test/highlight/init.lua index 2bf639fa..7faa9e08 100644 --- a/test/highlight/init.lua +++ b/test/highlight/init.lua @@ -1,22 +1,6 @@ local core = require 'core.highlight' local files = require 'files' - -local function catch_target(script) - local list = {} - local cur = 1 - while true do - local start, finish = script:find('<[!?].-[!?]>', cur) - if not start then - break - end - list[#list+1] = { - start = start + 2, - finish = finish - 2, - } - cur = finish + 1 - end - return list -end +local catch = require 'catch' local function founded(targets, results) if #targets ~= #results then @@ -35,20 +19,18 @@ local function founded(targets, results) end function TEST(script) - local target = catch_target(script) - for _, enter in ipairs(target) do - local start, finish = enter.start, enter.finish - files.removeAll() + files.removeAll() + local newScript, catched = catch(script, '!') + files.setText('', newScript) + for _, enter in ipairs(catched['!']) do + local start, finish = enter[1], enter[2] local pos = (start + finish) // 2 - local new_script = script:gsub('<[!?~]', ' '):gsub('[!?~]>', ' ') - files.setText('', new_script) - local positions = core('', pos) - if positions then - assert(founded(target, positions)) - else - assert(#target == 0) + local results = {} + for _, position in ipairs(positions) do + results[#results+1] = { position.start, position.finish } end + assert(founded(catched['!'], results)) end end -- cgit v1.2.3 From 087a93d3df198aef7f0b7fb5a5af34b09fa630a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 22 Sep 2021 20:51:51 +0800 Subject: update --- test/rename/init.lua | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/rename/init.lua b/test/rename/init.lua index 4b10756e..b20c0279 100644 --- a/test/rename/init.lua +++ b/test/rename/init.lua @@ -1,16 +1,21 @@ local core = require 'core.rename' local files = require 'files' +local catch = require 'catch' +local guide = require 'parser.guide' local function replace(text, positions) + local state = files.getState('') local buf = {} table.sort(positions, function (a, b) return a.start < b.start end) local lastPos = 1 for _, info in ipairs(positions) do - buf[#buf+1] = text:sub(lastPos, info.start - 1) + local start = guide.positionToOffset(state, info.start) + local finish = guide.positionToOffset(state, info.finish) + buf[#buf+1] = text:sub(lastPos, start) buf[#buf+1] = info.text - lastPos = info.finish + 1 + lastPos = finish + 1 end buf[#buf+1] = text:sub(lastPos) return table.concat(buf) @@ -21,10 +26,12 @@ function TEST(oldName, newName) return function (expectScript) files.removeAll() files.setText('', oldScript) - local pos = oldScript:find('[^%w_]'..oldName..'[^%w_]') - assert(pos) + local state = files.getState('') + local offset = oldScript:find('[^%w_]'..oldName..'[^%w_]') + assert(offset) + local position = guide.offsetToPosition(state, offset) - local positions = core.rename('', pos+1, newName) + local positions = core.rename('', position, newName) local script = oldScript if positions then script = replace(script, positions) -- cgit v1.2.3 From c608e84003aed61a16484296edad3fe4ff363322 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 22 Sep 2021 21:50:50 +0800 Subject: update --- test/signature/init.lua | 193 ++++++++++++++---------------------------------- 1 file changed, 55 insertions(+), 138 deletions(-) (limited to 'test') diff --git a/test/signature/init.lua b/test/signature/init.lua index 27051310..43bce29e 100644 --- a/test/signature/init.lua +++ b/test/signature/init.lua @@ -1,26 +1,25 @@ -local core = require 'core.signature' +local core = require 'core.signature' local files = require 'files' +local catch = require 'catch' rawset(_G, 'TEST', true) function TEST(script) return function (expect) - local pos = script:find('$', 1, true) - 1 - local new_script = script:gsub('%$', '') + local newScript, catched1 = catch(script, '?') + local newExpect, catched2 = catch(expect or '', '!') files.removeAll() - files.setText('', new_script) - local hovers = core('', pos) + files.setText('', newScript) + local hovers = core('', catched1['?'][1][1]) if hovers then assert(expect) local hover = hovers[#hovers] - local label = hover.label:gsub('^[\r\n]*(.-)[\r\n]*$', '%1'):gsub('\r\n', '\n') - expect.label = expect.label:gsub('^[\r\n]*(.-)[\r\n]*$', '%1'):gsub('\r\n', '\n') local arg = hover.params[hover.index].label - assert(expect.label == label) - assert(expect.arg[1] == arg[1]) - assert(expect.arg[2] == arg[2]) + assert(newExpect == hover.label) + assert(catched2['!'][1][1] == arg[1]) + assert(catched2['!'][1][2] == arg[2]) else assert(expect == nil) end @@ -31,93 +30,67 @@ TEST [[ local function x(a, b) end -x($ +x( ]] -{ - label = "function x(a: any, b: any)", - arg = {12, 17}, -} +'function x(, b: any)' TEST [[ local function x(a, b) end -x($) +x() ]] -{ - label = "function x(a: any, b: any)", - arg = {12, 17}, -} +'function x(, b: any)' TEST [[ local function x(a, b) end -x(xxx$) +x(xxx) ]] -{ - label = "function x(a: any, b: any)", - arg = {12, 17}, -} +'function x(, b: any)' TEST [[ local function x(a, b) end -x(xxx, $) +x(xxx, ) ]] -{ - label = "function x(a: any, b: any)", - arg = {20, 25}, -} +'function x(a: any, )' TEST [[ function mt:f(a) end -mt:f($ +mt:f( ]] -{ - label = 'function mt:f(a: any)', - arg = {15, 20}, -} +'function mt:f()' TEST [[ local function x(a, b) return 1 end -x($ +x( ]] -{ - label = "function x(a: any, b: any)", - arg = {12, 17}, -} +'function x(, b: any)' TEST [[ local function x(a, ...) return 1 end -x(1, 2, 3, $ +x(1, 2, 3, ]] -{ - label = "function x(a: any, ...)", - arg = {20, 22}, -} +'function x(a: any, )' TEST [[ -(''):sub($ +(''):sub( ]] -{ - label = [[ -function string:sub(i: integer, j?: integer) -]], - arg = {21, 30}, -} +'function string:sub(, j?: integer)' TEST [[ -(''):sub(1)$ +(''):sub(1) ]] (nil) @@ -125,39 +98,29 @@ TEST [[ local function f(a, b, c) end -f(1, 'string$') +f(1, 'string') ]] -{ - label = [[ -function f(a: any, b: any, c: any) -]], - arg = {20, 25}, -} +'function f(a: any, , c: any)' TEST [[ -pcall(function () $ end) +pcall(function () end) ]] (nil) TEST [[ -table.unpack {$} +table.unpack {} ]] (nil) TEST [[ ---@type fun(x: number, y: number):boolean local zzzz -zzzz($) +zzzz() ]] -{ - label = [[ -function zzzz(x: number, y: number) -]], - arg = {15, 23}, -} +'function zzzz(, y: number)' TEST [[ -('abc'):format(f($)) +('abc'):format(f()) ]] (nil) @@ -166,14 +129,9 @@ function Foo(param01, param02) end -Foo($) +Foo() ]] -{ - label = [[ -function Foo(param01: any, param02: any) -]], - arg = {14, 25}, -} +'function Foo(, param02: any)' TEST [[ function f1(a, b) @@ -182,51 +140,31 @@ end function f2(c, d) end -f2(f1(),$) +f2(f1(),) ]] -{ - label = [[ -function f2(c: any, d: any) -]], - arg = {21, 26}, -} +'function f2(c: any, )' TEST [[ local function f(a, b, c) end -f({},$) +f({},) ]] -{ - label = [[ -function f(a: any, b: any, c: any) -]], - arg = {20, 25}, -} +'function f(a: any, , c: any)' TEST [[ -for _ in pairs($) do +for _ in pairs() do end ]] -{ - label = [[ -function pairs(t: ) -]], - arg = {16, 21}, -} +'function pairs(!>)' TEST [[ function m:f() end -m.f($) +m.f() ]] -{ - label = [[ -function m.f(self: table) -]], - arg = {14, 24}, -} +'function m.f()' TEST [[ ---@alias nnn table @@ -234,59 +172,41 @@ TEST [[ ---@param x nnn local function f(x, y, z) end -f($) +f() ]] -{ - label = [[ -function f(x: table, y: any, z: any) -]], - arg = {12, 35}, -} - +'function f(!>, y: any, z: any)' TEST [[ local function x(a, b) end -x( aaaa $, 2) +x( aaaa , 2) ]] -{ - label = "function x(a: any, b: any)", - arg = {12, 17}, -} +"function x(, b: any)" TEST [[ local function x(a, b) end -x($ aaaa , 2) +x( aaaa , 2) ]] -{ - label = "function x(a: any, b: any)", - arg = {12, 17}, -} +'function x(, b: any)' TEST [[ local function x(a, b) end -x(aaaa ,$ 2) +x(aaaa , 2) ]] -{ - label = "function x(a: any, b: any)", - arg = {20, 25}, -} +'function x(a: any, )' TEST [[ local function x(a, b) end -x(aaaa , 2 $) +x(aaaa , 2 ) ]] -{ - label = "function x(a: any, b: any)", - arg = {20, 25}, -} +'function x(a: any, )' TEST [[ local fooC @@ -298,9 +218,6 @@ function fooC(callback, par) end fooC(function (x, s) -end,$) +end,) ]] -{ - label = 'function fooC(callback: fun(x: number, s: string):nil, par: number)', - arg = {56, 66}, -} +'function fooC(callback: fun(x: number, s: string):nil, )' -- cgit v1.2.3 From 687313e295f299c1e0e410d4d72d96b1f87b681c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 22 Sep 2021 22:07:48 +0800 Subject: update --- test/command/auto-require.lua | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'test') diff --git a/test/command/auto-require.lua b/test/command/auto-require.lua index 94bb5069..a52662fb 100644 --- a/test/command/auto-require.lua +++ b/test/command/auto-require.lua @@ -3,7 +3,7 @@ local files = require 'files' local autoRequire = require 'core.command.autoRequire' local client = require 'client' -local findInsertOffset = util.getUpvalue(autoRequire, 'findInsertOffset') +local findInsertRow = util.getUpvalue(autoRequire, 'findInsertRow') local applyAutoRequire = util.getUpvalue(autoRequire, 'applyAutoRequire') local originEditText = client.editText @@ -19,18 +19,25 @@ function TEST(text) files.removeAll() files.setText('', text) EditResult = nil - local offset, fmt = findInsertOffset('') - applyAutoRequire('', offset, name, name, fmt) + local row, fmt = findInsertRow('') + applyAutoRequire('', row, name, name, fmt) assert(util.equal(EditResult, expect)) end end end --- TODO change to position TEST '' 'test' { start = 0, - finish = -1, - text = '\nlocal test = require "test"\n' + finish = 0, + text = 'local test = require "test"\n' +} + +TEST [[ +local aaaaaa = require 'aaa' +]] 'test' { + start = 10000, + finish = 10000, + text = 'local test = require \'test\'\n' } client.editText = originEditText -- cgit v1.2.3 From b6f99a71289f37e3c473a43d0a5290866a0822eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 22 Sep 2021 23:26:28 +0800 Subject: update --- test/document_symbol/init.lua | 286 +++++++++++++++++++++--------------------- 1 file changed, 143 insertions(+), 143 deletions(-) (limited to 'test') diff --git a/test/document_symbol/init.lua b/test/document_symbol/init.lua index d745d53f..d3168197 100644 --- a/test/document_symbol/init.lua +++ b/test/document_symbol/init.lua @@ -63,8 +63,8 @@ A = 1 name = 'A', detail = 'global number = 1', kind = define.SymbolKind.Class, - range = {1, 5}, - selectionRange = {1, 1}, + range = {0, 5}, + selectionRange = {0, 1}, } } @@ -77,9 +77,9 @@ end name = 'f', detail = 'function ()', kind = define.SymbolKind.Function, - range = {7, 22}, - selectionRange = {16, 16}, - valueRange = {7, 22}, + range = {6, 10003}, + selectionRange = {15, 16}, + valueRange = {6, 10003}, } } @@ -92,9 +92,9 @@ end name = 'f', detail = 'function ()', kind = define.SymbolKind.Function, - range = {1, 16}, - selectionRange = {10, 10}, - valueRange = {1, 16}, + range = {0, 10003}, + selectionRange = {9, 10}, + valueRange = {0, 10003}, } } @@ -107,9 +107,9 @@ end name = '', detail = 'return function ()', kind = define.SymbolKind.Function, - range = {8, 22}, - selectionRange = {8, 8}, - valueRange = {8, 22}, + range = {7, 10003}, + selectionRange = {7, 15}, + valueRange = {7, 10003}, } } @@ -122,9 +122,9 @@ end name = 'f', detail = 'function ()', kind = define.SymbolKind.Function, - range = {1, 19}, - selectionRange = {1, 1}, - valueRange = {5, 19}, + range = {0, 10003}, + selectionRange = {0, 1}, + valueRange = {4, 10003}, } } @@ -137,9 +137,9 @@ end name = 'f', detail = 'function ()', kind = define.SymbolKind.Function, - range = {7, 25}, - selectionRange = {7, 7}, - valueRange = {11, 25}, + range = {6, 10003}, + selectionRange = {6, 7}, + valueRange = {10, 10003}, } } @@ -152,9 +152,9 @@ end name = 'mt:add', detail = 'function ()', kind = define.SymbolKind.Method, - range = {1, 21}, - selectionRange = {10, 15}, - valueRange = {1, 21}, + range = {0, 10003}, + selectionRange = {9, 15}, + valueRange = {0, 10003}, } } @@ -173,25 +173,25 @@ end name = 'A', detail = 'function ()', kind = define.SymbolKind.Function, - range = {1, 68}, - selectionRange = {10, 10}, - valueRange = {1, 68}, + range = {0, 50003}, + selectionRange = {9, 10}, + valueRange = {0, 50003}, children = { [1] = { name = 'A1', detail = 'function ()', kind = define.SymbolKind.Function, - range = {18, 38}, - selectionRange = {27, 28}, - valueRange = {18, 38}, + range = {10004, 20007}, + selectionRange = {10013, 10015}, + valueRange = {10004, 20007}, }, [2] = { name = 'A2', detail = 'function ()', kind = define.SymbolKind.Function, - range = {44, 64}, - selectionRange = {53, 54}, - valueRange = {44, 64}, + range = {30004, 40007}, + selectionRange = {30013, 30015}, + valueRange = {30004, 40007}, }, }, }, @@ -199,9 +199,9 @@ end name = 'B', detail = 'function ()', kind = define.SymbolKind.Function, - range = {70, 85}, - selectionRange = {79, 79}, - valueRange = {70, 85}, + range = {60000, 70003}, + selectionRange = {60009, 60010}, + valueRange = {60000, 70003}, }, } @@ -220,31 +220,31 @@ local z name = 'x', detail = 'local number = 1', kind = define.SymbolKind.Variable, - range = {7, 11}, - selectionRange = {7, 7}, + range = {6, 11}, + selectionRange = {6, 7}, }, [2] = { name = 'f', detail = 'function ()', kind = define.SymbolKind.Function, - range = {19, 79}, - selectionRange = {28, 28}, - valueRange = {19, 79}, + range = {10006, 50003}, + selectionRange = {10015, 10016}, + valueRange = {10006, 50003}, children = { [1] = { name = 'x', detail = 'local string = "x"', kind = define.SymbolKind.Variable, - range = {42, 48}, - selectionRange = {42, 42}, + range = {20010, 20017}, + selectionRange = {20010, 20011}, }, [2] = { name = 'y', detail = 'local {}', kind = define.SymbolKind.Variable, - range = {60, 65}, - selectionRange = {60, 60}, - valueRange = {64, 65}, + range = {30010, 30016}, + selectionRange = {30010, 30011}, + valueRange = {30014, 30016}, }, --[3] = { -- name = 'z', @@ -260,15 +260,15 @@ local z name = 'y', detail = 'local boolean = true', kind = define.SymbolKind.Variable, - range = {87, 94}, - selectionRange = {87, 87}, + range = {60006, 60014}, + selectionRange = {60006, 60007}, }, [4] = { name = 'z', detail = 'local', kind = define.SymbolKind.Variable, - range = {102, 102}, - selectionRange = {102, 102}, + range = {70006, 70007}, + selectionRange = {70006, 70007}, }, } @@ -284,30 +284,30 @@ local t = { name = 't', detail = 'local {a, b, c}', kind = define.SymbolKind.Variable, - range = {7, 46}, - selectionRange = {7, 7}, - valueRange = {11, 46}, + range = {6, 40001}, + selectionRange = {6, 7}, + valueRange = {10, 40001}, children = { [1] = { name = 'a', detail = 'field number = 1', kind = define.SymbolKind.Property, - range = {17, 21}, - selectionRange = {17, 17}, + range = {10004, 10009}, + selectionRange = {10004, 10005}, }, [2] = { name = 'b', detail = 'field number = 2', kind = define.SymbolKind.Property, - range = {28, 32}, - selectionRange = {28, 28}, + range = {20004, 20009}, + selectionRange = {20004, 20005}, }, [3] = { name = 'c', detail = 'field number = 3', kind = define.SymbolKind.Property, - range = {39, 43}, - selectionRange = {39, 39}, + range = {30004, 30009}, + selectionRange = {30004, 30005}, }, } } @@ -325,24 +325,24 @@ local t = { name = 't', detail = 'local {a}', kind = define.SymbolKind.Variable, - range = {7, 44}, - selectionRange = {7, 7}, - valueRange = {11, 44}, + range = {6, 40001}, + selectionRange = {6, 7}, + valueRange = {10, 40001}, children = { [1] = { name = 'a', detail = 'field {b}', kind = define.SymbolKind.Property, - range = {17, 42}, - selectionRange = {17, 17}, - valueRange = {21, 42}, + range = {10004, 30005}, + selectionRange = {10004, 10005}, + valueRange = {10008, 30005}, children = { [1] = { name = 'b', detail = EXISTS, kind = define.SymbolKind.Property, - range = {31, 35}, - selectionRange = {31, 31}, + range = {20008, 20013}, + selectionRange = {20008, 20009}, } } }, @@ -360,16 +360,16 @@ g = 1 name = 'g', detail = 'function ()', kind = define.SymbolKind.Function, - range = {7, 22}, - selectionRange = {16, 16}, - valueRange = {7, 22}, + range = {6, 10003}, + selectionRange = {15, 16}, + valueRange = {6, 10003}, }, [2] = { name = 'g', detail = 'setlocal number = 1', kind = define.SymbolKind.Variable, - range = {25, 29}, - selectionRange = {25, 25}, + range = {30000, 30005}, + selectionRange = {30000, 30001}, } } @@ -383,30 +383,30 @@ end name = 'f', detail = 'function (a, b, ...)', kind = define.SymbolKind.Function, - range = {1, 58}, - selectionRange = {10, 10}, - valueRange = {1, 58}, + range = {0, 30003}, + selectionRange = {9, 10}, + valueRange = {0, 30003}, children = { [1] = { name = 'a', detail = 'param', kind = define.SymbolKind.Constant, - range = {12, 12}, - selectionRange = {12, 12}, + range = {11, 12}, + selectionRange = {11, 12}, }, [2] = { name = 'b', detail = 'param', kind = define.SymbolKind.Constant, - range = {15, 15}, - selectionRange = {15, 15}, + range = {14, 15}, + selectionRange = {14, 15}, }, [3] = { name = 'x', detail = 'local', kind = define.SymbolKind.Variable, - range = {33, 39}, - selectionRange = {33, 33}, + range = {10010, 10017}, + selectionRange = {10010, 10011}, } } }, @@ -424,17 +424,17 @@ local v = t name = 't', detail = 'local {a, b}', kind = define.SymbolKind.Variable, - range = {7, 35}, - selectionRange = {7, 7}, - valueRange = {11, 35}, + range = {6, 30001}, + selectionRange = {6, 7}, + valueRange = {10, 30001}, children = EXISTS, }, [2] = { name = 'v', detail = 'local', kind = define.SymbolKind.Variable, - range = {44, 48}, - selectionRange = {44, 44}, + range = {50006, 50011}, + selectionRange = {50006, 50007}, }, } @@ -446,47 +446,47 @@ local function name = 'x', detail = 'local', kind = define.SymbolKind.Variable, - range = {7, 7}, - selectionRange = {7, 7}, + range = {6, 7}, + selectionRange = {6, 7}, }, [2] = { name = "", detail = "function ()", kind = 12, - range = {15, 22}, - selectionRange = {15, 15}, - valueRange = {15, 22}, + range = {10006, 10014}, + selectionRange = {10006, 10014}, + valueRange = {10006, 10014}, }, } TEST [[ local a, b = { - x = 1, - y = 1, - z = 1, + x1 = 1, + y1 = 1, + z1 = 1, }, { - x = 1, - y = 1, - z = 1, + x2 = 1, + y2= 1, + z2 = 1, } ]]{ [1] = { name = 'a', - detail = 'local {x, y, z}', + detail = 'local {x1, y1, z1}', kind = define.SymbolKind.Variable, - range = {7, 49}, - selectionRange = {7, 7}, - valueRange = {14, 49}, + range = {6, 40001}, + selectionRange = {6, 7}, + valueRange = {13, 40001}, children = EXISTS, }, [2] = { name = 'b', - detail = 'local {x, y, z}', + detail = 'local {x2, y2, z2}', kind = define.SymbolKind.Variable, - range = {10, 87}, - selectionRange = {10, 10}, - valueRange = {52, 87}, + range = {9, 80001}, + selectionRange = {9, 10}, + valueRange = {40003, 80001}, children = EXISTS, } } @@ -504,24 +504,24 @@ end name = 'x', detail = 'function ()', kind = define.SymbolKind.Function, - range = {7, 22}, - selectionRange = {16, 16}, - valueRange = {7, 22}, + range = {6, 10003}, + selectionRange = {15, 16}, + valueRange = {6, 10003}, }, [2] = { name = 'f', detail = 'function ()', kind = define.SymbolKind.Function, - range = {31, 58}, - selectionRange = {40, 40}, - valueRange = {31, 58}, + range = {30006, 50003}, + selectionRange = {30015, 30016}, + valueRange = {30006, 50003}, children = { [1] = { name = 'c', detail = 'local', kind = define.SymbolKind.Variable, - range = {54, 54}, - selectionRange = {54, 54}, + range = {40010, 40011}, + selectionRange = {40010, 40011}, }, }, } @@ -537,16 +537,16 @@ local t = f({ name = 't', detail = 'local', kind = define.SymbolKind.Variable, - range = {7, 26}, - selectionRange = {7, 7}, - valueRange = {11, 26}, + range = {6, 20002}, + selectionRange = {6, 7}, + valueRange = {10, 20002}, children = { [1] = { name = 'k', detail = 'field number = 1', kind = define.SymbolKind.Property, - range = {19, 23}, - selectionRange = {19, 19}, + range = {10004, 10009}, + selectionRange = {10004, 10005}, } } } @@ -563,31 +563,31 @@ end name = 't', detail = 'local {}', kind = define.SymbolKind.Variable, - range = {7, 12}, - selectionRange = {7, 7}, - valueRange = {11, 12}, + range = {6, 12}, + selectionRange = {6, 7}, + valueRange = {10, 12}, }, [2] = { name = 'f', detail = 'function (a, b)', kind = define.SymbolKind.Function, - range = {21, 40}, - selectionRange = {30, 30}, - valueRange = {21, 40}, + range = {20006, 30003}, + selectionRange = {20015, 20016}, + valueRange = {20006, 30003}, children = { [1] = { name = 'a', detail = 'param', kind = define.SymbolKind.Constant, - range = {32, 32}, - selectionRange = {32, 32}, + range = {20017, 20018}, + selectionRange = {20017, 20018}, }, [2] = { name = 'b', detail = 'param', kind = define.SymbolKind.Constant, - range = {35, 35}, - selectionRange = {35, 35}, + range = {20020, 20021}, + selectionRange = {20020, 20021}, } } } @@ -604,17 +604,17 @@ local a = f { name = 'a', detail = 'local', kind = define.SymbolKind.Variable, - range = {7, 43}, - selectionRange = {7, 7}, - valueRange = {11, 43}, + range = {6, 30001}, + selectionRange = {6, 7}, + valueRange = {10, 30001}, children = { [1] = { name = 'x', detail = 'function ()', kind = define.SymbolKind.Function, - range = {19, 41}, - selectionRange = {19, 19}, - valueRange = {23, 41}, + range = {10004, 20007}, + selectionRange = {10004, 10005}, + valueRange = {10008, 20007}, } } } @@ -630,9 +630,9 @@ end) name = '', detail = 'table.sort -> function (a, b)', kind = define.SymbolKind.Function, - range = {15, 50}, - selectionRange = {15, 15}, - valueRange = {15, 50}, + range = {14, 20003}, + selectionRange = {14, 22}, + valueRange = {14, 20003}, children = EXISTS, } } @@ -643,32 +643,32 @@ local root = { local function function_inside_function() end end - } +} ]] { [1] = { name = 'root', detail = 'local {inner_function}', kind = define.SymbolKind.Variable, - range = {7, 123}, - selectionRange = {7, 10}, - valueRange = {14, 123}, + range = {6, 50001}, + selectionRange = {6, 10}, + valueRange = {13, 50001}, children = { [1] = { name = 'inner_function', detail = 'function ()', kind = define.SymbolKind.Function, - range = {20, 117}, - selectionRange = {20, 33}, - valueRange = {37, 117}, + range = {10004, 40007}, + selectionRange = {10004, 10018}, + valueRange = {10021, 40007}, children = { [1] = { name = 'function_inside_function', detail = 'function ()', kind = define.SymbolKind.Function, - range = {63, 109}, - selectionRange = {72, 95}, - valueRange = {63, 109}, + range = {20014, 30011}, + selectionRange = {20023, 20047}, + valueRange = {20014, 30011}, }, }, }, -- cgit v1.2.3 From c2a8838012780eb57fa7de36ae0cfa6fd4388b96 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Wed, 22 Sep 2021 23:44:21 +0800 Subject: update --- test/code_action/init.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'test') diff --git a/test/code_action/init.lua b/test/code_action/init.lua index 11ce6ec7..70d8c9ec 100644 --- a/test/code_action/init.lua +++ b/test/code_action/init.lua @@ -1,6 +1,7 @@ local core = require 'core.code-action' local files = require 'files' local lang = require 'language' +local catch = require 'catch' rawset(_G, 'TEST', true) @@ -38,11 +39,10 @@ end function TEST(script) return function (expect) files.removeAll() - local start = script:find('', 1, true) - local new_script = script:gsub('<[!?]', ' '):gsub('[!?]>', ' ') - files.setText('', new_script) - local results = core('', start, finish) + + local newScript, catched = catch(script, '?') + files.setText('', newScript) + local results = core('', catched['?'][1][1], catched['?'][1][2]) assert(results) assert(eq(expect, results)) end -- cgit v1.2.3 From 0a60aa17c240d4fb080b091891f659a9d74aeffd 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, 23 Sep 2021 00:00:30 +0800 Subject: update --- test/full/example.lua | 14 +++++--------- test/full/init.lua | 7 ++++--- 2 files changed, 9 insertions(+), 12 deletions(-) (limited to 'test') diff --git a/test/full/example.lua b/test/full/example.lua index 5596233e..20de5528 100644 --- a/test/full/example.lua +++ b/test/full/example.lua @@ -12,26 +12,24 @@ local function testIfExit(path) config.set('Lua.workspace.preloadFileSize', 1000000000) local buf = util.loadFile(path:string()) if buf then - local vm + local state local clock = os.clock() local max = 1 local need - local parseClock = 0 local compileClock = 0 local luadocClock = 0 local noderClock = 0 local total for i = 1, max do - vm = TEST(buf) + state = TEST(buf) local luadocStart = os.clock() - luadoc(nil, vm) + luadoc(state) local luadocPassed = os.clock() - luadocStart local passed = os.clock() - clock local noderStart = os.clock() local noderPassed = os.clock() - noderStart - parseClock = parseClock + vm.parseClock - compileClock = compileClock + vm.compileClock + compileClock = compileClock + state.compileClock luadocClock = luadocClock + luadocPassed noderClock = noderClock + noderPassed if passed >= 1.0 or i == max then @@ -40,10 +38,9 @@ local function testIfExit(path) break end end - print(('基准编译测试[%s]单次耗时:%.10f(解析:%.10f, 编译:%.10f, LuaDoc: %.10f, Noder: %.10f)'):format( + print(('基准编译测试[%s]单次耗时:%.10f(解析:%.10f, LuaDoc: %.10f, Noder: %.10f)'):format( path:filename():string(), need, - parseClock / total, compileClock / total, luadocClock / total, noderClock / total @@ -52,7 +49,6 @@ local function testIfExit(path) local clock = os.clock() local max = 100 local need - local lines = parser:lines(buf) for i = 1, max do files.removeAll() files.open('') diff --git a/test/full/init.lua b/test/full/init.lua index 89d9b8b3..9584db6f 100644 --- a/test/full/init.lua +++ b/test/full/init.lua @@ -5,9 +5,10 @@ local util = require 'utility' rawset(_G, 'TEST', true) function TEST(script) - local ast = parser:compile(script, 'lua', 'Lua 5.3') - assert(ast) - return ast + local clock = os.clock() + local state = parser.compile(script, 'Lua', 'Lua 5.3') + state.compileClock = os.clock() - clock + return state end local function startCollectDiagTimes() -- cgit v1.2.3 From 7ddc57e0f0a8b32d7d8bfa9228e856d897fc8de9 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, 23 Sep 2021 20:38:07 +0800 Subject: update --- test/type_formatting/init.lua | 74 ++++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 25 deletions(-) (limited to 'test') diff --git a/test/type_formatting/init.lua b/test/type_formatting/init.lua index 9178ea4f..46b8223d 100644 --- a/test/type_formatting/init.lua +++ b/test/type_formatting/init.lua @@ -1,16 +1,16 @@ local core = require 'core.type-formatting' local files = require 'files' local util = require 'utility' +local catch = require 'catch' rawset(_G, 'TEST', true) function TEST(script) return function (expect) - local pos = script:find('$', 1, true) - 1 - local new_script = script:gsub('%$', '') files.removeAll() - files.setText('', new_script) - local edits = core('', pos, expect.ch) + local newScript, catched = catch(script, '?') + files.setText('', newScript) + local edits = core('', catched['?'][1][1], expect.ch) if edits then assert(expect.edits) assert(util.equal(edits, expect.edits)) @@ -21,80 +21,104 @@ function TEST(script) end TEST [[ -if true then $ end +if true then end ]] { ch = '\n', edits = { { - start = 13, + start = 12, finish = 13, text = '\n\t', }, { - start = 14, - finish = 17, + start = 13, + finish = 15, text = '', }, { - start = 18, - finish = 17, - text = '\nend', + start = 15, + finish = 15, + text = '\ne', }, } } TEST [[ -if true then $end +if true then end ]] { ch = '\n', edits = { { - start = 13, + start = 12, finish = 13, text = '\n\t', }, { - start = 14, - finish = 16, + start = 13, + finish = 14, text = '', }, { - start = 17, - finish = 16, - text = '\nend', + start = 14, + finish = 14, + text = '\ne', }, } } TEST [[ -if true then$end +if true thenend ]] { ch = '\n', edits = { { - start = 13, + start = 12, finish = 12, text = '\n\t', }, { - start = 13, - finish = 15, + start = 12, + finish = 13, text = '', }, + { + start = 13, + finish = 13, + text = '\ne', + }, + } +} + +TEST [[ + if true thenend +]] +{ + ch = '\n', + edits = { { start = 16, - finish = 15, - text = '\nend', + finish = 16, + text = '\n \t', + }, + { + start = 16, + finish = 17, + text = '', + }, + { + start = 17, + finish = 17, + text = '\n e', }, } } TEST [[ if true then - $ + end ]] { -- cgit v1.2.3 From 8870b6a8f8827c7eaa70f9663f754586aa2408fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 24 Sep 2021 15:02:50 +0800 Subject: resolve #639 --- test/hover/init.lua | 15 +++++++++++++++ test/type_inference/init.lua | 7 +++++++ 2 files changed, 22 insertions(+) (limited to 'test') diff --git a/test/hover/init.lua b/test/hover/init.lua index c16e466d..8058317d 100644 --- a/test/hover/init.lua +++ b/test/hover/init.lua @@ -1699,3 +1699,18 @@ print(b.) [[ field A.x: any ]] + +TEST [[ +---@class A +---@field x number +---@field y number + +---@type A +local +]] +[[ +local t: A { + x: number, + y: number, +} +]] diff --git a/test/type_inference/init.lua b/test/type_inference/init.lua index 286d47cb..23ebf54e 100644 --- a/test/type_inference/init.lua +++ b/test/type_inference/init.lua @@ -353,6 +353,13 @@ TEST 'table' [[ local ]] +TEST 'A' [[ +---@class A + +---@type A +local +]] + TEST 'table' [[ self.[#self.t+1] = {} ]] -- cgit v1.2.3 From 437bb61d0daf663a3eee894946f47bc550c39e52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 24 Sep 2021 18:57:03 +0800 Subject: fix #647 --- test/references/common.lua | 24 +++--------------------- 1 file changed, 3 insertions(+), 21 deletions(-) (limited to 'test') diff --git a/test/references/common.lua b/test/references/common.lua index 3669486b..4245a79d 100644 --- a/test/references/common.lua +++ b/test/references/common.lua @@ -221,30 +221,12 @@ TEST [[ ---@class A local a -a. = 1 - ---@type A local b -b.xxx = 1 -- Dont search this - ----@class C: A -local c -print(c.) -]] - -TEST [[ ----@class A -local - ----@class B -local b - -b.xx = 1 -- Dont search this - ----@type B +---@type A local c ----@type A -c. = 1 +b. = 1 +c. = 1 ]] -- cgit v1.2.3