anchor.diff:                                               miscFilesWorkspace: Workspace, 
                                                projectContextFactory: IFSharpWorkspaceProjectContextFactory) =
   
  -    // We have a lock because the `ScriptUpdated` event may happen concurrently when a document opens or closes.
  -    let gate = obj()
  -    let files = ConcurrentDictionary(StringComparer.OrdinalIgnoreCase)
  +    let files = ConcurrentDictionary<string, Lazy<IFSharpWorkspaceProjectContext>>(StringComparer.OrdinalIgnoreCase)
       let optionsManager = workspace.Services.GetRequiredService<IFSharpWorkspaceService>().FSharpProjectOptionsManager
   
       static let mustUpdateProjectReferences (refSourceFiles: string []) (projectContext: IFSharpWorkspaceProjectContext) =
  
positive.code:                 | None -> ()
                  | Some(document) ->                           
                      optionsManager.ClearSingleFileOptionsCache(document.Id)
                      projectContext.Dispose()
                      files.[newFilePath] <- projectContextFactory.CreateProjectContext(newFilePath)
              else
                  projectContext.Dispose() // fallback, shouldn't happen, but in case it does let's dispose of the project context so we don't leak
          | _ -> ()
  
  [<Sealed>]
  
negative.code:             // a F# miscellaneous project, which could be a script or not.
              if document.Project.IsFSharp && workspace.CurrentSolution.GetDocumentIdsWithFilePath(document.FilePath).Length = 0 then
                  let filePath = document.FilePath
                  let createProjectContext = lazy projectContextFactory.CreateProjectContext(filePath)
                  if files.TryAdd(filePath, createProjectContext) then
                      createProjectContext.Force() |> ignore
          )
  
          workspace.DocumentOpened.Add(fun args ->
              let document = args.Document
              if not document.Project.IsFSharpMiscellaneousOrMetadata then
                  match files.TryRemove(document.FilePath) with
                  | true, projectContext ->
                      (projectContext.Value :> IDisposable).Dispose()
                      tryRemove document
                  | _ ->
                      ()
          )
  
          workspace.DocumentClosed.Add(fun args ->
              let document = args.Document
              if document.Project.IsFSharpMiscellaneousOrMetadata then
                  tryRemove document
          )
  
          workspace.WorkspaceChanged.Add(fun args ->
  