14 types derived from SourceText
GenerateDocumentationAndConfigFiles (1)
Microsoft.CodeAnalysis (7)
Microsoft.CodeAnalysis.Analyzers (1)
Microsoft.CodeAnalysis.AnalyzerUtilities (1)
Microsoft.CodeAnalysis.CodeStyle (1)
Microsoft.CodeAnalysis.ResxSourceGenerator (1)
Microsoft.CodeAnalysis.Workspaces (1)
Roslyn.Diagnostics.Analyzers (1)
2126 references to SourceText
ConfigurationSchemaGenerator.Tests (2)
dotnet (1)
dotnet-format (39)
EventSourceGenerator (1)
GenerateDocumentationAndConfigFiles (102)
src\roslyn\src\Compilers\Core\Portable\EncodedStringText.cs (11)
72/// Initializes an instance of <see cref="SourceText"/> from the provided stream. This version differs
73/// from <see cref="SourceText.From(Stream, Encoding, SourceHashAlgorithm, bool)"/> in two ways:
91internal static SourceText Create(Stream stream,
103internal static SourceText Create(Stream stream,
136/// Try to create a <see cref="SourceText"/> from the given stream using the given encoding.
143/// <returns>The <see cref="SourceText"/> decoded from the stream.</returns>
146private static SourceText Decode(
165return SourceText.From(bytes.Array,
175return SourceText.From(data, encoding, checksumAlgorithm, throwIfBinaryDetected, canBeEmbedded);
249internal static SourceText Create(Stream stream, Lazy<Encoding> getEncoding, Encoding defaultEncoding, SourceHashAlgorithm checksumAlgorithm, bool canBeEmbedded)
252internal static SourceText Decode(Stream data, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
src\roslyn\src\RoslynAnalyzers\Microsoft.CodeAnalysis.Analyzers\Core\MetaAnalyzers\ReleaseTrackingHelper.cs (8)
46SourceText sourceText,
47Action<string, Version, string, SourceText, TextLine> onDuplicateEntryInRelease,
48Action<TextLine, InvalidEntryKind, string, SourceText> onInvalidEntry,
440public SourceText SourceText { get; }
449TextSpan span, SourceText sourceText,
458TextSpan span, SourceText sourceText,
478TextSpan span, SourceText sourceText,
497TextSpan span, SourceText sourceText,
src\roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\SourceTextExtensions_SharedWithCodeStyle.cs (5)
16public static string GetLeadingWhitespaceOfLineAtPosition(this SourceText text, int position)
32this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden, CancellationToken cancellationToken)
44this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden,
82public static bool AreOnSameLine(this SourceText text, SyntaxToken token1, SyntaxToken token2)
87public static bool AreOnSameLine(this SourceText text, int pos1, int pos2)
src\roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\RefactoringHelpers\AbstractRefactoringHelpers.cs (6)
25public abstract bool IsBetweenTypeMembers(SourceText sourceText, SyntaxNode root, int position, [NotNullWhen(true)] out SyntaxNode? typeDeclaration);
42private static TextSpan GetTrimmedTextSpan(SourceText sourceText, TextSpan span)
60SourceText sourceText, SyntaxNode root, TextSpan selectionRaw, bool allowEmptyNodes, int maxCount, ref TemporaryArray<TSyntaxNode> result, CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode
179SourceText sourceText, SyntaxNode root, int location)
251SourceText sourceText, SyntaxToken tokenOnLocation, int location)
533SourceText sourceText,
Microsoft.Analyzers.Extra.Tests (10)
Microsoft.Analyzers.Local.Tests (10)
Microsoft.AspNetCore.App.Analyzers (14)
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation (3)
Microsoft.AspNetCore.OpenApi.SourceGenerators (1)
Microsoft.AspNetCore.SignalR.Client.SourceGenerator (4)
Microsoft.CodeAnalysis (265)
EncodedStringText.cs (11)
72/// Initializes an instance of <see cref="SourceText"/> from the provided stream. This version differs
73/// from <see cref="SourceText.From(Stream, Encoding, SourceHashAlgorithm, bool)"/> in two ways:
91internal static SourceText Create(Stream stream,
103internal static SourceText Create(Stream stream,
136/// Try to create a <see cref="SourceText"/> from the given stream using the given encoding.
143/// <returns>The <see cref="SourceText"/> decoded from the stream.</returns>
146private static SourceText Decode(
165return SourceText.From(bytes.Array,
175return SourceText.From(data, encoding, checksumAlgorithm, throwIfBinaryDetected, canBeEmbedded);
249internal static SourceText Create(Stream stream, Lazy<Encoding> getEncoding, Encoding defaultEncoding, SourceHashAlgorithm checksumAlgorithm, bool canBeEmbedded)
252internal static SourceText Decode(Stream data, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
SourceGeneration\GeneratorContexts.cs (8)
85public void AddSource(string hintName, string source) => AddSource(hintName, SourceText.From(source, Encoding.UTF8, checksumAlgorithm: _checksumAlgorithm == SourceHashAlgorithm.None ? SourceHashAlgorithms.Default : _checksumAlgorithm));
88/// Adds a <see cref="SourceText"/> to the compilation
91/// <param name="sourceText">The <see cref="SourceText"/> to add to the compilation</param>
95public void AddSource(string hintName, SourceText sourceText) => _additionalSources.Add(hintName, sourceText.WithChecksumAlgorithmIfAny(_checksumAlgorithm));
277public void AddSource(string hintName, string source) => AddSource(hintName, SourceText.From(source, Encoding.UTF8));
280/// Adds a <see cref="SourceText"/> to the compilation that will be available during subsequent phases
283/// <param name="sourceText">The <see cref="SourceText"/> to add to the compilation</param>
287public void AddSource(string hintName, SourceText sourceText) => _additionalSources.Add(hintName, sourceText);
SourceGeneration\IncrementalContexts.cs (14)
243public void AddSource(string hintName, string source) => AddSource(hintName, SourceText.From(source, Encoding.UTF8));
246/// Adds a <see cref="SourceText"/> to the compilation that will be available during subsequent phases
249/// <param name="sourceText">The <see cref="SourceText"/> to add to the compilation</param>
253public void AddSource(string hintName, SourceText sourceText) => AdditionalSources.Add(hintName, sourceText);
256/// Adds a <see cref="SourceText" /> to the compilation containing the definition of <c>Microsoft.CodeAnalysis.EmbeddedAttribute</c>.
263public void AddEmbeddedAttributeDefinition() => AddSource("Microsoft.CodeAnalysis.EmbeddedAttribute", SourceText.From(_embeddedAttributeDefinition, encoding: Encoding.UTF8));
292public void AddSource(string hintName, string source) => AddSource(hintName, SourceText.From(source, Encoding.UTF8, checksumAlgorithm: ChecksumAlgorithm == SourceHashAlgorithm.None ? SourceHashAlgorithms.Default : ChecksumAlgorithm));
295/// Adds a <see cref="SourceText"/> to the compilation
298/// <param name="sourceText">The <see cref="SourceText"/> to add to the compilation</param>
302public void AddSource(string hintName, SourceText sourceText) => Sources.Add(hintName, sourceText.WithChecksumAlgorithmIfAny(ChecksumAlgorithm));
351public void AddSource(string hintName, string source) => AddSource(hintName, SourceText.From(source, Encoding.UTF8, checksumAlgorithm: ChecksumAlgorithm == SourceHashAlgorithm.None ? SourceHashAlgorithms.Default : ChecksumAlgorithm));
354/// Adds a <see cref="SourceText"/> to the compilation
357/// <param name="sourceText">The <see cref="SourceText"/> to add to the compilation</param>
361public void AddSource(string hintName, SourceText sourceText) => Sources.Add(hintName, sourceText.WithChecksumAlgorithmIfAny(ChecksumAlgorithm));
Text\CompositeText.cs (37)
18/// A composite of a sequence of <see cref="SourceText"/>s.
22private readonly ImmutableArray<SourceText> _segments;
28private CompositeText(ImmutableArray<SourceText> segments, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm)
67internal override ImmutableArray<SourceText> Segments
83public override SourceText GetSubText(TextSpan span)
94var newSegments = ArrayBuilder<SourceText>.GetInstance();
99var segment = _segments[segIndex];
157var segment = _segments[segIndex];
169internal static void AddSegments(ArrayBuilder<SourceText> segments, SourceText text)
182internal static SourceText ToSourceText(ArrayBuilder<SourceText> segments, SourceText original, bool adjustSegments)
194return SourceText.From(string.Empty, original.Encoding, original.ChecksumAlgorithm);
206private static void RemoveSplitLineBreaksAndEmptySegments(ArrayBuilder<SourceText> segments)
216var prevSegment = segments[i - 1];
217var curSegment = segments[i];
223segments.Insert(i, SourceText.From("\r\n"));
246private static void ReduceSegmentCountIfNecessary(ArrayBuilder<SourceText> segments)
267private static int GetMinimalSegmentSizeToUseForCombining(ArrayBuilder<SourceText> segments)
287private static int GetSegmentCountIfCombined(ArrayBuilder<SourceText> segments, int segmentSize)
322private static void CombineSegments(ArrayBuilder<SourceText> segments, int segmentSize)
354var newText = writer.ToSourceText();
363private static readonly ObjectPool<HashSet<SourceText>> s_uniqueSourcesPool
364= new ObjectPool<HashSet<SourceText>>(() => new HashSet<SourceText>(), 5);
369private static void ComputeLengthAndStorageSize(IReadOnlyList<SourceText> segments, out int length, out int size)
376var segment = segments[i];
382foreach (var segment in uniqueSources)
394private static void TrimInaccessibleText(ArrayBuilder<SourceText> segments)
406foreach (var segment in segments)
446var segment = compositeText.Segments[i];
480var segment = _compositeText.Segments[segmentIndex];
500var firstSegment = _compositeText.Segments[firstSegmentIndexInclusive];
510var nextSegment = _compositeText.Segments[nextSegmentIndex];
523var lastSegment = _compositeText.Segments[lastSegmentIndexInclusive];
561var previousSegment = _compositeText.Segments[firstSegmentIndexInclusive - 1];
Text\LargeText.cs (7)
18/// A <see cref="SourceText"/> optimized for very large sources. The text is stored as
26internal const int ChunkSize = SourceText.LargeObjectHeapLimitInChars; // 40K Unicode chars is 80KB which is less than the large object heap limit.
55internal static SourceText Decode(Stream stream, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
62return SourceText.From(string.Empty, encoding, checksumAlgorithm);
81internal static SourceText Decode(TextReader reader, int length, Encoding? encodingOpt, SourceHashAlgorithm checksumAlgorithm)
85return SourceText.From(string.Empty, encodingOpt, checksumAlgorithm);
228/// Called from <see cref="SourceText.Lines"/> to initialize the <see cref="TextLineCollection"/>. Thereafter,
Text\SourceText.cs (58)
93/// Constructs a <see cref="SourceText"/> from text in a string.
99/// If the encoding is not specified the resulting <see cref="SourceText"/> isn't debuggable.
100/// If an encoding-less <see cref="SourceText"/> is written to a file a <see cref="Encoding.UTF8"/> shall be used as a default.
107public static SourceText From(string text, Encoding? encoding = null, SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1)
118/// Constructs a <see cref="SourceText"/> from text in a string.
125/// If the encoding is not specified the resulting <see cref="SourceText"/> isn't debuggable.
126/// If an encoding-less <see cref="SourceText"/> is written to a file a <see cref="Encoding.UTF8"/> shall be used as a default.
133public static SourceText From(
156public static SourceText From(Stream stream, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected)
160/// Constructs a <see cref="SourceText"/> from stream content.
182public static SourceText From(
227public static SourceText From(byte[] buffer, int length, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected)
231/// Constructs a <see cref="SourceText"/> from a byte array.
251public static SourceText From(
394/// If an encoding-less <see cref="SourceText"/> is written to a file a <see cref="Encoding.UTF8"/> shall be used as a default.
412internal virtual ImmutableArray<SourceText> Segments
414get { return ImmutableArray<SourceText>.Empty; }
417internal virtual SourceText StorageKey
473/// The container of this <see cref="SourceText"/>.
499/// Gets a <see cref="SourceText"/> that contains the characters in the specified span of this text.
501public virtual SourceText GetSubText(TextSpan span)
508return SourceText.From(string.Empty, this.Encoding, this.ChecksumAlgorithm);
521/// Returns a <see cref="SourceText"/> that has the contents of this text including and after the start position.
523public SourceText GetSubText(int start)
541/// Write this <see cref="SourceText"/> to a text writer.
578/// that were used to produce this <see cref="SourceText"/> (if any of the <c>From</c> methods were used that
579/// take a <c>byte[]</c> or <see cref="Stream"/>). Otherwise, computed by writing this <see cref="SourceText"/>
584/// Two different <see cref="SourceText"/> instances with the same content (see <see cref="ContentEquals"/>) may
590/// Similarly, two different <see cref="SourceText"/> instances with <em>different</em> contents can have the
611/// Produces a hash of this <see cref="SourceText"/> based solely on the contents it contains. Two different
612/// <see cref="SourceText"/> instances that are <see cref="ContentEquals"/> will have the same content hash. Two
613/// instances of <see cref="SourceText"/> with different content are virtually certain to not have the same
767public virtual SourceText WithChanges(IEnumerable<TextChange> changes)
779var segments = ArrayBuilder<SourceText>.GetInstance();
817var subText = this.GetSubText(new TextSpan(position, change.Span.Start - position));
823var segment = SourceText.From(change.NewText!, this.Encoding, this.ChecksumAlgorithm);
840var subText = this.GetSubText(new TextSpan(position, this.Length - position));
844var newText = CompositeText.ToSourceText(segments, this, adjustSegments: true);
868/// <exception cref="ArgumentException">If any changes are not in bounds of this <see cref="SourceText"/>.</exception>
870public SourceText WithChanges(params TextChange[] changes)
878public SourceText Replace(TextSpan span, string newText)
886public SourceText Replace(int start, int length, string newText)
896public virtual IReadOnlyList<TextChangeRange> GetChangeRanges(SourceText oldText)
918public virtual IReadOnlyList<TextChange> GetTextChanges(SourceText oldText)
1015private readonly SourceText _text;
1019public LineInfo(SourceText text, SegmentedList<uint> lineStarts)
1198/// Compares the content with content of another <see cref="SourceText"/>.
1200public bool ContentEquals(SourceText other)
1225/// Implements equality comparison of the content of two different instances of <see cref="SourceText"/>.
1227protected virtual bool ContentEqualsImpl(SourceText other)
1321private readonly SourceText _text;
1323public StaticContainer(SourceText text)
1328public override SourceText CurrentText => _text;
1362/// Otherwise, returns a <see cref="SourceText"/> with the same <see cref="ChecksumAlgorithm"/> as <paramref name="checksumAlgorithm"/>, potentially by wrapping this instance.
1364internal SourceText WithChecksumAlgorithmIfAny(SourceHashAlgorithm checksumAlgorithm)
1374private readonly SourceText _underlying;
1376public SourceTextWithAlgorithm(SourceText underlying, SourceHashAlgorithm checksumAlgorithm) : base(checksumAlgorithm: checksumAlgorithm)
Microsoft.CodeAnalysis.Analyzers (121)
MetaAnalyzers\ReleaseTrackingHelper.cs (8)
46SourceText sourceText,
47Action<string, Version, string, SourceText, TextLine> onDuplicateEntryInRelease,
48Action<TextLine, InvalidEntryKind, string, SourceText> onInvalidEntry,
440public SourceText SourceText { get; }
449TextSpan span, SourceText sourceText,
458TextSpan span, SourceText sourceText,
478TextSpan span, SourceText sourceText,
497TextSpan span, SourceText sourceText,
src\roslyn\src\Compilers\Core\Portable\EncodedStringText.cs (11)
72/// Initializes an instance of <see cref="SourceText"/> from the provided stream. This version differs
73/// from <see cref="SourceText.From(Stream, Encoding, SourceHashAlgorithm, bool)"/> in two ways:
91internal static SourceText Create(Stream stream,
103internal static SourceText Create(Stream stream,
136/// Try to create a <see cref="SourceText"/> from the given stream using the given encoding.
143/// <returns>The <see cref="SourceText"/> decoded from the stream.</returns>
146private static SourceText Decode(
165return SourceText.From(bytes.Array,
175return SourceText.From(data, encoding, checksumAlgorithm, throwIfBinaryDetected, canBeEmbedded);
249internal static SourceText Create(Stream stream, Lazy<Encoding> getEncoding, Encoding defaultEncoding, SourceHashAlgorithm checksumAlgorithm, bool canBeEmbedded)
252internal static SourceText Decode(Stream data, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
src\roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\SourceTextExtensions_SharedWithCodeStyle.cs (5)
16public static string GetLeadingWhitespaceOfLineAtPosition(this SourceText text, int position)
32this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden, CancellationToken cancellationToken)
44this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden,
82public static bool AreOnSameLine(this SourceText text, SyntaxToken token1, SyntaxToken token2)
87public static bool AreOnSameLine(this SourceText text, int pos1, int pos2)
src\roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\RefactoringHelpers\AbstractRefactoringHelpers.cs (6)
25public abstract bool IsBetweenTypeMembers(SourceText sourceText, SyntaxNode root, int position, [NotNullWhen(true)] out SyntaxNode? typeDeclaration);
42private static TextSpan GetTrimmedTextSpan(SourceText sourceText, TextSpan span)
60SourceText sourceText, SyntaxNode root, TextSpan selectionRaw, bool allowEmptyNodes, int maxCount, ref TemporaryArray<TSyntaxNode> result, CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode
179SourceText sourceText, SyntaxNode root, int location)
251SourceText sourceText, SyntaxToken tokenOnLocation, int location)
533SourceText sourceText,
Microsoft.CodeAnalysis.AnalyzerUtilities (68)
src\roslyn\src\Compilers\Core\Portable\EncodedStringText.cs (11)
72/// Initializes an instance of <see cref="SourceText"/> from the provided stream. This version differs
73/// from <see cref="SourceText.From(Stream, Encoding, SourceHashAlgorithm, bool)"/> in two ways:
91internal static SourceText Create(Stream stream,
103internal static SourceText Create(Stream stream,
136/// Try to create a <see cref="SourceText"/> from the given stream using the given encoding.
143/// <returns>The <see cref="SourceText"/> decoded from the stream.</returns>
146private static SourceText Decode(
165return SourceText.From(bytes.Array,
175return SourceText.From(data, encoding, checksumAlgorithm, throwIfBinaryDetected, canBeEmbedded);
249internal static SourceText Create(Stream stream, Lazy<Encoding> getEncoding, Encoding defaultEncoding, SourceHashAlgorithm checksumAlgorithm, bool canBeEmbedded)
252internal static SourceText Decode(Stream data, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
src\roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\SourceTextExtensions_SharedWithCodeStyle.cs (5)
16public static string GetLeadingWhitespaceOfLineAtPosition(this SourceText text, int position)
32this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden, CancellationToken cancellationToken)
44this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden,
82public static bool AreOnSameLine(this SourceText text, SyntaxToken token1, SyntaxToken token2)
87public static bool AreOnSameLine(this SourceText text, int pos1, int pos2)
src\roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\RefactoringHelpers\AbstractRefactoringHelpers.cs (6)
25public abstract bool IsBetweenTypeMembers(SourceText sourceText, SyntaxNode root, int position, [NotNullWhen(true)] out SyntaxNode? typeDeclaration);
42private static TextSpan GetTrimmedTextSpan(SourceText sourceText, TextSpan span)
60SourceText sourceText, SyntaxNode root, TextSpan selectionRaw, bool allowEmptyNodes, int maxCount, ref TemporaryArray<TSyntaxNode> result, CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode
179SourceText sourceText, SyntaxNode root, int location)
251SourceText sourceText, SyntaxToken tokenOnLocation, int location)
533SourceText sourceText,
Microsoft.CodeAnalysis.CodeStyle (66)
src\roslyn\src\Compilers\Core\Portable\EncodedStringText.cs (11)
72/// Initializes an instance of <see cref="SourceText"/> from the provided stream. This version differs
73/// from <see cref="SourceText.From(Stream, Encoding, SourceHashAlgorithm, bool)"/> in two ways:
91internal static SourceText Create(Stream stream,
103internal static SourceText Create(Stream stream,
136/// Try to create a <see cref="SourceText"/> from the given stream using the given encoding.
143/// <returns>The <see cref="SourceText"/> decoded from the stream.</returns>
146private static SourceText Decode(
165return SourceText.From(bytes.Array,
175return SourceText.From(data, encoding, checksumAlgorithm, throwIfBinaryDetected, canBeEmbedded);
249internal static SourceText Create(Stream stream, Lazy<Encoding> getEncoding, Encoding defaultEncoding, SourceHashAlgorithm checksumAlgorithm, bool canBeEmbedded)
252internal static SourceText Decode(Stream data, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
src\roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\SourceTextExtensions_SharedWithCodeStyle.cs (5)
16public static string GetLeadingWhitespaceOfLineAtPosition(this SourceText text, int position)
32this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden, CancellationToken cancellationToken)
44this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden,
82public static bool AreOnSameLine(this SourceText text, SyntaxToken token1, SyntaxToken token2)
87public static bool AreOnSameLine(this SourceText text, int pos1, int pos2)
src\roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\RefactoringHelpers\AbstractRefactoringHelpers.cs (6)
25public abstract bool IsBetweenTypeMembers(SourceText sourceText, SyntaxNode root, int position, [NotNullWhen(true)] out SyntaxNode? typeDeclaration);
42private static TextSpan GetTrimmedTextSpan(SourceText sourceText, TextSpan span)
60SourceText sourceText, SyntaxNode root, TextSpan selectionRaw, bool allowEmptyNodes, int maxCount, ref TemporaryArray<TSyntaxNode> result, CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode
179SourceText sourceText, SyntaxNode root, int location)
251SourceText sourceText, SyntaxToken tokenOnLocation, int location)
533SourceText sourceText,
Microsoft.CodeAnalysis.CodeStyle.Fixes (39)
src\roslyn\src\Analyzers\Core\CodeFixes\ConflictMarkerResolution\AbstractConflictMarkerCodeFixProvider.cs (15)
75var text = await document.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
85SyntaxNode root, SourceText text, int position,
146SourceText text, int position,
210var text = startLine.Text!;
228var text = startLine.Text!;
246var text = currentLine.Text!;
316Action<SourceText, ArrayBuilder<TextChange>, int, int, int, int> addEdits,
319var text = await document.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
324var finalText = text.WithChanges(edits);
329SourceText text, ArrayBuilder<TextChange> edits,
342SourceText text, ArrayBuilder<TextChange> edits,
355SourceText text, ArrayBuilder<TextChange> edits,
389private static int GetEndIncludingLineBreak(SourceText text, int position)
405var text = await document.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
444var finalText = text.WithChanges(edits);
Microsoft.CodeAnalysis.CSharp (53)
Syntax\CSharpSyntaxTree.cs (10)
379internal static SyntaxTree CreateForDebugger(CSharpSyntaxNode root, SourceText text, CSharpParseOptions options)
415SourceText text,
459return ParseText(SourceText.From(text, encoding, SourceHashAlgorithm.Sha1), options, path, diagnosticOptions, isGeneratedCode, cancellationToken);
470SourceText text,
490SourceText text,
535public override SyntaxTree WithChangedText(SourceText newText)
538if (this.TryGetText(out SourceText? oldText))
554private SyntaxTree WithChanges(SourceText newText, IReadOnlyList<TextChangeRange> changes)
903SourceText text,
920=> ParseText(SourceText.From(text, encoding, SourceHashAlgorithm.Sha1), options, path, diagnosticOptions, isGeneratedCode: null, cancellationToken);
Syntax\SyntaxFactory.cs (10)
1591return CSharpSyntaxTree.ParseText(SourceText.From(text, encoding, SourceHashAlgorithm.Sha1), (CSharpParseOptions?)options, path, diagnosticOptions: null, isGeneratedCode: null, cancellationToken);
1595/// <inheritdoc cref="CSharpSyntaxTree.ParseText(SourceText, CSharpParseOptions?, string, CancellationToken)"/>
1597SourceText text,
1710public static SyntaxTokenParser CreateTokenParser(SourceText sourceText, CSharpParseOptions? options = null)
1950private static SourceText MakeSourceText(string text, int offset)
1952return SourceText.From(text, Encoding.UTF8).GetSubText(offset);
2838return ParseSyntaxTree(SourceText.From(text, encoding), options, path, diagnosticOptions, isGeneratedCode: null, cancellationToken);
2845SourceText text,
2866return ParseSyntaxTree(SourceText.From(text, encoding), options, path, diagnosticOptions, isGeneratedCode, cancellationToken);
2873SourceText text,
Microsoft.CodeAnalysis.CSharp.CodeStyle (21)
Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes (35)
Microsoft.CodeAnalysis.CSharp.Features (151)
Completion\CompletionProviders\CompletionUtilities.cs (8)
20internal static TextSpan GetCompletionItemSpan(SourceText text, int position)
60internal static bool IsTriggerCharacter(SourceText text, int characterPosition, in CompletionOptions options)
99internal static bool IsCompilerDirectiveTriggerCharacter(SourceText text, int characterPosition)
117internal static bool IsTriggerCharacterOrArgumentListCharacter(SourceText text, int characterPosition, in CompletionOptions options)
120private static bool IsArgumentListCharacter(SourceText text, int characterPosition)
126internal static bool IsTriggerAfterSpaceOrStartOfWordCharacter(SourceText text, int characterPosition, in CompletionOptions options)
136private static bool SpaceTypedNotBeforeWord(char ch, SourceText text, int characterPosition)
139public static bool IsStartingNewWord(SourceText text, int characterPosition)
StringIndentation\CSharpStringIndentationService.cs (5)
31var text = await document.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
79SourceText text, SyntaxToken token, ref TemporaryArray<StringIndentationRegion> result, CancellationToken cancellationToken)
94SourceText text, InterpolatedStringExpressionSyntax interpolatedString, ref TemporaryArray<StringIndentationRegion> result, CancellationToken cancellationToken)
137private static bool IgnoreInterpolation(SourceText text, int offset, InterpolationSyntax interpolation)
158private static bool TryGetIndentSpan(SourceText text, ExpressionSyntax expression, out int offset, out TextSpan indentSpan)
Microsoft.CodeAnalysis.CSharp.Scripting (3)
CSharpScript.cs (2)
37return Script.CreateInitialScript<T>(CSharpScriptCompiler.Instance, SourceText.From(code, options?.FileEncoding, SourceHashAlgorithms.Default), options, globalsType, assemblyLoader);
54return Script.CreateInitialScript<T>(CSharpScriptCompiler.Instance, SourceText.From(code, options?.FileEncoding), options, globalsType, assemblyLoader);
Microsoft.CodeAnalysis.CSharp.Workspaces (30)
Microsoft.CodeAnalysis.ExternalAccess.HotReload (6)
Api\HotReloadMSBuildWorkspace.cs (6)
182var oldText = await textDocument.GetTextAsync(cancellationToken).ConfigureAwait(false);
185var newText = await GetSourceTextAsync(path, oldText.Encoding, oldText.ChecksumAlgorithm, cancellationToken).ConfigureAwait(false);
210private static async ValueTask<SourceText> GetSourceTextAsync(string filePath, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, CancellationToken cancellationToken)
219SourceText sourceText;
222sourceText = SourceText.From(stream, encoding, checksumAlgorithm);
237sourceText = SourceText.From(stream, encoding, checksumAlgorithm);
Microsoft.CodeAnalysis.ExternalAccess.OmniSharp (3)
Microsoft.CodeAnalysis.Features (265)
Completion\CommonCompletionProvider.cs (4)
34public sealed override bool ShouldTriggerCompletion(SourceText text, int caretPosition, CompletionTrigger trigger, OptionSet options)
42internal override bool ShouldTriggerCompletion(LanguageServices languageServices, SourceText text, int caretPosition, CompletionTrigger trigger, CompletionOptions options, OptionSet passThroughOptions)
45private bool ShouldTriggerCompletionImpl(SourceText text, int caretPosition, CompletionTrigger trigger, in CompletionOptions options)
50public virtual bool IsInsertionTrigger(SourceText text, int insertedCharacterPosition, CompletionOptions options)
Completion\CommonCompletionUtilities.cs (4)
27public static TextSpan GetWordSpan(SourceText text, int position,
33public static TextSpan GetWordSpan(SourceText text, int position,
60public static bool IsStartingNewWord(SourceText text, int characterPosition, Func<char, bool> isWordStartCharacter, Func<char, bool> isWordCharacter)
185internal static bool IsTextualTriggerString(SourceText text, int characterPosition, string value)
Completion\Providers\CompletionUtilities.cs (4)
73public static CompletionItem SetOriginalIdentifierEnd(CompletionItem item, int position, SourceText text, ISyntaxFactsService syntaxFacts)
82public static KeyValuePair<string, string> GetOriginalIdentifierEndProperty(int position, SourceText text, ISyntaxFactsService syntaxFacts)
85private static int ScanForwardThroughIdentifier(int start, SourceText text, ISyntaxFactsService syntaxFacts)
102public static int GetCurrentSpanEnd(CompletionItem item, SourceText text, ISyntaxFactsService syntaxFacts)
DocumentationComments\AbstractDocumentationCommentSnippetService.cs (8)
42private bool IsAtEndOfDocCommentTriviaOnBlankLine(SourceText text, int endPosition)
79var text = document.Text;
103private List<string>? GetDocumentationCommentLines(SyntaxToken token, SourceText text, in DocumentationCommentOptions options, out string? indentText, out int caretOffset, out int spanToReplaceLength)
145private List<string>? GetDocumentationStubLines(SyntaxToken token, SourceText text, in DocumentationCommentOptions options, out int caretOffset, out int spanToReplaceLength, out string? existingCommentText)
189var text = document.Text;
264var text = document.Text;
316var text = document.Text;
356var text = document.Text;
EditAndContinue\AbstractEditAndContinueAnalyzer.cs (9)
500private static readonly SourceText s_emptySource = SourceText.From("");
709void LogRudeEdits(ImmutableArray<RudeEditDiagnostic> diagnostics, SourceText text, string filePath)
732private static async ValueTask<(Document? document, SourceText text)> GetDocumentContentAsync(Project project, DocumentId documentId, CancellationToken cancellationToken)
734SourceText text;
946SourceText newText,
1109SourceText newText,
1484private static bool TryGetTrackedStatement(ImmutableArray<ActiveStatementLineSpan> activeStatementSpans, ActiveStatementId id, SourceText text, MemberBody body, [NotNullWhen(true)] out SyntaxNode? trackedStatement, out int trackedStatementPart)
2702SourceText newText,
EditAndContinue\CommittedSolution.cs (12)
233var sourceText = await document.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
298var matchingSourceText = maybeMatchingSourceText.Value;
325private async ValueTask<(Optional<SourceText?> matchingSourceText, bool? hasDocument)> TryGetMatchingSourceTextAsync(Document document, SourceText sourceText, Document currentDocument, CancellationToken cancellationToken)
365private static async ValueTask<Optional<SourceText?>> TryGetMatchingSourceTextAsync(
367SourceText sourceText,
383var currentDocumentSourceText = await currentDocument.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
398return SourceText.From(text, defaultEncoding, checksumAlgorithm);
440private static bool IsMatchingSourceText(SourceText sourceText, ImmutableArray<byte> requiredChecksum, SourceHashAlgorithm checksumAlgorithm)
443private static Optional<SourceText?> TryGetPdbMatchingSourceTextFromDisk(
454var sourceText = SourceText.From(fileStream, defaultEncoding, checksumAlgorithm);
ExternalAccess\VSTypeScript\Api\VSTypeScriptCompletionProvider.cs (3)
15public sealed override bool ShouldTriggerCompletion(SourceText text, int caretPosition, CompletionTrigger trigger, OptionSet options)
21internal sealed override bool ShouldTriggerCompletion(LanguageServices languageServices, SourceText text, int caretPosition, CompletionTrigger trigger, CompletionOptions options, OptionSet passThroughOptions)
24protected abstract bool ShouldTriggerCompletionImpl(SourceText text, int caretPosition, CompletionTrigger trigger, bool triggerOnTypingLetters);
src\roslyn\src\Analyzers\Core\CodeFixes\ConflictMarkerResolution\AbstractConflictMarkerCodeFixProvider.cs (15)
75var text = await document.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
85SyntaxNode root, SourceText text, int position,
146SourceText text, int position,
210var text = startLine.Text!;
228var text = startLine.Text!;
246var text = currentLine.Text!;
316Action<SourceText, ArrayBuilder<TextChange>, int, int, int, int> addEdits,
319var text = await document.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
324var finalText = text.WithChanges(edits);
329SourceText text, ArrayBuilder<TextChange> edits,
342SourceText text, ArrayBuilder<TextChange> edits,
355SourceText text, ArrayBuilder<TextChange> edits,
389private static int GetEndIncludingLineBreak(SourceText text, int position)
405var text = await document.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
444var finalText = text.WithChanges(edits);
Microsoft.CodeAnalysis.Razor.Compiler (32)
Language\RazorSourceDocument.cs (15)
23public SourceText Text { get; }
66var sourceText = SourceText.From(stream, checksumAlgorithm: SourceHashAlgorithm.Sha256);
90var sourceText = SourceText.From(stream, encoding, checksumAlgorithm: SourceHashAlgorithm.Sha256);
118var sourceText = SourceText.From(stream, encoding, checksumAlgorithm: SourceHashAlgorithm.Sha256);
153var sourceText = SourceText.From(stream, checksumAlgorithm: SourceHashAlgorithm.Sha256);
218var sourceText = SourceText.From(content, encoding, checksumAlgorithm: SourceHashAlgorithm.Sha256);
246var sourceText = SourceText.From(content, encoding, checksumAlgorithm: SourceHashAlgorithm.Sha256);
256public static RazorSourceDocument Create(SourceText text, RazorSourceDocumentProperties properties)
271private RazorSourceDocument(SourceText sourceText, RazorSourceDocumentProperties properties)
Microsoft.CodeAnalysis.Rebuild (9)
Microsoft.CodeAnalysis.ResxSourceGenerator (77)
src\roslyn\src\Compilers\Core\Portable\EncodedStringText.cs (11)
72/// Initializes an instance of <see cref="SourceText"/> from the provided stream. This version differs
73/// from <see cref="SourceText.From(Stream, Encoding, SourceHashAlgorithm, bool)"/> in two ways:
91internal static SourceText Create(Stream stream,
103internal static SourceText Create(Stream stream,
136/// Try to create a <see cref="SourceText"/> from the given stream using the given encoding.
143/// <returns>The <see cref="SourceText"/> decoded from the stream.</returns>
146private static SourceText Decode(
165return SourceText.From(bytes.Array,
175return SourceText.From(data, encoding, checksumAlgorithm, throwIfBinaryDetected, canBeEmbedded);
249internal static SourceText Create(Stream stream, Lazy<Encoding> getEncoding, Encoding defaultEncoding, SourceHashAlgorithm checksumAlgorithm, bool canBeEmbedded)
252internal static SourceText Decode(Stream data, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
src\roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\SourceTextExtensions_SharedWithCodeStyle.cs (5)
16public static string GetLeadingWhitespaceOfLineAtPosition(this SourceText text, int position)
32this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden, CancellationToken cancellationToken)
44this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden,
82public static bool AreOnSameLine(this SourceText text, SyntaxToken token1, SyntaxToken token2)
87public static bool AreOnSameLine(this SourceText text, int pos1, int pos2)
src\roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\RefactoringHelpers\AbstractRefactoringHelpers.cs (6)
25public abstract bool IsBetweenTypeMembers(SourceText sourceText, SyntaxNode root, int position, [NotNullWhen(true)] out SyntaxNode? typeDeclaration);
42private static TextSpan GetTrimmedTextSpan(SourceText sourceText, TextSpan span)
60SourceText sourceText, SyntaxNode root, TextSpan selectionRaw, bool allowEmptyNodes, int maxCount, ref TemporaryArray<TSyntaxNode> result, CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode
179SourceText sourceText, SyntaxNode root, int location)
251SourceText sourceText, SyntaxToken tokenOnLocation, int location)
533SourceText sourceText,
Microsoft.CodeAnalysis.Scripting (12)
Hosting\CommandLine\CommandLineRunner.cs (5)
108SourceText? code = null;
200private int RunScript(ScriptOptions? options, SourceText? code, ErrorLogger? errorLogger, CancellationToken cancellationToken)
231var script = Script.CreateInitialScript<object>(_scriptCompiler, SourceText.From(initialScriptCodeOpt), options, globals.GetType(), assemblyLoaderOpt: null);
258var tree = _scriptCompiler.ParseSubmission(SourceText.From(input.ToString()), options.ParseOptions, cancellationToken);
283newScript = Script.CreateInitialScript<object>(_scriptCompiler, SourceText.From(code ?? string.Empty), options, globals.GetType(), assemblyLoaderOpt: null);
Script.cs (6)
39internal Script(ScriptCompiler compiler, ScriptBuilder builder, SourceText sourceText, ScriptOptions options, Type globalsTypeOpt, Script previousOpt)
54internal static Script<T> CreateInitialScript<T>(ScriptCompiler compiler, SourceText sourceText, ScriptOptions optionsOpt, Type globalsTypeOpt, InteractiveAssemblyLoader assemblyLoaderOpt)
79internal SourceText SourceText { get; }
117return new Script<TResult>(Compiler, Builder, SourceText.From(code ?? "", options.FileEncoding), options, GlobalsType, this);
130return new Script<TResult>(Compiler, Builder, SourceText.From(code, options.FileEncoding), options, GlobalsType, this);
344internal Script(ScriptCompiler compiler, ScriptBuilder builder, SourceText sourceText, ScriptOptions options, Type globalsTypeOpt, Script previousOpt)
Microsoft.CodeAnalysis.TestAnalyzerReference (6)
Microsoft.CodeAnalysis.VisualBasic (43)
Syntax\SyntaxNodeFactories.vb (6)
50Return ParseSyntaxTree(SourceText.From(text, encoding, SourceHashAlgorithm.Sha1), options, path, cancellationToken)
57text As SourceText,
79Return ParseSyntaxTree(SourceText.From(text, encoding), options, path, diagnosticOptions, cancellationToken)
86text As SourceText,
287Friend Shared Function MakeSourceText(text As String, offset As Integer) As SourceText
288Return SourceText.From(text, Encoding.UTF8).GetSubText(offset)
Microsoft.CodeAnalysis.VisualBasic.CodeStyle (1)
Microsoft.CodeAnalysis.VisualBasic.CodeStyle.Fixes (1)
src\roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Workspace\VisualBasic\Indentation\VisualBasicIndentationService.Indenter.vb (1)
42text As SourceText,
Microsoft.CodeAnalysis.VisualBasic.Features (31)
Microsoft.CodeAnalysis.VisualBasic.Scripting (2)
Microsoft.CodeAnalysis.VisualBasic.Workspaces (15)
src\roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Workspace\VisualBasic\Indentation\VisualBasicIndentationService.Indenter.vb (1)
42text As SourceText,
Microsoft.CodeAnalysis.Workspaces (382)
Shared\Extensions\SourceTextExtensions.cs (12)
36public static void GetLineAndOffset(this SourceText text, int position, out int lineNumber, out int offset)
44public static int GetOffset(this SourceText text, int position)
51this SourceText text,
62public static TextChangeRange GetEncompassingTextChangeRange(this SourceText newText, SourceText oldText)
79public static int IndexOf(this SourceText text, string value, int startIndex, bool caseSensitive)
110public static int LastIndexOf(this SourceText text, string value, int startIndex, bool caseSensitive)
146public static bool ContentEquals(this SourceText text, int position, string value)
164public static int IndexOfNonWhiteSpace(this SourceText text, int start, int length)
177public static void WriteTo(this SourceText sourceText, ObjectWriter writer, CancellationToken cancellationToken)
195private static void WriteChunksTo(SourceText sourceText, ObjectWriter writer, int length, CancellationToken cancellationToken)
226public static SourceText ReadFrom(ITextFactoryService textService, ObjectReader reader, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm, CancellationToken cancellationToken)
src\roslyn\src\Compilers\Core\Portable\EncodedStringText.cs (11)
72/// Initializes an instance of <see cref="SourceText"/> from the provided stream. This version differs
73/// from <see cref="SourceText.From(Stream, Encoding, SourceHashAlgorithm, bool)"/> in two ways:
91internal static SourceText Create(Stream stream,
103internal static SourceText Create(Stream stream,
136/// Try to create a <see cref="SourceText"/> from the given stream using the given encoding.
143/// <returns>The <see cref="SourceText"/> decoded from the stream.</returns>
146private static SourceText Decode(
165return SourceText.From(bytes.Array,
175return SourceText.From(data, encoding, checksumAlgorithm, throwIfBinaryDetected, canBeEmbedded);
249internal static SourceText Create(Stream stream, Lazy<Encoding> getEncoding, Encoding defaultEncoding, SourceHashAlgorithm checksumAlgorithm, bool canBeEmbedded)
252internal static SourceText Decode(Stream data, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
src\roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\SourceTextExtensions_SharedWithCodeStyle.cs (5)
16public static string GetLeadingWhitespaceOfLineAtPosition(this SourceText text, int position)
32this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden, CancellationToken cancellationToken)
44this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden,
82public static bool AreOnSameLine(this SourceText text, SyntaxToken token1, SyntaxToken token2)
87public static bool AreOnSameLine(this SourceText text, int pos1, int pos2)
src\roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\RefactoringHelpers\AbstractRefactoringHelpers.cs (6)
25public abstract bool IsBetweenTypeMembers(SourceText sourceText, SyntaxNode root, int position, [NotNullWhen(true)] out SyntaxNode? typeDeclaration);
42private static TextSpan GetTrimmedTextSpan(SourceText sourceText, TextSpan span)
60SourceText sourceText, SyntaxNode root, TextSpan selectionRaw, bool allowEmptyNodes, int maxCount, ref TemporaryArray<TSyntaxNode> result, CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode
179SourceText sourceText, SyntaxNode root, int location)
251SourceText sourceText, SyntaxToken tokenOnLocation, int location)
533SourceText sourceText,
Workspace\Host\TextFactory\TextFactoryService.cs (4)
25public SourceText CreateText(Stream stream, Encoding? defaultEncoding, SourceHashAlgorithm checksumAlgorithm, CancellationToken cancellationToken)
31public SourceText CreateText(TextReader reader, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm, CancellationToken cancellationToken)
36? SourceText.From(textReaderWithLength, textReaderWithLength.Length, encoding, checksumAlgorithm)
37: SourceText.From(reader.ReadToEnd(), encoding, checksumAlgorithm);
Workspace\Solution\DocumentState.cs (12)
106var text = await this.GetTextAsync(cancellationToken).ConfigureAwait(false);
166var text = textAndVersion.Text;
239var newText = newTextAndVersion.Text;
242var oldText = oldTree.GetText(cancellationToken);
250private static TreeAndVersion MakeNewTreeAndVersion(SyntaxTree oldTree, SourceText oldText, VersionStamp oldVersion, SyntaxTree newTree, SourceText newText, VersionStamp newVersion)
259private static bool TopLevelChanged(SyntaxTree oldTree, SourceText oldText, SyntaxTree newTree, SourceText newText)
444public new DocumentState UpdateText(SourceText newText, PreservationMode mode)
507else if (TryGetText(out var priorText))
672SourceText newText,
674SourceText? oldText = null)
Workspace\Solution\FileTextLoader.cs (7)
68GetType(), _ => new StrongBox<bool>(new Func<Stream, Workspace, SourceText>(CreateText).Method.DeclaringType != typeof(FileTextLoader))).Value;
72/// Creates <see cref="SourceText"/> from <see cref="Stream"/>.
76protected virtual SourceText CreateText(Stream stream, Workspace? workspace)
80/// Creates <see cref="SourceText"/> from <see cref="Stream"/>.
83private protected virtual SourceText CreateText(Stream stream, LoadTextOptions options, CancellationToken cancellationToken)
183var text = t.self.CreateText(readStream, t.options, t.cancellationToken);
207var text = t.self.CreateText(stream, t.options, t.cancellationToken);
Workspace\Solution\Solution.cs (18)
986var sourceText = SourceText.From(text, encoding: null, checksumAlgorithm: project.ChecksumAlgorithm);
995public Solution AddDocument(DocumentId documentId, string name, SourceText text, IEnumerable<string>? folders = null, string? filePath = null, bool isGenerated = false)
1028var sourceText = SourceText.From(string.Empty, encoding: null, project.ChecksumAlgorithm);
1034private Solution AddDocumentImpl(ProjectState project, DocumentId documentId, string name, SourceText text, IReadOnlyList<string>? folders, string? filePath, bool isGenerated)
1089=> this.AddAdditionalDocument(documentId, name, SourceText.From(text), folders, filePath);
1095public Solution AddAdditionalDocument(DocumentId documentId, string name, SourceText text, IEnumerable<string>? folders = null, string? filePath = null)
1126public Solution AddAnalyzerConfigDocument(DocumentId documentId, string name, SourceText text, IEnumerable<string>? folders = null, string? filePath = null)
1150private DocumentInfo CreateDocumentInfo(DocumentId documentId, string name, SourceText text, IEnumerable<string>? folders, string? filePath)
1288public Solution WithDocumentText(DocumentId documentId, SourceText text, PreservationMode mode = PreservationMode.PreserveValue)
1291internal Solution WithDocumentTexts(ImmutableArray<(DocumentId documentId, SourceText text)> texts, PreservationMode mode = PreservationMode.PreserveValue)
1311public Solution WithAdditionalDocumentText(DocumentId documentId, SourceText text, PreservationMode mode = PreservationMode.PreserveValue)
1332public Solution WithAnalyzerConfigDocumentText(DocumentId documentId, SourceText text, PreservationMode mode = PreservationMode.PreserveValue)
1645public Solution WithDocumentText(IEnumerable<DocumentId?> documentIds, SourceText text, PreservationMode mode = PreservationMode.PreserveValue)
1671SourceGeneratedDocumentIdentity documentIdentity, DateTime generationDateTime, SourceText text)
1684internal Solution WithFrozenSourceGeneratedDocuments(ImmutableArray<(SourceGeneratedDocumentIdentity documentIdentity, DateTime generationDateTime, SourceText text)> documents)
1685=> WithCompilationState(CompilationState.WithFrozenSourceGeneratedDocuments(documents.SelectAsArray(d => (d.documentIdentity, d.generationDateTime, (SourceText?)d.text, (SyntaxNode?)null))));
Workspace\Solution\SolutionCompilationState.cs (18)
806internal SolutionCompilationState WithDocumentTexts(ImmutableArray<(DocumentId documentId, SourceText text)> texts, PreservationMode mode)
810return UpdateDocumentsInMultipleProjects<DocumentState, SourceText, PreservationMode>(
817(ImmutableArray<(DocumentId, SourceText)>,
818ImmutableArray<(SourceGeneratedDocumentIdentity, DateTime, SourceText?, SyntaxNode?)>) GetOrdinaryAndSourceGeneratedDocuments()
823using var _1 = ArrayBuilder<(DocumentId, SourceText)>.GetInstance(capacity: texts.Length, out var ordinaryDocuments);
824using var _2 = ArrayBuilder<(SourceGeneratedDocumentIdentity, DateTime, SourceText?, SyntaxNode?)>.GetInstance(out var sourceGeneratedDocuments);
841private static bool SourceTextIsUnchanged(DocumentState oldDocument, SourceText text)
842=> oldDocument.TryGetText(out var oldText) && text == oldText;
850ImmutableArray<(SourceGeneratedDocumentIdentity documentIdentity, DateTime generationDateTime, SourceText? sourceText, SyntaxNode? syntaxNode)> sourceGeneratedDocuments,
962/// <inheritdoc cref="SolutionState.WithAdditionalDocumentText(DocumentId, SourceText, PreservationMode)"/>
964DocumentId documentId, SourceText text, PreservationMode mode)
970/// <inheritdoc cref="SolutionState.WithAnalyzerConfigDocumentText(DocumentId, SourceText, PreservationMode)"/>
972DocumentId documentId, SourceText text, PreservationMode mode)
1023ImmutableArray<(SourceGeneratedDocumentIdentity, DateTime, SourceText?, SyntaxNode?)>) GetOrdinaryAndSourceGeneratedDocuments()
1029using var _2 = ArrayBuilder<(SourceGeneratedDocumentIdentity, DateTime, SourceText?, SyntaxNode?)>.GetInstance(out var sourceGeneratedDocuments);
1405ImmutableArray<(SourceGeneratedDocumentIdentity documentIdentity, DateTime generationDateTime, SourceText? sourceText, SyntaxNode? syntaxNode)> documents)
1873public SolutionCompilationState WithDocumentText(IEnumerable<DocumentId?> documentIds, SourceText text, PreservationMode mode)
1875using var _ = ArrayBuilder<(DocumentId, SourceText)>.GetInstance(out var changedDocuments);
Workspace\Workspace.cs (18)
1138protected internal void OnDocumentTextChanged(DocumentId documentId, SourceText newText, PreservationMode mode)
1141private protected void OnDocumentTextChanged(DocumentId documentId, SourceText newText, PreservationMode mode, bool requireDocumentPresent)
1156protected internal void OnAdditionalDocumentTextChanged(DocumentId documentId, SourceText newText, PreservationMode mode)
1171protected internal void OnAnalyzerConfigDocumentTextChanged(DocumentId documentId, SourceText newText, PreservationMode mode)
1936var text = document.GetTextSynchronously(CancellationToken.None);
1945var text = document.GetTextSynchronously(CancellationToken.None);
1954var text = document.GetTextSynchronously(CancellationToken.None);
1971var currentText = newDoc.GetTextSynchronously(CancellationToken.None); // needs wait
1981var currentText = newDoc.GetTextSynchronously(CancellationToken.None); // needs wait
1998if (!oldDoc.TryGetText(out var oldText))
2003var currentText = newDoc.GetTextSynchronously(CancellationToken.None); // needs wait
2006else if (!newDoc.TryGetText(out var newText))
2202protected virtual void ApplyDocumentAdded(DocumentInfo info, SourceText text)
2224protected virtual void ApplyDocumentTextChanged(DocumentId id, SourceText text)
2246protected virtual void ApplyAdditionalDocumentAdded(DocumentInfo info, SourceText text)
2268protected virtual void ApplyAdditionalDocumentTextChanged(DocumentId id, SourceText text)
2279protected virtual void ApplyAnalyzerConfigDocumentAdded(DocumentInfo info, SourceText text)
2301protected virtual void ApplyAnalyzerConfigDocumentTextChanged(DocumentId id, SourceText text)
Workspace\Workspace_Editor.cs (11)
396var newText = textContainer.CurrentText;
397if (oldDocument.TryGetText(out var oldText) &&
486private static TextAndVersion GetProperTextAndVersion(SourceText oldText, SourceText newText, VersionStamp version, string? filePath)
495private void SignupForTextChanges(DocumentId documentId, SourceTextContainer textContainer, bool isCurrentContext, Action<Workspace, DocumentId, SourceText, PreservationMode> onChangedHandler)
556Func<Solution, DocumentId, SourceText, PreservationMode, Solution> withDocumentText,
558Action<Workspace, DocumentId, SourceText, PreservationMode> onDocumentTextChanged)
588var oldText = oldDocument.GetTextSynchronously(CancellationToken.None);
591var newText = data.textContainer.CurrentText;
850private SourceText GetOpenDocumentText(Solution solution, DocumentId documentId)
855Contract.ThrowIfFalse(doc.TryGetText(out var text));
Microsoft.CodeAnalysis.Workspaces.MSBuild (9)
MSBuild\MSBuildWorkspace.cs (9)
394protected override void ApplyDocumentTextChanged(DocumentId documentId, SourceText text)
412protected override void ApplyAdditionalDocumentTextChanged(DocumentId documentId, SourceText text)
430private static Encoding? DetermineEncoding(SourceText text, TextDocument document)
445var onDiskText = EncodedStringText.Create(stream);
458protected override void ApplyDocumentAdded(DocumentInfo info, SourceText text)
496private void SaveDocumentText(DocumentId id, string fullPath, SourceText newText, Encoding encoding)
726internal void OnDocumentTextChangedInternal(DocumentId documentId, SourceText newText)
731internal void OnAdditionalDocumentTextChangedInternal(DocumentId documentId, SourceText newText)
736internal void OnAnalyzerConfigDocumentTextChangedInternal(DocumentId documentId, SourceText newText)
Microsoft.Diagnostics.DataContractReader.DataGenerator (3)
Microsoft.DotNet.CodeAnalysis (2)
Microsoft.DotNet.HotReload.Utils.Generator (1)
Microsoft.DotNet.HotReload.Watch (1)
Microsoft.DotNet.ProjectTools (5)
Microsoft.Extensions.Logging.Generators (1)
Microsoft.Extensions.Options.SourceGeneration (1)
Microsoft.Gen.BuildMetadata (1)
Microsoft.Gen.BuildMetadata.Unit.Tests (5)
Microsoft.Gen.ComplianceReports.Unit.Tests (5)
Microsoft.Gen.ContextualOptions.Unit.Tests (5)
Microsoft.Gen.Logging (1)
Microsoft.Gen.Logging.Unit.Tests (5)
Microsoft.Gen.MetadataExtractor.Unit.Tests (5)
Microsoft.Gen.Metrics (2)
Microsoft.Gen.Metrics.Unit.Tests (5)
Microsoft.Gen.MetricsReports.Unit.Tests (5)
Microsoft.Maui.Controls.SourceGen (4)
Microsoft.ML.AutoML.SourceGenerator (3)
Roslyn.Diagnostics.Analyzers (92)
src\roslyn\src\Compilers\Core\Portable\EncodedStringText.cs (11)
72/// Initializes an instance of <see cref="SourceText"/> from the provided stream. This version differs
73/// from <see cref="SourceText.From(Stream, Encoding, SourceHashAlgorithm, bool)"/> in two ways:
91internal static SourceText Create(Stream stream,
103internal static SourceText Create(Stream stream,
136/// Try to create a <see cref="SourceText"/> from the given stream using the given encoding.
143/// <returns>The <see cref="SourceText"/> decoded from the stream.</returns>
146private static SourceText Decode(
165return SourceText.From(bytes.Array,
175return SourceText.From(data, encoding, checksumAlgorithm, throwIfBinaryDetected, canBeEmbedded);
249internal static SourceText Create(Stream stream, Lazy<Encoding> getEncoding, Encoding defaultEncoding, SourceHashAlgorithm checksumAlgorithm, bool canBeEmbedded)
252internal static SourceText Decode(Stream data, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
src\roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\SourceTextExtensions_SharedWithCodeStyle.cs (5)
16public static string GetLeadingWhitespaceOfLineAtPosition(this SourceText text, int position)
32this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden, CancellationToken cancellationToken)
44this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden,
82public static bool AreOnSameLine(this SourceText text, SyntaxToken token1, SyntaxToken token2)
87public static bool AreOnSameLine(this SourceText text, int pos1, int pos2)
src\roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\RefactoringHelpers\AbstractRefactoringHelpers.cs (6)
25public abstract bool IsBetweenTypeMembers(SourceText sourceText, SyntaxNode root, int position, [NotNullWhen(true)] out SyntaxNode? typeDeclaration);
42private static TextSpan GetTrimmedTextSpan(SourceText sourceText, TextSpan span)
60SourceText sourceText, SyntaxNode root, TextSpan selectionRaw, bool allowEmptyNodes, int maxCount, ref TemporaryArray<TSyntaxNode> result, CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode
179SourceText sourceText, SyntaxNode root, int location)
251SourceText sourceText, SyntaxToken tokenOnLocation, int location)
533SourceText sourceText,
Roslyn.Diagnostics.CSharp.Analyzers (17)
Roslyn.Diagnostics.VisualBasic.Analyzers (2)
src\roslyn\src\Workspaces\SharedUtilitiesAndExtensions\Workspace\VisualBasic\Indentation\VisualBasicIndentationService.Indenter.vb (1)
42text As SourceText,
SuperFileCheck (2)
System.Private.CoreLib.Generators (1)
System.Text.Json.SourceGeneration (18)
JsonSourceGenerator.Emitter.cs (15)
90private partial void AddSource(string hintName, SourceText sourceText);
105SourceText? sourceText = GenerateTypeInfo(contextGenerationSpec, typeGenerationSpec);
176private static SourceText CompleteSourceFileAndReturnText(SourceWriter writer)
187private SourceText? GenerateTypeInfo(ContextGenerationSpec contextSpec, TypeGenerationSpec typeGenerationSpec)
225private static SourceText GenerateForTypeWithBuiltInConverter(ContextGenerationSpec contextSpec, TypeGenerationSpec typeMetadata)
242private static SourceText GenerateForTypeWithCustomConverter(ContextGenerationSpec contextSpec, TypeGenerationSpec typeMetadata)
263private static SourceText GenerateForNullable(ContextGenerationSpec contextSpec, TypeGenerationSpec typeMetadata)
284private static SourceText GenerateForUnsupportedType(ContextGenerationSpec contextSpec, TypeGenerationSpec typeMetadata)
300private static SourceText GenerateForEnum(ContextGenerationSpec contextSpec, TypeGenerationSpec typeMetadata)
316private SourceText GenerateForCollection(ContextGenerationSpec contextSpec, TypeGenerationSpec typeGenerationSpec)
496private SourceText GenerateForObject(ContextGenerationSpec contextSpec, TypeGenerationSpec typeMetadata)
613private static SourceText GenerateForUnion(ContextGenerationSpec contextSpec, TypeGenerationSpec typeMetadata)
1895private static SourceText GetRootJsonContextImplementation(ContextGenerationSpec contextSpec, bool emitGetConverterForNullablePropertyMethod, bool emitValueTypeSetterDelegate)
2184private static SourceText GetGetTypeInfoImplementation(ContextGenerationSpec contextSpec)
2226private SourceText GetPropertyNameInitialization(ContextGenerationSpec contextSpec)
System.Windows.Forms.Analyzers (1)