diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-01-21 17:42:08 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-01-21 17:42:08 +0800 |
commit | e9818422596439666f2cf17d6fe83c472809320d (patch) | |
tree | 3361e7d258bce98fe10ad41a1cbdd2c9f329c2b7 /server/test/completion | |
parent | ed21959eea02f2479ec87b6798d38b368542d881 (diff) | |
download | lua-language-server-e9818422596439666f2cf17d6fe83c472809320d.zip |
修正自动完成的BUG
Diffstat (limited to 'server/test/completion')
-rw-r--r-- | server/test/completion/init.lua | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua index bb2199aa..df841b96 100644 --- a/server/test/completion/init.lua +++ b/server/test/completion/init.lua @@ -57,6 +57,31 @@ 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 + rawset(_G, 'TEST', true) function TEST(script) @@ -66,7 +91,9 @@ function TEST(script) local ast = parser:ast(new_script) local vm = core.vm(ast) assert(vm) - local result = core.completion(vm, pos) + local word = findWord(pos, new_script) + local startPos = findStartPos(pos, new_script) or pos + local result = core.completion(vm, startPos, word) if expect then assert(result) assert(eq(expect, result)) |