anchor.diff:              // 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
  -                lock gate (fun () ->
  -                    if files.ContainsKey(filePath) |> not then
  -                        files.[filePath] <- projectContextFactory.CreateProjectContext(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
  -                if files.ContainsKey(document.FilePath) then
  -                    lock gate (fun () ->
  -                        tryRemove document
  -                    )
  +                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
  -                lock gate (fun () ->
  -                    tryRemove document
  -                )
  +                tryRemove document
           )
   
           workspace.WorkspaceChanged.Add(fun args ->
  
positive.code: 
              match files.TryRemove(document.FilePath) with
              | true, projectContext ->
                  (projectContext :> IDisposable).Dispose()
              | _ ->
                  ()
  
  
negative.code:                 | None -> ()
                  | Some(document) ->                           
                      optionsManager.ClearSingleFileOptionsCache(document.Id)
                      projectContext.Value.Dispose()
                      let newProjectContext = lazy projectContextFactory.CreateProjectContext(newFilePath)
                      if files.TryAdd(newFilePath, newProjectContext) then
                          newProjectContext.Force() |> ignore
              else
                  projectContext.Value.Dispose() // fallback, shouldn't happen, but in case it does let's dispose of the project context so we don't leak
          | _ -> ()
  
  [<Sealed>]
  