From d435c11519fdd09a759cb7b2b91848bf86b2ac51 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, 15 insertions(+), 3 deletions(-) diff --git a/src/FsAutoComplete.Core/CompilerServiceInterface.fs b/src/FsAutoComplete.Core/CompilerServiceInterface.fs index a40b70486..870407994 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 () = @@ -211,9 +216,16 @@ type FSharpCompilerServiceChecker(hasAnalyzers, typecheckCacheSize, parallelRefe } member self.GetProjectOptionsFromScript(file: string, source, tfm) = - match tfm with - | FSIRefs.TFM.NetFx -> self.GetNetFxScriptOptions(file, source) - | FSIRefs.TFM.NetCore -> self.GetNetCoreScriptOptions(file, source) + 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 =