diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-24 18:26:57 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-24 18:26:57 +0800 |
commit | 1ec9c8e266df6db7a72608bfb5431f444e3a12ff (patch) | |
tree | c1f9bb92e9a350e1bd335ca38029b84f0e75884c | |
parent | b7782be38cb8f9d3f94b615976cdfed00e4c183f (diff) | |
download | lua-language-server-1ec9c8e266df6db7a72608bfb5431f444e3a12ff.zip |
过滤一些结果
-rw-r--r-- | server/src/matcher/completion.lua | 19 | ||||
-rw-r--r-- | server/src/workspace.lua | 8 | ||||
-rw-r--r-- | server/test/crossfile/completion.lua | 46 |
3 files changed, 60 insertions, 13 deletions
diff --git a/server/src/matcher/completion.lua b/server/src/matcher/completion.lua index 64ed9428..6debe930 100644 --- a/server/src/matcher/completion.lua +++ b/server/src/matcher/completion.lua @@ -231,7 +231,9 @@ local function searchAsArg(vm, inCall, inString, callback) return end for _, v in ipairs(results) do - callback(v, CompletionItemKind.Module) + if v ~= inString[1] then + callback(v, CompletionItemKind.Module) + end end end end @@ -344,14 +346,15 @@ return function (vm, pos) if not result then return nil end - inString = getString(vm, pos) - if inString then - local calls = findCall(vm, pos) - if not calls then - return nil - end - inCall = calls[#calls] + end + + inString = getString(vm, pos) + if inString then + local calls = findCall(vm, pos) + if not calls then + return nil end + inCall = calls[#calls] end local list = {} diff --git a/server/src/workspace.lua b/server/src/workspace.lua index 862a163b..f87912e6 100644 --- a/server/src/workspace.lua +++ b/server/src/workspace.lua @@ -161,9 +161,9 @@ function mt:convertPathAsRequire(filename, start) return list end -function mt:matchPath(str) - str = str:lower() - local first = str:match '[^%.]+' +function mt:matchPath(input) + input = input:lower() + local first = input:match '[^%.]+' if not first then return nil end @@ -175,7 +175,7 @@ function mt:matchPath(str) local list = self:convertPathAsRequire(filename, start + 1) if list then for _, str in ipairs(list) do - if not results[str] then + if not results[str] and #str >= #input then results[str] = true results[#results+1] = str end diff --git a/server/test/crossfile/completion.lua b/server/test/crossfile/completion.lua index 37f1f5d7..180745cb 100644 --- a/server/test/crossfile/completion.lua +++ b/server/test/crossfile/completion.lua @@ -1,4 +1,4 @@ -local service = require 'server' +local service = require 'service' local workspace = require 'workspace' local fs = require 'bee.filesystem' local matcher = require 'matcher' @@ -147,3 +147,47 @@ TEST { }, } } + +TEST { + { + path = 'abc.lua', + content = '', + }, + { + path = 'abc/init.lua', + content = '', + }, + { + path = 'test.lua', + content = 'require "abc@"', + main = true, + }, + completion = { + { + label = 'abc.init', + kind = CompletionItemKind.Module, + }, + } +} + +TEST { + { + path = 'abc.lua', + content = '', + }, + { + path = 'abc/init.lua', + content = '', + }, + { + path = 'test.lua', + content = 'require "abc.@"', + main = true, + }, + completion = { + { + label = 'abc.init', + kind = CompletionItemKind.Module, + }, + } +} |