Esempio n. 1
0
        }                                                                                           // will raise an exception if file is null

        // the actual update routine

        /// <summary>
        /// Attempts to perform the necessary updates when replacing the range [start, start + count) by newText for the given file
        /// wrapping each step in a QsCompilerError.RaiseOnFailure.
        /// </summary>
        private static void Update(this FileContentManager file, int start, int count, IEnumerable <string> newText)
        {
            CodeLine[] replacements = QsCompilerError.RaiseOnFailure(() =>
                                                                     ComputeCodeLines(newText, start > 0 ? file.GetLine(start - 1) : null).ToArray(),
                                                                     "scope tracking update failed during computing the replacements");

            IEnumerable <CodeLine> updateRemaining = QsCompilerError.RaiseOnFailure(() =>
                                                                                    ComputeUpdates(file, start, count, replacements),
                                                                                    "scope tracking update failed during computing the updates");

            QsCompilerError.RaiseOnFailure(() =>
            {
                if (updateRemaining == null)
                {
                    file.ContentUpdate(start, count, replacements);
                }
                else
                {
                    file.ContentUpdate(start, file.NrLines() - start, replacements.Concat(updateRemaining).ToArray());
                }
            }, "the proposed ContentUpdate failed");

            QsCompilerError.RaiseOnFailure(() =>
            {
                if (updateRemaining == null)
                {
                    file.AddScopeDiagnostics(file.ComputeScopeDiagnostics(start, replacements.Length));
                }
                else
                {
                    file.AddScopeDiagnostics(file.ComputeScopeDiagnostics(start));
                }
                file.AddScopeDiagnostics(file.CheckForMissingClosings());
            }, "updating the scope diagnostics failed");
        }