diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-06 17:51:35 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-06 17:51:35 +0800 |
commit | f9b3e7070d4239687e8db16393b81213c4a701cd (patch) | |
tree | c0498f6834e55b2d477eff086b43d4824fd89956 /server/src | |
parent | ca0341d0760a067b6554d5b7aeb8357ec84e564f (diff) | |
download | lua-language-server-f9b3e7070d4239687e8db16393b81213c4a701cd.zip |
向前找符号
Diffstat (limited to 'server/src')
-rw-r--r-- | server/src/core/completion.lua | 12 | ||||
-rw-r--r-- | server/src/vm/vm.lua | 4 |
2 files changed, 15 insertions, 1 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index a04ffc52..07144255 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -155,7 +155,7 @@ end local function getKind(cata, value) if value:getType() == 'function' then local func = value:getFunction() - if func:getObject() then + if func and func:getObject() then return CompletionItemKind.Method else return CompletionItemKind.Function @@ -233,12 +233,22 @@ local function searchFields(vm, source, word, callback) end end +local KEYS = {'and', 'break', 'do', 'else', 'elseif', 'end', 'false', 'for', 'function', 'goto', 'if', 'in', 'local', 'nil', 'not', 'or', 'repeat', 'return', 'then', 'true', 'until', 'while', 'toclose'} +local function searchKeyWords(vm, source, word, callback) + for _, key in ipairs(KEYS) do + if matchKey(word, key) then + callback(key, nil, CompletionItemKind.Keyword) + end + end +end + local function searchAsGlobal(vm, source, word, callback) if word == '' then return end searchLocals(vm, source, word, callback) searchFields(vm, source, word, callback) + searchKeyWords(vm, source, word, callback) end local function searchAsSuffix(vm, source, word, callback) diff --git a/server/src/vm/vm.lua b/server/src/vm/vm.lua index e384eedc..aa4c6cc9 100644 --- a/server/src/vm/vm.lua +++ b/server/src/vm/vm.lua @@ -476,7 +476,10 @@ function mt:getSimple(simple, max) source:bindValue(value, 'get') elseif source.type == ':' then object = value + source:set('parent', value) + source:set('object', object) elseif source.type == '.' then + source:set('parent', value) end end return value @@ -860,6 +863,7 @@ function mt:doFunction(action) local value = self:buildFunction(action) local source = name[#name] self:instantSource(source) + source:set('object', parent) if source.type == 'index' then local index = self:getIndex(source[1]) parent:setChild(index, value) |