@@ -42,23 +42,31 @@ local function GetRelativePath(Path: string, RelativeTo: string)
4242 return Path
4343end
4444
45- local function GetLibraries (RelativeTo : string , _Libraries , _Uri : Uri ? )
45+
46+ local LibraryCache
47+ local LibraryCacheExpiration = 0
48+ local function GetLibraries (_Libraries , _Uri : Uri ? )
49+ if not _Libraries and LibraryCache and LibraryCacheExpiration > os.clock () then
50+ return LibraryCache
51+ end
52+
4653 local Libraries = (_Libraries or {})
4754 local Uri = (_Uri or lsp .workspace .getRootUri ())
4855
49- RelativeTo = NormalizePath (RelativeTo )
50-
5156 for _ , Entry in lsp .fs .listDirectory (Uri ) do
5257 local Name = string.sub (Entry :toString (), # Uri :toString () + 2 )
5358 local Library = string.match (Name , "(.*)%.meta%.json$" )
5459
5560 if Library and IsLibrary (Entry ) then
56- Libraries [Library ] = (string.sub (GetRelativePath ( Entry .path , RelativeTo ) , 1 , - # Name - 1 ) .. Library )
61+ Libraries [Library ] = (string.sub (Entry .path , 1 , - # Name - 1 ) .. Library )
5762 else
58- pcall (GetLibraries , RelativeTo , Libraries , Entry )
63+ pcall (GetLibraries , Libraries , Entry )
5964 end
6065 end
6166
67+ LibraryCache = Libraries
68+ LibraryCacheExpiration = (os.clock () + 5 )
69+
6270 return Libraries
6371end
6472
@@ -67,7 +75,12 @@ return {
6775 local Changes = {}
6876 local Line , LineStart = 1 , 1
6977
70- local Libraries = GetLibraries (GetParentDirectory (Context .filePath ))
78+ local Libraries = {}
79+ local Parent = GetParentDirectory (Context .filePath )
80+
81+ for Index , Library in GetLibraries () do
82+ Libraries [Index ] = GetRelativePath (Library , Parent )
83+ end
7184
7285 for Index = 1 , # Source do
7386 if string.sub (Source , Index , Index ) == "\n " then
0 commit comments