diff options
author | sumneko <sumneko@hotmail.com> | 2019-04-19 11:44:20 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-04-19 11:44:20 +0800 |
commit | 4aa6774eb322be64db441db1153326f180c8ff6a (patch) | |
tree | b091ef53fbd69f6d4557094d99ee2618601df451 /server/test | |
parent | 1a889f53a34fdb2ae77bfe7189a5e00a2e723187 (diff) | |
download | lua-language-server-4aa6774eb322be64db441db1153326f180c8ff6a.zip |
class的自动完成
Diffstat (limited to 'server/test')
-rw-r--r-- | server/test/completion/init.lua | 122 | ||||
-rw-r--r-- | server/test/crossfile/completion.lua | 31 | ||||
-rw-r--r-- | server/test/definition/emmy.lua | 9 | ||||
-rw-r--r-- | server/test/definition/init.lua | 1 |
4 files changed, 60 insertions, 103 deletions
diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua index 6dc998c7..560f6fa4 100644 --- a/server/test/completion/init.lua +++ b/server/test/completion/init.lua @@ -58,57 +58,16 @@ local function eq(a, b) return a == b end -local function findStartPos(pos, buf) - local res = nil - for i = pos, 1, -1 do - local c = buf:sub(i, i) - if c:find '[%w_]' then - res = i - else - break - end - end - if not res then - for i = pos, 1, -1 do - local c = buf:sub(i, i) - if c == '.' or c == ':' then - res = i - elseif c:find '[%s%c]' then - else - break - end - end - end - if not res then - return pos - end - return res -end - -local function findWord(position, text) - local word = text - for i = position, 1, -1 do - local c = text:sub(i, i) - if not c:find '[%w_]' then - word = text:sub(i+1, position) - break - end - end - return word:match('^([%w_]*)') -end - rawset(_G, 'TEST', true) function TEST(script) return function (expect) local pos = script:find('$', 1, true) - 1 - local new_script = script:gsub('%$', ' ') + local new_script = script:gsub('%$', '') local ast = parser:ast(new_script, 'lua', 'Lua 5.4') local vm = buildVM(ast) assert(vm) - local word = findWord(pos, new_script) - local startPos = findStartPos(pos, new_script) - local result = core.completion(vm, new_script, startPos, word) + local result = core.completion(vm, new_script, pos) if expect then assert(result) assert(eq(expect, result)) @@ -414,7 +373,7 @@ collectgarbage('$') documentation = EXISTS, textEdit = { start = 16, - finish = 18, + finish = 17, newText = '"collect"', }, }, @@ -424,7 +383,7 @@ collectgarbage('$') documentation = EXISTS, textEdit = { start = 16, - finish = 18, + finish = 17, newText = '"stop"', }, }, @@ -434,7 +393,7 @@ collectgarbage('$') documentation = EXISTS, textEdit = { start = 16, - finish = 18, + finish = 17, newText = '"restart"', }, }, @@ -444,7 +403,7 @@ collectgarbage('$') documentation = EXISTS, textEdit = { start = 16, - finish = 18, + finish = 17, newText = '"count"', }, }, @@ -454,7 +413,7 @@ collectgarbage('$') documentation = EXISTS, textEdit = { start = 16, - finish = 18, + finish = 17, newText = '"step"', }, }, @@ -464,7 +423,7 @@ collectgarbage('$') documentation = EXISTS, textEdit = { start = 16, - finish = 18, + finish = 17, newText = '"setpause"', }, }, @@ -474,7 +433,7 @@ collectgarbage('$') documentation = EXISTS, textEdit = { start = 16, - finish = 18, + finish = 17, newText = '"setstepmul"', }, }, @@ -484,7 +443,7 @@ collectgarbage('$') documentation = EXISTS, textEdit = { start = 16, - finish = 18, + finish = 17, newText = '"isrunning"', }, }, @@ -536,7 +495,7 @@ self.results.list[#$] kind = CompletionItemKind.Snippet, textEdit = { start = 20, - finish = 21, + finish = 20, newText = 'self.results.list+1] = ', }, }, @@ -551,7 +510,7 @@ self.results.list[#self.re$] kind = CompletionItemKind.Snippet, textEdit = { start = 20, - finish = 28, + finish = 27, newText = 'self.results.list+1] = ', }, }, @@ -570,7 +529,7 @@ fff[#ff$] kind = CompletionItemKind.Snippet, textEdit = { start = 6, - finish = 9, + finish = 8, newText = 'fff+1] = ', }, }, @@ -589,7 +548,7 @@ local _ = fff.kkk[#$] kind = CompletionItemKind.Snippet, textEdit = { start = 20, - finish = 21, + finish = 20, newText = 'fff.kkk]', }, }, @@ -736,25 +695,25 @@ end (nil) require 'config' .config.runtime.version = 'Lua 5.4' -TEST [[ -local *$ -]] -{ - { - label = 'toclose', - kind = CompletionItemKind.Keyword, - } -} - -TEST [[ -local *tocl$ -]] -{ - { - label = 'toclose', - kind = CompletionItemKind.Keyword, - } -} +--TEST [[ +--local *$ +--]] +--{ +-- { +-- label = 'toclose', +-- kind = CompletionItemKind.Keyword, +-- } +--} + +--TEST [[ +--local *tocl$ +--]] +--{ +-- { +-- label = 'toclose', +-- kind = CompletionItemKind.Keyword, +-- } +--} TEST [[ local mt = {} @@ -810,3 +769,18 @@ TEST [[ kind = CompletionItemKind.Keyword } } + +TEST [[ +---@class ABC +---@class BBC : $ +]] +{ + { + label = 'ABC', + kind = CompletionItemKind.Class, + }, + { + label = 'BBC', + kind = CompletionItemKind.Class, + }, +} diff --git a/server/test/crossfile/completion.lua b/server/test/crossfile/completion.lua index c982607b..cc31ed5d 100644 --- a/server/test/crossfile/completion.lua +++ b/server/test/crossfile/completion.lua @@ -61,31 +61,6 @@ local function eq(a, b) return a == b end -local function findStartPos(pos, buf) - local res = nil - for i = pos-1, 1, -1 do - local c = buf:sub(i, i) - if c:find '%a' then - res = i - else - break - end - end - return res -end - -local function findWord(position, text) - local word = text - for i = position-1, 1, -1 do - local c = text:sub(i, i) - if not c:find '[%w_]' then - word = text:sub(i+1, position) - break - end - end - return word:match('^([%w_]*)') -end - function TEST(data) local lsp = service() local ws = workspace(lsp, 'test') @@ -99,7 +74,7 @@ function TEST(data) local uri = ws:uriEncode(fs.path(info.path)) local script = info.content if info.main then - pos = script:find('$', 1, true) + pos = script:find('$', 1, true) - 1 script = script:gsub('%$', '') mainUri = uri mainBuf = script @@ -114,9 +89,7 @@ function TEST(data) local vm = lsp:loadVM(mainUri) assert(vm) - local word = findWord(pos, mainBuf) - local startPos = findStartPos(pos, mainBuf) or pos - local result = core.completion(vm, mainBuf, startPos, word) + local result = core.completion(vm, mainBuf, pos) local expect = data.completion if expect then assert(result) diff --git a/server/test/definition/emmy.lua b/server/test/definition/emmy.lua new file mode 100644 index 00000000..5761d312 --- /dev/null +++ b/server/test/definition/emmy.lua @@ -0,0 +1,9 @@ +TEST [[ +---@class <!A!> +---@class B : <?A?> +]] + +TEST [[ +---@class <!A!> +---@type B|<?A?> +]] diff --git a/server/test/definition/init.lua b/server/test/definition/init.lua index e095e474..d699744a 100644 --- a/server/test/definition/init.lua +++ b/server/test/definition/init.lua @@ -62,3 +62,4 @@ require 'definition.table' require 'definition.method' require 'definition.label' require 'definition.bug' +require 'definition.emmy' |