diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-03-29 14:53:45 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-03-29 14:53:45 +0800 |
commit | c0f1352581b5a4b046fc775c066feacf576156ba (patch) | |
tree | ac2c74f88c9a4cb05703a08d895cfd33c57ec2d5 /server | |
parent | 5f33254d4ec014ffc9358614b1894a0c7df08103 (diff) | |
download | lua-language-server-c0f1352581b5a4b046fc775c066feacf576156ba.zip |
用API而不是自己遍历
Diffstat (limited to 'server')
-rw-r--r-- | server/src/core/completion.lua | 29 | ||||
-rw-r--r-- | server/src/core/definition.lua | 4 | ||||
-rw-r--r-- | server/src/core/diagnostics.lua | 5 | ||||
-rw-r--r-- | server/src/core/document_symbol.lua | 4 | ||||
-rw-r--r-- | server/src/core/implementation.lua | 7 | ||||
-rw-r--r-- | server/src/core/signature.lua | 6 | ||||
-rw-r--r-- | server/src/method/workspace/executeCommand.lua | 5 |
7 files changed, 28 insertions, 32 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index adbac085..9db87c2b 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -180,10 +180,10 @@ local function getValueData(cata, name, value) end local function searchLocals(vm, source, word, callback) - for _, src in ipairs(vm.sources) do + vm:eachSource(function (src) local loc = src:bindLocal() if not loc then - goto CONTINUE + return end if src.start <= source.start @@ -192,8 +192,7 @@ local function searchLocals(vm, source, word, callback) then callback(loc:getName(), src, CompletionItemKind.Variable, getValueData('local', loc:getName(), loc:getValue())) end - :: CONTINUE :: - end + end) end local function sortPairs(t) @@ -234,13 +233,13 @@ local function searchFields(vm, source, word, callback) end local function searchIndex(vm, source, word, callback) - for _, src in ipairs(vm.sources) do + vm:eachSource(function (src) if src:get 'table index' then if matchKey(word, src[1]) then callback(src[1], src, CompletionItemKind.Property) end end - end + end) end local function searchCloseGlobal(vm, source, word, callback) @@ -251,7 +250,7 @@ local function searchCloseGlobal(vm, source, word, callback) local close = loc:close() -- 因为闭包的关系落在局部变量finish到close范围内的全局变量一定能访问到该局部变量 - for _, src in ipairs(vm.sources) do + vm:eachSource(function (src) if (src:get 'global' or src:bindLocal()) and src.start >= source.finish and src.finish <= close @@ -260,7 +259,7 @@ local function searchCloseGlobal(vm, source, word, callback) callback(src[1], src, CompletionItemKind.Variable) end end - end + 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'} @@ -361,14 +360,14 @@ end local function searchCallArg(vm, source, word, callback, pos) local results = {} - for _, src in ipairs(vm.sources) do + vm:eachSource(function (src) if src.type == 'call' and src.start <= pos and src.finish >= pos then results[#results+1] = src end - end + end) if #results == 0 then return nil end @@ -436,28 +435,28 @@ local function searchAllWords(vm, source, word, callback) if source.type == 'string' then return end - for _, src in ipairs(vm.sources) do + vm:eachSource(function (src) if src.type == 'name' and matchKey(word, src[1]) then callback(src[1], src, CompletionItemKind.Text) end - end + end) end local function searchSpecial(vm, source, word, callback, pos) -- 尝试 XXX[#XXX+1] -- 1. 搜索 [] local index - for _, src in ipairs(vm.sources) do + vm:eachSource(function (src) if src.type == 'index' and src.start <= pos and src.finish >= pos then index = src - break + return true end - end + end) if not index then return nil end diff --git a/server/src/core/definition.lua b/server/src/core/definition.lua index 23b9eb03..534d86db 100644 --- a/server/src/core/definition.lua +++ b/server/src/core/definition.lua @@ -4,7 +4,7 @@ local function parseValueSimily(vm, source, lsp) return nil end local positions = {} - for _, other in ipairs(vm.sources) do + vm:eachSource(function (other) if other == source then goto CONTINUE end @@ -20,7 +20,7 @@ local function parseValueSimily(vm, source, lsp) } end :: CONTINUE :: - end + end) if #positions == 0 then return nil end diff --git a/server/src/core/diagnostics.lua b/server/src/core/diagnostics.lua index f2e2d1f7..ff030348 100644 --- a/server/src/core/diagnostics.lua +++ b/server/src/core/diagnostics.lua @@ -114,12 +114,11 @@ local function isContainPos(obj, start, finish) end local function isInString(vm, start, finish) - for _, source in ipairs(vm.sources) do + return vm:eachSource(function (source) if source.type == 'string' and isContainPos(source, start, finish) then return true end - end - return false + end) end function mt:searchSpaces(callback) diff --git a/server/src/core/document_symbol.lua b/server/src/core/document_symbol.lua index 7e978767..48e01332 100644 --- a/server/src/core/document_symbol.lua +++ b/server/src/core/document_symbol.lua @@ -248,11 +248,11 @@ return function (vm) local symbols = {} local used = {} - for _, source in ipairs(vm.sources) do + vm:eachSource(function (source) buildSource(vm, source, used, function (data) symbols[#symbols+1] = data end) - end + end) local packedSymbols = packSymbols(symbols) diff --git a/server/src/core/implementation.lua b/server/src/core/implementation.lua index 832181f5..1b8006b1 100644 --- a/server/src/core/implementation.lua +++ b/server/src/core/implementation.lua @@ -4,9 +4,9 @@ local function parseValueSimily(vm, source, lsp) return nil end local positions = {} - for _, other in ipairs(vm.sources) do + vm:eachSource(function (other) if other == source then - goto CONTINUE + return end if other[1] == key and not other:bindLocal() @@ -19,8 +19,7 @@ local function parseValueSimily(vm, source, lsp) other.finish, } end - :: CONTINUE :: - end + end) if #positions == 0 then return nil end diff --git a/server/src/core/signature.lua b/server/src/core/signature.lua index ca20f054..23dba97a 100644 --- a/server/src/core/signature.lua +++ b/server/src/core/signature.lua @@ -6,14 +6,14 @@ local findSource = require 'core.find_source' local function findCall(vm, pos) local results = {} - for _, src in ipairs(vm.sources) do - if src.type == 'call' + vm:eachSource(function (src) + if src.type == 'call' and src.start <= pos and src.finish >= pos then results[#results+1] = src end - end + end) if #results == 0 then return nil end diff --git a/server/src/method/workspace/executeCommand.lua b/server/src/method/workspace/executeCommand.lua index 00ee09a3..5a8612c5 100644 --- a/server/src/method/workspace/executeCommand.lua +++ b/server/src/method/workspace/executeCommand.lua @@ -14,12 +14,11 @@ local function isContainPos(obj, start, finish) end local function isInString(vm, start, finish) - for _, source in ipairs(vm.sources) do + return vm:eachSource(function (source) if source.type == 'string' and isContainPos(source, start, finish) then return true end - end - return false + end) end local function posToRange(lines, start, finish) |