summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-01-21 17:01:12 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-01-21 17:01:12 +0800
commit71d24c50b9b44dbd1b14958e7941fb7c9a1ab11c (patch)
treee15c1d3662f799cfe7c47211f21f6f7142a9068c /server
parent3573568a50627ccf1b87ec5ebce585b4207b1826 (diff)
downloadlua-language-server-71d24c50b9b44dbd1b14958e7941fb7c9a1ab11c.zip
修正bug
Diffstat (limited to 'server')
-rw-r--r--server/src/core/completion.lua6
-rw-r--r--server/src/method/textDocument/completion.lua49
-rw-r--r--server/src/service.lua8
3 files changed, 42 insertions, 21 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index 3e855ca6..13a36d94 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -547,7 +547,7 @@ local function clearList(list, source)
end
end
-return function (vm, pos, buf)
+return function (vm, pos, word)
local list = {}
local callback = makeList(list)
local inCall = findCall(vm, pos)
@@ -567,8 +567,8 @@ return function (vm, pos, buf)
searchAllWords(result.key, vm, callback)
clearList(list, source)
else
- if buf then
- searchAllWords(buf:sub(pos-1, pos-1), vm, callback)
+ if word then
+ searchAllWords(word, vm, callback)
end
end
end
diff --git a/server/src/method/textDocument/completion.lua b/server/src/method/textDocument/completion.lua
index 2e1eb5f0..8af4db95 100644
--- a/server/src/method/textDocument/completion.lua
+++ b/server/src/method/textDocument/completion.lua
@@ -17,48 +17,60 @@ local function posToRange(lines, start, finish)
end
local function findStartPos(pos, buf)
- local res = pos
for i = pos-1, 1, -1 do
local c = buf:sub(i, i)
if c:find '%a' then
- res = i
+ goto CONTINUE
end
if c == '.' or c == ':' then
- break
+ return nil
+ end
+ do return i + 1 end
+ ::CONTINUE::
+ end
+ return 1
+end
+
+local function findWord(position, text)
+ for i = position-1, 1, -1 do
+ local c = text:sub(i, i)
+ if not c:find '%w' then
+ return text:sub(i+1, position)
end
end
- return res
+ return text:sub(1, position)
end
return function (lsp, params)
local uri = params.textDocument.uri
- local vm, lines, buf = lsp:getVM(uri)
- if not vm then
- vm, lines, buf = lsp:loadVM(uri)
- if not vm then
- return nil
- end
+ local text = lsp:getText(uri)
+ if not text then
+ return nil
end
+
+ local lines = parser:lines(text, 'utf8')
-- lua是从1开始的,因此都要+1
local position = lines:position(params.position.line + 1, params.position.character + 1)
+ local word = findWord(position, text)
+ local startPos = findStartPos(position, text)
- local startPos = findStartPos(position, buf)
- if not startPos then
- vm, lines, buf = lsp:loadVM(uri)
+ local vm = lsp:getVM(uri)
+ if not vm or not startPos then
+ vm = lsp:loadVM(uri)
if not vm then
return nil
end
end
+ startPos = startPos or position
- local items = core.completion(vm, startPos or position, buf)
+ local items = core.completion(vm, startPos, word)
if not items or #items == 0 then
- vm, lines, buf = lsp:loadVM(uri)
+ vm = lsp:loadVM(uri)
if not vm then
return nil
end
- position = lines:position(params.position.line + 1, params.position.character + 1)
- startPos = findStartPos(position, buf)
- items = core.completion(vm, startPos or position, buf)
+ startPos = startPos or position
+ items = core.completion(vm, startPos, word)
if not items or #items == 0 then
return nil
end
@@ -71,6 +83,7 @@ return function (lsp, params)
item.textEdit.finish = nil
end
end
+
local response = {
isIncomplete = false,
items = items,
diff --git a/server/src/service.lua b/server/src/service.lua
index 4174c54c..01c28f97 100644
--- a/server/src/service.lua
+++ b/server/src/service.lua
@@ -301,6 +301,14 @@ function mt:getVM(uri)
return obj.vm, obj.lines, obj.text
end
+function mt:getText(uri)
+ local obj = self._file[uri]
+ if not obj then
+ return nil
+ end
+ return obj.text
+end
+
function mt:getAstErrors(uri)
local obj = self._file[uri]
if not obj then