summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server/main.lua2
-rw-r--r--server/src/core/completion.lua70
-rw-r--r--server/src/core/matchKey.lua30
-rw-r--r--server/test/completion/init.lua24
-rw-r--r--server/test/crossfile/completion.lua18
5 files changed, 65 insertions, 79 deletions
diff --git a/server/main.lua b/server/main.lua
index ac7860c5..685fce01 100644
--- a/server/main.lua
+++ b/server/main.lua
@@ -22,7 +22,7 @@ local function tryDebugger()
log.info('Debugger startup, listen port: 11411')
end
---pcall(tryDebugger)
+pcall(tryDebugger)
require 'utility'
require 'global_protect'
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
diff --git a/server/test/completion/init.lua b/server/test/completion/init.lua
index 6a3b6f29..21a80509 100644
--- a/server/test/completion/init.lua
+++ b/server/test/completion/init.lua
@@ -216,6 +216,11 @@ loc$
]]
{
{
+ label = 'collectgarbage',
+ kind = CompletionItemKind.Function,
+ documentation = EXISTS,
+ },
+ {
label = 'local',
kind = CompletionItemKind.Keyword,
}
@@ -320,6 +325,11 @@ local t = {
kind = CompletionItemKind.Property,
},
{
+ label = 'next',
+ kind = CompletionItemKind.Function,
+ documentation = EXISTS,
+ },
+ {
label = 'xpcall',
kind = CompletionItemKind.Function,
documentation = EXISTS,
@@ -746,6 +756,16 @@ else$
detail = EXISTS,
},
{
+ label = 'select',
+ kind = CompletionItemKind.Function,
+ documentation = EXISTS,
+ },
+ {
+ label = 'setmetatable',
+ kind = CompletionItemKind.Function,
+ documentation = EXISTS,
+ },
+ {
label = 'else',
kind = CompletionItemKind.Keyword,
},
@@ -968,5 +988,9 @@ end
{
label = 'type',
kind = CompletionItemKind.Keyword,
+ },
+ {
+ label = 'return',
+ kind = CompletionItemKind.Keyword,
}
}
diff --git a/server/test/crossfile/completion.lua b/server/test/crossfile/completion.lua
index 2c781e9e..67928fb6 100644
--- a/server/test/crossfile/completion.lua
+++ b/server/test/crossfile/completion.lua
@@ -427,31 +427,31 @@ TEST {
{
path = 'a.lua',
content = [[
- abc = 1
+ zabc = 1
]]
},
{
path = 'a.lua',
content = [[
- abcd = print
+ zabcd = print
]]
},
{
path = 'a.lua',
content = [[
- abcdef = 1
+ zabcdef = 1
]]
},
{
path = 'b.lua',
content = [[
- ab$
+ zab$
]],
main = true,
},
completion = {
{
- label = 'abcdef',
+ label = 'zabcdef',
kind = CompletionItemKind.Enum,
detail = '= 1',
},
@@ -468,25 +468,25 @@ TEST {
{
path = 'a.lua',
content = [[
- print(abc)
+ print(zabc)
]]
},
{
path = 'a.lua',
content = [[
- abcdef = 1
+ zabcdef = 1
]]
},
{
path = 'b.lua',
content = [[
- ab$
+ zab$
]],
main = true,
},
completion = {
{
- label = 'abcdef',
+ label = 'zabcdef',
kind = CompletionItemKind.Enum,
detail = '= 1',
},