Example #1
0
        internal CodeFragment SetClosingComments(IEnumerable <string?> commentsAfter)
        {
            var relevantComments = commentsAfter.SkipWhile(c => c == null).Reverse();

            relevantComments = relevantComments.SkipWhile(c => c == null).Reverse();
            var comments = new QsComments(this.Comments.OpeningComments, relevantComments.Select(c => c ?? string.Empty).ToImmutableArray());

            return(new CodeFragment(this.Indentation, this.Range, this.Text, this.FollowedBy, comments, this.Kind, this.IncludeInCompilation));
        }
Example #2
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, Range range, string text, char next, QsComments?comments, QsFragmentKind?kind, bool include)
 {
     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();
     this.FollowedBy           = next;
     this.Comments             = comments ?? QsComments.Empty;
     this.Kind                 = kind; // nothing here should be modifiable
     this.Range                = range;
     this.HeaderRange          = GetHeaderRange(this.Text, this.Kind);
     this.IncludeInCompilation = include;
 }
Example #3
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, 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;
 }