summaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-25 09:42:19 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-25 09:42:19 +0800
commitaf44e932a9d73a43b5d6524712856b3e5c1ca462 (patch)
treefcc989650c533be9fda8a8ea04438a7e8a789f17 /server/src
parent15aa26dfdd8e79f297f8c781c7de1ab228099c7e (diff)
downloadlua-language-server-af44e932a9d73a43b5d6524712856b3e5c1ca462.zip
require列出的模块会根据相似度排序
Diffstat (limited to 'server/src')
-rw-r--r--server/src/matcher/completion.lua2
-rw-r--r--server/src/workspace.lua33
2 files changed, 26 insertions, 9 deletions
diff --git a/server/src/matcher/completion.lua b/server/src/matcher/completion.lua
index 6debe930..8b309880 100644
--- a/server/src/matcher/completion.lua
+++ b/server/src/matcher/completion.lua
@@ -226,7 +226,7 @@ local function searchAsArg(vm, inCall, inString, callback)
if not vm.lsp or not vm.lsp.workspace then
return
end
- local results = vm.lsp.workspace:matchPath(inString[1])
+ local results = vm.lsp.workspace:matchPath(vm.uri, inString[1])
if not results then
return
end
diff --git a/server/src/workspace.lua b/server/src/workspace.lua
index f87912e6..ba324aad 100644
--- a/server/src/workspace.lua
+++ b/server/src/workspace.lua
@@ -161,33 +161,50 @@ function mt:convertPathAsRequire(filename, start)
return list
end
-function mt:matchPath(input)
+function mt:matchPath(baseUri, input)
input = input:lower()
local first = input:match '[^%.]+'
if not first then
return nil
end
+ local baseName = self:uriDecode(baseUri):string():lower()
local rootLen = #self.root:string()
- local results = {}
+ local map = {}
for filename in pairs(self.files) do
local start = filename:find('/' .. first, rootLen + 1, true)
if start then
local list = self:convertPathAsRequire(filename, start + 1)
if list then
for _, str in ipairs(list) do
- if not results[str] and #str >= #input then
- results[str] = true
- results[#results+1] = str
+ if #str >= #input then
+ if not map[str]
+ or similarity(filename, baseName) > similarity(map[str], baseName)
+ then
+ map[str] = filename
+ end
end
end
end
end
end
- if #results == 0 then
+
+ local list = {}
+ for str in pairs(map) do
+ list[#list+1] = str
+ end
+ if #list == 0 then
return nil
end
- table.sort(results)
- return results
+ table.sort(list, function (a, b)
+ local sa = similarity(map[a], baseName)
+ local sb = similarity(map[b], baseName)
+ if sa == sb then
+ return a < b
+ else
+ return sa > sb
+ end
+ end)
+ return list
end
function mt:searchPath(baseUri, str)