diff options
author | sumneko <sumneko@hotmail.com> | 2019-04-25 17:37:45 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-04-25 17:37:45 +0800 |
commit | 39e7ac384e45781331fc8c33a6a76746d770f031 (patch) | |
tree | ead5b78bf00e582e9ccc21b4d2b083f177c86547 /server | |
parent | f06ff4184d48f1f72a853d0d6652ae9c2cc6594d (diff) | |
download | lua-language-server-39e7ac384e45781331fc8c33a6a76746d770f031.zip |
#的自动完成支持任意simple了
Diffstat (limited to 'server')
-rw-r--r-- | server/src/core/completion.lua | 26 |
1 files changed, 8 insertions, 18 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index 8b6b7676..3162a48e 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -593,7 +593,7 @@ local function searchAllWords(vm, source, word, callback, pos) end) end -local function searchSpecialHashSign(vm, pos, callback) +local function searchSpecialHashSign(vm, pos, text, callback) -- 尝试 XXX[#XXX+1] -- 1. 搜索 [] local index @@ -617,7 +617,7 @@ local function searchSpecialHashSign(vm, pos, callback) if inside.op ~= '#' then return nil end - -- 3. [] 左侧必须是纯 name 构成的 simple ,且index 是 simple 的最后一项 + -- 3. [] 左侧必须是 simple ,且index 是 simple 的最后一项 local simple = index:get 'simple' if not simple then return nil @@ -625,20 +625,10 @@ local function searchSpecialHashSign(vm, pos, callback) if simple[#simple] ~= index then return nil end - local chars = {} - for i = 1, #simple - 1 do - local src = simple[i] - if src.type == 'name' then - chars[#chars+1] = src[1] - elseif src.type == '.' then - chars[#chars+1] = '.' - else - return nil - end - end + local chars = text:sub(simple.start, simple[#simple-1].finish) -- 4. 创建代码片段 if simple:get 'as action' then - local label = table.concat(chars) .. '+1' + local label = chars .. '+1' callback(label, nil, CompletionItemKind.Snippet, { textEdit = { start = inside.start + 1, @@ -647,7 +637,7 @@ local function searchSpecialHashSign(vm, pos, callback) }, }) else - local label = table.concat(chars) + local label = chars callback(label, nil, CompletionItemKind.Snippet, { textEdit = { start = inside.start + 1, @@ -658,8 +648,8 @@ local function searchSpecialHashSign(vm, pos, callback) end end -local function searchSpecial(vm, source, word, callback, pos) - searchSpecialHashSign(vm, pos, callback) +local function searchSpecial(vm, source, word, callback, pos, text) + searchSpecialHashSign(vm, pos, text, callback) end local function makeList(source, pos, word) @@ -804,7 +794,7 @@ return function (vm, text, pos, oldText) if searchToclose(text, source, word, callback) then return list end - searchSpecial(vm, source, word, callback, pos) + searchSpecial(vm, source, word, callback, pos, text) searchCallArg(vm, source, word, callback, pos) searchSource(vm, source, word, callback) if not oldText or #list > 0 then |