From ee28ad3c8fb0167b3d0c182316de20e099c74a03 Mon Sep 17 00:00:00 2001 From: Jimmy Byrd Date: Sat, 15 Jul 2023 10:48:59 -0400 Subject: [PATCH] Remove Async.SwitchToNewThreadCalls (#1144) since https://github.com/dotnet/fsharp/issues/14899 got merged in FCS, it seems we don't hit threadpool exhaustion issues anymore --- src/FsAutoComplete.Core/CompilerServiceInterface.fs | 12 ------------ .../LspServers/AdaptiveFSharpLspServer.fs | 1 + 2 files changed, 1 insertion(+), 12 deletions(-) diff --git a/src/FsAutoComplete.Core/CompilerServiceInterface.fs b/src/FsAutoComplete.Core/CompilerServiceInterface.fs index 7f4bc9299..1ea00f523 100644 --- a/src/FsAutoComplete.Core/CompilerServiceInterface.fs +++ b/src/FsAutoComplete.Core/CompilerServiceInterface.fs @@ -165,8 +165,6 @@ type FSharpCompilerServiceChecker(hasAnalyzers, typecheckCacheSize) = let allFlags = Array.append [| "--targetprofile:mscorlib" |] fsiAdditionalArguments - do! Async.SwitchToNewThread() - let! (opts, errors) = checker.GetProjectOptionsFromScript( UMX.untag file, @@ -192,8 +190,6 @@ type FSharpCompilerServiceChecker(hasAnalyzers, typecheckCacheSize) = let allFlags = Array.append [| "--targetprofile:netstandard" |] fsiAdditionalArguments - do! Async.SwitchToNewThread() - let! (opts, errors) = checker.GetProjectOptionsFromScript( UMX.untag file, @@ -269,7 +265,6 @@ type FSharpCompilerServiceChecker(hasAnalyzers, typecheckCacheSize) = ) let path = UMX.untag filePath - do! Async.SwitchToNewThread() return! checker.ParseFile(path, source, options) } @@ -299,7 +294,6 @@ type FSharpCompilerServiceChecker(hasAnalyzers, typecheckCacheSize) = let path = UMX.untag filePath try - do! Async.SwitchToNewThread() let! (p, c) = checker.ParseAndCheckFileInProject(path, version, source, options, userOpName = opName) let parseErrors = p.Diagnostics |> Array.map (fun p -> p.Message) @@ -394,8 +388,6 @@ type FSharpCompilerServiceChecker(hasAnalyzers, typecheckCacheSize) = >> Log.addContextDestructured "file" file ) - do! Async.SwitchToNewThread() - match FSharpCompilerServiceChecker.GetDependingProjects file options with | None -> return [||] | Some(opts, []) -> @@ -407,7 +399,6 @@ type FSharpCompilerServiceChecker(hasAnalyzers, typecheckCacheSize) = opts :: dependentProjects |> List.map (fun (opts) -> async { - do! Async.SwitchToNewThread() let opts = clearProjectReferences opts let! res = checker.ParseAndCheckProject opts return res.GetUsesOfSymbol symbol @@ -424,8 +415,6 @@ type FSharpCompilerServiceChecker(hasAnalyzers, typecheckCacheSize) = >> Log.addContextDestructured "file" file ) - do! Async.SwitchToNewThread() - return! checker.FindBackgroundReferencesInFile( file, @@ -444,7 +433,6 @@ type FSharpCompilerServiceChecker(hasAnalyzers, typecheckCacheSize) = >> Log.addContextDestructured "file" fileName ) - do! Async.SwitchToNewThread() let! parseResult = checker.ParseFile(UMX.untag fileName, source, options) return parseResult.GetNavigationItems().Declarations } diff --git a/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs b/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs index 3321c2438..aa91a1933 100644 --- a/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs +++ b/src/FsAutoComplete/LspServers/AdaptiveFSharpLspServer.fs @@ -385,6 +385,7 @@ type AdaptiveFSharpLspServer match parseAndCheck.GetCheckResults.ImplementationFile with | Some tast -> + // Since analyzers are not async, we need to switch to a new thread to not block threadpool do! Async.SwitchToNewThread() let res =