diff options
Diffstat (limited to 'server/src/core')
-rw-r--r-- | server/src/core/completion.lua | 70 | ||||
-rw-r--r-- | server/src/core/matchKey.lua | 30 |
2 files changed, 31 insertions, 69 deletions
diff --git a/server/src/core/completion.lua b/server/src/core/completion.lua index bf9b8d84..f84243a5 100644 --- a/server/src/core/completion.lua +++ b/server/src/core/completion.lua @@ -3,6 +3,7 @@ local getFunctionHover = require 'core.hover.function' local getFunctionHoverAsLib = require 'core.hover.lib_function' local sourceMgr = require 'vm.source' local config = require 'config' +local matchKey = require 'core.matchKey' local State local CompletionItemKind = { @@ -41,75 +42,6 @@ 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 - end - if me == '' then - return true - end - if #me > #other then - return false - end - local lMe = me:lower() - local lOther = other:lower() - if lMe:sub(1, 1) ~= lOther:sub(1, 1) then - return false - end - if lMe == lOther:sub(1, #lMe) then - return true - end - local used = {} - local cur = 1 - local lookup - local researched - for i = 1, #lMe do - local c = lMe:sub(i, i) - -- 1. 看当前字符是否匹配 - if c == lOther:sub(cur, cur) then - used[cur] = true - goto NEXT - end - -- 2. 看前一个字符是否匹配 - if not used[cur-1] then - if c == lOther:sub(cur-1, cur-1) then - used[cur-1] = true - goto NEXT - end - end - -- 3. 向后找这个字 - lookup = lOther:find(c, cur+1, true) - if lookup then - cur = lookup - used[cur] = true - goto NEXT - end - - -- 4. 重新搜索整个字符串,但是只允许1次,否则失败.如果找不到也失败 - if researched then - return false - else - researched = true - for j = 1, cur - 2 do - if c == lOther:sub(j, j) then - used[j] = true - goto NEXT - end - end - return false - end - -- 5. 找到下一个可用的字,如果超出长度且把自己所有字都用尽就算成功 - ::NEXT:: - repeat - cur = cur + 1 - until not used[cur] - if cur > #lOther then - return i == #lMe - end - end - return true -end - local function getDucumentation(name, value) if value:getType() == 'function' then local lib = value:getLib() diff --git a/server/src/core/matchKey.lua b/server/src/core/matchKey.lua new file mode 100644 index 00000000..b46250cb --- /dev/null +++ b/server/src/core/matchKey.lua @@ -0,0 +1,30 @@ +return function (me, other) + if me == other then + return true + end + if me == '' then + return true + end + if #me > #other then + return false + end + local lMe = me:lower() + local lOther = other:lower() + if lMe == lOther:sub(1, #lMe) then + return true + end + local chars = {} + for i = 1, #lOther do + local c = lOther:sub(i, i) + chars[c] = (chars[c] or 0) + 1 + end + for i = 1, #lMe do + local c = lMe:sub(i, i) + if chars[c] and chars[c] > 0 then + chars[c] = chars[c] - 1 + else + return false + end + end + return true +end |