9 types derived from SourceText
Microsoft.CodeAnalysis (6)
Microsoft.CodeAnalysis.CSharp.Features (1)
Microsoft.CodeAnalysis.EditorFeatures.Text (1)
Microsoft.CodeAnalysis.Test.Utilities (1)
3968 references to SourceText
Analyzer.Utilities.UnitTests (5)
BuildValidator (4)
ConfigurationSchemaGenerator.Tests (2)
CSharpSyntaxGenerator (6)
GenerateDocumentationAndConfigFiles (12)
src\RoslynAnalyzers\Microsoft.CodeAnalysis.Analyzers\Core\MetaAnalyzers\ReleaseTrackingHelper.cs (8)
45SourceText sourceText,
46Action<string, Version, string, SourceText, TextLine> onDuplicateEntryInRelease,
47Action<TextLine, InvalidEntryKind, string, SourceText> onInvalidEntry,
439public SourceText SourceText { get; }
448TextSpan span, SourceText sourceText,
457TextSpan span, SourceText sourceText,
477TextSpan span, SourceText sourceText,
496TextSpan span, SourceText sourceText,
IdeCoreBenchmarks (12)
Metrics (5)
Metrics.Legacy (5)
Microsoft.Analyzers.Extra.Tests (10)
Microsoft.Analyzers.Local.Tests (10)
Microsoft.AspNetCore.Analyzer.Testing (3)
Microsoft.AspNetCore.App.Analyzers (14)
Microsoft.AspNetCore.App.Analyzers.Test (7)
Microsoft.AspNetCore.Components.Analyzers.Tests (1)
Microsoft.AspNetCore.Components.SdkAnalyzers.Tests (1)
Microsoft.AspNetCore.Http.Extensions.Tests (19)
RequestDelegateGenerator\CompileTimeCreationTests.cs (10)
56project = project.AddDocument("TestMapActions.cs", SourceText.From(source, Encoding.UTF8)).Project;
57project = project.AddDocument("OtherTestMapActions.cs", SourceText.From(otherSource, Encoding.UTF8)).Project;
82project = project.AddDocument("TestMapActions.cs", SourceText.From(source, Encoding.UTF8)).Project;
83project = project.AddDocument("OtherTestMapActions.cs", SourceText.From(otherSource, Encoding.UTF8)).Project;
165project = project.AddDocument("TestMapActions.cs", SourceText.From(source, Encoding.UTF8), filePath: Path.Combine(currentDirectory, "TestMapActions.cs")).Project;
232project = project.AddDocument("TestMapActions.cs", SourceText.From(source, Encoding.UTF8)).Project;
286project = project.AddDocument("TestMapActions.cs", SourceText.From(source, Encoding.UTF8)).Project;
333project = project.AddDocument("TestMapActions.cs", SourceText.From(source, Encoding.UTF8)).Project;
669project = project.AddDocument("TestMapActions.cs", SourceText.From(source, Encoding.UTF8)).Project;
726project = project.AddDocument("TestMapActions.cs", SourceText.From(source, Encoding.UTF8)).Project;
Microsoft.AspNetCore.Http.Microbenchmarks (7)
Microsoft.AspNetCore.Http.ValidationsGenerator (1)
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation (3)
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.Test (1)
Microsoft.AspNetCore.OpenApi.SourceGenerators (1)
Microsoft.AspNetCore.OpenApi.SourceGenerators.Tests (5)
Microsoft.AspNetCore.SignalR.Client.SourceGenerator (4)
Microsoft.CodeAnalysis (250)
EncodedStringText.cs (11)
53/// Initializes an instance of <see cref="SourceText"/> from the provided stream. This version differs
54/// from <see cref="SourceText.From(Stream, Encoding, SourceHashAlgorithm, bool)"/> in two ways:
72internal static SourceText Create(Stream stream,
84internal static SourceText Create(Stream stream,
117/// Try to create a <see cref="SourceText"/> from the given stream using the given encoding.
124/// <returns>The <see cref="SourceText"/> decoded from the stream.</returns>
127private static SourceText Decode(
146return SourceText.From(bytes.Array,
156return SourceText.From(data, encoding, checksumAlgorithm, throwIfBinaryDetected, canBeEmbedded);
230internal static SourceText Create(Stream stream, Lazy<Encoding> getEncoding, Encoding defaultEncoding, SourceHashAlgorithm checksumAlgorithm, bool canBeEmbedded)
233internal static SourceText Decode(Stream data, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
SourceGeneration\GeneratorContexts.cs (8)
82public void AddSource(string hintName, string source) => AddSource(hintName, SourceText.From(source, Encoding.UTF8));
85/// Adds a <see cref="SourceText"/> to the compilation
88/// <param name="sourceText">The <see cref="SourceText"/> to add to the compilation</param>
92public void AddSource(string hintName, SourceText sourceText) => _additionalSources.Add(hintName, sourceText);
274public void AddSource(string hintName, string source) => AddSource(hintName, SourceText.From(source, Encoding.UTF8));
277/// Adds a <see cref="SourceText"/> to the compilation that will be available during subsequent phases
280/// <param name="sourceText">The <see cref="SourceText"/> to add to the compilation</param>
284public void AddSource(string hintName, SourceText sourceText) => _additionalSources.Add(hintName, sourceText);
SourceGeneration\IncrementalContexts.cs (10)
125public void AddSource(string hintName, string source) => AddSource(hintName, SourceText.From(source, Encoding.UTF8));
128/// Adds a <see cref="SourceText"/> to the compilation that will be available during subsequent phases
131/// <param name="sourceText">The <see cref="SourceText"/> to add to the compilation</param>
135public void AddSource(string hintName, SourceText sourceText) => AdditionalSources.Add(hintName, sourceText);
138/// Adds a <see cref="SourceText" /> to the compilation containing the definition of <c>Microsoft.CodeAnalysis.EmbeddedAttribute</c>.
145public void AddEmbeddedAttributeDefinition() => AddSource("Microsoft.CodeAnalysis.EmbeddedAttribute", SourceText.From(_embeddedAttributeDefinition, encoding: Encoding.UTF8));
172public void AddSource(string hintName, string source) => AddSource(hintName, SourceText.From(source, Encoding.UTF8));
175/// Adds a <see cref="SourceText"/> to the compilation
178/// <param name="sourceText">The <see cref="SourceText"/> to add to the compilation</param>
182public void AddSource(string hintName, SourceText sourceText) => Sources.Add(hintName, sourceText);
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];
522var lastSegment = _compositeText.Segments[lastSegmentIndexInclusive];
554var 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);
227/// Called from <see cref="SourceText.Lines"/> to initialize the <see cref="TextLineCollection"/>. Thereafter,
Text\SourceText.cs (54)
91/// Constructs a <see cref="SourceText"/> from text in a string.
97/// If the encoding is not specified the resulting <see cref="SourceText"/> isn't debuggable.
98/// If an encoding-less <see cref="SourceText"/> is written to a file a <see cref="Encoding.UTF8"/> shall be used as a default.
105public static SourceText From(string text, Encoding? encoding = null, SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1)
116/// Constructs a <see cref="SourceText"/> from text in a string.
123/// If the encoding is not specified the resulting <see cref="SourceText"/> isn't debuggable.
124/// If an encoding-less <see cref="SourceText"/> is written to a file a <see cref="Encoding.UTF8"/> shall be used as a default.
131public static SourceText From(
154public static SourceText From(Stream stream, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected)
158/// Constructs a <see cref="SourceText"/> from stream content.
180public static SourceText From(
225public static SourceText From(byte[] buffer, int length, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected)
229/// Constructs a <see cref="SourceText"/> from a byte array.
249public static SourceText From(
392/// If an encoding-less <see cref="SourceText"/> is written to a file a <see cref="Encoding.UTF8"/> shall be used as a default.
410internal virtual ImmutableArray<SourceText> Segments
412get { return ImmutableArray<SourceText>.Empty; }
415internal virtual SourceText StorageKey
471/// The container of this <see cref="SourceText"/>.
497/// Gets a <see cref="SourceText"/> that contains the characters in the specified span of this text.
499public virtual SourceText GetSubText(TextSpan span)
506return SourceText.From(string.Empty, this.Encoding, this.ChecksumAlgorithm);
519/// Returns a <see cref="SourceText"/> that has the contents of this text including and after the start position.
521public SourceText GetSubText(int start)
539/// Write this <see cref="SourceText"/> to a text writer.
576/// that were used to produce this <see cref="SourceText"/> (if any of the <c>From</c> methods were used that
577/// take a <c>byte[]</c> or <see cref="Stream"/>). Otherwise, computed by writing this <see cref="SourceText"/>
582/// Two different <see cref="SourceText"/> instances with the same content (see <see cref="ContentEquals"/>) may
588/// Similarly, two different <see cref="SourceText"/> instances with <em>different</em> contents can have the
609/// Produces a hash of this <see cref="SourceText"/> based solely on the contents it contains. Two different
610/// <see cref="SourceText"/> instances that are <see cref="ContentEquals"/> will have the same content hash. Two
611/// instances of <see cref="SourceText"/> with different content are virtually certain to not have the same
748public virtual SourceText WithChanges(IEnumerable<TextChange> changes)
760var segments = ArrayBuilder<SourceText>.GetInstance();
798var subText = this.GetSubText(new TextSpan(position, change.Span.Start - position));
804var segment = SourceText.From(change.NewText!, this.Encoding, this.ChecksumAlgorithm);
821var subText = this.GetSubText(new TextSpan(position, this.Length - position));
825var newText = CompositeText.ToSourceText(segments, this, adjustSegments: true);
849/// <exception cref="ArgumentException">If any changes are not in bounds of this <see cref="SourceText"/>.</exception>
851public SourceText WithChanges(params TextChange[] changes)
859public SourceText Replace(TextSpan span, string newText)
867public SourceText Replace(int start, int length, string newText)
877public virtual IReadOnlyList<TextChangeRange> GetChangeRanges(SourceText oldText)
899public virtual IReadOnlyList<TextChange> GetTextChanges(SourceText oldText)
964private readonly SourceText _text;
968public LineInfo(SourceText text, SegmentedList<int> lineStarts)
1139/// Compares the content with content of another <see cref="SourceText"/>.
1141public bool ContentEquals(SourceText other)
1166/// Implements equality comparison of the content of two different instances of <see cref="SourceText"/>.
1168protected virtual bool ContentEqualsImpl(SourceText other)
1262private readonly SourceText _text;
1264public StaticContainer(SourceText text)
1269public override SourceText CurrentText => _text;
Microsoft.CodeAnalysis.Analyzers (32)
MetaAnalyzers\ReleaseTrackingHelper.cs (8)
45SourceText sourceText,
46Action<string, Version, string, SourceText, TextLine> onDuplicateEntryInRelease,
47Action<TextLine, InvalidEntryKind, string, SourceText> onInvalidEntry,
439public SourceText SourceText { get; }
448TextSpan span, SourceText sourceText,
457TextSpan span, SourceText sourceText,
477TextSpan span, SourceText sourceText,
496TextSpan span, SourceText sourceText,
Microsoft.CodeAnalysis.AnalyzerUtilities (5)
Microsoft.CodeAnalysis.BannedApiAnalyzers (7)
Microsoft.CodeAnalysis.CodeStyle (55)
src\Compilers\Core\Portable\EncodedStringText.cs (11)
53/// Initializes an instance of <see cref="SourceText"/> from the provided stream. This version differs
54/// from <see cref="SourceText.From(Stream, Encoding, SourceHashAlgorithm, bool)"/> in two ways:
72internal static SourceText Create(Stream stream,
84internal static SourceText Create(Stream stream,
117/// Try to create a <see cref="SourceText"/> from the given stream using the given encoding.
124/// <returns>The <see cref="SourceText"/> decoded from the stream.</returns>
127private static SourceText Decode(
146return SourceText.From(bytes.Array,
156return SourceText.From(data, encoding, checksumAlgorithm, throwIfBinaryDetected, canBeEmbedded);
230internal static SourceText Create(Stream stream, Lazy<Encoding> getEncoding, Encoding defaultEncoding, SourceHashAlgorithm checksumAlgorithm, bool canBeEmbedded)
233internal static SourceText Decode(Stream data, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
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)
Microsoft.CodeAnalysis.CodeStyle.Fixes (44)
src\Analyzers\Core\CodeFixes\ConflictMarkerResolution\AbstractConflictMarkerCodeFixProvider.cs (15)
74var text = await document.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
84SyntaxNode root, SourceText text, int position,
145SourceText text, int position,
209var text = startLine.Text!;
227var text = startLine.Text!;
245var text = currentLine.Text!;
315Action<SourceText, ArrayBuilder<TextChange>, int, int, int, int> addEdits,
318var text = await document.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
323var finalText = text.WithChanges(edits);
328SourceText text, ArrayBuilder<TextChange> edits,
341SourceText text, ArrayBuilder<TextChange> edits,
354SourceText text, ArrayBuilder<TextChange> edits,
388private static int GetEndIncludingLineBreak(SourceText text, int position)
404var text = await document.GetValueTextAsync(cancellationToken).ConfigureAwait(false);
443var finalText = text.WithChanges(edits);
Microsoft.CodeAnalysis.CodeStyle.UnitTestUtilities (5)
Microsoft.CodeAnalysis.CSharp (50)
Syntax\CSharpSyntaxTree.cs (10)
380internal static SyntaxTree CreateForDebugger(CSharpSyntaxNode root, SourceText text, CSharpParseOptions options)
416SourceText text,
460return ParseText(SourceText.From(text, encoding, SourceHashAlgorithm.Sha1), options, path, diagnosticOptions, isGeneratedCode, cancellationToken);
471SourceText text,
491SourceText text,
534public override SyntaxTree WithChangedText(SourceText newText)
537if (this.TryGetText(out SourceText? oldText))
553private SyntaxTree WithChanges(SourceText newText, IReadOnlyList<TextChangeRange> changes)
911SourceText text,
928=> ParseText(SourceText.From(text, encoding, SourceHashAlgorithm.Sha1), options, path, diagnosticOptions, isGeneratedCode: null, cancellationToken);
Syntax\SyntaxFactory.cs (10)
1562return CSharpSyntaxTree.ParseText(SourceText.From(text, encoding, SourceHashAlgorithm.Sha1), (CSharpParseOptions?)options, path, diagnosticOptions: null, isGeneratedCode: null, cancellationToken);
1566/// <inheritdoc cref="CSharpSyntaxTree.ParseText(SourceText, CSharpParseOptions?, string, CancellationToken)"/>
1568SourceText text,
1682public static SyntaxTokenParser CreateTokenParser(SourceText sourceText, CSharpParseOptions? options = null)
1911private static SourceText MakeSourceText(string text, int offset)
1913return SourceText.From(text, Encoding.UTF8).GetSubText(offset);
2790return ParseSyntaxTree(SourceText.From(text, encoding), options, path, diagnosticOptions, isGeneratedCode: null, cancellationToken);
2797SourceText text,
2818return ParseSyntaxTree(SourceText.From(text, encoding), options, path, diagnosticOptions, isGeneratedCode, cancellationToken);
2825SourceText text,
Microsoft.CodeAnalysis.CSharp.CodeStyle (20)
Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes (16)
src\Analyzers\CSharp\CodeFixes\NewLines\ArrowExpressionClausePlacement\ArrowExpressionClausePlacementCodeFixProvider.cs (1)
66SourceText text,
src\Analyzers\CSharp\CodeFixes\NewLines\ConditionalExpressionPlacement\ConditionalExpressionPlacementCodeFixProvider.cs (1)
67SourceText text,
Microsoft.CodeAnalysis.CSharp.CommandLine.UnitTests (2)
Microsoft.CodeAnalysis.CSharp.EditorFeatures (43)
StringCopyPaste\StringCopyPasteHelpers.cs (11)
29public static char SafeCharAt(SourceText text, int index)
104public static int GetFirstNonWhitespaceIndex(SourceText text, TextLine line)
169public static int SkipU8Suffix(SourceText text, int end)
183public static int GetLongestQuoteSequence(SourceText text, TextSpan span)
186public static int GetLongestOpenBraceSequence(SourceText text, TextSpan span)
189public static int GetLongestCloseBraceSequence(SourceText text, TextSpan span)
197private static int GetLongestCharacterSequence(SourceText text, TextSpan span, char character)
503var text = SourceText.From(change.NewText);
521private static string? GetCommonIndentationPrefix(string? commonIndentPrefix, SourceText text, TextSpan lineWhitespaceSpan)
542public static bool RawContentMustBeMultiLine(SourceText text, ImmutableArray<TextSpan> spans)
Microsoft.CodeAnalysis.CSharp.EditorFeatures.UnitTests (109)
PdbSourceDocument\AbstractPdbSourceDocumentTests.cs (10)
120protected static async Task<(SourceText?, TextSpan)> GetGeneratedSourceTextAsync(
161var result = pdbService.TryAddDocumentToWorkspace((MetadataAsSourceWorkspace)masWorkspace!, file.FilePath, new StaticSourceTextContainer(SourceText.From(string.Empty)), out _);
198var sourceText = SourceText.From(source, encoding: encoding ?? Encoding.UTF8);
206SourceText source,
248protected static void CompileTestSource(string path, SourceText source, Project project, Location pdbLocation, Location sourceLocation, bool buildReferenceAssembly, bool windowsPdb, Encoding? fallbackEncoding = null)
258protected static void CompileTestSource(string dllFilePath, string sourceCodePath, string? pdbFilePath, string assemblyName, SourceText source, Project project, Location pdbLocation, Location sourceLocation, bool buildReferenceAssembly, bool windowsPdb, Encoding? fallbackEncoding = null)
263protected static void CompileTestSource(string dllFilePath, string[] sourceCodePaths, string? pdbFilePath, string assemblyName, SourceText[] sources, Project project, Location pdbLocation, Location sourceLocation, bool buildReferenceAssembly, bool windowsPdb, Encoding? fallbackEncoding = null)
344protected sealed class StaticSourceTextContainer(SourceText sourceText) : SourceTextContainer
346public override SourceText CurrentText => sourceText;
PdbSourceDocument\ImplementationAssemblyLookupServiceTests.cs (28)
43var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
81var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
123var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
161var sourceText = SourceText.From(metadataSource, Encoding.UTF8);
185sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
222var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
245sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
283var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
306sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
338var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
361sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
389var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
412sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
454var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
477sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
512var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
535var typeForwardSourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
PdbSourceDocument\PdbSourceDocumentTests.cs (20)
409var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
439var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
475var sourceText = SourceText.From(metadataSource, Encoding.UTF8);
522var sourceText = SourceText.From(metadataSource, Encoding.UTF8);
548sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
725CompileTestSource(path, SourceText.From(source2, Encoding.UTF8), project, Location.OnDisk, Location.OnDisk, buildReferenceAssembly: false, windowsPdb: false);
876var sourceText = SourceText.From(source, Encoding.UTF8);
927var sourceText1 = SourceText.From(source1, Encoding.UTF8);
928var sourceText2 = SourceText.From(source2, Encoding.UTF8);
975var result = service.TryAddDocumentToWorkspace(requestPath, new StaticSourceTextContainer(SourceText.From(string.Empty)), out var documentId);
998var openResult = service.TryAddDocumentToWorkspace(file.FilePath, new StaticSourceTextContainer(SourceText.From(string.Empty)), out var documentId);
1049var openResult = service.TryAddDocumentToWorkspace(fileOne.FilePath, new StaticSourceTextContainer(SourceText.From(string.Empty)), out var documentId);
1060Assert.Throws<System.InvalidOperationException>(() => service.TryAddDocumentToWorkspace(fileTwo.FilePath, new StaticSourceTextContainer(SourceText.From(string.Empty)), out var documentIdTwo));
Microsoft.CodeAnalysis.CSharp.EditorFeatures2.UnitTests (5)
Microsoft.CodeAnalysis.CSharp.Emit.UnitTests (3)
Microsoft.CodeAnalysis.CSharp.Emit2.UnitTests (6)
PDB\PDBTests.cs (4)
47var tree3 = SyntaxFactory.ParseSyntaxTree(SourceText.From("class C { }", encoding: null), path: "Bar.cs");
68var tree4 = SyntaxFactory.ParseSyntaxTree(SourceText.From("class D { public void F() { } }", new UTF8Encoding(false, false)), path: "Baz.cs");
104context.AddSource("hint2", SourceText.From("class G2 { void F() {} }", Encoding.UTF8, checksumAlgorithm: SourceHashAlgorithm.Sha256));
106Assert.Throws<ArgumentException>(() => context.AddSource("hint3", SourceText.From("class G3 { void F() {} }", encoding: null, checksumAlgorithm: SourceHashAlgorithm.Sha256)));
Microsoft.CodeAnalysis.CSharp.Features (114)
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)
Completion\CompletionProviders\ExplicitInterfaceMemberCompletionProvider.ItemGetter.cs (1)
34SourceText text,
src\Analyzers\CSharp\CodeFixes\NewLines\ArrowExpressionClausePlacement\ArrowExpressionClausePlacementCodeFixProvider.cs (1)
66SourceText text,
src\Analyzers\CSharp\CodeFixes\NewLines\ConditionalExpressionPlacement\ConditionalExpressionPlacementCodeFixProvider.cs (1)
67SourceText text,
StringIndentation\CSharpStringIndentationService.cs (4)
78SourceText text, SyntaxToken token, ref TemporaryArray<StringIndentationRegion> result, CancellationToken cancellationToken)
93SourceText text, InterpolatedStringExpressionSyntax interpolatedString, ref TemporaryArray<StringIndentationRegion> result, CancellationToken cancellationToken)
136private static bool IgnoreInterpolation(SourceText text, int offset, InterpolationSyntax interpolation)
157private static bool TryGetIndentSpan(SourceText text, ExpressionSyntax expression, out int offset, out TextSpan indentSpan)
Microsoft.CodeAnalysis.CSharp.Features.UnitTests (13)
EditAndContinue\CSharpEditAndContinueAnalyzerTests.cs (13)
45AddDocument("test.cs", SourceText.From(source, Encoding.UTF8), filePath: Path.Combine(TempRoot.Root, "test.cs")).Project.Solution;
305var oldText = await oldDocument.GetTextAsync();
308var newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2));
310var newText = await newDocument.GetTextAsync();
373var newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2));
435var newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2));
517var newSolution = workspace.CurrentSolution.WithDocumentText(documentId, SourceText.From(source2));
586var newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2));
625var newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2));
666var newSolution = oldSolution.AddDocument(newDocId, "goo.cs", SourceText.From(source2), filePath: Path.Combine(TempRoot.Root, "goo.cs"));
712var newSolution = oldSolution.AddDocument(newDocId, "goo.cs", SourceText.From(source2), filePath: Path.Combine(TempRoot.Root, "goo.cs"));
745var newSolution = oldSolution.AddDocument(documentId, "goo.cs", SourceText.From(source2), filePath: filePath);
802var newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2));
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.Semantic.UnitTests (56)
SourceGeneration\AdditionalSourcesCollectionTests.cs (23)
54asc.Add(hintName, SourceText.From("public class D{}", Encoding.UTF8));
70asc.Add(hintName, SourceText.From("public class D{}", Encoding.UTF8));
110var exception = Assert.Throws<ArgumentException>(nameof(hintName), () => asc.Add(hintName, SourceText.From("public class D{}", Encoding.UTF8)));
120asc.Add("file3.cs", SourceText.From("", Encoding.UTF8));
121asc.Add("file1.cs", SourceText.From("", Encoding.UTF8));
122asc.Add("file2.cs", SourceText.From("", Encoding.UTF8));
123asc.Add("file5.cs", SourceText.From("", Encoding.UTF8));
124asc.Add("file4.cs", SourceText.From("", Encoding.UTF8));
144asc.Add(names[i], SourceText.From("", Encoding.UTF8));
166asc.Add(hintName1, SourceText.From("", Encoding.UTF8));
167var exception = Assert.Throws<ArgumentException>("hintName", () => asc.Add(hintName2, SourceText.From("", Encoding.UTF8)));
176asc.Add("hintName1", SourceText.From("", Encoding.UTF8));
177asc.Add("hintName2", SourceText.From("", Encoding.UTF8));
180asc2.Add("hintName3", SourceText.From("", Encoding.UTF8));
181asc2.Add("hintName1", SourceText.From("", Encoding.UTF8));
200asc.Add(addHintName, SourceText.From("", Encoding.UTF8));
212asc.Add(addHintName, SourceText.From("", Encoding.UTF8));
224asc.Add("file1.cs", SourceText.From("", Encoding.UTF8));
225asc.Add("file2.cs", SourceText.From("", Encoding.UTF32));
226asc.Add("file3.cs", SourceText.From("", Encoding.Unicode));
229Assert.Throws<ArgumentException>(() => asc.Add("file4.cs", SourceText.From("")));
232Assert.Throws<ArgumentException>(() => asc.Add("file5.cs", SourceText.From("", encoding: null)));
234var exception = Assert.Throws<ArgumentException>(() => asc.Add("file5.cs", SourceText.From("", encoding: null)));
SourceGeneration\GeneratorDriverTests.cs (12)
460sgc.AddSource("test", SourceText.From("public class D{}", Encoding.UTF8));
463Assert.Throws<ArgumentException>("hintName", () => sgc.AddSource("test", SourceText.From("public class D{}", Encoding.UTF8)));
466Assert.Throws<ArgumentException>("hintName", () => sgc.AddSource("test.cs", SourceText.From("public class D{}", Encoding.UTF8)));
491spc.AddSource("test", SourceText.From("public class D{}", Encoding.UTF8));
494Assert.Throws<ArgumentException>("hintName", () => spc.AddSource("test", SourceText.From("public class D{}", Encoding.UTF8)));
497Assert.Throws<ArgumentException>("hintName", () => spc.AddSource("test.cs", SourceText.From("public class D{}", Encoding.UTF8)));
504spc.AddSource("test", SourceText.From("public class D{}", Encoding.UTF8));
586var generator = new CallbackGenerator((ic) => { }, (sgc) => { sgc.AddSource("test", SourceText.From("public class D {}", Encoding.UTF8)); });
616var generator = new CallbackGenerator((ic) => { }, (sgc) => { sgc.AddSource("test", SourceText.From("public class D {}", Encoding.UTF8)); sgc.AddSource("test2", SourceText.From("public class E {}", Encoding.UTF8)); });
756e.AddSource("a", SourceText.From("public class E {}", Encoding.UTF8));
780var generator = new CallbackGenerator((ic) => { }, (sgc) => { sgc.AddSource("a", SourceText.From("")); });
Microsoft.CodeAnalysis.CSharp.Symbol.UnitTests (5)
Microsoft.CodeAnalysis.CSharp.Syntax.UnitTests (335)
IncrementalParsing\IncrementalParsingTests.cs (228)
31var itext = SourceText.From(text);
38var itext = SourceText.From(text);
494var text = tree.GetText();
526var text = tree.GetText();
567var text = tree.GetText();
618var initialText = initialTree.GetText();
626var withOpenBraceDeletedText = initialText.WithChanges(new TextChange(openBraceLine.SpanIncludingLineBreak, ""));
837var withCloseBraceDeletedText = withOpenBraceDeletedText.WithChanges(new TextChange(closeBraceLine.SpanIncludingLineBreak, ""));
1391var text = SourceText.From(@"partial class C{}");
1395var newText = text.WithChanges(new TextChange(new TextSpan(0, 8), ""));
1405var text = SourceText.From(@"partial class C{}");
1409var newText = text.WithChanges(new TextChange(new TextSpan(0, 8), ""));
1419SourceText oldText = SourceText.From(@"
1435SourceText oldText = SourceText.From(@"
1451SourceText oldText = SourceText.From(@"
1468SourceText oldText = SourceText.From(@"
1484SourceText oldText = SourceText.From(@"
1497SourceText oldText = SourceText.From(@"
1513SourceText oldText = SourceText.From(@"
1525SourceText oldText = SourceText.From(@"
1537SourceText oldText = SourceText.From(@" class A
1553SourceText oldText = SourceText.From(@"public class TestClass
1566SourceText oldText = SourceText.From(@"using System;
1581SourceText oldText = SourceText.From(@"public class MyClass {
1593SourceText oldText = SourceText.From(@"
1607SourceText startingText = SourceText.From(@"
1628SourceText startingText = SourceText.From(@"
1647SourceText startingText = SourceText.From(@"
1667SourceText oldText = SourceText.From(@"class MyClass
1687SourceText oldText = SourceText.From(@"
1711SourceText oldText = SourceText.From(@"
1735SourceText oldText = SourceText.From(@"interface IGoo
1759SourceText oldText = SourceText.From(@"interface IGoo
1783SourceText oldText = SourceText.From(@"using System.Runtime.CompilerServices;
1805SourceText oldText = SourceText.From(@"class A
1829SourceText oldText = SourceText.From(@"public class MyClass {
1851SourceText oldText = SourceText.From(@"public class MyClass {
1942SourceText oldText = SourceText.From(@"class filesystem{
1961SourceText oldText = SourceText.From(@"class CSTR020mod{ public static void CSTR020() { ON ERROR GOTO ErrorTrap; } }");
1977SourceText oldText = SourceText.From(@"class A
1997SourceText oldText = SourceText.From(@"public class DynClassDrived
2019SourceText oldText = SourceText.From(@"public class MemberClass
2039SourceText oldText = SourceText.From(@"public class MemberClass
2058SourceText oldText = SourceText.From(@"class Test
2080SourceText oldText = SourceText.From(
2107SourceText oldText = SourceText.From(
2133SourceText oldText = SourceText.From(
2158SourceText oldText = SourceText.From(
2180SourceText oldText = SourceText.From(
2235SourceText oldText = SourceText.From(
2257SourceText oldText = SourceText.From(
2278SourceText oldText = SourceText.From(
2299SourceText oldText = SourceText.From(
2322SourceText oldText = SourceText.From(
2343SourceText oldText = SourceText.From(
2363SourceText oldText = SourceText.From(
2381SourceText oldText = SourceText.From(
2402SourceText oldText = SourceText.From(
2425SourceText oldText = SourceText.From(
2442SourceText oldText = SourceText.From(
2460SourceText oldText = SourceText.From(
2478SourceText oldText = SourceText.From(
2499SourceText oldText = SourceText.From(
2534SourceText oldText = SourceText.From(
2558SourceText oldText = SourceText.From(
2576SourceText oldText = SourceText.From(
2594SourceText oldText = SourceText.From(
2613SourceText oldText = SourceText.From(
2644SourceText oldText = SourceText.From(
2669SourceText oldText = SourceText.From(
2688SourceText oldText = SourceText.From(
2706SourceText oldText = SourceText.From(
2725SourceText oldText = SourceText.From(
2744SourceText oldText = SourceText.From(
2765SourceText oldText = SourceText.From(
2784SourceText oldText = SourceText.From(
2811SourceText oldText = SourceText.From(
2839SourceText oldText = SourceText.From(
2861SourceText oldText = SourceText.From(
2880SourceText oldText = SourceText.From(
2912SourceText oldText = SourceText.From(
2945SourceText oldText = SourceText.From(
2971SourceText oldText = SourceText.From(
2996SourceText oldText = SourceText.From(
3026SourceText oldText = SourceText.From(
3055SourceText oldText = SourceText.From(
3076SourceText oldText = SourceText.From(
3108SourceText oldText = SourceText.From(
3136SourceText oldText = SourceText.From(
3174var text = SourceText.From(str);
3177var text2 = text.WithChanges(
3192SourceText oldText = SourceText.From(@"
3200var newText = oldText.WithChanges(new TextChange(new TextSpan(0, 0), "{"));
3210SourceText oldText = SourceText.From(@"System.Console.WriteLine(true)
3216var newText = oldText.WithChanges(new TextChange(new TextSpan(0, 0), @"System.Console.WriteLine(false)
3239SourceText oldText = SourceText.From(@"System.Console.WriteLine(true)
3245var newText = oldText.WithInsertAt(
3269SourceText oldText = SourceText.From(@"System.Console.WriteLine(true)
3275var newText = oldText.WithChanges(new TextChange(new TextSpan(0, 0), @"if (false)
3329var oldIText = oldTree.GetText();
3333var newIText = oldIText.WithChanges(change);
3407var currIText = currTree.GetText();
3447var currIText = currTree.GetText();
3527var oldText = SourceText.From(items[0]);
3531var newText = oldText.WithChanges(change); // f is a method decl parameter
3558var oldText = SourceText.From(@"
3584var newText = SourceText.From(@"
3627var text = tree.GetText();
3648var text = tree.GetText();
3669var text = tree.GetText();
3690var text = tree.GetText();
3711var text = tree.GetText();
3732var text = tree.GetText();
3756var text = tree.GetText();
3780var text = tree.GetText();
3804var text = tree.GetText();
3828var text = tree.GetText();
3852var text = tree.GetText();
3878var text = tree.GetText();
3904var text = tree.GetText();
3929var text = tree.GetText();
3955var text = tree.GetText();
3973var text = tree.GetText();
3991var text = tree.GetText();
4009var text = tree.GetText();
4024var text = tree.GetText();
4038var text = tree.GetText();
4052var text = tree.GetText();
4090var text = tree.GetText();
4111var text = tree.GetText();
4154private static void CommentOutText(SourceText oldText, int locationOfChange, int widthOfChange, out SyntaxTree incrementalTree, out SyntaxTree parsedTree)
4156var newText = oldText.WithChanges(
4166private static void RemoveText(SourceText oldText, int locationOfChange, int widthOfChange, out SyntaxTree incrementalTree, out SyntaxTree parsedTree)
4168var newText = oldText.WithChanges(new TextChange(new TextSpan(locationOfChange, widthOfChange), ""));
4188private static void CharByCharIncrementalParse(SourceText oldText, char newChar, out SyntaxTree incrementalTree, out SyntaxTree parsedTree)
4194var newText = oldText.WithChanges(new TextChange(new TextSpan(oldText.Length, 0), newChar.ToString()));
4199private static void TokenByTokenBottomUp(SourceText oldText, string token, out SyntaxTree incrementalTree, out SyntaxTree parsedTree)
4202SourceText newText = SourceText.From(token + oldText.ToString());
Syntax\SyntaxTreeTests.cs (15)
86SyntaxTreeFactoryKind.ParseText => CSharpSyntaxTree.ParseText(SourceText.From(source, Encoding.UTF8, SourceHashAlgorithm.Sha256), parseOptions),
87SyntaxTreeFactoryKind.Subclass => new MockCSharpSyntaxTree(root, SourceText.From(source, Encoding.UTF8, SourceHashAlgorithm.Sha256), parseOptions),
142SourceText.From(""),
149var newTree = tree.WithChangedText(SourceText.From("class C { }"));
157SourceText.From(""),
173SourceText.From(""),
189SourceText.From(""),
247var newText = newTree.GetText();
259var oldText = SourceText.From("class B {}", Encoding.Unicode, SourceHashAlgorithms.Default);
265var newText = newTree.GetText();
289var newText = newTree.GetText();
301var oldText = SourceText.From("class B {}", Encoding.Unicode, SourceHashAlgorithms.Default);
305var newText = newTree.GetText();
TextExtensions.cs (18)
22public static SourceText WithReplace(this SourceText text, int offset, int length, string newText)
27return SourceText.From(newFullText);
30public static SourceText WithReplaceFirst(this SourceText text, string oldText, string newText)
37return SourceText.From(newFullText);
40public static SourceText WithReplace(this SourceText text, int startIndex, string oldText, string newText)
47return SourceText.From(newFullText);
50public static SourceText WithInsertAt(this SourceText text, int offset, string newText)
55public static SourceText WithInsertBefore(this SourceText text, string existingText, string newText)
61return SourceText.From(newFullText);
64public static SourceText WithRemoveAt(this SourceText text, int offset, int length)
69public static SourceText WithRemoveFirst(this SourceText text, string oldText)
Microsoft.CodeAnalysis.CSharp.Test.Utilities (6)
Microsoft.CodeAnalysis.CSharp.Workspaces (26)
Microsoft.CodeAnalysis.CSharp.Workspaces.UnitTests (3)
Microsoft.CodeAnalysis.EditorFeatures (107)
EditorConfigSettings\Updater\SettingsUpdateHelper.cs (13)
24public static SourceText? TryUpdateAnalyzerConfigDocument(SourceText originalText,
46public static SourceText? TryUpdateAnalyzerConfigDocument(
47SourceText originalText,
102public static SourceText? TryUpdateAnalyzerConfigDocument(SourceText originalText,
106var updatedText = originalText;
111SourceText? newText;
154private static (SourceText? newText, TextLine? lastValidHeaderSpanEnd, TextLine? lastValidSpecificHeaderSpanEnd) UpdateIfExistsInFile(SourceText editorConfigText,
291private static (SourceText? newText, TextLine? lastValidHeaderSpanEnd, TextLine? lastValidSpecificHeaderSpanEnd) AddMissingRule(SourceText editorConfigText,
349var result = editorConfigText.WithChanges(new TextChange(new TextSpan(editorConfigText.Length, 0), prefix + newEntry));
EditorConfigSettings\Updater\SettingsUpdaterBase.cs (8)
24protected abstract SourceText? GetNewText(SourceText analyzerConfigDocument, IReadOnlyList<(TOption option, TValue value)> settingsToUpdate, CancellationToken token);
50public async Task<SourceText?> GetChangedEditorConfigAsync(AnalyzerConfigDocument? analyzerConfigDocument, CancellationToken token)
58var newText = GetNewText(originalText, _queue, token);
78var newText = await GetChangedEditorConfigAsync(analyzerConfigDocument, token).ConfigureAwait(false);
88public async Task<SourceText?> GetChangedEditorConfigAsync(SourceText originalText, CancellationToken token)
92var newText = GetNewText(originalText, _queue, token);
InlineRename\InlineRenameSession.cs (5)
201private sealed class NullTextBufferException(Document document, SourceText text) : Exception("Cannot retrieve textbuffer from document.")
205private readonly SourceText _text = text;
926async Task<ImmutableArray<(DocumentId documentId, string newName, SyntaxNode newRoot, SourceText newText)>> CalculateFinalDocumentChangesAsync(
932using var _ = PooledObjects.ArrayBuilder<(DocumentId documentId, string newName, SyntaxNode newRoot, SourceText newText)>.GetInstance(out var result);
953ImmutableArray<(DocumentId documentId, string newName, SyntaxNode newRoot, SourceText newText)> documentChanges)
Microsoft.CodeAnalysis.EditorFeatures.Test.Utilities (19)
Microsoft.CodeAnalysis.EditorFeatures.Text (20)
Microsoft.CodeAnalysis.EditorFeatures.UnitTests (50)
Diagnostics\DiagnosticAnalyzerServiceTests.cs (8)
172project = project.AddAnalyzerConfigDocument(".editorconfig", filePath: "z:\\.editorconfig", text: SourceText.From(editorconfigText)).Project;
175var document = project.AddDocument("test.cs", SourceText.From("class A {}"), filePath: "z:\\test.cs");
261loader: TextLoader.From(TextAndVersion.Create(SourceText.From("class A {}"), VersionStamp.Create(), filePath: "test.cs")),
309text: SourceText.From(analyzerConfigText),
339loader: TextLoader.From(TextAndVersion.Create(SourceText.From("class A {}"), VersionStamp.Create(), filePath: "test.cs")),
416var text = await additionalDoc.GetTextAsync();
578var text = await document.GetTextAsync();
833return workspace.AddDocument(project.Id, "Empty.cs", SourceText.From("class A { B B {get} }"));
Microsoft.CodeAnalysis.EditorFeatures.Wpf (4)
Microsoft.CodeAnalysis.EditorFeatures2.UnitTests (26)
IntelliSense\CSharpCompletionCommandHandlerTests.vb (8)
4208Public Overrides Function IsInsertionTrigger(text As SourceText, characterPosition As Integer, options As CompletionOptions) As Boolean
8224Public Overrides Function ShouldTriggerCompletion(text As SourceText, caretPosition As Integer, trigger As CompletionTrigger, options As OptionSet) As Boolean
8269Public Overrides Function ShouldTriggerCompletion(text As SourceText, caretPosition As Integer, trigger As CompletionTrigger, options As OptionSet) As Boolean
9611Public Overrides Function ShouldTriggerCompletion(text As SourceText, caretPosition As Integer, trigger As CompletionTrigger, options As OptionSet) As Boolean
10272Public Overrides Function IsInsertionTrigger(text As SourceText, characterPosition As Integer, options As CompletionOptions) As Boolean
10345Public Overrides Function IsInsertionTrigger(text As SourceText, characterPosition As Integer, options As CompletionOptions) As Boolean
10638Public Overrides Function IsInsertionTrigger(text As SourceText, characterPosition As Integer, options As CompletionOptions) As Boolean
10774Public Overrides Function ShouldTriggerCompletion(text As SourceText, caretPosition As Integer, trigger As CompletionTrigger, options As OptionSet) As Boolean
Microsoft.CodeAnalysis.ExternalAccess.FSharp (12)
Completion\FSharpCompletionProviderBase.cs (3)
13public sealed override bool ShouldTriggerCompletion(SourceText text, int caretPosition, CompletionTrigger trigger, OptionSet options)
16internal sealed override bool ShouldTriggerCompletion(Host.LanguageServices languageServices, SourceText text, int caretPosition, CompletionTrigger trigger, CompletionOptions options, OptionSet passthroughOptions)
19protected abstract bool ShouldTriggerCompletionImpl(SourceText text, int caretPosition, CompletionTrigger trigger);
Microsoft.CodeAnalysis.ExternalAccess.OmniSharp (2)
Microsoft.CodeAnalysis.ExternalAccess.Razor.Features (2)
Microsoft.CodeAnalysis.Features (150)
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\AbstractOverrideCompletionProvider.ItemGetter.cs (1)
20SourceText text,
DocumentationComments\AbstractDocumentationCommentSnippetService.cs (9)
42private bool IsAtEndOfDocCommentTriviaOnBlankLine(SourceText text, int endPosition)
80var text = document.Text;
110private List<string>? GetDocumentationCommentLines(SyntaxToken token, SourceText text, in DocumentationCommentOptions options, out string? indentText, out int caretOffset, out int spanToReplaceLength)
141private List<string>? GetDocumentationCommentLinesNoIndentation(SyntaxToken token, SourceText text, in DocumentationCommentOptions options, out int caretOffset, out int spanToReplaceLength, out string? indentText)
158private List<string>? GetDocumentationStubLines(SyntaxToken token, SourceText text, in DocumentationCommentOptions options, out int caretOffset, out int spanToReplaceLength, out string? existingCommentText)
202var text = document.Text;
279var text = document.Text;
330var text = document.Text;
370var text = document.Text;
EditAndContinue\AbstractEditAndContinueAnalyzer.cs (8)
505private static readonly SourceText s_emptySource = SourceText.From("");
536SourceText oldText;
719void LogRudeEdits(ImmutableArray<RudeEditDiagnostic> diagnostics, SourceText text, string filePath)
790SourceText newText,
954SourceText newText,
1330private static bool TryGetTrackedStatement(ImmutableArray<ActiveStatementLineSpan> activeStatementSpans, ActiveStatementId id, SourceText text, MemberBody body, [NotNullWhen(true)] out SyntaxNode? trackedStatement, out int trackedStatementPart)
2528SourceText newText,
EditAndContinue\CommittedSolution.cs (9)
309private async ValueTask<(Optional<SourceText?> matchingSourceText, bool? hasDocument)> TryGetMatchingSourceTextAsync(Document document, SourceText sourceText, Document? currentDocument, CancellationToken cancellationToken)
322private static async ValueTask<Optional<SourceText?>> TryGetMatchingSourceTextAsync(
323TraceLog log, SourceText sourceText, string filePath, Document? currentDocument, IPdbMatchingSourceTextProvider sourceTextProvider, ImmutableArray<byte> requiredChecksum, SourceHashAlgorithm checksumAlgorithm, CancellationToken cancellationToken)
342return SourceText.From(text, sourceText.Encoding, checksumAlgorithm);
438private static bool IsMatchingSourceText(SourceText sourceText, ImmutableArray<byte> requiredChecksum, SourceHashAlgorithm checksumAlgorithm)
441private static Optional<SourceText?> TryGetPdbMatchingSourceTextFromDisk(
456var sourceText = SourceText.From(fileStream, encoding, 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\Analyzers\Core\CodeFixes\ConflictMarkerResolution\AbstractConflictMarkerCodeFixProvider.cs (10)
84SyntaxNode root, SourceText text, int position,
145SourceText text, int position,
209var text = startLine.Text!;
227var text = startLine.Text!;
245var text = currentLine.Text!;
315Action<SourceText, ArrayBuilder<TextChange>, int, int, int, int> addEdits,
328SourceText text, ArrayBuilder<TextChange> edits,
341SourceText text, ArrayBuilder<TextChange> edits,
354SourceText text, ArrayBuilder<TextChange> edits,
388private static int GetEndIncludingLineBreak(SourceText text, int position)
Microsoft.CodeAnalysis.Features.Test.Utilities (20)
Microsoft.CodeAnalysis.Features.UnitTests (34)
EditAndContinue\CompileTimeSolutionProviderTests.cs (5)
48AddAdditionalDocument(additionalDocumentId, "additional", SourceText.From(""), filePath: additionalFilePath).
49AddAnalyzerConfigDocument(analyzerConfigId, "config", SourceText.From(""), filePath: "RazorSourceGenerator.razorencconfig").
102context.AddSource("hint", SourceText.From(s));
117.AddAdditionalDocument(additionalDocumentId, "additional", SourceText.From(""), filePath: "additional.razor")
118.AddAnalyzerConfigDocument(analyzerConfigId, "config", SourceText.From(analyzerConfigText), filePath: "Z:\\RazorSourceGenerator.razorencconfig"),
EditAndContinue\EditAndContinueWorkspaceServiceTests.cs (11)
68var sourceTreeA1 = SyntaxFactory.ParseSyntaxTree(SourceText.From(sourceBytesA1, sourceBytesA1.Length, encodingA, SourceHashAlgorithms.Default), TestOptions.Regular, sourceFileA.Path);
69var sourceTreeB1 = SyntaxFactory.ParseSyntaxTree(SourceText.From(sourceBytesB1, sourceBytesB1.Length, encodingB, SourceHashAlgorithms.Default), TestOptions.Regular, sourceFileB.Path);
70var sourceTreeC1 = SyntaxFactory.ParseSyntaxTree(SourceText.From(sourceBytesC1, sourceBytesC1.Length, encodingC, SourceHashAlgorithm.Sha1), TestOptions.Regular, sourceFileC.Path);
346var sourceText = CreateText("class D {}");
408solution = solution.AddDocument(designTimeOnlyDocumentId, designTimeOnlyFileName, SourceText.From(sourceDesignTimeOnly, Encoding.UTF8), filePath: designTimeOnlyFilePath);
428solution = solution.AddDocument(designTimeOnlyDocumentId, designTimeOnlyFileName, SourceText.From(sourceDesignTimeOnly, Encoding.UTF8), filePath: designTimeOnlyFilePath);
623AddDocument("a.cs", SourceText.From(source1, Encoding.UTF8, SourceHashAlgorithm.Sha1), filePath: sourceFile.Path);
923AddDocument(documentId, "test.cs", SourceText.From(source1, encoding, SourceHashAlgorithm.Sha1), filePath: sourceFile.Path);
1787context.AddSource("generated.cs", SourceText.From("generated: " + additionalText, Encoding.UTF8, SourceHashAlgorithm.Sha256));
2136solution = solution.WithDocumentText(document1.Id, SourceText.From("class C1 { void M() { System.Console.WriteLine(2); } }", encoding: null, SourceHashAlgorithms.Default));
3637DocumentId AddProjectAndLinkDocument(string projectName, Document doc, SourceText text)
Microsoft.CodeAnalysis.LanguageServer (4)
Microsoft.CodeAnalysis.LanguageServer.Protocol (83)
Workspaces\LspWorkspaceManager.cs (7)
115private ImmutableDictionary<Uri, (SourceText Text, string LanguageId)> _trackedDocuments = ImmutableDictionary<Uri, (SourceText, string)>.Empty.WithComparers(LspUriComparer.Instance);
156public async ValueTask StartTrackingAsync(Uri uri, SourceText documentText, string languageId, CancellationToken cancellationToken)
234public void UpdateTrackedDocument(Uri uri, SourceText newSourceText)
247public ImmutableDictionary<Uri, (SourceText Text, string LanguageId)> GetTrackedLspText() => _trackedDocuments;
481ImmutableArray<(SourceGeneratedDocumentIdentity Identity, DateTime Generated, SourceText Text)> sourceGenereatedDocuments,
525private static async ValueTask<bool> AreChecksumsEqualAsync(TextDocument document, SourceText lspText, CancellationToken cancellationToken)
Microsoft.CodeAnalysis.LanguageServer.Protocol.UnitTests (36)
Completion\CompletionFeaturesTests.cs (4)
583Project project, LanguageServices languageServices, SourceText text, int caretPosition, CompletionTrigger trigger,
597var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
876Project project, LanguageServices languageServices, SourceText text, int caretPosition, CompletionTrigger trigger,
890var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
Workspaces\LspWorkspaceManagerTests.cs (5)
87await testLspServer.TestWorkspace.ChangeDocumentAsync(firstDocument.Id, SourceText.From($"Some more text{markupOne}", System.Text.Encoding.UTF8, SourceHashAlgorithms.Default));
121await testLspServer.TestWorkspace.ChangeDocumentAsync(secondDocument.Id, SourceText.From("Two is now three!", System.Text.Encoding.UTF8, SourceHashAlgorithms.Default));
223var newSolution = testLspServer.TestWorkspace.CurrentSolution.AddDocument(newDocumentId, "NewDoc.cs", SourceText.From("New Doc", System.Text.Encoding.UTF8, SourceHashAlgorithms.Default), filePath: @"C:\NewDoc.cs");
558.AddDocument(filePath, SourceText.From("ProjectSystemText"), filePath: filePath)
615testLspServer.TestWorkspace.CurrentSolution.WithDocumentText(document.Id, SourceText.From("New Disk Contents")));
Microsoft.CodeAnalysis.LanguageServer.UnitTests (11)
Microsoft.CodeAnalysis.PublicApiAnalyzers (20)
DeclarePublicApiAnalyzer.cs (8)
135bool TryGetAndValidateApiFiles(CompilationStartAnalysisContext context, bool isPublic, List<Diagnostic> errors, [NotNullWhen(true)] out ImmutableDictionary<AdditionalText, SourceText>? additionalFiles, [NotNullWhen(true)] out ApiData? shippedData, [NotNullWhen(true)] out ApiData? unshippedData)
157private static ApiData ReadApiData(SourceText sourceText, bool isShippedApi)
198private static bool TryGetApiData(CompilationStartAnalysisContext context, bool isPublic, List<Diagnostic> errors, [NotNullWhen(true)] out ImmutableDictionary<AdditionalText, SourceText>? additionalFiles, [NotNullWhen(true)] out ApiData? shippedData, [NotNullWhen(true)] out ApiData? unshippedData)
351out ImmutableDictionary<AdditionalText, SourceText> additionalFiles,
355additionalFiles = ImmutableDictionary<AdditionalText, SourceText>.Empty;
368var text = additionalText.GetText(context.CancellationToken);
378private static bool ValidateApiFiles(ImmutableDictionary<AdditionalText, SourceText> additionalFiles, ApiData shippedData, ApiData unshippedData, bool isPublic, List<Diagnostic> errors)
405private static void ValidateApiList(ImmutableDictionary<AdditionalText, SourceText> additionalFiles, Dictionary<string, ApiLine> publicApiMap, ImmutableArray<ApiLine> apiList, bool isPublic, List<Diagnostic> errors)
DeclarePublicApiAnalyzer.Impl.cs (7)
25private sealed record AdditionalFileInfo(SourceText SourceText, bool IsShippedApi)
27public string GetPath(ImmutableDictionary<AdditionalText, SourceText> additionalFiles)
43public SourceText SourceText => FileInfo.SourceText;
46public string GetPath(ImmutableDictionary<AdditionalText, SourceText> additionalFiles)
49public Location GetLocation(ImmutableDictionary<AdditionalText, SourceText> additionalFiles)
76private readonly ImmutableDictionary<AdditionalText, SourceText> _additionalFiles;
86internal Impl(Compilation compilation, ImmutableDictionary<AdditionalText, SourceText> additionalFiles, ApiData shippedData, ApiData unshippedData, bool isPublic, AnalyzerOptions analyzerOptions)
Microsoft.CodeAnalysis.PublicApiAnalyzers.CodeFixes (37)
DeclarePublicApiFix.cs (19)
94var sourceText = await surfaceAreaDocument.GetTextAsync(cancellationToken).ConfigureAwait(false);
102private static Solution AddPublicApiFiles(Project project, SourceText unshippedText, bool isPublic)
105project = AddAdditionalDocument(project, isPublic ? DeclarePublicApiAnalyzer.PublicShippedFileName : DeclarePublicApiAnalyzer.InternalShippedFileName, SourceText.From(string.Empty));
110static Project AddAdditionalDocument(Project project, string name, SourceText text)
122private static SourceText AddSymbolNamesToSourceText(SourceText? sourceText, IEnumerable<string> newSymbolNames)
134return sourceText?.Replace(new TextSpan(0, sourceText.Length), newText) ?? SourceText.From(newText);
152private static SourceText RemoveSymbolNamesFromSourceText(SourceText sourceText, ImmutableHashSet<string> linesToRemove)
163SourceText newSourceText = sourceText.Replace(new TextSpan(0, sourceText.Length), string.Join(endOfLine, newLines) + sourceText.GetEndOfFileText(endOfLine));
167internal static List<string> GetLinesFromSourceText(SourceText? sourceText)
229var updatedPublicSurfaceAreaText = new List<KeyValuePair<DocumentId, SourceText>>();
230var addedPublicSurfaceAreaText = new List<KeyValuePair<ProjectId, SourceText>>();
238var sourceText = publicSurfaceAreaAdditionalDocument != null ?
293SourceText newSourceText = AddSymbolNamesToSourceText(sourceText, newSymbolNames);
298updatedPublicSurfaceAreaText.Add(new KeyValuePair<DocumentId, SourceText>(publicSurfaceAreaAdditionalDocument.Id, newSourceText));
302addedPublicSurfaceAreaText.Add(new KeyValuePair<ProjectId, SourceText>(project.Id, newSourceText));
308foreach (KeyValuePair<DocumentId, SourceText> pair in updatedPublicSurfaceAreaText)
315foreach (KeyValuePair<ProjectId, SourceText> pair in addedPublicSurfaceAreaText)
Microsoft.CodeAnalysis.Rebuild (9)
Microsoft.CodeAnalysis.Rebuild.UnitTests (3)
Microsoft.CodeAnalysis.Remote.ServiceHub (2)
Microsoft.CodeAnalysis.Remote.Workspaces (1)
Microsoft.CodeAnalysis.ResxSourceGenerator (13)
Microsoft.CodeAnalysis.ResxSourceGenerator.UnitTests (2)
Microsoft.CodeAnalysis.Scripting (12)
Hosting\CommandLine\CommandLineRunner.cs (5)
110SourceText? code = null;
202private int RunScript(ScriptOptions? options, SourceText? code, ErrorLogger? errorLogger, CancellationToken cancellationToken)
233var script = Script.CreateInitialScript<object>(_scriptCompiler, SourceText.From(initialScriptCodeOpt), options, globals.GetType(), assemblyLoaderOpt: null);
260var tree = _scriptCompiler.ParseSubmission(SourceText.From(input.ToString()), options.ParseOptions, cancellationToken);
285newScript = Script.CreateInitialScript<object>(_scriptCompiler, SourceText.From(code ?? string.Empty), options, globals.GetType(), assemblyLoaderOpt: null);
Script.cs (6)
40internal Script(ScriptCompiler compiler, ScriptBuilder builder, SourceText sourceText, ScriptOptions options, Type globalsTypeOpt, Script previousOpt)
55internal static Script<T> CreateInitialScript<T>(ScriptCompiler compiler, SourceText sourceText, ScriptOptions optionsOpt, Type globalsTypeOpt, InteractiveAssemblyLoader assemblyLoaderOpt)
80internal SourceText SourceText { get; }
118return new Script<TResult>(Compiler, Builder, SourceText.From(code ?? "", options.FileEncoding), options, GlobalsType, this);
131return new Script<TResult>(Compiler, Builder, SourceText.From(code, options.FileEncoding), options, GlobalsType, this);
345internal Script(ScriptCompiler compiler, ScriptBuilder builder, SourceText sourceText, ScriptOptions options, Type globalsTypeOpt, Script previousOpt)
Microsoft.CodeAnalysis.Scripting.TestUtilities (3)
Microsoft.CodeAnalysis.Test.Utilities (32)
Microsoft.CodeAnalysis.TestAnalyzerReference (6)
Microsoft.CodeAnalysis.UnitTests (514)
EmbeddedTextTests.cs (29)
39Assert.Throws<ArgumentException>("text", () => EmbeddedText.FromSource("path", SourceText.From("source")));
42Assert.Throws<ArgumentException>("text", () => EmbeddedText.FromSource("path", SourceText.From(new byte[0], 0, Encoding.UTF8, canBeEmbedded: false)));
43Assert.Throws<ArgumentException>("text", () => EmbeddedText.FromSource("path", SourceText.From(new MemoryStream(new byte[0]), Encoding.UTF8, canBeEmbedded: false)));
84AssertEx.Equal(SourceText.CalculateChecksum(new byte[0], 0, 0, SourceHashAlgorithm.Sha1), text.Checksum);
92var checksum = SourceText.CalculateChecksum(new byte[0], 0, 0, SourceHashAlgorithm.Sha1);
103var source = SourceText.From("", new UTF8Encoding(encoderShouldEmitUTF8Identifier: false), SourceHashAlgorithm.Sha1);
105var checksum = SourceText.CalculateChecksum(new byte[0], 0, 0, SourceHashAlgorithm.Sha1);
117var checksum = SourceText.CalculateChecksum(bytes, 0, bytes.Length, SourceHashAlgorithm.Sha1);
132var checksum = SourceText.CalculateChecksum(bytes, 0, bytes.Length, SourceHashAlgorithm.Sha1);
145var source = SourceText.From(SmallSource, Encoding.UTF8, SourceHashAlgorithm.Sha1);
159var checksum = SourceText.CalculateChecksum(bytes, 0, bytes.Length, SourceHashAlgorithms.Default);
174var checksum = SourceText.CalculateChecksum(bytes, 0, bytes.Length, SourceHashAlgorithms.Default);
187var source = SourceText.From(LargeSource, Encoding.Unicode, SourceHashAlgorithms.Default);
200var expected = SourceText.From(SmallSource, Encoding.UTF8, SourceHashAlgorithm.Sha1);
203var actual = SourceText.From(new StringReader(SmallSource), SmallSource.Length, Encoding.UTF8, SourceHashAlgorithm.Sha1);
215var expected = SourceText.From(LargeSource, Encoding.UTF8, SourceHashAlgorithm.Sha1);
218var actual = SourceText.From(new StringReader(LargeSource), LargeSource.Length, Encoding.UTF8, SourceHashAlgorithm.Sha1);
235var source = useStream ?
236SourceText.From(new MemoryStream(bytes), Encoding.ASCII, SourceHashAlgorithm.Sha1, canBeEmbedded: true) :
237SourceText.From(bytes, bytes.Length, Encoding.ASCII, SourceHashAlgorithm.Sha1, canBeEmbedded: true);
242AssertEx.Equal(SourceText.CalculateChecksum(bytes, 0, bytes.Length, SourceHashAlgorithm.Sha1), source.GetChecksum());
252var source = EncodedStringText.Create(new MemoryStream(new byte[] { 0xA9, 0x0D, 0x0A }), canBeEmbedded: true);
Text\LargeTextTests.cs (24)
18private static SourceText CreateSourceText(string s, Encoding encoding = null)
31private static SourceText CreateSourceText(Stream stream, Encoding encoding = null)
36private static SourceText CreateSourceText(TextReader reader, int length, Encoding encoding = null)
46var text = CreateSourceText(HelloWorld);
56var text = CreateSourceText(stream);
64var text = CreateSourceText(HelloWorld);
76var text = CreateSourceText(HelloWorld);
123var text = SourceText.From(stream);
155private static void CheckLine(SourceText text, int lineNumber, int start, int length, int newlineLength, string lineText)
199var data = CreateSourceText("goo" + newline + " bar");
212var data = CreateSourceText(text);
223var data = CreateSourceText("goo\r\nbar");
232var data = CreateSourceText("goo\n\rbar\u2028");
244var data = CreateSourceText("goo\r");
254var data = CreateSourceText("goo\r\n");
264var data = CreateSourceText("goo\r\rbar");
277var data = CreateSourceText("goo" + cr + crLf + cr + "bar");
292var data = CreateSourceText("goo" + cr + crLf + lf + "bar");
303var data = CreateSourceText("");
314var data = CreateSourceText(text);
324var data = CreateSourceText(text);
332var expectedSourceText = CreateSourceText(expected);
335var actualSourceText = CreateSourceText(actual, expected.Length);
Text\SourceTextTests.cs (91)
29SourceText[] texts = [SourceText.From(string.Empty), SourceText.From([], 0), SourceText.From(new MemoryStream())];
31foreach (var text1 in texts)
35foreach (var text2 in texts)
43private static void TestIsEmpty(SourceText text)
56Assert.Same(s_utf8, SourceText.From(HelloWorld, s_utf8).Encoding);
57Assert.Same(s_unicode, SourceText.From(HelloWorld, s_unicode).Encoding);
60Assert.Same(s_unicode, SourceText.From(bytes, bytes.Length, s_unicode).Encoding);
61Assert.Equal(utf8NoBOM, SourceText.From(bytes, bytes.Length, null).Encoding);
64Assert.Same(s_unicode, SourceText.From(stream, s_unicode).Encoding);
65Assert.Equal(utf8NoBOM, SourceText.From(stream, null).Encoding);
74Assert.Equal(utf8BOM, SourceText.From(bytes, bytes.Length, s_unicode).Encoding);
75Assert.Equal(utf8BOM, SourceText.From(bytes, bytes.Length, null).Encoding);
78Assert.Equal(utf8BOM, SourceText.From(stream, s_unicode).Encoding);
79Assert.Equal(utf8BOM, SourceText.From(stream, null).Encoding);
85Assert.Equal(SourceHashAlgorithm.Sha1, SourceText.From(HelloWorld).ChecksumAlgorithm);
88Assert.Equal(SourceHashAlgorithm.Sha1, SourceText.From(bytes, bytes.Length).ChecksumAlgorithm);
91Assert.Equal(SourceHashAlgorithm.Sha1, SourceText.From(stream).ChecksumAlgorithm);
99Assert.Equal(algorithm, SourceText.From(HelloWorld, checksumAlgorithm: algorithm).ChecksumAlgorithm);
102Assert.Equal(algorithm, SourceText.From(bytes, bytes.Length, checksumAlgorithm: algorithm).ChecksumAlgorithm);
105Assert.Equal(algorithm, SourceText.From(stream, checksumAlgorithm: algorithm).ChecksumAlgorithm);
121verifyChecksumAndContentHash(SourceText.From(HelloWorld, encodingNoBOM, checksumAlgorithm), checksumNoBOM, expectedContentHash);
122verifyChecksumAndContentHash(SourceText.From(HelloWorld, encodingBOM, checksumAlgorithm), checksumBOM, expectedContentHash);
131verifyChecksumAndContentHash(SourceText.From(bytesNoBOM, bytesNoBOM.Length, null, checksumAlgorithm), checksumNoBOM, expectedContentHash);
132verifyChecksumAndContentHash(SourceText.From(bytesNoBOM, bytesNoBOM.Length, encodingNoBOM, checksumAlgorithm), checksumNoBOM, expectedContentHash);
133verifyChecksumAndContentHash(SourceText.From(bytesNoBOM, bytesNoBOM.Length, encodingBOM, checksumAlgorithm), checksumNoBOM, expectedContentHash);
136verifyChecksumAndContentHash(SourceText.From(bytesBOM, bytesBOM.Length, null, checksumAlgorithm), checksumBOM, expectedContentHash);
137verifyChecksumAndContentHash(SourceText.From(bytesBOM, bytesBOM.Length, encodingNoBOM, checksumAlgorithm), checksumBOM, expectedContentHash);
138verifyChecksumAndContentHash(SourceText.From(bytesBOM, bytesBOM.Length, encodingBOM, checksumAlgorithm), checksumBOM, expectedContentHash);
141verifyChecksumAndContentHash(SourceText.From(streamNoBOM, null, checksumAlgorithm), checksumNoBOM, expectedContentHash);
142verifyChecksumAndContentHash(SourceText.From(streamNoBOM, encodingNoBOM, checksumAlgorithm), checksumNoBOM, expectedContentHash);
143verifyChecksumAndContentHash(SourceText.From(streamNoBOM, encodingBOM, checksumAlgorithm), checksumNoBOM, expectedContentHash);
146verifyChecksumAndContentHash(SourceText.From(streamBOM, null, checksumAlgorithm), checksumBOM, expectedContentHash);
147verifyChecksumAndContentHash(SourceText.From(streamBOM, encodingNoBOM, checksumAlgorithm), checksumBOM, expectedContentHash);
148verifyChecksumAndContentHash(SourceText.From(streamBOM, encodingBOM, checksumAlgorithm), checksumBOM, expectedContentHash);
166verifyChecksumAndContentHash(fromChanges(SourceText.From(HelloWorld, encodingNoBOM, checksumAlgorithm)), checksumNoBOM, expectedContentHash);
167verifyChecksumAndContentHash(fromChanges(SourceText.From(HelloWorld, encodingBOM, checksumAlgorithm)), checksumBOM, expectedContentHash);
172verifyChecksumAndContentHash(fromChanges(SourceText.From(streamNoBOM, encodingNoBOM, checksumAlgorithm)), checksumNoBOM, expectedContentHash);
173verifyChecksumAndContentHash(fromChanges(SourceText.From(streamNoBOM, encodingBOM, checksumAlgorithm)), checksumBOM, expectedContentHash);
176verifyChecksumAndContentHash(fromChanges(SourceText.From(streamBOM, encodingNoBOM, checksumAlgorithm)), checksumBOM, expectedContentHash);
177verifyChecksumAndContentHash(fromChanges(SourceText.From(streamBOM, encodingBOM, checksumAlgorithm)), checksumBOM, expectedContentHash);
181static void verifyChecksumAndContentHash(SourceText text, ImmutableArray<byte> expectedChecksum, ImmutableArray<byte> expectedContentHash)
189static SourceText fromChanges(SourceText text)
193var changed = text.WithChanges(change);
201private static SourceText FromLargeTextWriter(string source, Encoding encoding, SourceHashAlgorithm checksumAlgorithm)
213var f = SourceText.From(HelloWorld, s_utf8);
215Assert.True(f.ContentEquals(SourceText.From(HelloWorld, s_utf8)));
216Assert.False(f.ContentEquals(SourceText.From(HelloWorld + "o", s_utf8)));
217Assert.True(SourceText.From(HelloWorld, s_utf8).ContentEquals(SourceText.From(HelloWorld, s_utf8)));
219var e1 = EncodedStringText.Create(new MemoryStream(s_unicode.GetBytes(HelloWorld)), s_unicode);
220var e2 = EncodedStringText.Create(new MemoryStream(s_utf8.GetBytes(HelloWorld)), s_utf8);
256var allSourceTexts = new List<SourceText>();
269foreach (var sourceText1 in allSourceTexts)
271foreach (var sourceText2 in allSourceTexts)
321Assert.False(SourceText.IsBinary(""));
323Assert.False(SourceText.IsBinary("\0abc"));
324Assert.False(SourceText.IsBinary("a\0bc"));
325Assert.False(SourceText.IsBinary("abc\0"));
326Assert.False(SourceText.IsBinary("a\0b\0c"));
328Assert.True(SourceText.IsBinary("\0\0abc"));
329Assert.True(SourceText.IsBinary("a\0\0bc"));
330Assert.True(SourceText.IsBinary("abc\0\0"));
333Assert.False(SourceText.IsBinary(encoding.GetString(new byte[] { 0x81, 0x8D, 0x8F, 0x90, 0x9D })));
335Assert.False(SourceText.IsBinary("abc def baz aeiouy \u00E4\u00EB\u00EF\u00F6\u00FC\u00FB"));
336Assert.True(SourceText.IsBinary(encoding.GetString(Net461.Resources.System)));
343Assert.Throws<InvalidDataException>(() => SourceText.From(bytes, bytes.Length, throwIfBinaryDetected: true));
346Assert.Throws<InvalidDataException>(() => SourceText.From(stream, throwIfBinaryDetected: true));
353var expectedSourceText = SourceText.From(expected);
356var actualSourceText = SourceText.From(actual, expected.Length);
360Assert.Same(s_utf8, SourceText.From(actual, expected.Length, s_utf8).Encoding);
361Assert.Same(s_unicode, SourceText.From(actual, expected.Length, s_unicode).Encoding);
362Assert.Null(SourceText.From(actual, expected.Length, null).Encoding);
368var expected = new string('l', SourceText.LargeObjectHeapLimitInChars);
369var expectedSourceText = SourceText.From(expected);
372var actualSourceText = SourceText.From(actual, expected.Length);
379Assert.Same(s_utf8, SourceText.From(actual, expected.Length, s_utf8).Encoding);
380Assert.Same(s_unicode, SourceText.From(actual, expected.Length, s_unicode).Encoding);
381Assert.Null(SourceText.From(actual, expected.Length, null).Encoding);
392Encoding actualEncoding = SourceText.TryReadByteOrderMark(data, validLength, out actualPreambleLength);
425var sourceText = SourceText.From("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
444var sourceText = SourceText.From(Text);
456SourceText.From("ABC").Write(TextWriter.Null, TextSpan.FromBounds(4, 4)));
465SourceText.From("ABC").Write(TextWriter.Null, TextSpan.FromBounds(2, 4)));
Text\StringTextDecodingTests.cs (20)
19private static SourceText CreateMemoryStreamBasedEncodedText(string text, Encoding writeEncoding, Encoding readEncodingOpt, SourceHashAlgorithm algorithm = SourceHashAlgorithm.Sha1)
26private static SourceText CreateMemoryStreamBasedEncodedText(byte[] bytes, Encoding readEncodingOpt, SourceHashAlgorithm algorithm = SourceHashAlgorithm.Sha1)
39private static SourceText CreateMemoryStreamBasedEncodedText(byte[] bytes,
59var data = CreateMemoryStreamBasedEncodedText(TestResources.General.ShiftJisSource, () => sjis);
69var data = CreateMemoryStreamBasedEncodedText(TestResources.General.ShiftJisSource, sjis);
78var data = CreateMemoryStreamBasedEncodedText("The quick brown fox jumps over the lazy dog", Encoding.ASCII, readEncodingOpt: null);
88var data = CreateMemoryStreamBasedEncodedText("The quick brown fox jumps over the lazy dog", Encoding.Unicode, readEncodingOpt: null);
97var data = CreateMemoryStreamBasedEncodedText("The quick brown fox jumps over the lazy dog", Encoding.BigEndianUnicode, readEncodingOpt: null);
106var data = CreateMemoryStreamBasedEncodedText("", Encoding.ASCII, readEncodingOpt: null);
116var data = CreateMemoryStreamBasedEncodedText("", Encoding.Unicode, readEncodingOpt: null);
125var data = CreateMemoryStreamBasedEncodedText("", Encoding.BigEndianUnicode, readEncodingOpt: null);
134var data = CreateMemoryStreamBasedEncodedText("", Encoding.UTF8, readEncodingOpt: null, algorithm: SourceHashAlgorithm.Sha256);
170var sourceText = EncodedStringText.Create(stream);
195var sourceText = EncodedStringText.Create(stream);
225var sourceText = EncodedStringText.Create(stream);
244var text = CreateMemoryStreamBasedEncodedText("goo", writeEncoding, readEncoding);
274var text = CreateMemoryStreamBasedEncodedText("goo", writeEncoding, readEncoding);
310var encodedText = EncodedStringText.Create(fs);
324var encodedText = EncodedStringText.Create(fs);
340var sourceText = EncodedStringText.Create(ms);
Text\StringTextTest.cs (37)
46var data = SourceText.From("goo", Encoding.UTF8);
54var data = SourceText.From("goo");
61var data = SourceText.From(string.Empty);
69Assert.Throws<ArgumentNullException>(() => SourceText.From((string)null, Encoding.UTF8));
75Assert.Throws<ArgumentNullException>(() => SourceText.From((Stream)null, Encoding.UTF8));
76Assert.Throws<ArgumentException>(() => SourceText.From(new TestStream(canRead: false, canSeek: true), Encoding.UTF8));
77Assert.Throws<NotImplementedException>(() => SourceText.From(new TestStream(canRead: true, canSeek: false), Encoding.UTF8));
83var data = SourceText.From(string.Empty, Encoding.UTF8);
108private void CheckLine(SourceText text, int lineNumber, int start, int length, int newlineLength, string lineText)
152var data = SourceText.From("goo" + newLine + " bar");
165var data = SourceText.From(text);
176var data = SourceText.From("goo\r\nbar");
185var data = SourceText.From("goo\n\rbar\u2028");
196var data = SourceText.From("");
207var data = SourceText.From(text);
217var data = SourceText.From(text);
224var data = SourceText.From("The quick brown fox jumps over the lazy dog", Encoding.UTF8);
234var source = SourceText.From(new MemoryStream(bytes), Encoding.ASCII);
249var source = SourceText.From(new MemoryStream(bytes), Encoding.ASCII);
261var source = SourceText.From(new MemoryStream(bytes));
276var source = SourceText.From(stream, Encoding.ASCII);
Text\TextChangeTests.cs (251)
32var text = SourceText.From("Hello World");
33var subText = text.GetSubText(6);
40var text = SourceText.From("Hello World");
41var subText = text.GetSubText(new TextSpan(0, 5));
48var text = SourceText.From("Hello World");
49var subText = text.GetSubText(new TextSpan(6, 5));
56var text = SourceText.From("Hello World");
57var subText = text.GetSubText(new TextSpan(4, 3));
64var text = SourceText.From("Hello World");
65var newText = text.Replace(6, 0, "Beautiful ");
72var text = SourceText.From("Hello World");
73var newText = text.Replace(6, 0, "Beautiful ");
86var text = SourceText.From("Hello World");
87var newText = text.WithChanges(
97var text = SourceText.From("Hello World");
110var text = SourceText.From("Hello World");
117var newText = text.WithChanges(changes);
124var text = SourceText.From("Hello World");
132var newText = text.WithChanges(changes);
139var text = SourceText.From("Hello World");
141var newText = text.WithChanges(
151var text = SourceText.From("Hello World");
153var newText = text.WithChanges(
163var text = SourceText.From("Hello World");
170var newText = text.WithChanges(changes);
177var text = SourceText.From("Hello World");
179var newText = text.WithChanges(
189var text = SourceText.From("Hello World", Encoding.Unicode, SourceHashAlgorithms.Default);
190var newText = text.WithChanges(
194var subText = newText.GetSubText(new TextSpan(3, 4));
204var text = SourceText.From("Hello World");
205var newText = text.WithChanges(
214var text = SourceText.From("Hello World");
215var newText = text.WithChanges(
231var text = SourceText.From(new string('.', 2048), Encoding.Unicode, SourceHashAlgorithms.Default); // start bigger than GetText() copy buffer
239var newText = text.WithChanges(changes);
270var changedText = SourceText.From(originalText).WithChanges(changes);
271Assert.Equal(SourceText.From(changedText.ToString()).Lines, changedText.Lines, new TextLineEqualityComparer());
348var text = SourceText.From(str);
368var text = SourceText.From(str);
387var text = SourceText.From("abcdefghijklmnopqrstuvwxyz");
392var subtext = text.GetSubText(new TextSpan(5, 10));
401var text = SourceText.From("abcdefghijklmnopqrstuvwxyz");
403var newText = text.Replace(new TextSpan(0, 20), "");
412var text = SourceText.From("abcdefghijklmnopqrstuvwxyz");
414var newText = text.Replace(new TextSpan(10, 6), "");
423var text = SourceText.From("abcdefghijklmnopqrstuvwxyz");
426var newText = text.Replace(new TextSpan(10, 1), "");
439var text = SourceText.From("abcdefghijklmnopqrstuvwxyz");
442var textWithSegments = text.Replace(new TextSpan(10, 0), "*");
456var text = SourceText.From("abcdefghijklmnopqrstuvwxyz");
459var textWithSegments = text.Replace(new TextSpan(10, 0), "*");
463var textWithFewerSegments = textWithSegments.Replace(new TextSpan(9, 3), "");
476var text = SourceText.From("abcdefghijklmnopqrstuvwxyz");
479var textWithSegments = text.Replace(new TextSpan(0, text.Length), "");
490var t = SourceText.From(a);
520var t = SourceText.From(a);
546SourceText secondEdit;
562private void CreateEdits(out WeakReference weakFirstEdit, out SourceText secondEdit)
564var text = SourceText.From("This is the old text");
565var firstEdit = text.Replace(11, 3, "new");
575var largeText = CreateLargeText(chunk1);
588private SourceText CreateLargeText(params char[][] chunks)
593private ImmutableArray<char[]> GetChunks(SourceText text)
610var text = SourceText.From("small preamble");
612var largeText = CreateLargeText(chunk1);
635var original = SourceText.From("Hello World");
636var change1 = original.WithChanges(new TextChange(new TextSpan(5, 6), string.Empty)); // prepare a ChangedText instance
637var change2 = change1.WithChanges(); // this should not cause exception
646var original = SourceText.From("Hello World");
647var change1 = original.WithChanges(new TextChange(new TextSpan(5, 6), string.Empty)); // prepare a ChangedText instance
648var change2 = change1.WithChanges(new TextChange(new TextSpan(2, 0), string.Empty)); // this should not cause exception
656var original = SourceText.From("Hello World");
657var change1 = original.WithChanges(new TextChange(new TextSpan(6, 0), "Cruel "));
658var change2 = change1.WithChanges(new TextChange(new TextSpan(7, 3), "oo"));
671var original = SourceText.From("01234");
672var change1 = original.WithChanges(new TextChange(new TextSpan(1, 3), "aa"));
673var change2 = change1.WithChanges(new TextChange(new TextSpan(2, 0), "bb"));
685var original = SourceText.From("012");
686var change1 = original.WithChanges(new TextChange(new TextSpan(1, 1), "aaa"));
687var change2 = change1.WithChanges(new TextChange(new TextSpan(3, 0), "bb"));
699var original = SourceText.From("01234");
700var change1 = original.WithChanges(new TextChange(new TextSpan(1, 3), "aa"));
701var change2 = change1.WithChanges(new TextChange(new TextSpan(2, 1), "bb"));
712var original = SourceText.From("Hello World");
713var change1 = original.WithChanges(new TextChange(new TextSpan(6, 0), "Cruel "));
714var change2 = change1.WithChanges(new TextChange(new TextSpan(2, 14), "ar"));
726var original = SourceText.From("Hello World");
727var change1 = original.WithChanges(new TextChange(new TextSpan(6, 0), "Cruel "));
728var change2 = change1.WithChanges(new TextChange(new TextSpan(4, 6), " Bel"));
740var original = SourceText.From("Hello World");
741var change1 = original.WithChanges(new TextChange(new TextSpan(6, 0), "Cruel "));
742var change2 = change1.WithChanges(new TextChange(new TextSpan(7, 6), "wazy V"));
754var original = SourceText.From("01234");
755var change1 = original.WithChanges(new TextChange(new TextSpan(1, 0), "aa"));
756var change2 = change1.WithChanges(new TextChange(new TextSpan(1, 0), "bb"));
767var original = SourceText.From("01234");
768var change1 = original.WithChanges(new TextChange(new TextSpan(1, 3), "aa"));
769var change2 = change1.WithChanges(new TextChange(new TextSpan(1, 0), "bb"));
780var original = SourceText.From("01234");
781var change1 = original.WithChanges(new TextChange(new TextSpan(1, 0), "aa"));
782var change2 = change1.WithChanges(new TextChange(new TextSpan(1, 1), "bb"));
793var original = SourceText.From("01234");
794var change1 = original.WithChanges(new TextChange(new TextSpan(1, 0), "aa"));
795var change2 = change1.WithChanges(new TextChange(new TextSpan(1, 2), "bb"));
806var original = SourceText.From("01234");
807var change1 = original.WithChanges(new TextChange(new TextSpan(1, 0), "aa"));
808var change2 = change1.WithChanges(new TextChange(new TextSpan(1, 3), "bb"));
820var original = SourceText.From("01234");
821var change1 = original.WithChanges(new TextChange(new TextSpan(1, 3), "aa"));
822var change2 = change1.WithChanges(new TextChange(new TextSpan(1, 1), "bb"));
834var original = SourceText.From("01234");
835var change1 = original.WithChanges(new TextChange(new TextSpan(1, 3), "aa"));
836var change2 = change1.WithChanges(new TextChange(new TextSpan(1, 3), "bb"));
846var original = SourceText.From("Hell");
847var change1 = original.WithChanges(new TextChange(new TextSpan(4, 0), "o "));
848var change2 = change1.WithChanges(new TextChange(new TextSpan(6, 0), "World"));
860var original = SourceText.From("Hell ");
861var change1 = original.WithChanges(new TextChange(new TextSpan(4, 0), "o"));
862var change2 = change1.WithChanges(new TextChange(new TextSpan(6, 0), "World"));
876var original = SourceText.From("Hell Word");
877var change1 = original.WithChanges(new TextChange(new TextSpan(8, 0), "l"));
878var change2 = change1.WithChanges(new TextChange(new TextSpan(4, 0), "o"));
892var original = SourceText.From("Hell");
893var change1 = original.WithChanges(new TextChange(new TextSpan(4, 0), " World"));
895var change2 = change1.WithChanges(new TextChange(new TextSpan(4, 0), "o"));
907var original = SourceText.From("Hell");
909var final = GetChangesWithoutMiddle(
965var originalText = SourceText.From(string.Join("", Enumerable.Range(0, random.Next(10))));
989var change1 = originalText.WithChanges(oldChangesBuilder);
1008var change2 = change1.WithChanges(newChangesBuilder);
1046var originalText = SourceText.From("01234");
1047var change1 = originalText.WithChanges(new TextChange(new TextSpan(0, 2), "a"));
1048var change2 = change1.WithChanges(new TextChange(new TextSpan(0, 2), "bb"));
1060var original = SourceText.From("01234");
1061var change1 = original.WithChanges(new TextChange(new TextSpan(0, 0), "aa"), new TextChange(new TextSpan(1, 1), "aa"));
1062var change2 = change1.WithChanges(new TextChange(new TextSpan(0, 1), "b"), new TextChange(new TextSpan(2, 2), ""));
1074var originalText = SourceText.From("01234");
1075var change1 = originalText.WithChanges(new TextChange(new TextSpan(0, 0), "a"));
1076var change2 = change1.WithChanges(new TextChange(new TextSpan(0, 2), ""), new TextChange(new TextSpan(2, 0), "bb"));
1088var originalText = SourceText.From("01234");
1089var change1 = originalText.WithChanges(new TextChange(new TextSpan(0, 1), "aa"), new TextChange(new TextSpan(3, 1), "aa"));
1090var change2 = change1.WithChanges(new TextChange(new TextSpan(0, 0), "bbb"));
1101var originalText = SourceText.From("012345");
1102var change1 = originalText.WithChanges(new TextChange(new TextSpan(0, 3), "a"), new TextChange(new TextSpan(5, 0), "aaa"));
1103var change2 = change1.WithChanges(new TextChange(new TextSpan(0, 2), ""), new TextChange(new TextSpan(3, 1), "bb"));
1115var originalText = SourceText.From("01234567");
1116var change1 = originalText.WithChanges(new TextChange(new TextSpan(0, 1), "aaaaa"), new TextChange(new TextSpan(3, 1), "aaaa"), new TextChange(new TextSpan(6, 1), "aaaaa"));
1117var change2 = change1.WithChanges(new TextChange(new TextSpan(0, 0), "b"), new TextChange(new TextSpan(2, 0), "b"), new TextChange(new TextSpan(3, 4), "bbbbb"), new TextChange(new TextSpan(9, 5), "bbbbb"), new TextChange(new TextSpan(15, 3), ""));
1129var originalText = SourceText.From("01234");
1130var change1 = originalText.WithChanges(new TextChange(new TextSpan(0, 1), "a"));
1131var change2 = change1.WithChanges(new TextChange(new TextSpan(0, 1), "b"), new TextChange(new TextSpan(2, 2), "b"));
1143var originalText = SourceText.From("01234");
1144var change1 = originalText.WithChanges(new TextChange(new TextSpan(0, 1), "aa"));
1145var change2 = change1.WithChanges(new TextChange(new TextSpan(0, 0), "b"), new TextChange(new TextSpan(1, 2), "b"));
1157var originalText = SourceText.From("012345");
1158var change1 = originalText.WithChanges(new TextChange(new TextSpan(0, 2), "a"), new TextChange(new TextSpan(3, 2), "a"));
1159var change2 = change1.WithChanges(new TextChange(new TextSpan(0, 3), "bbb"));
1171var originalText = SourceText.From("0123456");
1172var change1 = originalText.WithChanges(new TextChange(new TextSpan(0, 4), ""), new TextChange(new TextSpan(5, 1), ""));
1173var change2 = change1.WithChanges(new TextChange(new TextSpan(0, 1), ""), new TextChange(new TextSpan(1, 0), ""));
1185var originalText = SourceText.From("012345");
1186var change1 = originalText.WithChanges(new TextChange(new TextSpan(0, 2), ""), new TextChange(new TextSpan(3, 1), ""), new TextChange(new TextSpan(4, 0), ""), new TextChange(new TextSpan(4, 0), ""), new TextChange(new TextSpan(4, 0), ""));
1187var change2 = change1.WithChanges(new TextChange(new TextSpan(0, 1), ""), new TextChange(new TextSpan(1, 1), ""), new TextChange(new TextSpan(2, 0), ""));
1199var originalText = SourceText.From("01234");
1200var change1 = originalText.WithChanges(new TextChange(new TextSpan(0, 1), ""), new TextChange(new TextSpan(2, 1), ""));
1201var change2 = change1.WithChanges(new TextChange(new TextSpan(0, 0), ""), new TextChange(new TextSpan(1, 1), ""));
1223var text = SourceText.From(content);
1233var changedText = text.WithChanges(edits1);
1244var changedText2 = changedText.WithChanges(edits2);
1255private SourceText GetChangesWithoutMiddle(
1256SourceText original,
1257Func<SourceText, SourceText> fnChange1,
1258Func<SourceText, SourceText> fnChange2)
1261SourceText change2;
1274SourceText original,
1275Func<SourceText, SourceText> fnChange1,
1276Func<SourceText, SourceText> fnChange2,
1278out SourceText change2)
1280var c1 = fnChange1(original);
Text\TextUtilitiesTests.cs (8)
35Assert.Equal(0, TextUtilities.GetLengthOfLineBreak(SourceText.From("aoeu"), 0));
36Assert.Equal(0, TextUtilities.GetLengthOfLineBreak(SourceText.From("aoeu"), 2));
45Assert.Equal(1, TextUtilities.GetLengthOfLineBreak(SourceText.From("\naoeu"), 0));
46Assert.Equal(1, TextUtilities.GetLengthOfLineBreak(SourceText.From("a\nbaou"), 1));
47Assert.Equal(0, TextUtilities.GetLengthOfLineBreak(SourceText.From("a\n"), 0));
56Assert.Equal(2, TextUtilities.GetLengthOfLineBreak(SourceText.From("\r\n"), 0));
57Assert.Equal(1, TextUtilities.GetLengthOfLineBreak(SourceText.From("\n\r"), 0));
66Assert.Equal(1, TextUtilities.GetLengthOfLineBreak(SourceText.From("\r"), 0));
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,
282Friend Shared Function MakeSourceText(text As String, offset As Integer) As SourceText
283Return SourceText.From(text, Encoding.UTF8).GetSubText(offset)
Microsoft.CodeAnalysis.VisualBasic.CodeStyle.Fixes (2)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\VisualBasic\Indentation\VisualBasicIndentationService.Indenter.vb (1)
42text As SourceText,
Microsoft.CodeAnalysis.VisualBasic.CodeStyle.UnitTests (1)
Microsoft.CodeAnalysis.VisualBasic.EditorFeatures (4)
Microsoft.CodeAnalysis.VisualBasic.Emit.UnitTests (2)
Microsoft.CodeAnalysis.VisualBasic.ExpressionCompiler (7)
SyntaxHelpers.vb (7)
38Dim text = SourceText.From(expr, encoding:=Nothing, SourceHashAlgorithms.Default)
52Dim targetText = SourceText.From(target, encoding:=Nothing, SourceHashAlgorithms.Default)
61Dim assignmentText = SourceText.From(assignment.ToString(), encoding:=Nothing, SourceHashAlgorithms.Default)
154Dim text = SourceText.From(source, encoding:=Nothing, SourceHashAlgorithms.Default)
162Private Function ParseDebuggerExpressionInternal(source As SourceText, consumeFullText As Boolean) As InternalSyntax.ExpressionSyntax
174Dim text = SourceText.From(source, encoding:=Nothing, SourceHashAlgorithms.Default)
186Private Function CreateSyntaxTree(root As InternalSyntax.VisualBasicSyntaxNode, text As SourceText) As SyntaxTree
Microsoft.CodeAnalysis.VisualBasic.Features (31)
Microsoft.CodeAnalysis.VisualBasic.Features.UnitTests (7)
EditAndContinue\VisualBasicEditAndContinueAnalyzerTests.vb (6)
30AddDocument("test.vb", SourceText.From(source, Encoding.UTF8), filePath:=Path.Combine(TempRoot.Root, "test.vb")).Project.Solution
471Dim newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2))
556Dim newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2))
614Dim newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2))
645Dim newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2))
676Dim newSolution = oldSolution.AddDocument(newDocId, "goo.vb", SourceText.From(source2), filePath:=Path.Combine(TempRoot.Root, "goo.vb"))
Microsoft.CodeAnalysis.VisualBasic.Scripting (2)
Microsoft.CodeAnalysis.VisualBasic.Semantic.UnitTests (11)
Microsoft.CodeAnalysis.VisualBasic.Symbol.UnitTests (2)
Microsoft.CodeAnalysis.VisualBasic.Syntax.UnitTests (98)
Microsoft.CodeAnalysis.VisualBasic.Test.Utilities (16)
BasicTestSource.vb (3)
24Dim sourceTest = SourceText.From(text, If(encoding, Encoding.UTF8), checksumAlgorithm)
49SourceText.From(source, encoding:=Nothing, SourceHashAlgorithms.Default),
56Return sources.Select(Function(s) VisualBasicSyntaxTree.ParseText(SourceText.From(s, encoding:=Nothing, SourceHashAlgorithms.Default), If(parseOptions, TestOptions.RegularLatest))).ToArray()
CompilationTestUtils.vb (4)
22Return source.Select(Function(s) VisualBasicSyntaxTree.ParseText(SourceText.From(s, encoding:=Nothing, SourceHashAlgorithms.Default), parseOptions))
636Return VisualBasicSyntaxTree.ParseText(SourceText.From(FilterString(programElement.Value), Encoding.UTF8, SourceHashAlgorithms.Default), path:=If(programElement.@name, ""))
653Dim text = SourceText.From(codeWithoutMarker, Encoding.UTF8)
1024Private Function GetLineText(text As SourceText, position As Integer, ByRef offsetInLine As Integer) As String
Microsoft.CodeAnalysis.VisualBasic.Workspaces (15)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\VisualBasic\Indentation\VisualBasicIndentationService.Indenter.vb (1)
42text As SourceText,
Microsoft.CodeAnalysis.VisualBasic.Workspaces.UnitTests (5)
Microsoft.CodeAnalysis.Workspaces (360)
Shared\Extensions\SourceTextExtensions.cs (12)
35public static void GetLineAndOffset(this SourceText text, int position, out int lineNumber, out int offset)
43public static int GetOffset(this SourceText text, int position)
50this SourceText text,
61public static TextChangeRange GetEncompassingTextChangeRange(this SourceText newText, SourceText oldText)
78public static int IndexOf(this SourceText text, string value, int startIndex, bool caseSensitive)
109public static int LastIndexOf(this SourceText text, string value, int startIndex, bool caseSensitive)
145public static bool ContentEquals(this SourceText text, int position, string value)
163public static int IndexOfNonWhiteSpace(this SourceText text, int start, int length)
176public static void WriteTo(this SourceText sourceText, ObjectWriter writer, CancellationToken cancellationToken)
194private static void WriteChunksTo(SourceText sourceText, ObjectWriter writer, int length, CancellationToken cancellationToken)
225public static SourceText ReadFrom(ITextFactoryService textService, ObjectReader reader, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm, CancellationToken cancellationToken)
src\Compilers\Core\Portable\EncodedStringText.cs (11)
53/// Initializes an instance of <see cref="SourceText"/> from the provided stream. This version differs
54/// from <see cref="SourceText.From(Stream, Encoding, SourceHashAlgorithm, bool)"/> in two ways:
72internal static SourceText Create(Stream stream,
84internal static SourceText Create(Stream stream,
117/// Try to create a <see cref="SourceText"/> from the given stream using the given encoding.
124/// <returns>The <see cref="SourceText"/> decoded from the stream.</returns>
127private static SourceText Decode(
146return SourceText.From(bytes.Array,
156return SourceText.From(data, encoding, checksumAlgorithm, throwIfBinaryDetected, canBeEmbedded);
230internal static SourceText Create(Stream stream, Lazy<Encoding> getEncoding, Encoding defaultEncoding, SourceHashAlgorithm checksumAlgorithm, bool canBeEmbedded)
233internal static SourceText Decode(Stream data, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
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)
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 (11)
106var text = await this.GetTextAsync(cancellationToken).ConfigureAwait(false);
166var text = textAndVersion.Text;
239var newText = newTextAndVersion.Text;
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 (17)
946var sourceText = SourceText.From(text, encoding: null, checksumAlgorithm: project.ChecksumAlgorithm);
955public Solution AddDocument(DocumentId documentId, string name, SourceText text, IEnumerable<string>? folders = null, string? filePath = null, bool isGenerated = false)
986var sourceText = SourceText.From(string.Empty, encoding: null, project.ChecksumAlgorithm);
992private Solution AddDocumentImpl(ProjectState project, DocumentId documentId, string name, SourceText text, IReadOnlyList<string>? folders, string? filePath, bool isGenerated)
1047=> this.AddAdditionalDocument(documentId, name, SourceText.From(text), folders, filePath);
1053public Solution AddAdditionalDocument(DocumentId documentId, string name, SourceText text, IEnumerable<string>? folders = null, string? filePath = null)
1084public Solution AddAnalyzerConfigDocument(DocumentId documentId, string name, SourceText text, IEnumerable<string>? folders = null, string? filePath = null)
1108private DocumentInfo CreateDocumentInfo(DocumentId documentId, string name, SourceText text, IEnumerable<string>? folders, string? filePath)
1246public Solution WithDocumentText(DocumentId documentId, SourceText text, PreservationMode mode = PreservationMode.PreserveValue)
1249internal Solution WithDocumentTexts(ImmutableArray<(DocumentId documentId, SourceText text)> texts, PreservationMode mode = PreservationMode.PreserveValue)
1269public Solution WithAdditionalDocumentText(DocumentId documentId, SourceText text, PreservationMode mode = PreservationMode.PreserveValue)
1290public Solution WithAnalyzerConfigDocumentText(DocumentId documentId, SourceText text, PreservationMode mode = PreservationMode.PreserveValue)
1599public Solution WithDocumentText(IEnumerable<DocumentId?> documentIds, SourceText text, PreservationMode mode = PreservationMode.PreserveValue)
1625SourceGeneratedDocumentIdentity documentIdentity, DateTime generationDateTime, SourceText text)
1638internal Solution WithFrozenSourceGeneratedDocuments(ImmutableArray<(SourceGeneratedDocumentIdentity documentIdentity, DateTime generationDateTime, SourceText text)> documents)
Workspace\Solution\SolutionCompilationState.cs (18)
788internal SolutionCompilationState WithDocumentTexts(ImmutableArray<(DocumentId documentId, SourceText text)> texts, PreservationMode mode)
792return UpdateDocumentsInMultipleProjects<DocumentState, SourceText, PreservationMode>(
799(ImmutableArray<(DocumentId, SourceText)>,
800ImmutableArray<(SourceGeneratedDocumentIdentity, DateTime, SourceText, SyntaxNode?)>) GetOrdinaryAndSourceGeneratedDocuments()
805using var _1 = ArrayBuilder<(DocumentId, SourceText)>.GetInstance(capacity: texts.Length, out var ordinaryDocuments);
806using var _2 = ArrayBuilder<(SourceGeneratedDocumentIdentity, DateTime, SourceText, SyntaxNode?)>.GetInstance(out var sourceGeneratedDocuments);
823private static bool SourceTextIsUnchanged(DocumentState oldDocument, SourceText text)
824=> oldDocument.TryGetText(out var oldText) && text == oldText;
832ImmutableArray<(SourceGeneratedDocumentIdentity documentIdentity, DateTime generationDateTime, SourceText sourceText, SyntaxNode? syntaxNode)> sourceGeneratedDocuments,
944/// <inheritdoc cref="SolutionState.WithAdditionalDocumentText(DocumentId, SourceText, PreservationMode)"/>
946DocumentId documentId, SourceText text, PreservationMode mode)
952/// <inheritdoc cref="SolutionState.WithAnalyzerConfigDocumentText(DocumentId, SourceText, PreservationMode)"/>
954DocumentId documentId, SourceText text, PreservationMode mode)
1005ImmutableArray<(SourceGeneratedDocumentIdentity, DateTime, SourceText, SyntaxNode?)>) GetOrdinaryAndSourceGeneratedDocuments()
1011using var _2 = ArrayBuilder<(SourceGeneratedDocumentIdentity, DateTime, SourceText, SyntaxNode?)>.GetInstance(out var sourceGeneratedDocuments);
1389ImmutableArray<(SourceGeneratedDocumentIdentity documentIdentity, DateTime generationDateTime, SourceText sourceText, SyntaxNode? syntaxNode)> documents)
1882public SolutionCompilationState WithDocumentText(IEnumerable<DocumentId?> documentIds, SourceText text, PreservationMode mode)
1884using var _ = ArrayBuilder<(DocumentId, SourceText)>.GetInstance(out var changedDocuments);
Workspace\Workspace.cs (18)
1140protected internal void OnDocumentTextChanged(DocumentId documentId, SourceText newText, PreservationMode mode)
1143private protected void OnDocumentTextChanged(DocumentId documentId, SourceText newText, PreservationMode mode, bool requireDocumentPresent)
1158protected internal void OnAdditionalDocumentTextChanged(DocumentId documentId, SourceText newText, PreservationMode mode)
1173protected internal void OnAnalyzerConfigDocumentTextChanged(DocumentId documentId, SourceText newText, PreservationMode mode)
1940var text = document.GetTextSynchronously(CancellationToken.None);
1949var text = document.GetTextSynchronously(CancellationToken.None);
1958var text = document.GetTextSynchronously(CancellationToken.None);
1975var currentText = newDoc.GetTextSynchronously(CancellationToken.None); // needs wait
1985var currentText = newDoc.GetTextSynchronously(CancellationToken.None); // needs wait
2002if (!oldDoc.TryGetText(out var oldText))
2007var currentText = newDoc.GetTextSynchronously(CancellationToken.None); // needs wait
2010else if (!newDoc.TryGetText(out var newText))
2206protected virtual void ApplyDocumentAdded(DocumentInfo info, SourceText text)
2228protected virtual void ApplyDocumentTextChanged(DocumentId id, SourceText text)
2250protected virtual void ApplyAdditionalDocumentAdded(DocumentInfo info, SourceText text)
2272protected virtual void ApplyAdditionalDocumentTextChanged(DocumentId id, SourceText text)
2283protected virtual void ApplyAnalyzerConfigDocumentAdded(DocumentInfo info, SourceText text)
2305protected virtual void ApplyAnalyzerConfigDocumentTextChanged(DocumentId id, SourceText text)
Workspace\Workspace_Editor.cs (11)
395var newText = textContainer.CurrentText;
396if (oldDocument.TryGetText(out var oldText) &&
485private static TextAndVersion GetProperTextAndVersion(SourceText oldText, SourceText newText, VersionStamp version, string? filePath)
494private void SignupForTextChanges(DocumentId documentId, SourceTextContainer textContainer, bool isCurrentContext, Action<Workspace, DocumentId, SourceText, PreservationMode> onChangedHandler)
555Func<Solution, DocumentId, SourceText, PreservationMode, Solution> withDocumentText,
557Action<Workspace, DocumentId, SourceText, PreservationMode> onDocumentTextChanged)
587var oldText = oldDocument.GetTextSynchronously(CancellationToken.None);
590var newText = data.textContainer.CurrentText;
849private SourceText GetOpenDocumentText(Solution solution, DocumentId documentId)
854Contract.ThrowIfFalse(doc.TryGetText(out var text));
Microsoft.CodeAnalysis.Workspaces.MSBuild (5)
Microsoft.CodeAnalysis.Workspaces.MSBuild.UnitTests (42)
Microsoft.CodeAnalysis.Workspaces.Test.Utilities (22)
Formatting\FormattingTestBase.cs (6)
49var document = project.AddDocument("Document", SourceText.From(code));
83private static async Task AssertFormatAsync(SolutionServices services, string expected, SyntaxNode root, ImmutableArray<TextSpan> spans, SyntaxFormattingOptions options, SourceText sourceText)
90var resultText = sourceText.WithChanges(result);
99private static bool TryAdjustSpans(SourceText inputText, IList<TextChange> changes, SourceText outputText, ImmutableArray<TextSpan> inputSpans, out ImmutableArray<TextSpan> outputSpans)
127protected static void AssertResult(string expected, SourceText sourceText, IList<TextChange> result)
Microsoft.CodeAnalysis.Workspaces.UnitTests (313)
FindReferencesTests.cs (5)
40return solution.AddProject(pi).AddDocument(did, $"{projectName}.{suffix}", SourceText.From(code));
56return solution.AddProject(pi).AddDocument(did, $"{projectName}.{suffix}", SourceText.From(code));
66.AddDocument(did, "goo.cs", SourceText.From(sourceText));
82solution = solution.AddDocument(did, $"goo{docCounter++}.cs", SourceText.From(sourceText));
126.AddDocument(did, "goo.cs", SourceText.From(text));
Formatter\FormatterTests.cs (6)
42=> Task.FromResult(document.WithText(SourceText.From($"Formatted with options: {lineFormattingOptions.ToString().Replace("\r", "\\r").Replace("\n", "\\n")}")));
52var document = workspace.AddDocument(project.Id, "File.dummy", SourceText.From("dummy"));
58var formattedText = await formattedDocument.GetTextAsync();
70var document = workspace.AddDocument(project.Id, "File.dummy", SourceText.From("dummy"));
115var csDocument = workspace.AddDocument(csProject.Id, "File.cs", SourceText.From("class C { }"));
116var vbDocument = workspace.AddDocument(vbProject.Id, "File.vb", SourceText.From("Class C : End Class"));
SolutionTests\SolutionTests.cs (131)
58.AddDocument(DocumentId.CreateNewId(projectId), "goo.cs", SourceText.From("public class Goo { }", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: Path.Combine(s_projectDir, "goo.cs"))
59.AddAdditionalDocument(DocumentId.CreateNewId(projectId), "add.txt", SourceText.From("text", Encoding.UTF8, SourceHashAlgorithms.Default))
60.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId), "editorcfg", SourceText.From(editorConfig ?? "#empty", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: Path.Combine(s_projectDir, "editorcfg"))));
80.AddDocument(DocumentId.CreateNewId(projectId1), "goo.cs", SourceText.From(docContents, Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "goo.cs")
81.AddAdditionalDocument(DocumentId.CreateNewId(projectId1), "add.txt", SourceText.From("text", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "add.txt")
82.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId1), "editorcfg", SourceText.From("config", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "/a/b")
84.AddDocument(DocumentId.CreateNewId(projectId2), "goo.cs", SourceText.From(docContents, Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "goo.cs")
85.AddAdditionalDocument(DocumentId.CreateNewId(projectId2), "add.txt", SourceText.From("text", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "add.txt")
86.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId2), "editorcfg", SourceText.From("config", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "/a/b")));
332.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId), "editorcfg", SourceText.From("config"));
348var text = SourceText.From("new text", encoding: null, SourceHashAlgorithm.Sha1);
359Assert.Throws<ArgumentNullException>(() => solution.WithDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity));
372var textAndVersion = TextAndVersion.Create(SourceText.From("new text"), VersionStamp.Default);
375Assert.True(newSolution1.GetDocument(documentId)!.TryGetText(out var actualText));
383Assert.Throws<ArgumentNullException>(() => solution.WithDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity));
396var text = SourceText.From("new text");
449var text = SourceText.From("new text", encoding: null, SourceHashAlgorithm.Sha1);
494private static Solution UpdateSolution(PreservationMode mode, TextUpdateType updateType, Solution solution, DocumentId documentId1, SourceText text, TextAndVersion textAndVersion)
537var text = SourceText.From("new text", encoding: null, SourceHashAlgorithm.Sha1);
620var text = SourceText.From("new text without pp directives", encoding: null, SourceHashAlgorithm.Sha1);
703var text = SourceText.From("#if true", encoding: null, SourceHashAlgorithm.Sha1);
779var text = SourceText.From("new text", encoding: null, SourceHashAlgorithm.Sha1);
841.AddDocument(DocumentId.CreateNewId(projectId1), "goo.cs", SourceText.From(docContents, Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "goo.cs")
843.AddDocument(DocumentId.CreateNewId(projectId2), "goo.cs", SourceText.From(docContents, Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "goo.cs")));
866var text = SourceText.From(" ", encoding: null, SourceHashAlgorithm.Sha1);
918var text = SourceText.From("new text");
921Assert.True(newSolution1.GetAdditionalDocument(documentId)!.TryGetText(out var actualText));
927Assert.Throws<ArgumentNullException>(() => solution.WithAdditionalDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity));
940var textAndVersion = TextAndVersion.Create(SourceText.From("new text"), VersionStamp.Default);
943Assert.True(newSolution1.GetAdditionalDocument(documentId)!.TryGetText(out var actualText));
951Assert.Throws<ArgumentNullException>(() => solution.WithAdditionalDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity));
964var text = SourceText.From("new text");
967Assert.True(newSolution1.GetAnalyzerConfigDocument(documentId)!.TryGetText(out var actualText));
973Assert.Throws<ArgumentNullException>(() => solution.WithAnalyzerConfigDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity));
986var textAndVersion = TextAndVersion.Create(SourceText.From("new text"), VersionStamp.Default);
989Assert.True(newSolution1.GetAnalyzerConfigDocument(documentId)!.TryGetText(out var actualText));
997Assert.Throws<ArgumentNullException>(() => solution.WithAnalyzerConfigDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity));
1091.AddDocument(d1, "d1.cs", SourceText.From("class D1;", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: Path.Combine(s_projectDir, "d1.cs"))
1092.AddDocument(d2, "d2.cs", SourceText.From("class D2;", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: Path.Combine(s_projectDir, "d2.cs"))
1093.AddAdditionalDocument(a1, "a1.txt", SourceText.From("text1", Encoding.UTF8, SourceHashAlgorithms.Default))
1094.AddAdditionalDocument(a2, "a2.txt", SourceText.From("text2", Encoding.UTF8, SourceHashAlgorithms.Default))
1095.AddAnalyzerConfigDocument(c1, "c1", SourceText.From("#empty1", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: Path.Combine(s_projectDir, "editorcfg"))
1096.AddAnalyzerConfigDocument(c2, "c2", SourceText.From("#empty2", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: Path.Combine(s_projectDir, "editorcfg"));
1106loader: TextLoader.From(TextAndVersion.Create(SourceText.From("class NewD1;", Encoding.UTF32, SourceHashAlgorithm.Sha256), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD1.cs"))),
1115loader: TextLoader.From(TextAndVersion.Create(SourceText.From("class NewD3;", Encoding.UTF8, SourceHashAlgorithms.Default), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD3.cs"))),
1125loader: TextLoader.From(TextAndVersion.Create(SourceText.From("new text1", Encoding.UTF32, SourceHashAlgorithm.Sha256), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD1.cs"))),
1134loader: TextLoader.From(TextAndVersion.Create(SourceText.From("new text3", Encoding.UTF8, SourceHashAlgorithms.Default), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD3.cs"))),
1144loader: TextLoader.From(TextAndVersion.Create(SourceText.From("#new empty1", Encoding.UTF32, SourceHashAlgorithm.Sha256), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD1.cs"))),
1153loader: TextLoader.From(TextAndVersion.Create(SourceText.From("#new empty3", Encoding.UTF8, SourceHashAlgorithms.Default), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD3.cs"))),
1617var textC = SourceText.From("class C {}", encoding: null, checksumAlgorithm: SourceHashAlgorithm.Sha1);
2309var solution4 = solution3.AddAnalyzerConfigDocument(editorConfigId, ".editorconfig", SourceText.From(editorConfigContent), filePath: Path.Combine(s_projectDir, "subfolder", ".editorconfig"));
2420var sourceText = SourceText.From("text", checksumAlgorithm: SourceHashAlgorithms.Default);
2434Assert.Throws<ArgumentNullException>("text", () => solution.AddDocument(documentId, "name", text: (SourceText)null!));
2481var root = CSharp.SyntaxFactory.ParseSyntaxTree(SourceText.From("class C {}", encoding: null, SourceHashAlgorithm.Sha1)).GetRoot();
3162.AddDocument(documentId, "DocumentName", SourceText.From("class Class{}"));
3202var text2 = tree2.GetText();
3315var observedText2 = sol.GetDocument(did).GetTextAsync().Result;
3333var docText = doc.GetTextAsync().Result;
3355var docText = doc.GetTextAsync().Result;
3380var docText = doc.GetTextAsync().Result;
3526private static ObjectReference<SourceText> GetObservedText(Solution solution, DocumentId documentId, string expectedText = null)
3528var observedText = solution.GetDocument(documentId).GetTextAsync().Result;
3535return new ObjectReference<SourceText>(observedText);
3557private static ObjectReference<SourceText> GetObservedTextAsync(Solution solution, DocumentId documentId, string expectedText = null)
3559var observedText = solution.GetDocument(documentId).GetTextAsync().Result;
3566return new ObjectReference<SourceText>(observedText);
3774.AddDocument(did, "test", SourceText.From(language == LanguageNames.CSharp ? "class C {}" : "Class C : End Class", Encoding.UTF8, SourceHashAlgorithm.Sha256), filePath: "old path");
3917var text = await doc.GetTextAsync().ConfigureAwait(false);
3986var solution2 = solution.WithDocumentText(did3, SourceText.From(text4));
3999var doc = ws.AddDocument(proj.Id, "a.cs", SourceText.From("public class c { }", Encoding.UTF32));
4064workspace.AddDocument(project1.Id, "Broken.cs", SourceText.From("class "));
4086project = project.AddDocument("Extra.cs", SourceText.From("class Extra { }")).Project;
4088var documentToFreeze = project.AddDocument("DocumentToFreeze.cs", SourceText.From(""));
4111project = project.AddDocument("Extra.cs", SourceText.From("class Extra { }")).Project;
4113var documentToFreeze = project.AddDocument("DocumentToFreeze.cs", SourceText.From(""));
4139project = project.AddDocument("Extra.cs", SourceText.From("class Extra { }")).Project;
4141var documentToFreezeOriginal = project.AddDocument("DocumentToFreeze.cs", SourceText.From("class DocumentToFreeze { void M() { } }"));
4145var solution = project.Solution.WithDocumentText(documentToFreezeOriginal.Id, SourceText.From("class DocumentToFreeze { void M() { /*no top level change*/ } }"));
4184project = project.AddDocument("Extra.cs", SourceText.From("class Extra { }")).Project;
4186var documentToFreezeOriginal = project.AddDocument("DocumentToFreeze.cs", SourceText.From("class DocumentToFreeze { void M() { } }"));
4190var solution = project.Solution.WithDocumentText(documentToFreezeOriginal.Id, SourceText.From("class DocumentToFreeze { void M() { } public void NewMethod() { } }"));
4252var document = workspace.AddDocument(project2.Id, "Test.cs", SourceText.From(""));
4356document = document.WithText(SourceText.From("// Source File with Changes"));
4382.WithDocumentText(documentId1, SourceText.From("// Document 1 Changed"))
4383.WithDocumentText(documentId2, SourceText.From("// Document 2 Changed"))
4384.WithDocumentText(documentId3, SourceText.From("// Document 3 Changed"));
4569var text = SourceText.From("// empty", encoding: null, SourceHashAlgorithms.Default);
4572var sourceText = strongTree.GetText();
4704loader: TextLoader.From(TextAndVersion.Create(SourceText.From("[*.*]\r\n\r\ndotnet_diagnostic.CA1234.severity = error"), VersionStamp.Default)))));
4737loader: TextLoader.From(TextAndVersion.Create(SourceText.From("[*.*]\r\n\r\ndotnet_diagnostic.CA1234.severity = error"), VersionStamp.Default)))));
4778loader: TextLoader.From(TextAndVersion.Create(SourceText.From("[*.*]\r\n\r\ndotnet_diagnostic.CA1234.severity = error"), VersionStamp.Default)))));
4790TextLoader.From(TextAndVersion.Create(SourceText.From("[*.*]\r\n\r\ndotnet_diagnostic.CA6789.severity = error"), VersionStamp.Default)),
4826loader: TextLoader.From(TextAndVersion.Create(SourceText.From("is_global = true\r\n\r\ndotnet_diagnostic.CA1234.severity = error"), VersionStamp.Default)))));
4872loader: TextLoader.From(TextAndVersion.Create(SourceText.From("[*.*]\r\n\r\ngenerated_code = true"), VersionStamp.Default)))));
5454var text = SourceText.From("public class C { }");
5475var newDocText = await newDoc.GetTextAsync();
5476var sameText = await newDoc.GetTextAsync();
5480var treeText = newDocTree.GetText();
5502var sourceTextToRelease = ObjectReference.CreateFromFactory(static () => SourceText.From(Guid.NewGuid().ToString()));
5550.AddDocument(documentId, "test.cs", SourceText.From("public class C { }"), filePath: sourcePath)
5551.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId), ".editorconfig", SourceText.From($"[{pattern}]\nindent_style = tab"), filePath: configPath);
5611project = project.AddDocument("Extra.cs", SourceText.From("class Extra { }")).Project;
5628project = project.AddDocument("Extra.cs", SourceText.From("class Extra { }")).Project;
5649project1 = project2.Solution.GetProject(project1.Id).AddDocument("Doc1", SourceText.From("class Doc1 { }")).Project;
5650project2 = project1.Solution.GetProject(project2.Id).AddDocument("Doc2", SourceText.From("class Doc2 { }")).Project;
5677project1 = project2.Solution.GetProject(project1.Id).AddDocument("Doc1", SourceText.From("class Doc1 { }")).Project;
5678project2 = project1.Solution.GetProject(project2.Id).AddDocument("Doc2", SourceText.From("class Doc2 { }")).Project;
5707project1 = project2.Solution.GetProject(project1.Id).AddDocument("Doc1", SourceText.From("class Doc1 { }")).Project;
5708project2 = project1.Solution.GetProject(project2.Id).AddDocument("Doc2", SourceText.From("class Doc2 { }")).Project;
5739project1 = project1.AddDocument("Doc1", SourceText.From("class Doc1 { }")).Project;
5748var forkedProject1 = frozenSolution.WithDocumentText(project1.Documents.Single().Id, SourceText.From("class Doc2 { }")).GetProject(project1.Id);
5767project1 = project1.AddDocument("Doc1", SourceText.From("class Doc1 { }")).Project;
5787var forkedProject1 = frozenSolution.WithDocumentText(project1.Documents.Single().Id, SourceText.From("class Doc2 { }")).GetProject(project1.Id);
5816project = project.AddDocument("Extra.ts", SourceText.From("class Extra { }")).Project;
5839.AddDocument($"Document", SourceText.From("class C { }"), filePath: @"c:\test\Document.cs").Project;
5849.AddDocument($"Document", SourceText.From("class C { }"), filePath: @"c:\test\Document.cs").Project;
5860old => old.WithDocumentText(documentId1, SourceText.From(lastContents)),
SolutionTests\SolutionWithSourceGeneratorTests.cs (40)
205project = project.AdditionalDocuments.First().WithAdditionalDocumentText(SourceText.From("Changed text!")).Project;
229project = project.AddDocument("Source.cs", SourceText.From("")).Project;
262project = project.Solution.WithDocumentText(documentId, SourceText.From("// Changed Source File")).Projects.Single();
305project = project.Solution.WithAdditionalDocumentText(additionalDocumentId, SourceText.From("Hello, everyone!")).Projects.Single();
310project = project.Solution.WithAdditionalDocumentText(additionalDocumentId, SourceText.From("Good evening, everyone!")).Projects.Single();
374SourceText.From("Hello, world!!!!")).Projects.Single();
488project = project.Documents.Single().WithText(SourceText.From("// Change")).Project;
564var existingText = await project.Documents.Single().GetTextAsync();
565var newText = existingText.WithChanges(new TextChange(new TextSpan(existingText.Length, length: 0), " With Change"));
594var differentOpenTextContainer = SourceText.From("// Open Text").Container;
618var differentOpenTextContainer = SourceText.From("// StaticContent", Encoding.UTF8).Container;
633.AddAdditionalDocument("Test.txt", SourceText.From(""));
638var differentOpenTextContainer = SourceText.From("// Open Text").Container;
669var differentOpenTextContainer = SourceText.From("// Open Text").Container;
696var differentOpenTextContainer = SourceText.From("// Open Text").Container;
733documentToFreeze = documentToFreeze.WithText(SourceText.From("// Changed Source File"));
763document = document.WithText(SourceText.From("// Something else"));
792document = document.WithText(SourceText.From("// Something else"));
826document = document.WithText(SourceText.From("// Something else"));
887identity, DateTime.Now, SourceText.From("// Frozen Document"));
914[(sourceGeneratedDocument1.Identity, DateTime.Now, SourceText.From("// Frozen 1")), (sourceGeneratedDocument2.Identity, DateTime.Now, SourceText.From("// Frozen 2"))]);
934sourceGeneratedDocumentIdentity, sourceGeneratedDocument.GenerationDateTime, SourceText.From("// Hello, World"));
998[(ordinaryDocument.Id, SourceText.From("// Regular modified")),
999(sourceGeneratedDocument.Id, SourceText.From("// Source gen modified"))]);
1003var sourceText = await updatedDocument.GetTextAsync();
1031var sourceText = await sourceGeneratedDocument.GetTextAsync();
1060var sourceText = await sourceGeneratedDocument.GetTextAsync();
1113sourceGeneratedDocument = sourceGeneratedDocument.WithText(SourceText.From("// Something else"));
1114var sourceText = await sourceGeneratedDocument.GetTextAsync();
1141sourceGeneratedDocument = sourceGeneratedDocument.WithText(SourceText.From("// Something else"));
1142var sourceText = await sourceGeneratedDocument.GetTextAsync();
1145sourceGeneratedDocument = sourceGeneratedDocument.WithText(SourceText.From("// Thrice is nice"));
1177var solution = sourceGeneratedDocument1.WithText(SourceText.From("// Change doc 1")).Project.Solution;
1184solution = sourceGeneratedDocument2!.WithText(SourceText.From("// Change doc 2")).Project.Solution;
1226newDocument = newDocument.WithText(SourceText.From("// Changed frozen document"));
1235identity, DateTime.Now, SourceText.From("// Frozen Document"));
1272identity, DateTime.Now, SourceText.From("// Frozen Document"));
1303identity, DateTime.Now, SourceText.From("// Frozen Document"));
1338identity, DateTime.Now, SourceText.From("// Frozen Document"));
SyntaxPathTests.cs (14)
90var text = SourceText.From(string.Empty);
95var newText = text.WithChanges(new TextChange(new TextSpan(0, 0), "class C {}"));
104var text = SourceText.From("class C {}");
109var newText = text.WithChanges(new TextChange(new TextSpan(0, text.Length), ""));
397var text = SourceText.From("using X; class C {}");
402var newText = WithReplaceFirst(text, "using X;", "");
409internal static SourceText WithReplaceFirst(SourceText text, string oldText, string newText)
416return SourceText.From(newFullText);
429var oldFullText = syntaxTree.GetText();
430var newFullText = oldFullText.WithChanges(new TextChange(new TextSpan(offset, length), newText));
WorkspaceTests\AdhocWorkspaceTests.cs (22)
73var doc = ws.AddDocument(project.Id, name, SourceText.From(source));
155loader: TextLoader.From(TextAndVersion.Create(SourceText.From(""), VersionStamp.Create())));
213var text = SourceText.From("public class C { }");
227Assert.False(doc.TryGetText(out var currentText));
247var text = SourceText.From("public class C { }");
261Assert.False(doc.TryGetText(out var currentText));
281var text = SourceText.From("public class C { }");
300Assert.False(doc.TryGetText(out var currentText));
320var text = SourceText.From("public class C { }");
334Assert.False(doc.TryGetText(out var currentText));
366var actualText = await newDoc.GetTextAsync();
378var docid1 = ws.AddDocument(projid, "A.cs", SourceText.From("public class A { }")).Id;
379var docid2 = ws.AddDocument(projid, "B.cs", SourceText.From("public class B { }")).Id;
415var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
446var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
482var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
514var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
545var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
WorkspaceTests\WorkspaceTests.cs (7)
25var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
27var changedDoc = originalDoc.WithText(SourceText.From("new"));
38var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
54var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
73var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
90var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
147public Document AddDocument(ProjectId projectId, string name, SourceText text)
Microsoft.DotNet.CodeAnalysis (2)
Microsoft.Extensions.Logging.Generators (1)
Microsoft.Extensions.Options.SourceGeneration (1)
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)
Microsoft.VisualStudio.LanguageServices (91)
ProjectSystem\VisualStudioWorkspaceImpl.AddAdditionalDocumentUndoUnit.cs (1)
18SourceText text)
ProjectSystem\VisualStudioWorkspaceImpl.AddAnalyzerConfigDocumentUndoUnit.cs (1)
17SourceText text)
ProjectSystem\VisualStudioWorkspaceImpl.cs (12)
759protected override void ApplyDocumentAdded(DocumentInfo info, SourceText text)
762protected override void ApplyAdditionalDocumentAdded(DocumentInfo info, SourceText text)
765protected override void ApplyAnalyzerConfigDocumentAdded(DocumentInfo info, SourceText text)
771private void AddDocumentCore(DocumentInfo info, SourceText initialText, TextDocumentKind documentKind)
877SourceText? initialText = null,
896SourceText? initialText = null,
913SourceText text)
978SourceText? initialText,
1184protected override void ApplyDocumentTextChanged(DocumentId documentId, SourceText newText)
1187protected override void ApplyAdditionalDocumentTextChanged(DocumentId documentId, SourceText newText)
1190protected override void ApplyAnalyzerConfigDocumentTextChanged(DocumentId documentId, SourceText newText)
1193private void ApplyTextDocumentChange(DocumentId documentId, SourceText newText)
Venus\ContainedDocument.cs (13)
208public void UpdateText(SourceText newText)
210var originalText = SubjectBuffer.CurrentSnapshot.AsText();
233private ITextSnapshot ApplyChanges(SourceText originalText, IEnumerable<TextChange> changes)
261private IEnumerable<TextChange> FilterTextChanges(SourceText originalText, List<TextSpan> editorVisibleSpansInOriginal, IEnumerable<TextChange> changes)
348private IEnumerable<TextChange> GetSubTextChanges(SourceText originalText, TextChange changeInOriginalText, TextSpan visibleSpanInOriginalText)
365SourceText originalText, TextSpan visibleSpanInOriginalText, string leftText, string rightText, int offsetInOriginalText, List<TextChange> changes)
399SourceText originalText, TextSpan visibleSpanInOriginalText, string leftText, string rightText, int offsetInOriginalText)
503SourceText originalText, TextSpan visibleSpanInOriginalText,
824public BaseIndentationFormattingRule GetBaseIndentationRule(SyntaxNode root, SourceText text, List<TextSpan> spans, int spanIndex)
872private static void GetVisibleAndTextSpan(SourceText text, List<TextSpan> spans, int spanIndex, out TextSpan visibleSpan, out TextSpan visibleTextSpan)
884private int GetBaseIndentation(SyntaxNode root, SourceText text, TextSpan span)
911private static TextSpan GetVisibleTextSpan(SourceText text, TextSpan visibleSpan, bool uptoFirstAndLastLine = false)
949private int GetAdditionalIndentation(SyntaxNode root, SourceText text, TextSpan span, int hostIndentationSize)
Workspace\VisualStudioDocumentNavigationService.cs (7)
138static VsTextSpan GetVsTextSpanFromPosition(SourceText text, int position, int virtualSpace)
160Func<SourceText, VsTextSpan> getVsTextSpan,
161Func<SourceText, TextSpan, VsTextSpan> getVsTextSpanForMapping,
184Func<SourceText, VsTextSpan> getVsTextSpan,
185Func<SourceText, TextSpan, VsTextSpan> getVsTextSpanForMapping,
245Func<SourceText, VsTextSpan> getVsTextSpan)
346private static VsTextSpan GetVsTextSpan(SourceText text, TextSpan textSpan, bool allowInvalidSpan)
Microsoft.VisualStudio.LanguageServices.CSharp (40)
CodeModel\CSharpCodeModelService.NodeLocator.cs (31)
33protected override VirtualTreePoint? GetStartPoint(SourceText text, LineFormattingOptions options, SyntaxNode node, EnvDTE.vsCMPart part)
84protected override VirtualTreePoint? GetEndPoint(SourceText text, LineFormattingOptions options, SyntaxNode node, EnvDTE.vsCMPart part)
135private static VirtualTreePoint GetBodyStartPoint(SourceText text, SyntaxToken openBrace)
147private static VirtualTreePoint GetBodyStartPoint(SourceText text, LineFormattingOptions options, SyntaxToken openBrace, SyntaxToken closeBrace, int memberStartColumn)
211private static VirtualTreePoint GetBodyEndPoint(SourceText text, SyntaxToken closeBrace)
221private static VirtualTreePoint GetStartPoint(SourceText text, ArrowExpressionClauseSyntax node, EnvDTE.vsCMPart part)
242private static VirtualTreePoint GetStartPoint(SourceText text, AttributeSyntax node, EnvDTE.vsCMPart part)
275private static VirtualTreePoint GetStartPoint(SourceText text, AttributeArgumentSyntax node, EnvDTE.vsCMPart part)
305private static VirtualTreePoint GetStartPoint(SourceText text, BaseTypeDeclarationSyntax node, EnvDTE.vsCMPart part)
353private static VirtualTreePoint GetStartPoint(SourceText text, LineFormattingOptions options, BaseMethodDeclarationSyntax node, EnvDTE.vsCMPart part)
442private static VirtualTreePoint GetStartPoint(SourceText text, LineFormattingOptions options, BasePropertyDeclarationSyntax node, EnvDTE.vsCMPart part)
507private static VirtualTreePoint GetStartPoint(SourceText text, LineFormattingOptions options, AccessorDeclarationSyntax node, EnvDTE.vsCMPart part)
556private static VirtualTreePoint GetStartPoint(SourceText text, BaseNamespaceDeclarationSyntax node, EnvDTE.vsCMPart part)
605private static VirtualTreePoint GetStartPoint(SourceText text, DelegateDeclarationSyntax node, EnvDTE.vsCMPart part)
645private static VirtualTreePoint GetStartPoint(SourceText text, UsingDirectiveSyntax node, EnvDTE.vsCMPart part)
678private static VirtualTreePoint GetStartPoint(SourceText text, VariableDeclaratorSyntax node, EnvDTE.vsCMPart part)
719private static VirtualTreePoint GetStartPoint(SourceText text, EnumMemberDeclarationSyntax node, EnvDTE.vsCMPart part)
759private static VirtualTreePoint GetStartPoint(SourceText text, ParameterSyntax node, EnvDTE.vsCMPart part)
799private static VirtualTreePoint GetEndPoint(SourceText text, ArrowExpressionClauseSyntax node, EnvDTE.vsCMPart part)
817private static VirtualTreePoint GetEndPoint(SourceText text, AttributeSyntax node, EnvDTE.vsCMPart part)
850private static VirtualTreePoint GetEndPoint(SourceText text, AttributeArgumentSyntax node, EnvDTE.vsCMPart part)
880private static VirtualTreePoint GetEndPoint(SourceText text, BaseTypeDeclarationSyntax node, EnvDTE.vsCMPart part)
921private static VirtualTreePoint GetEndPoint(SourceText text, BaseMethodDeclarationSyntax node, EnvDTE.vsCMPart part)
995private static VirtualTreePoint GetEndPoint(SourceText text, BasePropertyDeclarationSyntax node, EnvDTE.vsCMPart part)
1055private static VirtualTreePoint GetEndPoint(SourceText text, AccessorDeclarationSyntax node, EnvDTE.vsCMPart part)
1094private static VirtualTreePoint GetEndPoint(SourceText text, DelegateDeclarationSyntax node, EnvDTE.vsCMPart part)
1135private static VirtualTreePoint GetEndPoint(SourceText text, BaseNamespaceDeclarationSyntax node, EnvDTE.vsCMPart part)
1184private static VirtualTreePoint GetEndPoint(SourceText text, UsingDirectiveSyntax node, EnvDTE.vsCMPart part)
1217private static VirtualTreePoint GetEndPoint(SourceText text, EnumMemberDeclarationSyntax node, EnvDTE.vsCMPart part)
1258private static VirtualTreePoint GetEndPoint(SourceText text, VariableDeclaratorSyntax node, EnvDTE.vsCMPart part)
1300private static VirtualTreePoint GetEndPoint(SourceText text, ParameterSyntax node, EnvDTE.vsCMPart part)
Microsoft.VisualStudio.LanguageServices.CSharp.UnitTests (7)
Microsoft.VisualStudio.LanguageServices.LiveShare (6)
Microsoft.VisualStudio.LanguageServices.Test.Utilities2 (1)
Microsoft.VisualStudio.LanguageServices.UnitTests (4)
Microsoft.VisualStudio.LanguageServices.VisualBasic (47)
CodeModel\VisualBasicCodeModelService.NodeLocator.vb (44)
38Protected Overrides Function GetStartPoint(text As SourceText, options As LineFormattingOptions, node As SyntaxNode, part As EnvDTE.vsCMPart) As VirtualTreePoint?
128Protected Overrides Function GetEndPoint(text As SourceText, options As LineFormattingOptions, node As SyntaxNode, part As EnvDTE.vsCMPart) As VirtualTreePoint?
218Private Shared Function GetAttributesStartPoint(text As SourceText, attributes As SyntaxList(Of AttributeListSyntax), part As EnvDTE.vsCMPart) As VirtualTreePoint?
252Private Shared Function GetAttributesEndPoint(text As SourceText, attributes As SyntaxList(Of AttributeListSyntax), part As EnvDTE.vsCMPart) As VirtualTreePoint?
300Private Shared Function GetTypeBlockStartPoint(text As SourceText, options As LineFormattingOptions, typeBlock As TypeBlockSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
360Private Shared Function GetTypeBlockEndPoint(text As SourceText, typeBlock As TypeBlockSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
386Private Shared Function GetEnumBlockStartPoint(text As SourceText, options As LineFormattingOptions, enumBlock As EnumBlockSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
431Private Shared Function GetEnumBlockEndPoint(text As SourceText, enumBlock As EnumBlockSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
457Private Shared Function GetMethodBlockStartPoint(text As SourceText, options As LineFormattingOptions, methodBlock As MethodBlockBaseSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
516Private Shared Function GetDeclareStatementStartPoint(text As SourceText, declareStatement As DeclareStatementSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
552Private Shared Function GetDeclareStatementEndPoint(text As SourceText, declareStatement As DeclareStatementSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
581Private Shared Function GetMethodStatementStartPoint(text As SourceText, methodStatement As MethodStatementSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
617Private Shared Function GetMethodBlockEndPoint(text As SourceText, methodBlock As MethodBlockBaseSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
672Private Shared Function GetMethodStatementEndPoint(text As SourceText, methodStatement As MethodStatementSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
701Private Shared Function GetPropertyBlockStartPoint(text As SourceText, propertyBlock As PropertyBlockSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
705Private Shared Function GetPropertyStatementStartPoint(text As SourceText, propertyStatement As PropertyStatementSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
740Private Shared Function GetPropertyBlockEndPoint(text As SourceText, propertyBlock As PropertyBlockSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
744Private Shared Function GetPropertyStatementEndPoint(text As SourceText, propertyStatement As PropertyStatementSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
785Private Shared Function GetEventBlockStartPoint(text As SourceText, options As LineFormattingOptions, eventBlock As EventBlockSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
825Private Shared Function GetEventStatementStartPoint(text As SourceText, eventStatement As EventStatementSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
862Private Shared Function GetEventBlockEndPoint(text As SourceText, eventBlock As EventBlockSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
866Private Shared Function GetEventStatementEndPoint(text As SourceText, eventStatement As EventStatementSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
907Private Shared Function GetDelegateStatementStartPoint(text As SourceText, delegateStatement As DelegateStatementSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
943Private Shared Function GetDelegateStatementEndPoint(text As SourceText, delegateStatement As DelegateStatementSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
982Private Shared Function GetNamespaceBlockStartPoint(text As SourceText, options As LineFormattingOptions, namespaceBlock As NamespaceBlockSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
1038Private Shared Function GetNamespaceBlockEndPoint(text As SourceText, namespaceBlock As NamespaceBlockSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
1069Private Shared Function GetVariableStartPoint(text As SourceText, variable As ModifiedIdentifierSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
1101Private Shared Function GetVariableStartPoint(text As SourceText, enumMember As EnumMemberDeclarationSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
1126Private Shared Function GetVariableEndPoint(text As SourceText, variable As ModifiedIdentifierSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
1153Private Shared Function GetVariableEndPoint(text As SourceText, enumMember As EnumMemberDeclarationSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
1177Private Shared Function GetParameterStartPoint(text As SourceText, parameter As ParameterSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
1207Private Shared Function GetParameterEndPoint(text As SourceText, parameter As ParameterSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
1231Private Shared Function GetImportsStatementStartPoint(text As SourceText, importsStatement As ImportsStatementSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
1257Private Shared Function GetImportsStatementEndPoint(text As SourceText, importsStatement As ImportsStatementSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
1283Private Shared Function GetOptionStatementStartPoint(text As SourceText, optionStatement As OptionStatementSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
1309Private Shared Function GetOptionStatementEndPoint(text As SourceText, optionStatement As OptionStatementSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
1335Private Shared Function GetInheritsStatementStartPoint(text As SourceText, inheritsStatement As InheritsStatementSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
1361Private Shared Function GetInheritsStatementEndPoint(text As SourceText, inheritsStatement As InheritsStatementSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
1387Private Shared Function GetImplementsStatementStartPoint(text As SourceText, implementsStatement As ImplementsStatementSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
1413Private Shared Function GetImplementsStatementEndPoint(text As SourceText, implementsStatement As ImplementsStatementSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
1439Private Shared Function GetAttributeStartPoint(text As SourceText, attribute As AttributeSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
1468Private Shared Function GetAttributeEndPoint(text As SourceText, attribute As AttributeSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
1496Private Shared Function GetAttributeArgumentStartPoint(text As SourceText, argument As ArgumentSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
1531Private Shared Function GetAttributeArgumentEndPoint(text As SourceText, argument As ArgumentSyntax, part As EnvDTE.vsCMPart) As VirtualTreePoint?
Microsoft.VisualStudio.LanguageServices.Xaml (4)
Roslyn.Diagnostics.Analyzers (13)
Roslyn.VisualStudio.DiagnosticsWindow (2)
Roslyn.VisualStudio.Next.UnitTests (80)
Remote\SnapshotSerializationTests.cs (10)
50var document1 = project1.AddDocument("Document1", SourceText.From(csCode));
54var document2 = project2.AddDocument("Document2", SourceText.From(vbCode));
60.AddAdditionalDocument("Additional", SourceText.From("hello"), ["test"], @".\Add").Project.Solution;
67loader: TextLoader.From(TextAndVersion.Create(SourceText.From("root = true"), VersionStamp.Create())))]);
153var document = workspace.CurrentSolution.AddProject("Project", "Project.dll", LanguageNames.CSharp).AddDocument("Document", SourceText.From(code));
173var document = solution.AddProject("Project", "Project.dll", LanguageNames.CSharp).AddDocument("Document", SourceText.From(code));
532var document = CreateWorkspace().CurrentSolution.AddProject("empty", "empty", LanguageNames.CSharp).AddDocument("empty", SourceText.From(""));
607var sourceText = SourceText.From("Hello", Encoding.UTF8);
625sourceText = SourceText.From("Hello", new NotSerializableEncoding());
Services\ServiceHubServicesTests.cs (50)
99var oldText = await oldDocument.GetTextAsync();
102var newText = oldText.WithChanges(new TextChange(TextSpan.FromBounds(0, 0), "/* test */"));
411params ImmutableArray<(string hintName, SourceText text)>[] values)
419ImmutableArray<ImmutableArray<(string hintName, SourceText text)>> values)
422ImmutableArray<(string hintName, SourceText text)> sourceTexts = default;
448var tempDoc = project.AddDocument("X.cs", SourceText.From("// "));
463Assert.True(localWorkspace.SetCurrentSolution(s => s.WithDocumentText(tempDocId, SourceText.From("// " + i)), WorkspaceChangeKind.SolutionChanged));
499var localText = await localDoc.GetTextAsync();
500var remoteText = await localDoc.GetTextAsync();
508private static SourceText CreateText(string content, Encoding encoding = null, SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1)
509=> SourceText.From(content, encoding ?? Encoding.UTF8, checksumAlgorithm);
511private static SourceText CreateStreamText(string content, bool useBOM, bool useMemoryStream)
518return SourceText.From(stream, encoding, SourceHashAlgorithm.Sha1, throwIfBinaryDetected: true);
522return SourceText.From(bytes, bytes.Length, encoding, SourceHashAlgorithm.Sha1, throwIfBinaryDetected: true);
536var sourceText = CreateText(Guid.NewGuid().ToString());
570var sourceText = CreateText(Guid.NewGuid().ToString());
674var contents = CreateText(Guid.NewGuid().ToString());
682var contents = CreateText(Guid.NewGuid().ToString());
732return ImmutableArray.Create(("hint", SourceText.From($"// generated document {callCount}", Encoding.UTF8)));
754solution = solution.WithTextDocumentText(tempDocId, SourceText.From("// new contents"));
787var tempDoc = project.AddDocument("X.cs", SourceText.From("// "));
816return ImmutableArray.Create(("hint", SourceText.From($"// generated document {callCount}", Encoding.UTF8)));
871return ImmutableArray.Create(("hint", SourceText.From($"// generated document {callCount}", Encoding.UTF8)));
925var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
934var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
976var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
985var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
1017var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
1026var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
1060var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
1069var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
1112var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
1122var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
1165var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
1175var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
1218var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
1228var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
1263var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
1273var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
1308var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
1317var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
1351var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
1360var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
1443Contract.ThrowIfFalse(workspace.TryApplyChanges(workspace.CurrentSolution.WithDocumentText(normalDocId, SourceText.From("// new text"))));
1557var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
1636private static SourceText GetNewText(Document document, string csAddition, string vbAddition)
1640return SourceText.From(document.State.GetTextSynchronously(CancellationToken.None).ToString() + csAddition);
1643return SourceText.From(document.State.GetTextSynchronously(CancellationToken.None).ToString() + vbAddition);
1757solution = current.AddDocument($"Document{i}", SourceText.From(documents[i])).Project.Solution;
1763solution = current.AddAdditionalDocument($"AdditionalDocument{i}", SourceText.From(additionalDocuments[i])).Project.Solution;
Services\SolutionServiceTests.cs (18)
159await VerifySolutionUpdate(code, s => s.WithDocumentText(s.Projects.First().DocumentIds.First(), SourceText.From(code + " ")));
314project = project.AddDocument("newDocument", SourceText.From("// new text")).Project;
334loader: TextLoader.From(TextAndVersion.Create(SourceText.From("test"), VersionStamp.Create())));
345return s.WithAdditionalDocumentText(additionalDocumentId, SourceText.From("changed"));
366loader: TextLoader.From(TextAndVersion.Create(SourceText.From("root = true"), VersionStamp.Create(), filePath: configPath)),
378return s.WithAnalyzerConfigDocumentText(analyzerConfigDocumentId, SourceText.From("root = false"));
398loader: TextLoader.From(TextAndVersion.Create(SourceText.From("class A { }"), VersionStamp.Create())));
409return s.WithDocumentText(documentId, SourceText.From("class Changed { }"));
436var currentSolution = remoteSolution1.WithDocumentText(remoteSolution1.Projects.First().Documents.First().Id, SourceText.From(code + " class Test2 { }"));
445currentSolution = oopSolution2.WithDocumentText(oopSolution2.Projects.First().Documents.First().Id, SourceText.From(code + " class Test3 { }"));
521var frozenText1 = SourceText.From("// Hello, World!");
530var frozenText2 = SourceText.From("// Hello, World! A second time!");
834solution = solution.GetProject(project1.Id).AddDocument("X.cs", SourceText.From("// X")).Project.Solution;
835solution = solution.GetProject(project2.Id).AddDocument("Y.vb", SourceText.From("' Y")).Project.Solution;
889solution = solution.GetProject(project1.Id).AddDocument("X.cs", SourceText.From("// X")).Project.Solution;
890solution = solution.GetProject(project2.Id).AddDocument("Y.cs", SourceText.From("// Y")).Project.Solution;
StackDepthTest (1)
System.Private.CoreLib.Generators (1)
System.Text.Json.SourceGeneration (17)
JsonSourceGenerator.Emitter.cs (14)
98private partial void AddSource(string hintName, SourceText sourceText);
113SourceText? sourceText = GenerateTypeInfo(contextGenerationSpec, typeGenerationSpec);
183private static SourceText CompleteSourceFileAndReturnText(SourceWriter writer)
194private SourceText? GenerateTypeInfo(ContextGenerationSpec contextSpec, TypeGenerationSpec typeGenerationSpec)
229private static SourceText GenerateForTypeWithBuiltInConverter(ContextGenerationSpec contextSpec, TypeGenerationSpec typeMetadata)
246private static SourceText GenerateForTypeWithCustomConverter(ContextGenerationSpec contextSpec, TypeGenerationSpec typeMetadata)
267private static SourceText GenerateForNullable(ContextGenerationSpec contextSpec, TypeGenerationSpec typeMetadata)
288private static SourceText GenerateForUnsupportedType(ContextGenerationSpec contextSpec, TypeGenerationSpec typeMetadata)
304private static SourceText GenerateForEnum(ContextGenerationSpec contextSpec, TypeGenerationSpec typeMetadata)
320private SourceText GenerateForCollection(ContextGenerationSpec contextSpec, TypeGenerationSpec typeGenerationSpec)
494private SourceText GenerateForObject(ContextGenerationSpec contextSpec, TypeGenerationSpec typeMetadata)
1111private static SourceText GetRootJsonContextImplementation(ContextGenerationSpec contextSpec, bool emitGetConverterForNullablePropertyMethod)
1379private static SourceText GetGetTypeInfoImplementation(ContextGenerationSpec contextSpec)
1421private SourceText GetPropertyNameInitialization(ContextGenerationSpec contextSpec)
System.Windows.Forms.Analyzers (1)
System.Windows.Forms.Analyzers.CSharp.Tests (7)
System.Windows.Forms.Analyzers.Tests (12)
Test.Utilities (6)
Text.Analyzers (10)
Text.Analyzers.UnitTests (1)