summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-01-07 13:51:35 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-01-07 13:51:35 +0800
commitead4c5d4b13c71be990bf66f07365e8d457a011d (patch)
treeb5dacc880aba6a1d1443871b9fbe42b87114f4c0 /server/src
parent5b1886a9cfa7c8dc1947bf7bb19e9fd3d04d604d (diff)
downloadlua-language-server-ead4c5d4b13c71be990bf66f07365e8d457a011d.zip
自动完成会检查点和冒号
Diffstat (limited to 'server/src')
-rw-r--r--server/src/core/completion.lua40
-rw-r--r--server/src/core/vm.lua4
2 files changed, 27 insertions, 17 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index 34409bd5..b2688c68 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -190,6 +190,9 @@ local function getDetail(var)
end
local function getDocument(var, source)
+ if not source then
+ return nil
+ end
if var.value.type == 'function' then
return {
kind = 'markdown',
@@ -305,11 +308,13 @@ end
local function findClosePos(vm, pos)
local curDis = math.maxinteger
local parent = nil
+ local inputSource = nil
local function found(object, source)
local dis = pos - source.finish
if dis > 1 and dis < curDis then
curDis = dis
parent = object
+ inputSource = source
end
end
for sources, object in pairs(vm.results.sources) do
@@ -329,12 +334,19 @@ local function findClosePos(vm, pos)
if parent.type ~= 'local' and parent.type ~= 'field' then
return nil
end
+ local sep = inputSource.dot or inputSource.colon
+ if not sep then
+ return nil
+ end
+ if sep.finish > pos then
+ return nil
+ end
-- 造个假的 DirtyName
local source = {
type = 'name',
start = pos,
finish = pos,
- object = parent.source.colon and parent,
+ object = sep.type == ':' and parent,
[1] = '',
}
local result = {
@@ -399,8 +411,7 @@ local function findCall(vm, pos)
return results[#results]
end
-local function makeList(source)
- local list = {}
+local function makeList(list, source)
local mark = {}
local function callback(var, defualt, data)
local key
@@ -425,7 +436,7 @@ local function makeList(source)
data.documentation = data.documentation or getDocument(var, source)
end
end
- return list, callback
+ return callback
end
local function searchInResult(result, source, vm, pos, callback)
@@ -482,16 +493,8 @@ local function searchSpecial(vm, pos, callback)
end
return function (vm, pos)
- local result, source = findResult(vm, pos)
- if not result then
- result, source = findClosePos(vm, pos)
- end
-
- if not result then
- return nil
- end
-
- local list, callback = makeList(source)
+ local list = {}
+ local callback = makeList(list)
local inCall = findCall(vm, pos)
local inString = findString(vm, pos)
if inCall then
@@ -499,7 +502,14 @@ return function (vm, pos)
end
searchSpecial(vm, pos, callback)
if not inString then
- searchInResult(result, source, vm, pos, callback)
+ local result, source = findResult(vm, pos)
+ if not result then
+ result, source = findClosePos(vm, pos)
+ end
+ if result then
+ callback = makeList(list, source)
+ searchInResult(result, source, vm, pos, callback)
+ end
end
if #list == 0 then
return nil
diff --git a/server/src/core/vm.lua b/server/src/core/vm.lua
index 290125f1..34df77a8 100644
--- a/server/src/core/vm.lua
+++ b/server/src/core/vm.lua
@@ -1022,9 +1022,9 @@ function mt:getSimple(simple, mode)
parentName = parentName .. '.' .. field.key
elseif tp == ':' then
object = field
- field.source.colon = obj
+ simple[i-1].colon = obj
elseif tp == '.' then
- field.source.dot = obj
+ simple[i-1].dot = obj
end
end
if mode == 'value' then