From 0967e3ad5e797015a40e9cfdf6e5dca58a3289c5 Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Thu, 25 Apr 2024 10:55:30 -0400 Subject: [PATCH] only allow one GetProjectOptionsFromScript at a time https://github.com/ionide/ionide-vscode-fsharp/issues/2005 --- .../CompilerServiceInterface.fs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/FsAutoComplete.Core/CompilerServiceInterface.fs b/src/FsAutoComplete.Core/CompilerServiceInterface.fs index a40b70486..4dd597b14 100644 --- a/src/FsAutoComplete.Core/CompilerServiceInterface.fs +++ b/src/FsAutoComplete.Core/CompilerServiceInterface.fs @@ -12,6 +12,7 @@ open FSharp.Compiler.Symbols open Microsoft.Extensions.Caching.Memory open System open FsToolkit.ErrorHandling +open System.Threading @@ -34,6 +35,10 @@ type FSharpCompilerServiceChecker(hasAnalyzers, typecheckCacheSize, parallelRefe let entityCache = EntityCache() + // FCS can't seem to handle parallel project restores for script files + // https://github.com/ionide/ionide-vscode-fsharp/issues/2005 + let scriptLocker = new SemaphoreSlim(1,1) + // This is used to hold previous check results for autocompletion. // We can't seem to rely on the checker for previous cached versions let memoryCache () = @@ -210,10 +215,15 @@ type FSharpCompilerServiceChecker(hasAnalyzers, typecheckCacheSize, parallelRefe return modified, errors } - member self.GetProjectOptionsFromScript(file: string, source, tfm) = - match tfm with - | FSIRefs.TFM.NetFx -> self.GetNetFxScriptOptions(file, source) - | FSIRefs.TFM.NetCore -> self.GetNetCoreScriptOptions(file, source) + member self.GetProjectOptionsFromScript(file: string, source, tfm) = async { + try + do! scriptLocker.WaitAsync() |> Async.AwaitTask + match tfm with + | FSIRefs.TFM.NetFx -> return! self.GetNetFxScriptOptions(file, source) + | FSIRefs.TFM.NetCore -> return! self.GetNetCoreScriptOptions(file, source) + finally + scriptLocker.Release() |> ignore + } member __.ScriptTypecheckRequirementsChanged =