Пример #1
0
        /// <summary>
        /// Dequeues all lines whose content has changed and extracts the code fragments overlapping with those lines that need to be reprocessed.
        /// Does nothing if no lines have been modified.
        /// Recomputes and pushes the syntax diagnostics for the extracted fragments and all end-of-file diagnostics otherwise.
        /// Processes the extracted fragment and inserts the processed fragments into the corresponding data structure
        /// Throws an ArgumentNullException if file is null.
        /// </summary>
        internal static void UpdateLanguageProcessing(this FileContentManager file)
        {
            if (file == null)
            {
                throw new ArgumentNullException(nameof(file));
            }

            file.SyncRoot.EnterUpgradeableReadLock();
            try
            {
                var changedLines = file.DequeueContentChanges();
                if (!changedLines.Any())
                {
                    return;
                }

                var reprocess   = QsCompilerError.RaiseOnFailure(() => file.FragmentsToProcess(changedLines).ToList(), "processing the edited lines failed");
                var diagnostics = reprocess.CheckForEmptyFragments(file.FileName.Value)
                                  .Concat(ParseCode(ref reprocess, file.FileName.Value)).ToList();

                QsCompilerError.RaiseOnFailure(() => file.TokensUpdate(reprocess), "the computed token update failed");
                QsCompilerError.RaiseOnFailure(() => file.AddSyntaxDiagnostics(diagnostics), "updating the SyntaxDiagnostics failed");
            }
            finally { file.SyncRoot.ExitUpgradeableReadLock(); }
        }