Ejemplo n.º 1
0
 /// <summary>
 /// Note that the only thing that may be set to null is the fragment kind - all other properties need to be set upon initialization
 /// </summary>
 private CodeFragment(int indent, LSP.Range r, string text, char next, QsComments comments, QsFragmentKind kind, bool include)
 {
     if (!Utils.IsValidRange(r))
     {
         throw new ArgumentException("invalid range for code fragment");
     }
     if (!DelimitingChars.Contains(next) && next != MissingDelimiter)
     {
         throw new ArgumentException("a CodeFragment needs to be followed by a DelimitingChar");
     }
     this.Indentation          = indent < 0 ? throw new ArgumentException("indentation needs to be positive") : indent;
     this.Text                 = text?.TrimEnd() ?? throw new ArgumentNullException(nameof(text));
     this.FollowedBy           = next;
     this.Comments             = comments ?? QsComments.Empty;
     this.Kind                 = kind; // nothing here should be modifiable
     this.fragmentRange        = r.Copy();
     this.HeaderRange          = GetHeaderRange(this.Text, this.Kind);
     this.IncludeInCompilation = include;
 }
Ejemplo n.º 2
0
        /// <summary>
        /// Verifies the given Range, and returns a *new* Range with updated line numbers.
        /// Throws an ArgumentNullException if the given Range is null.
        /// Throws an ArgumentException if the given Range is invalid.
        /// Throws and ArgumentOutOfRangeException if the updated line number is negative.
        /// </summary>
        public static LSP.Range WithUpdatedLineNumber(this LSP.Range range, int lineNrChange)
        {
            if (lineNrChange == 0)
            {
                return(range ?? throw new ArgumentNullException(nameof(range)));
            }
            if (!Utils.IsValidRange(range))
            {
                throw new ArgumentException($"invalid Range in {nameof(WithUpdatedLineNumber)}");                             // range can be empty
            }
            if (range.Start.Line + lineNrChange < 0)
            {
                throw new ArgumentOutOfRangeException(nameof(lineNrChange));
            }
            var updated = range.Copy();

            updated.Start.Line += lineNrChange;
            updated.End.Line   += lineNrChange;
            return(updated);
        }