summaryrefslogtreecommitdiff
path: root/server/src/core
diff options
context:
space:
mode:
authorsumneko <sumneko@hotmail.com>2019-04-18 14:31:31 +0800
committersumneko <sumneko@hotmail.com>2019-04-18 14:31:31 +0800
commitcc8fc15d26a1dfd2f30485ba21f2f313141932d0 (patch)
tree1db6eb2bb54dda2b5e1ab883bf542375b18ddc4c /server/src/core
parent0699bff5ce3807964cda703ba00caa9dc5e90cf0 (diff)
downloadlua-language-server-cc8fc15d26a1dfd2f30485ba21f2f313141932d0.zip
自动完成
Diffstat (limited to 'server/src/core')
-rw-r--r--server/src/core/completion.lua22
1 files changed, 20 insertions, 2 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua
index 3b6e67e7..cef8b798 100644
--- a/server/src/core/completion.lua
+++ b/server/src/core/completion.lua
@@ -37,6 +37,8 @@ for _, k in ipairs(KEYS) do
KEYMAP[k] = true
end
+local EMMY_KEYWORD = {'class', 'type', 'alias', 'param', 'return', 'field', 'generic', 'vararg', 'language', 'see'}
+
local function matchKey(me, other)
if me == other then
return true
@@ -359,6 +361,14 @@ local function searchAsArg(vm, source, word, callback)
searchCloseGlobal(vm, source, word, callback)
end
+local function searchEmmyKeyword(vm, source, word, callback)
+ for _, kw in ipairs(EMMY_KEYWORD) do
+ if matchKey(word, kw) then
+ callback(kw, nil, CompletionItemKind.Keyword)
+ end
+ end
+end
+
local function searchSource(vm, source, word, callback)
if source:get 'table index' then
searchAsIndex(vm, source, word, callback)
@@ -384,6 +394,10 @@ local function searchSource(vm, source, word, callback)
searchAsSuffix(vm, source, word, callback)
return
end
+ if source.type == 'emmyIncomplete' then
+ searchEmmyKeyword(vm, source, word, callback)
+ return
+ end
end
local function searchInRequire(vm, select, source, callback)
@@ -506,7 +520,7 @@ local function searchAllWords(vm, source, word, callback, pos)
end)
end
-local function searchSpecial(vm, source, word, callback, pos)
+local function searchSpecialHashSign(vm, pos, callback)
-- 尝试 XXX[#XXX+1]
-- 1. 搜索 []
local index
@@ -571,6 +585,10 @@ local function searchSpecial(vm, source, word, callback, pos)
end
end
+local function searchSpecial(vm, source, word, callback, pos)
+ searchSpecialHashSign(vm, pos, callback)
+end
+
local function makeList(source, pos, word)
local list = {}
local mark = {}
@@ -624,7 +642,7 @@ local function searchToclose(text, word, callback, pos)
end
return function (vm, text, pos, word, oldText)
- local source = findSource(vm, pos) or findSource(vm, pos-1)
+ local source = findSource(vm, pos) or findSource(vm, pos-1) or findSource(vm, pos+1)
if not source then
return nil
end