diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2021-09-22 16:54:15 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2021-09-22 16:54:15 +0800 |
commit | a45e980f0d51c47229d18d0f859e718d203b472f (patch) | |
tree | c9d0a3924f9693ff41e70b405db13fbc815a2903 /test/crossfile | |
parent | b66a9c9340d63e1a22ba7d5ccad8d9df244240d1 (diff) | |
download | lua-language-server-a45e980f0d51c47229d18d0f859e718d203b472f.zip |
update
Diffstat (limited to 'test/crossfile')
-rw-r--r-- | test/crossfile/completion.lua | 58 | ||||
-rw-r--r-- | test/crossfile/diagnostic.lua | 27 |
2 files changed, 35 insertions, 50 deletions
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 = {} |