summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-27 16:18:41 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-27 16:18:41 +0800
commit36f9bc4a4cf4a1406ac01031a051888db6940a01 (patch)
tree98254eb5f90250ac8ad993f755565244d67abd0f
parentfaf56c7e9d08776207c4592e6aee87a79241fdcc (diff)
downloadlua-language-server-36f9bc4a4cf4a1406ac01031a051888db6940a01.zip
修正自动完成有时失效的问题
-rw-r--r--server/src/method/textDocument/completion.lua8
-rw-r--r--server/src/parser/lines.lua4
-rw-r--r--server/test/completion/init.lua10
3 files changed, 10 insertions, 12 deletions
diff --git a/server/src/method/textDocument/completion.lua b/server/src/method/textDocument/completion.lua
index 2e084a87..fd5d1ed6 100644
--- a/server/src/method/textDocument/completion.lua
+++ b/server/src/method/textDocument/completion.lua
@@ -18,7 +18,7 @@ end
local function findStartPos(pos, buf)
local res = nil
- for i = pos-1, 1, -1 do
+ for i = pos, 1, -1 do
local c = buf:sub(i, i)
if c:find '[%w_]' then
res = i
@@ -27,9 +27,9 @@ local function findStartPos(pos, buf)
end
end
if not res then
- for i = pos-1, 1, -1 do
+ for i = pos, 1, -1 do
local c = buf:sub(i, i)
- if c:find '[%.%:]' then
+ if c == '.' or c == ':' then
res = i
elseif c:find '[%s%c]' then
else
@@ -45,7 +45,7 @@ end
local function findWord(position, text)
local word = text
- for i = position-1, 1, -1 do
+ for i = position, 1, -1 do
local c = text:sub(i, i)
if not c:find '[%w_]' then
word = text:sub(i+1, position)
diff --git a/server/src/parser/lines.lua b/server/src/parser/lines.lua
index ddb3e0b3..95e92573 100644
--- a/server/src/parser/lines.lua
+++ b/server/src/parser/lines.lua
@@ -102,13 +102,11 @@ local function isCharByte(byte)
end
function mt:positionAsChar(row, col, code)
- local pos = self:position(row, col+1, code)
+ local pos = self:position(row, col, code)
if isCharByte(self.buf:byte(pos, pos)) then
return pos
elseif isCharByte(self.buf:byte(pos+1, pos+1)) then
return pos + 1
- elseif isCharByte(self.buf:byte(pos-1, pos-1)) then
- return pos - 1
end
return pos
end
diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua
index 14c14476..962befa0 100644
--- a/server/test/completion/init.lua
+++ b/server/test/completion/init.lua
@@ -60,7 +60,7 @@ end
local function findStartPos(pos, buf)
local res = nil
- for i = pos-1, 1, -1 do
+ for i = pos, 1, -1 do
local c = buf:sub(i, i)
if c:find '[%w_]' then
res = i
@@ -69,9 +69,9 @@ local function findStartPos(pos, buf)
end
end
if not res then
- for i = pos-1, 1, -1 do
+ for i = pos, 1, -1 do
local c = buf:sub(i, i)
- if c:find '[%.%:]' then
+ if c == '.' or c == ':' then
res = i
elseif c:find '[%s%c]' then
else
@@ -87,7 +87,7 @@ end
local function findWord(position, text)
local word = text
- for i = position-1, 1, -1 do
+ for i = position, 1, -1 do
local c = text:sub(i, i)
if not c:find '[%w_]' then
word = text:sub(i+1, position)
@@ -101,7 +101,7 @@ rawset(_G, 'TEST', true)
function TEST(script)
return function (expect)
- local pos = script:find('@', 1, true)
+ local pos = script:find('@', 1, true) - 1
local new_script = script:gsub('@', ' ')
local ast = parser:ast(new_script)
local vm = buildVM(ast)