summaryrefslogtreecommitdiff
path: root/script/workspace/workspace.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-01-05 15:15:23 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-01-05 15:15:23 +0800
commit586953c48638abf79c1855d9ba82f22bbcd6d448 (patch)
treebb912e0cfe74488d80439cfe64e53954a1e34979 /script/workspace/workspace.lua
parent8dc74fe9232e08f5263bbaab659dd1a8ab84ae50 (diff)
downloadlua-language-server-586953c48638abf79c1855d9ba82f22bbcd6d448.zip
improve getLinks
Diffstat (limited to 'script/workspace/workspace.lua')
-rw-r--r--script/workspace/workspace.lua27
1 files changed, 27 insertions, 0 deletions
diff --git a/script/workspace/workspace.lua b/script/workspace/workspace.lua
index cb033582..f99092bc 100644
--- a/script/workspace/workspace.lua
+++ b/script/workspace/workspace.lua
@@ -300,9 +300,19 @@ function m.findUrisByFilePath(path)
if type(path) ~= 'string' then
return {}
end
+ local lpath = path:lower():gsub('[/\\]+', '/')
+ local vm = require 'vm'
+ local resultCache = vm.getCache 'findUrisByRequirePath.result'
+ if resultCache[path] then
+ return resultCache[path].results, resultCache[path].posts
+ end
+ tracy.ZoneBeginN('findUrisByFilePath #1')
local results = {}
local posts = {}
for uri in files.eachFile() do
+ if not uri:find(lpath, 1, true) then
+ goto CONTINUE
+ end
local pathLen = #path
local curPath = furi.decode(files.getOriginUri(uri))
local curLen = #curPath
@@ -315,7 +325,13 @@ function m.findUrisByFilePath(path)
posts[uri] = post:gsub('^[/\\]+', '')
end
end
+ ::CONTINUE::
end
+ tracy.ZoneEnd()
+ resultCache[path] = {
+ results = results,
+ posts = posts,
+ }
return results, posts
end
@@ -325,6 +341,12 @@ function m.findUrisByRequirePath(path)
if type(path) ~= 'string' then
return {}
end
+ local vm = require 'vm'
+ local cache = vm.getCache 'findUrisByRequirePath'
+ if cache[path] then
+ return cache[path].results, cache[path].searchers
+ end
+ tracy.ZoneBeginN('findUrisByRequirePath')
local results = {}
local mark = {}
local searchers = {}
@@ -350,6 +372,11 @@ function m.findUrisByRequirePath(path)
end
end
end
+ tracy.ZoneEnd()
+ cache[path] = {
+ results = results,
+ searchers = searchers,
+ }
return results, searchers
end