summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-03-29 10:06:57 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-03-29 10:06:57 +0800
commit51fdb8bbd4a78703ca0dd95a68d09e8a188407c3 (patch)
treeea4333c239be74efc934a859cb7276ea3caad444 /server
parent7ab564aad9fe823ff90614b106853f05be001fe4 (diff)
downloadlua-language-server-51fdb8bbd4a78703ca0dd95a68d09e8a188407c3.zip
修正相似度排序的问题
Diffstat (limited to 'server')
-rw-r--r--server/src/workspace.lua14
-rw-r--r--server/test/crossfile/completion.lua8
2 files changed, 15 insertions, 7 deletions
diff --git a/server/src/workspace.lua b/server/src/workspace.lua
index fe1289f4..b05105a0 100644
--- a/server/src/workspace.lua
+++ b/server/src/workspace.lua
@@ -225,10 +225,18 @@ function mt:matchPath(baseUri, input)
if list then
for _, str in ipairs(list) do
if #str >= #input and str:sub(1, #input) == input then
- if not map[str]
- or similarity(filename, baseName) > similarity(map[str], baseName)
- then
+ if not map[str] then
map[str] = filename
+ else
+ local s1 = similarity(filename, baseName)
+ local s2 = similarity(map[str], baseName)
+ if s1 > s2 then
+ map[str] = filename
+ elseif s1 == s2 then
+ if filename < map[str] then
+ map[str] = filename
+ end
+ end
end
end
end
diff --git a/server/test/crossfile/completion.lua b/server/test/crossfile/completion.lua
index b5c3bc1b..16d1460f 100644
--- a/server/test/crossfile/completion.lua
+++ b/server/test/crossfile/completion.lua
@@ -298,15 +298,15 @@ TEST {
},
completion = {
{
- label = 'x111',
+ label = 'x000',
kind = CompletionItemKind.File,
- documentation = 'abc/x111.lua',
+ documentation = 'x000.lua',
textEdit = EXISTS,
},
{
- label = 'x000',
+ label = 'x111',
kind = CompletionItemKind.File,
- documentation = 'x000.lua',
+ documentation = 'abc/x111.lua',
textEdit = EXISTS,
},
}