diff options
author | sumneko <sumneko@hotmail.com> | 2019-04-18 17:22:09 +0800 |
---|---|---|
committer | sumneko <sumneko@hotmail.com> | 2019-04-18 17:22:09 +0800 |
commit | d138a03445f19238aa33901546e7033aca2eff33 (patch) | |
tree | 8b2a1c8a021901e5780a5c8391059a8d72c6aadc /server/src/core | |
parent | f077aa010aa2ae0a2cc6edbc345eaf4056b96e2b (diff) | |
download | lua-language-server-d138a03445f19238aa33901546e7033aca2eff33.zip |
整理代码
Diffstat (limited to 'server/src/core')
-rw-r--r-- | server/src/core/completion.lua | 13 | ||||
-rw-r--r-- | server/src/core/find_source.lua | 24 |
2 files changed, 29 insertions, 8 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index cef8b798..78dab7bc 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -642,7 +642,18 @@ 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) or findSource(vm, pos+1) + local filter = { + ['name'] = true, + ['string'] = true, + ['.'] = true, + [':'] = true, + ['emmyName'] = true, + ['emmyIncomplete'] = true, + ['call'] = true, + } + local source = findSource(vm, pos, filter) + or findSource(vm, pos-1, filter) + or findSource(vm, pos+1, filter) if not source then return nil end diff --git a/server/src/core/find_source.lua b/server/src/core/find_source.lua index 79ff85f9..cac3a263 100644 --- a/server/src/core/find_source.lua +++ b/server/src/core/find_source.lua @@ -9,13 +9,23 @@ local function isValidSource(source) return source.start ~= nil and source.start ~= 0 end -local function findAtPos(sources, pos, level) +local function matchFilter(source, filter) + if not filter then + return true + end + return filter[source.type] +end + +local function findAtPos(vm, pos, filter) local res = {} - for _, source in ipairs(sources) do - if isValidSource(source) and isContainPos(source, pos) then + vm:eachSource(function (source) + if isValidSource(source) + and isContainPos(source, pos) + and matchFilter(source, filter) + then res[#res+1] = source end - end + end) if #res == 0 then return nil end @@ -35,13 +45,13 @@ local function findAtPos(sources, pos, level) end return rangeA < rangeB end) - local source = res[level or 1] + local source = res[1] if not source then return nil end return source end -return function (vm, pos, level) - return findAtPos(vm.sources, pos, level) +return function (vm, pos, filter) + return findAtPos(vm, pos, filter) end |