diff options
-rw-r--r-- | script-beta/core/completion.lua | 24 | ||||
-rw-r--r-- | script-beta/parser/guide.lua | 9 | ||||
-rw-r--r-- | test-beta/completion/init.lua | 11 |
3 files changed, 29 insertions, 15 deletions
diff --git a/script-beta/core/completion.lua b/script-beta/core/completion.lua index 20c15630..8ac0a16e 100644 --- a/script-beta/core/completion.lua +++ b/script-beta/core/completion.lua @@ -272,6 +272,29 @@ local function checkField(word, start, parent, oop, results) return used end +local function checkTableField(ast, word, start, results) + local source = guide.eachSourceContain(ast.ast, start, function (source) + if source.start == start + and source.parent + and source.parent.type == 'table' then + return source + end + end) + if not source then + return + end + guide.eachSourceType(ast.ast, 'tablefield', function (src) + local key = src.field[1] + if matchKey(word, key) + and src ~= source then + results[#results+1] = { + label = key, + kind = ckind.Property, + } + end + end) +end + local function checkCommon(word, text, results) local used = {} for _, result in ipairs(results) do @@ -604,6 +627,7 @@ local function tryWord(ast, text, offset, results) end if not hasSpace then checkLocal(ast, word, start, results) + checkTableField(ast, word, start, results) local env = guide.getLocal(ast.ast, '_ENV', start) checkField(word, start, env, false, results) end diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 443c2293..d9dab5ed 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -364,13 +364,14 @@ end --- 遍历所有的source function m.eachSource(ast, callback) local list = { ast } + local index = 1 while true do - local len = #list - if len == 0 then + local obj = list[index] + if not obj then return end - local obj = list[len] - list[len] = nil + list[index] = false + index = index + 1 callback(obj) m.addChilds(list, obj, m.childMap) end diff --git a/test-beta/completion/init.lua b/test-beta/completion/init.lua index 29d870f8..c3421a52 100644 --- a/test-beta/completion/init.lua +++ b/test-beta/completion/init.lua @@ -376,7 +376,6 @@ local t = { { label = 'xxxx', kind = CompletionItemKind.Variable, - detail = EXISTS, }, { label = 'xxyy', @@ -389,28 +388,18 @@ local t = { { label = 'next', kind = CompletionItemKind.Function, - documentation = EXISTS, - detail = EXISTS, }, { label = 'next()', kind = CompletionItemKind.Snippet, - documentation = EXISTS, - detail = EXISTS, - insertText = EXISTS, }, { label = 'xpcall', kind = CompletionItemKind.Function, - documentation = EXISTS, - detail = EXISTS, }, { label = 'xpcall()', kind = CompletionItemKind.Snippet, - documentation = EXISTS, - detail = EXISTS, - insertText = EXISTS, }, } |