summaryrefslogtreecommitdiff
path: root/server/src/workspace.lua
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/workspace.lua
parent15aa26dfdd8e79f297f8c781c7de1ab228099c7e (diff)
downloadlua-language-server-af44e932a9d73a43b5d6524712856b3e5c1ca462.zip
require列出的模块会根据相似度排序
Diffstat (limited to 'server/src/workspace.lua')
-rw-r--r--server/src/workspace.lua33
1 files changed, 25 insertions, 8 deletions
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)