/// <summary>
        /// Dequeues all lines whose tokens has changed and verifies the positions of these tokens.
        /// Does nothing if no lines have been modified.
        /// Recomputes and pushes the context diagnostics for the processed tokens otherwise.
        /// </summary>
        internal static void UpdateContext(this FileContentManager file)
        {
            file.SyncRoot.EnterUpgradeableReadLock();
            try
            {
                var changedLines = file.DequeueTokenChanges();
                if (!changedLines.Any())
                {
                    return;
                }
                QsCompilerError.RaiseOnFailure(
                    () =>
                {
                    var verifiedLines = file.VerifyContext(changedLines, out List <Diagnostic> diagnostics);
                    file.UpdateContextDiagnostics(verifiedLines, diagnostics);
                },
                    "updating the ContextDiagnostics failed");

                var edited = file.CallablesWithContentModifications(changedLines);
                file.MarkCallableAsContentEdited(edited);
            }
            finally
            {
                file.SyncRoot.ExitUpgradeableReadLock();
            }
        }