Skip to content

Commit 40b599a

Browse files
author
Eli Dowling
committed
fixed mistake in cache hash checking code
1 parent ad91310 commit 40b599a

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

src/FSharpLanguageServer/ProjectManager/FileCache.fs

+10-7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ let settings =
4848
ConstructorHandling=ConstructorHandling.AllowNonPublicDefaultConstructor,
4949
Converters=[|new FileInfoConverter()|]
5050
)
51+
5152
let extraEncoders=
5253
Extra.empty
5354
|>(Extra.withCustom
@@ -56,33 +57,35 @@ let extraEncoders=
5657
|>Extra.withCustom
5758
(fun (x:Range)->Encode.string <|System.Text.Json.JsonSerializer.Serialize(x))
5859
(fun path value->Ok (System.Text.Json.JsonSerializer.Deserialize<Range>(value.ToString()) ))
60+
5961
///Uses various methods to decide if the cache is still valid or if it needs to be discarded and replaced.
6062
let isCacheValid (fsprojPath:string) (cachePath:string) (cacheData:CacheData)=
6163

6264
let assetsPath=Path.Combine(Path.GetDirectoryName(cachePath),"project.assets.json")
6365
let assetHash= getHash assetsPath
6466
let fsprojHash= getHash fsprojPath
6567
cacheData.assetsHash=assetHash && cacheData.fsprojHash=fsprojHash && cacheData.version=currentVersion
68+
6669
///**Attempts to get cached project data.**
6770
///
6871
///O returns the data if the project.assets.json files hash has not changed. A change would indicate that the cached data may no longer be valid.
6972
let tryGetCached (fsproj:FileInfo)=
70-
let cachePath=getCachePath fsproj.FullName
71-
if File.Exists(cachePath)then
72-
let cacheJson= File.ReadAllText(cachePath)
73+
let cacheFilePath=getCachePath fsproj.FullName
74+
if File.Exists(cacheFilePath)then
75+
let cacheJson= File.ReadAllText(cacheFilePath)
7376

7477
try
75-
let cacheData=match(Decode.Auto.fromString(cacheJson,extra=extraEncoders))with|Ok a->a|Error e->failwithf "error %A"e
78+
let existingCacheData=match(Decode.Auto.fromString(cacheJson,extra=extraEncoders))with|Ok a->a|Error e->failwithf "error %A"e
7679

77-
if isCacheValid fsproj.FullName cacheJson cacheData then Ok cacheData
80+
if isCacheValid fsproj.FullName cacheFilePath existingCacheData then Ok existingCacheData
7881
else
79-
File.Delete(cachePath)
82+
File.Delete(cacheFilePath)
8083
lgInfo "Not using cached projOptions for '{proj}' because the project.assets.json hash has changed" fsproj.FullName
8184
Error "Hash had changed"
8285
with
8386
|e->
8487
lgWarn2 "Cached projectOptions for '{proj}' could not be read, deleting it \nReson {exception}" fsproj e
85-
File.Delete(cachePath)
88+
File.Delete(cacheFilePath)
8689
Error(sprintf "%A" e)
8790
else Error "no cache file exists"
8891

0 commit comments

Comments
 (0)