9 types derived from SourceText
Microsoft.CodeAnalysis (6)
Microsoft.CodeAnalysis.CSharp.Features (1)
Microsoft.CodeAnalysis.EditorFeatures.Text (1)
Microsoft.CodeAnalysis.Test.Utilities (1)
3759 references to SourceText
BuildValidator (4)
ConfigurationSchemaGenerator.Tests (2)
CSharpSyntaxGenerator (6)
IdeCoreBenchmarks (12)
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 (16)
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.Mvc.Razor.RuntimeCompilation (3)
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.Test (1)
Microsoft.AspNetCore.SignalR.Client.SourceGenerator (4)
Microsoft.CodeAnalysis (248)
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 (8)
121public void AddSource(string hintName, string source) => AddSource(hintName, SourceText.From(source, Encoding.UTF8));
124/// Adds a <see cref="SourceText"/> to the compilation that will be available during subsequent phases
127/// <param name="sourceText">The <see cref="SourceText"/> to add to the compilation</param>
131public void AddSource(string hintName, SourceText sourceText) => AdditionalSources.Add(hintName, sourceText);
158public void AddSource(string hintName, string source) => AddSource(hintName, SourceText.From(source, Encoding.UTF8));
161/// Adds a <see cref="SourceText"/> to the compilation
164/// <param name="sourceText">The <see cref="SourceText"/> to add to the compilation</param>
168public 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.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)
17public static string GetLeadingWhitespaceOfLineAtPosition(this SourceText text, int position)
33this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden, CancellationToken cancellationToken)
45this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden,
83public static bool AreOnSameLine(this SourceText text, SyntaxToken token1, SyntaxToken token2)
88public 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 (17)
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)
121protected static async Task<(SourceText?, TextSpan)> GetGeneratedSourceTextAsync(
162var result = pdbService.TryAddDocumentToWorkspace((MetadataAsSourceWorkspace)masWorkspace!, file.FilePath, new StaticSourceTextContainer(SourceText.From(string.Empty)), out _);
199var sourceText = SourceText.From(source, encoding: encoding ?? Encoding.UTF8);
207SourceText source,
249protected static void CompileTestSource(string path, SourceText source, Project project, Location pdbLocation, Location sourceLocation, bool buildReferenceAssembly, bool windowsPdb, Encoding? fallbackEncoding = null)
259protected 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)
264protected 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)
345protected class StaticSourceTextContainer(SourceText sourceText) : SourceTextContainer
347public 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 (119)
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)
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;
304var oldText = await oldDocument.GetTextAsync();
307var newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2));
309var newText = await newDocument.GetTextAsync();
372var newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2));
434var newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2));
516var newSolution = workspace.CurrentSolution.WithDocumentText(documentId, SourceText.From(source2));
585var newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2));
624var newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2));
665var newSolution = oldSolution.AddDocument(newDocId, "goo.cs", SourceText.From(source2), filePath: Path.Combine(TempRoot.Root, "goo.cs"));
711var newSolution = oldSolution.AddDocument(newDocId, "goo.cs", SourceText.From(source2), filePath: Path.Combine(TempRoot.Root, "goo.cs"));
744var newSolution = oldSolution.AddDocument(documentId, "goo.cs", SourceText.From(source2), filePath: filePath);
799var 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 (334)
IncrementalParsing\IncrementalParsingTests.cs (227)
29var itext = SourceText.From(text);
36var itext = SourceText.From(text);
495var text = tree.GetText();
527var text = tree.GetText();
568var text = tree.GetText();
619var initialText = initialTree.GetText();
627var withOpenBraceDeletedText = initialText.WithChanges(new TextChange(openBraceLine.SpanIncludingLineBreak, ""));
838var withCloseBraceDeletedText = withOpenBraceDeletedText.WithChanges(new TextChange(closeBraceLine.SpanIncludingLineBreak, ""));
961var text = SourceText.From(@"partial class C{}");
965var newText = text.WithChanges(new TextChange(new TextSpan(0, 8), ""));
975var text = SourceText.From(@"partial class C{}");
979var newText = text.WithChanges(new TextChange(new TextSpan(0, 8), ""));
989SourceText oldText = SourceText.From(@"
1005SourceText oldText = SourceText.From(@"
1021SourceText oldText = SourceText.From(@"
1038SourceText oldText = SourceText.From(@"
1054SourceText oldText = SourceText.From(@"
1067SourceText oldText = SourceText.From(@"
1083SourceText oldText = SourceText.From(@"
1095SourceText oldText = SourceText.From(@"
1107SourceText oldText = SourceText.From(@" class A
1123SourceText oldText = SourceText.From(@"public class TestClass
1136SourceText oldText = SourceText.From(@"using System;
1151SourceText oldText = SourceText.From(@"public class MyClass {
1163SourceText oldText = SourceText.From(@"
1177SourceText startingText = SourceText.From(@"
1198SourceText startingText = SourceText.From(@"
1217SourceText startingText = SourceText.From(@"
1237SourceText oldText = SourceText.From(@"class MyClass
1257SourceText oldText = SourceText.From(@"
1281SourceText oldText = SourceText.From(@"
1305SourceText oldText = SourceText.From(@"interface IGoo
1329SourceText oldText = SourceText.From(@"interface IGoo
1353SourceText oldText = SourceText.From(@"using System.Runtime.CompilerServices;
1375SourceText oldText = SourceText.From(@"class A
1399SourceText oldText = SourceText.From(@"public class MyClass {
1421SourceText oldText = SourceText.From(@"public class MyClass {
1512SourceText oldText = SourceText.From(@"class filesystem{
1531SourceText oldText = SourceText.From(@"class CSTR020mod{ public static void CSTR020() { ON ERROR GOTO ErrorTrap; } }");
1547SourceText oldText = SourceText.From(@"class A
1567SourceText oldText = SourceText.From(@"public class DynClassDrived
1589SourceText oldText = SourceText.From(@"public class MemberClass
1609SourceText oldText = SourceText.From(@"public class MemberClass
1628SourceText oldText = SourceText.From(@"class Test
1650SourceText oldText = SourceText.From(
1677SourceText oldText = SourceText.From(
1703SourceText oldText = SourceText.From(
1728SourceText oldText = SourceText.From(
1750SourceText oldText = SourceText.From(
1805SourceText oldText = SourceText.From(
1827SourceText oldText = SourceText.From(
1848SourceText oldText = SourceText.From(
1869SourceText oldText = SourceText.From(
1892SourceText oldText = SourceText.From(
1913SourceText oldText = SourceText.From(
1933SourceText oldText = SourceText.From(
1951SourceText oldText = SourceText.From(
1972SourceText oldText = SourceText.From(
1995SourceText oldText = SourceText.From(
2012SourceText oldText = SourceText.From(
2030SourceText oldText = SourceText.From(
2048SourceText oldText = SourceText.From(
2069SourceText oldText = SourceText.From(
2104SourceText oldText = SourceText.From(
2128SourceText oldText = SourceText.From(
2146SourceText oldText = SourceText.From(
2164SourceText oldText = SourceText.From(
2183SourceText oldText = SourceText.From(
2214SourceText oldText = SourceText.From(
2239SourceText oldText = SourceText.From(
2258SourceText oldText = SourceText.From(
2276SourceText oldText = SourceText.From(
2295SourceText oldText = SourceText.From(
2314SourceText oldText = SourceText.From(
2335SourceText oldText = SourceText.From(
2354SourceText oldText = SourceText.From(
2381SourceText oldText = SourceText.From(
2409SourceText oldText = SourceText.From(
2431SourceText oldText = SourceText.From(
2450SourceText oldText = SourceText.From(
2482SourceText oldText = SourceText.From(
2515SourceText oldText = SourceText.From(
2541SourceText oldText = SourceText.From(
2566SourceText oldText = SourceText.From(
2596SourceText oldText = SourceText.From(
2625SourceText oldText = SourceText.From(
2646SourceText oldText = SourceText.From(
2678SourceText oldText = SourceText.From(
2706SourceText oldText = SourceText.From(
2744var text = SourceText.From(str);
2747var text2 = text.WithChanges(
2762SourceText oldText = SourceText.From(@"
2770var newText = oldText.WithChanges(new TextChange(new TextSpan(0, 0), "{"));
2780SourceText oldText = SourceText.From(@"System.Console.WriteLine(true)
2786var newText = oldText.WithChanges(new TextChange(new TextSpan(0, 0), @"System.Console.WriteLine(false)
2809SourceText oldText = SourceText.From(@"System.Console.WriteLine(true)
2815var newText = oldText.WithInsertAt(
2839SourceText oldText = SourceText.From(@"System.Console.WriteLine(true)
2845var newText = oldText.WithChanges(new TextChange(new TextSpan(0, 0), @"if (false)
2899var oldIText = oldTree.GetText();
2903var newIText = oldIText.WithChanges(change);
2977var currIText = currTree.GetText();
3017var currIText = currTree.GetText();
3097var oldText = SourceText.From(items[0]);
3101var newText = oldText.WithChanges(change); // f is a method decl parameter
3128var oldText = SourceText.From(@"
3154var newText = SourceText.From(@"
3197var text = tree.GetText();
3218var text = tree.GetText();
3239var text = tree.GetText();
3260var text = tree.GetText();
3281var text = tree.GetText();
3302var text = tree.GetText();
3326var text = tree.GetText();
3350var text = tree.GetText();
3374var text = tree.GetText();
3398var text = tree.GetText();
3422var text = tree.GetText();
3448var text = tree.GetText();
3474var text = tree.GetText();
3499var text = tree.GetText();
3525var text = tree.GetText();
3543var text = tree.GetText();
3561var text = tree.GetText();
3579var text = tree.GetText();
3594var text = tree.GetText();
3608var text = tree.GetText();
3622var text = tree.GetText();
3660var text = tree.GetText();
3687private static void CommentOutText(SourceText oldText, int locationOfChange, int widthOfChange, out SyntaxTree incrementalTree, out SyntaxTree parsedTree)
3689var newText = oldText.WithChanges(
3699private static void RemoveText(SourceText oldText, int locationOfChange, int widthOfChange, out SyntaxTree incrementalTree, out SyntaxTree parsedTree)
3701var newText = oldText.WithChanges(new TextChange(new TextSpan(locationOfChange, widthOfChange), ""));
3721private static void CharByCharIncrementalParse(SourceText oldText, char newChar, out SyntaxTree incrementalTree, out SyntaxTree parsedTree)
3727var newText = oldText.WithChanges(new TextChange(new TextSpan(oldText.Length, 0), newChar.ToString()));
3732private static void TokenByTokenBottomUp(SourceText oldText, string token, out SyntaxTree incrementalTree, out SyntaxTree parsedTree)
3735SourceText 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 (106)
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 class NullTextBufferException(Document document, SourceText text) : Exception("Cannot retrieve textbuffer from document.")
205private readonly SourceText _text = text;
925async Task<ImmutableArray<(DocumentId documentId, string newName, SyntaxNode newRoot, SourceText newText)>> CalculateFinalDocumentChangesAsync(
931using var _ = PooledObjects.ArrayBuilder<(DocumentId documentId, string newName, SyntaxNode newRoot, SourceText newText)>.GetInstance(out var result);
952ImmutableArray<(DocumentId documentId, string newName, SyntaxNode newRoot, SourceText newText)> documentChanges)
Microsoft.CodeAnalysis.EditorFeatures.Test.Utilities (27)
Microsoft.CodeAnalysis.EditorFeatures.Text (20)
Microsoft.CodeAnalysis.EditorFeatures.UnitTests (50)
Diagnostics\DiagnosticAnalyzerServiceTests.cs (8)
173project = project.AddAnalyzerConfigDocument(".editorconfig", filePath: "z:\\.editorconfig", text: SourceText.From(editorconfigText)).Project;
176var document = project.AddDocument("test.cs", SourceText.From("class A {}"), filePath: "z:\\test.cs");
312loader: TextLoader.From(TextAndVersion.Create(SourceText.From("class A {}"), VersionStamp.Create(), filePath: "test.cs")),
361text: SourceText.From(analyzerConfigText),
391loader: TextLoader.From(TextAndVersion.Create(SourceText.From("class A {}"), VersionStamp.Create(), filePath: "test.cs")),
469var text = await additionalDoc.GetTextAsync();
634var text = await document.GetTextAsync();
891return 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)
4207Public Overrides Function IsInsertionTrigger(text As SourceText, characterPosition As Integer, options As CompletionOptions) As Boolean
8225Public Overrides Function ShouldTriggerCompletion(text As SourceText, caretPosition As Integer, trigger As CompletionTrigger, options As OptionSet) As Boolean
8270Public Overrides Function ShouldTriggerCompletion(text As SourceText, caretPosition As Integer, trigger As CompletionTrigger, options As OptionSet) As Boolean
9612Public Overrides Function ShouldTriggerCompletion(text As SourceText, caretPosition As Integer, trigger As CompletionTrigger, options As OptionSet) As Boolean
10273Public Overrides Function IsInsertionTrigger(text As SourceText, characterPosition As Integer, options As CompletionOptions) As Boolean
10346Public Overrides Function IsInsertionTrigger(text As SourceText, characterPosition As Integer, options As CompletionOptions) As Boolean
10639Public Overrides Function IsInsertionTrigger(text As SourceText, characterPosition As Integer, options As CompletionOptions) As Boolean
10775Public 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)
14public sealed override bool ShouldTriggerCompletion(SourceText text, int caretPosition, CompletionTrigger trigger, OptionSet options)
17internal sealed override bool ShouldTriggerCompletion(Host.LanguageServices languageServices, SourceText text, int caretPosition, CompletionTrigger trigger, CompletionOptions options, OptionSet passthroughOptions)
20protected abstract bool ShouldTriggerCompletionImpl(SourceText text, int caretPosition, CompletionTrigger trigger);
Microsoft.CodeAnalysis.ExternalAccess.OmniSharp (2)
Microsoft.CodeAnalysis.ExternalAccess.Razor (2)
Microsoft.CodeAnalysis.Features (144)
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)
207internal static bool IsTextualTriggerString(SourceText text, int characterPosition, string value)
DocumentationComments\AbstractDocumentationCommentSnippetService.cs (8)
58var text = document.Text;
87private List<string>? GetDocumentationCommentLines(SyntaxToken token, SourceText text, in DocumentationCommentOptions options, out string? indentText, out int caretOffset, out int spanToReplaceLength)
118private List<string>? GetDocumentationCommentLinesNoIndentation(SyntaxToken token, SourceText text, in DocumentationCommentOptions options, out int caretOffset, out int spanToReplaceLength)
134private List<string>? GetDocumentationStubLines(SyntaxToken token, SourceText text, in DocumentationCommentOptions options, out int caretOffset, out int spanToReplaceLength, out string? existingCommentText)
178var text = document.Text;
255var text = document.Text;
298var text = document.Text;
338var text = document.Text;
EditAndContinue\AbstractEditAndContinueAnalyzer.cs (8)
509private static readonly SourceText s_emptySource = SourceText.From("");
539SourceText oldText;
713static void LogRudeEdits(ArrayBuilder<RudeEditDiagnostic> diagnostics, SourceText text, string filePath)
784SourceText newText,
938SourceText newText,
1307private static bool TryGetTrackedStatement(ImmutableArray<ActiveStatementLineSpan> activeStatementSpans, ActiveStatementId id, SourceText text, MemberBody body, [NotNullWhen(true)] out SyntaxNode? trackedStatement, out int trackedStatementPart)
2505SourceText newText,
EditAndContinue\CommittedSolution.cs (9)
309private async ValueTask<(Optional<SourceText?> matchingSourceText, bool? hasDocument)> TryGetMatchingSourceTextAsync(Document document, SourceText sourceText, Document? currentDocument, CancellationToken cancellationToken)
321private static async ValueTask<Optional<SourceText?>> TryGetMatchingSourceTextAsync(
322SourceText sourceText, string filePath, Document? currentDocument, IPdbMatchingSourceTextProvider sourceTextProvider, ImmutableArray<byte> requiredChecksum, SourceHashAlgorithm checksumAlgorithm, CancellationToken cancellationToken)
341return SourceText.From(text, sourceText.Encoding, checksumAlgorithm);
436private static bool IsMatchingSourceText(SourceText sourceText, ImmutableArray<byte> requiredChecksum, SourceHashAlgorithm checksumAlgorithm)
439private static Optional<SourceText?> TryGetPdbMatchingSourceTextFromDisk(string sourceFilePath, Encoding? encoding, ImmutableArray<byte> requiredChecksum, SourceHashAlgorithm checksumAlgorithm)
449var 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 (21)
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)
67var sourceTreeA1 = SyntaxFactory.ParseSyntaxTree(SourceText.From(sourceBytesA1, sourceBytesA1.Length, encodingA, SourceHashAlgorithms.Default), TestOptions.Regular, sourceFileA.Path);
68var sourceTreeB1 = SyntaxFactory.ParseSyntaxTree(SourceText.From(sourceBytesB1, sourceBytesB1.Length, encodingB, SourceHashAlgorithms.Default), TestOptions.Regular, sourceFileB.Path);
69var sourceTreeC1 = SyntaxFactory.ParseSyntaxTree(SourceText.From(sourceBytesC1, sourceBytesC1.Length, encodingC, SourceHashAlgorithm.Sha1), TestOptions.Regular, sourceFileC.Path);
345var sourceText = CreateText("class D {}");
407solution = solution.AddDocument(designTimeOnlyDocumentId, designTimeOnlyFileName, SourceText.From(sourceDesignTimeOnly, Encoding.UTF8), filePath: designTimeOnlyFilePath);
427solution = solution.AddDocument(designTimeOnlyDocumentId, designTimeOnlyFileName, SourceText.From(sourceDesignTimeOnly, Encoding.UTF8), filePath: designTimeOnlyFilePath);
622AddDocument("a.cs", SourceText.From(source1, Encoding.UTF8, SourceHashAlgorithm.Sha1), filePath: sourceFile.Path);
922AddDocument(documentId, "test.cs", SourceText.From(source1, encoding, SourceHashAlgorithm.Sha1), filePath: sourceFile.Path);
1790context.AddSource("generated.cs", SourceText.From("generated: " + additionalText, Encoding.UTF8, SourceHashAlgorithm.Sha256));
2139solution = solution.WithDocumentText(document1.Id, SourceText.From("class C1 { void M() { System.Console.WriteLine(2); } }", encoding: null, SourceHashAlgorithms.Default));
3602DocumentId AddProjectAndLinkDocument(string projectName, Document doc, SourceText text)
Microsoft.CodeAnalysis.LanguageServer (4)
Microsoft.CodeAnalysis.LanguageServer.Protocol (88)
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;
478ImmutableArray<(SourceGeneratedDocumentIdentity Identity, DateTime Generated, SourceText Text)> sourceGenereatedDocuments,
522private 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)
88await testLspServer.TestWorkspace.ChangeDocumentAsync(firstDocument.Id, SourceText.From($"Some more text{markupOne}", System.Text.Encoding.UTF8, SourceHashAlgorithms.Default));
122await testLspServer.TestWorkspace.ChangeDocumentAsync(secondDocument.Id, SourceText.From("Two is now three!", System.Text.Encoding.UTF8, SourceHashAlgorithms.Default));
224var 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.Rebuild (9)
Microsoft.CodeAnalysis.Rebuild.UnitTests (3)
Microsoft.CodeAnalysis.Remote.ServiceHub (2)
Microsoft.CodeAnalysis.Remote.Workspaces (1)
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
470Dim newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2))
555Dim newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2))
613Dim newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2))
644Dim newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2))
675Dim 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 (352)
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)
17public static string GetLeadingWhitespaceOfLineAtPosition(this SourceText text, int position)
33this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden, CancellationToken cancellationToken)
45this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden,
83public static bool AreOnSameLine(this SourceText text, SyntaxToken token1, SyntaxToken token2)
88public 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)
108var text = await this.GetTextAsync(cancellationToken).ConfigureAwait(false);
168var text = textAndVersion.Text;
241var newText = newTextAndVersion.Text;
252private static TreeAndVersion MakeNewTreeAndVersion(SyntaxTree oldTree, SourceText oldText, VersionStamp oldVersion, SyntaxTree newTree, SourceText newText, VersionStamp newVersion)
261private static bool TopLevelChanged(SyntaxTree oldTree, SourceText oldText, SyntaxTree newTree, SourceText newText)
446public new DocumentState UpdateText(SourceText newText, PreservationMode mode)
506else if (TryGetText(out var priorText))
685SourceText newText,
687SourceText? 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)
938var sourceText = SourceText.From(text, encoding: null, checksumAlgorithm: project.ChecksumAlgorithm);
947public Solution AddDocument(DocumentId documentId, string name, SourceText text, IEnumerable<string>? folders = null, string? filePath = null, bool isGenerated = false)
978var sourceText = SourceText.From(string.Empty, encoding: null, project.ChecksumAlgorithm);
984private Solution AddDocumentImpl(ProjectState project, DocumentId documentId, string name, SourceText text, IReadOnlyList<string>? folders, string? filePath, bool isGenerated)
1039=> this.AddAdditionalDocument(documentId, name, SourceText.From(text), folders, filePath);
1045public Solution AddAdditionalDocument(DocumentId documentId, string name, SourceText text, IEnumerable<string>? folders = null, string? filePath = null)
1076public Solution AddAnalyzerConfigDocument(DocumentId documentId, string name, SourceText text, IEnumerable<string>? folders = null, string? filePath = null)
1100private DocumentInfo CreateDocumentInfo(DocumentId documentId, string name, SourceText text, IEnumerable<string>? folders, string? filePath)
1238public Solution WithDocumentText(DocumentId documentId, SourceText text, PreservationMode mode = PreservationMode.PreserveValue)
1241internal Solution WithDocumentTexts(ImmutableArray<(DocumentId documentId, SourceText text)> texts, PreservationMode mode = PreservationMode.PreserveValue)
1261public Solution WithAdditionalDocumentText(DocumentId documentId, SourceText text, PreservationMode mode = PreservationMode.PreserveValue)
1282public Solution WithAnalyzerConfigDocumentText(DocumentId documentId, SourceText text, PreservationMode mode = PreservationMode.PreserveValue)
1592public Solution WithDocumentText(IEnumerable<DocumentId?> documentIds, SourceText text, PreservationMode mode = PreservationMode.PreserveValue)
1618SourceGeneratedDocumentIdentity documentIdentity, DateTime generationDateTime, SourceText text)
1630internal Solution WithFrozenSourceGeneratedDocuments(ImmutableArray<(SourceGeneratedDocumentIdentity documentIdentity, DateTime generationDateTime, SourceText text)> documents)
Workspace\Solution\SolutionCompilationState.cs (11)
781internal SolutionCompilationState WithDocumentTexts(ImmutableArray<(DocumentId documentId, SourceText text)> texts, PreservationMode mode)
782=> UpdateDocumentsInMultipleProjects<DocumentState, SourceText, PreservationMode>(
788private static bool SourceTextIsUnchanged(DocumentState oldDocument, SourceText text)
789=> oldDocument.TryGetText(out var oldText) && text == oldText;
906/// <inheritdoc cref="SolutionState.WithAdditionalDocumentText(DocumentId, SourceText, PreservationMode)"/>
908DocumentId documentId, SourceText text, PreservationMode mode)
914/// <inheritdoc cref="SolutionState.WithAnalyzerConfigDocumentText(DocumentId, SourceText, PreservationMode)"/>
916DocumentId documentId, SourceText text, PreservationMode mode)
1315ImmutableArray<(SourceGeneratedDocumentIdentity documentIdentity, DateTime generationDateTime, SourceText sourceText)> documents)
1759public SolutionCompilationState WithDocumentText(IEnumerable<DocumentId?> documentIds, SourceText text, PreservationMode mode)
1761using var _ = ArrayBuilder<(DocumentId, SourceText)>.GetInstance(out var changedDocuments);
Workspace\Workspace.cs (18)
1100protected internal void OnDocumentTextChanged(DocumentId documentId, SourceText newText, PreservationMode mode)
1103private protected void OnDocumentTextChanged(DocumentId documentId, SourceText newText, PreservationMode mode, bool requireDocumentPresent)
1118protected internal void OnAdditionalDocumentTextChanged(DocumentId documentId, SourceText newText, PreservationMode mode)
1133protected internal void OnAnalyzerConfigDocumentTextChanged(DocumentId documentId, SourceText newText, PreservationMode mode)
1900var text = document.GetTextSynchronously(CancellationToken.None);
1909var text = document.GetTextSynchronously(CancellationToken.None);
1918var text = document.GetTextSynchronously(CancellationToken.None);
1935var currentText = newDoc.GetTextSynchronously(CancellationToken.None); // needs wait
1945var currentText = newDoc.GetTextSynchronously(CancellationToken.None); // needs wait
1962if (!oldDoc.TryGetText(out var oldText))
1967var currentText = newDoc.GetTextSynchronously(CancellationToken.None); // needs wait
1970else if (!newDoc.TryGetText(out var newText))
2175protected virtual void ApplyDocumentAdded(DocumentInfo info, SourceText text)
2197protected virtual void ApplyDocumentTextChanged(DocumentId id, SourceText text)
2219protected virtual void ApplyAdditionalDocumentAdded(DocumentInfo info, SourceText text)
2241protected virtual void ApplyAdditionalDocumentTextChanged(DocumentId id, SourceText text)
2252protected virtual void ApplyAnalyzerConfigDocumentAdded(DocumentInfo info, SourceText text)
2274protected 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 (23)
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 (296)
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)
60.AddDocument(DocumentId.CreateNewId(projectId), "goo.cs", SourceText.From("public class Goo { }", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: Path.Combine(s_projectDir, "goo.cs"))
61.AddAdditionalDocument(DocumentId.CreateNewId(projectId), "add.txt", SourceText.From("text", Encoding.UTF8, SourceHashAlgorithms.Default))
62.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId), "editorcfg", SourceText.From(editorConfig ?? "#empty", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: Path.Combine(s_projectDir, "editorcfg"))));
82.AddDocument(DocumentId.CreateNewId(projectId1), "goo.cs", SourceText.From(docContents, Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "goo.cs")
83.AddAdditionalDocument(DocumentId.CreateNewId(projectId1), "add.txt", SourceText.From("text", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "add.txt")
84.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId1), "editorcfg", SourceText.From("config", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "/a/b")
86.AddDocument(DocumentId.CreateNewId(projectId2), "goo.cs", SourceText.From(docContents, Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "goo.cs")
87.AddAdditionalDocument(DocumentId.CreateNewId(projectId2), "add.txt", SourceText.From("text", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "add.txt")
88.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId2), "editorcfg", SourceText.From("config", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "/a/b")));
334.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId), "editorcfg", SourceText.From("config"));
350var text = SourceText.From("new text", encoding: null, SourceHashAlgorithm.Sha1);
361Assert.Throws<ArgumentNullException>(() => solution.WithDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity));
374var textAndVersion = TextAndVersion.Create(SourceText.From("new text"), VersionStamp.Default);
377Assert.True(newSolution1.GetDocument(documentId)!.TryGetText(out var actualText));
385Assert.Throws<ArgumentNullException>(() => solution.WithDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity));
398var text = SourceText.From("new text");
451var text = SourceText.From("new text", encoding: null, SourceHashAlgorithm.Sha1);
496private static Solution UpdateSolution(PreservationMode mode, TextUpdateType updateType, Solution solution, DocumentId documentId1, SourceText text, TextAndVersion textAndVersion)
539var text = SourceText.From("new text", encoding: null, SourceHashAlgorithm.Sha1);
622var text = SourceText.From("new text without pp directives", encoding: null, SourceHashAlgorithm.Sha1);
705var text = SourceText.From("#if true", encoding: null, SourceHashAlgorithm.Sha1);
781var text = SourceText.From("new text", encoding: null, SourceHashAlgorithm.Sha1);
843.AddDocument(DocumentId.CreateNewId(projectId1), "goo.cs", SourceText.From(docContents, Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "goo.cs")
845.AddDocument(DocumentId.CreateNewId(projectId2), "goo.cs", SourceText.From(docContents, Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "goo.cs")));
868var text = SourceText.From(" ", encoding: null, SourceHashAlgorithm.Sha1);
920var text = SourceText.From("new text");
923Assert.True(newSolution1.GetAdditionalDocument(documentId)!.TryGetText(out var actualText));
929Assert.Throws<ArgumentNullException>(() => solution.WithAdditionalDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity));
942var textAndVersion = TextAndVersion.Create(SourceText.From("new text"), VersionStamp.Default);
945Assert.True(newSolution1.GetAdditionalDocument(documentId)!.TryGetText(out var actualText));
953Assert.Throws<ArgumentNullException>(() => solution.WithAdditionalDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity));
966var text = SourceText.From("new text");
969Assert.True(newSolution1.GetAnalyzerConfigDocument(documentId)!.TryGetText(out var actualText));
975Assert.Throws<ArgumentNullException>(() => solution.WithAnalyzerConfigDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity));
988var textAndVersion = TextAndVersion.Create(SourceText.From("new text"), VersionStamp.Default);
991Assert.True(newSolution1.GetAnalyzerConfigDocument(documentId)!.TryGetText(out var actualText));
999Assert.Throws<ArgumentNullException>(() => solution.WithAnalyzerConfigDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity));
1093.AddDocument(d1, "d1.cs", SourceText.From("class D1;", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: Path.Combine(s_projectDir, "d1.cs"))
1094.AddDocument(d2, "d2.cs", SourceText.From("class D2;", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: Path.Combine(s_projectDir, "d2.cs"))
1095.AddAdditionalDocument(a1, "a1.txt", SourceText.From("text1", Encoding.UTF8, SourceHashAlgorithms.Default))
1096.AddAdditionalDocument(a2, "a2.txt", SourceText.From("text2", Encoding.UTF8, SourceHashAlgorithms.Default))
1097.AddAnalyzerConfigDocument(c1, "c1", SourceText.From("#empty1", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: Path.Combine(s_projectDir, "editorcfg"))
1098.AddAnalyzerConfigDocument(c2, "c2", SourceText.From("#empty2", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: Path.Combine(s_projectDir, "editorcfg"));
1108loader: TextLoader.From(TextAndVersion.Create(SourceText.From("class NewD1;", Encoding.UTF32, SourceHashAlgorithm.Sha256), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD1.cs"))),
1117loader: TextLoader.From(TextAndVersion.Create(SourceText.From("class NewD3;", Encoding.UTF8, SourceHashAlgorithms.Default), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD3.cs"))),
1127loader: TextLoader.From(TextAndVersion.Create(SourceText.From("new text1", Encoding.UTF32, SourceHashAlgorithm.Sha256), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD1.cs"))),
1136loader: TextLoader.From(TextAndVersion.Create(SourceText.From("new text3", Encoding.UTF8, SourceHashAlgorithms.Default), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD3.cs"))),
1146loader: TextLoader.From(TextAndVersion.Create(SourceText.From("#new empty1", Encoding.UTF32, SourceHashAlgorithm.Sha256), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD1.cs"))),
1155loader: TextLoader.From(TextAndVersion.Create(SourceText.From("#new empty3", Encoding.UTF8, SourceHashAlgorithms.Default), VersionStamp.Create(), filePath: Path.Combine(s_projectDir, "newD3.cs"))),
1619var textC = SourceText.From("class C {}", encoding: null, checksumAlgorithm: SourceHashAlgorithm.Sha1);
2311var solution4 = solution3.AddAnalyzerConfigDocument(editorConfigId, ".editorconfig", SourceText.From(editorConfigContent), filePath: Path.Combine(s_projectDir, "subfolder", ".editorconfig"));
2422var sourceText = SourceText.From("text", checksumAlgorithm: SourceHashAlgorithms.Default);
2436Assert.Throws<ArgumentNullException>("text", () => solution.AddDocument(documentId, "name", text: (SourceText)null!));
2483var root = CSharp.SyntaxFactory.ParseSyntaxTree(SourceText.From("class C {}", encoding: null, SourceHashAlgorithm.Sha1)).GetRoot();
3161.AddDocument(documentId, "DocumentName", SourceText.From("class Class{}"));
3201var text2 = tree2.GetText();
3314var observedText2 = sol.GetDocument(did).GetTextAsync().Result;
3332var docText = doc.GetTextAsync().Result;
3354var docText = doc.GetTextAsync().Result;
3379var docText = doc.GetTextAsync().Result;
3525private static ObjectReference<SourceText> GetObservedText(Solution solution, DocumentId documentId, string expectedText = null)
3527var observedText = solution.GetDocument(documentId).GetTextAsync().Result;
3534return new ObjectReference<SourceText>(observedText);
3556private static ObjectReference<SourceText> GetObservedTextAsync(Solution solution, DocumentId documentId, string expectedText = null)
3558var observedText = solution.GetDocument(documentId).GetTextAsync().Result;
3565return new ObjectReference<SourceText>(observedText);
3773.AddDocument(did, "test", SourceText.From(language == LanguageNames.CSharp ? "class C {}" : "Class C : End Class", Encoding.UTF8, SourceHashAlgorithm.Sha256), filePath: "old path");
3916var text = await doc.GetTextAsync().ConfigureAwait(false);
3978var solution2 = solution.WithDocumentText(did3, SourceText.From(text4));
3991var doc = ws.AddDocument(proj.Id, "a.cs", SourceText.From("public class c { }", Encoding.UTF32));
4052workspace.AddDocument(project1.Id, "Broken.cs", SourceText.From("class "));
4074project = project.AddDocument("Extra.cs", SourceText.From("class Extra { }")).Project;
4076var documentToFreeze = project.AddDocument("DocumentToFreeze.cs", SourceText.From(""));
4099project = project.AddDocument("Extra.cs", SourceText.From("class Extra { }")).Project;
4101var documentToFreeze = project.AddDocument("DocumentToFreeze.cs", SourceText.From(""));
4127project = project.AddDocument("Extra.cs", SourceText.From("class Extra { }")).Project;
4129var documentToFreezeOriginal = project.AddDocument("DocumentToFreeze.cs", SourceText.From("class DocumentToFreeze { void M() { } }"));
4133var solution = project.Solution.WithDocumentText(documentToFreezeOriginal.Id, SourceText.From("class DocumentToFreeze { void M() { /*no top level change*/ } }"));
4172project = project.AddDocument("Extra.cs", SourceText.From("class Extra { }")).Project;
4174var documentToFreezeOriginal = project.AddDocument("DocumentToFreeze.cs", SourceText.From("class DocumentToFreeze { void M() { } }"));
4178var solution = project.Solution.WithDocumentText(documentToFreezeOriginal.Id, SourceText.From("class DocumentToFreeze { void M() { } public void NewMethod() { } }"));
4236var document = workspace.AddDocument(project2.Id, "Test.cs", SourceText.From(""));
4340document = document.WithText(SourceText.From("// Source File with Changes"));
4366.WithDocumentText(documentId1, SourceText.From("// Document 1 Changed"))
4367.WithDocumentText(documentId2, SourceText.From("// Document 2 Changed"))
4368.WithDocumentText(documentId3, SourceText.From("// Document 3 Changed"));
4553var text = SourceText.From("// empty", encoding: null, SourceHashAlgorithms.Default);
4556var sourceText = strongTree.GetText();
4688loader: TextLoader.From(TextAndVersion.Create(SourceText.From("[*.*]\r\n\r\ndotnet_diagnostic.CA1234.severity = error"), VersionStamp.Default)))));
4721loader: TextLoader.From(TextAndVersion.Create(SourceText.From("[*.*]\r\n\r\ndotnet_diagnostic.CA1234.severity = error"), VersionStamp.Default)))));
4762loader: TextLoader.From(TextAndVersion.Create(SourceText.From("[*.*]\r\n\r\ndotnet_diagnostic.CA1234.severity = error"), VersionStamp.Default)))));
4774TextLoader.From(TextAndVersion.Create(SourceText.From("[*.*]\r\n\r\ndotnet_diagnostic.CA6789.severity = error"), VersionStamp.Default)),
4810loader: TextLoader.From(TextAndVersion.Create(SourceText.From("is_global = true\r\n\r\ndotnet_diagnostic.CA1234.severity = error"), VersionStamp.Default)))));
4856loader: TextLoader.From(TextAndVersion.Create(SourceText.From("[*.*]\r\n\r\ngenerated_code = true"), VersionStamp.Default)))));
5421var text = SourceText.From("public class C { }");
5442var newDocText = await newDoc.GetTextAsync();
5443var sameText = await newDoc.GetTextAsync();
5447var treeText = newDocTree.GetText();
5469var sourceTextToRelease = ObjectReference.CreateFromFactory(static () => SourceText.From(Guid.NewGuid().ToString()));
5517.AddDocument(documentId, "test.cs", SourceText.From("public class C { }"), filePath: sourcePath)
5518.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId), ".editorconfig", SourceText.From($"[{pattern}]\nindent_style = tab"), filePath: configPath);
5578project = project.AddDocument("Extra.cs", SourceText.From("class Extra { }")).Project;
5595project = project.AddDocument("Extra.cs", SourceText.From("class Extra { }")).Project;
5616project1 = project2.Solution.GetProject(project1.Id).AddDocument("Doc1", SourceText.From("class Doc1 { }")).Project;
5617project2 = project1.Solution.GetProject(project2.Id).AddDocument("Doc2", SourceText.From("class Doc2 { }")).Project;
5644project1 = project2.Solution.GetProject(project1.Id).AddDocument("Doc1", SourceText.From("class Doc1 { }")).Project;
5645project2 = project1.Solution.GetProject(project2.Id).AddDocument("Doc2", SourceText.From("class Doc2 { }")).Project;
5674project1 = project2.Solution.GetProject(project1.Id).AddDocument("Doc1", SourceText.From("class Doc1 { }")).Project;
5675project2 = project1.Solution.GetProject(project2.Id).AddDocument("Doc2", SourceText.From("class Doc2 { }")).Project;
5706project1 = project1.AddDocument("Doc1", SourceText.From("class Doc1 { }")).Project;
5715var forkedProject1 = frozenSolution.WithDocumentText(project1.Documents.Single().Id, SourceText.From("class Doc2 { }")).GetProject(project1.Id);
5734project1 = project1.AddDocument("Doc1", SourceText.From("class Doc1 { }")).Project;
5754var forkedProject1 = frozenSolution.WithDocumentText(project1.Documents.Single().Id, SourceText.From("class Doc2 { }")).GetProject(project1.Id);
5783project = project.AddDocument("Extra.ts", SourceText.From("class Extra { }")).Project;
5806.AddDocument($"Document", SourceText.From("class C { }"), filePath: @"c:\test\Document.cs").Project;
5816.AddDocument($"Document", SourceText.From("class C { }"), filePath: @"c:\test\Document.cs").Project;
5827old => old.WithDocumentText(documentId1, SourceText.From(lastContents)),
SolutionTests\SolutionWithSourceGeneratorTests.cs (23)
206project = project.AdditionalDocuments.First().WithAdditionalDocumentText(SourceText.From("Changed text!")).Project;
230project = project.AddDocument("Source.cs", SourceText.From("")).Project;
263project = project.Solution.WithDocumentText(documentId, SourceText.From("// Changed Source File")).Projects.Single();
306project = project.Solution.WithAdditionalDocumentText(additionalDocumentId, SourceText.From("Hello, everyone!")).Projects.Single();
311project = project.Solution.WithAdditionalDocumentText(additionalDocumentId, SourceText.From("Good evening, everyone!")).Projects.Single();
375SourceText.From("Hello, world!!!!")).Projects.Single();
489project = project.Documents.Single().WithText(SourceText.From("// Change")).Project;
565var existingText = await project.Documents.Single().GetTextAsync();
566var newText = existingText.WithChanges(new TextChange(new TextSpan(existingText.Length, length: 0), " With Change"));
595var differentOpenTextContainer = SourceText.From("// Open Text").Container;
619var differentOpenTextContainer = SourceText.From("// StaticContent", Encoding.UTF8).Container;
634.AddAdditionalDocument("Test.txt", SourceText.From(""));
639var differentOpenTextContainer = SourceText.From("// Open Text").Container;
670var differentOpenTextContainer = SourceText.From("// Open Text").Container;
697var differentOpenTextContainer = SourceText.From("// Open Text").Container;
734documentToFreeze = documentToFreeze.WithText(SourceText.From("// Changed Source File"));
764document = document.WithText(SourceText.From("// Something else"));
793document = document.WithText(SourceText.From("// Something else"));
827document = document.WithText(SourceText.From("// Something else"));
888identity, DateTime.Now, SourceText.From("// Frozen Document"));
915[(sourceGeneratedDocument1.Identity, DateTime.Now, SourceText.From("// Frozen 1")), (sourceGeneratedDocument2.Identity, DateTime.Now, SourceText.From("// Frozen 2"))]);
935sourceGeneratedDocumentIdentity, sourceGeneratedDocument.GenerationDateTime, SourceText.From("// Hello, World"));
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.Metrics (2)
Microsoft.Gen.Metrics.Unit.Tests (5)
Microsoft.Gen.MetricsReports.Unit.Tests (5)
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)
758protected override void ApplyDocumentAdded(DocumentInfo info, SourceText text)
761protected override void ApplyAdditionalDocumentAdded(DocumentInfo info, SourceText text)
764protected override void ApplyAnalyzerConfigDocumentAdded(DocumentInfo info, SourceText text)
770private void AddDocumentCore(DocumentInfo info, SourceText initialText, TextDocumentKind documentKind)
876SourceText? initialText = null,
895SourceText? initialText = null,
912SourceText text)
977SourceText? 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,
250Func<SourceText, VsTextSpan> getVsTextSpan)
351private static VsTextSpan GetVsTextSpan(SourceText text, TextSpan textSpan, bool allowInvalidSpan)
Microsoft.VisualStudio.LanguageServices.CSharp (41)
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.VisualStudio.DiagnosticsWindow (2)
Roslyn.VisualStudio.Next.UnitTests (83)
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 (53)
87var oldText = await oldDocument.GetTextAsync();
90var newText = oldText.WithChanges(new TextChange(TextSpan.FromBounds(0, 0), "/* test */"));
399params ImmutableArray<(string hintName, SourceText text)>[] values)
407ImmutableArray<ImmutableArray<(string hintName, SourceText text)>> values)
410ImmutableArray<(string hintName, SourceText text)> sourceTexts = default;
436var tempDoc = project.AddDocument("X.cs", SourceText.From("// "));
451Assert.True(localWorkspace.SetCurrentSolution(s => s.WithDocumentText(tempDocId, SourceText.From("// " + i)), WorkspaceChangeKind.SolutionChanged));
487var localText = await localDoc.GetTextAsync();
488var remoteText = await localDoc.GetTextAsync();
496private static SourceText CreateText(string content, Encoding encoding = null, SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1)
497=> SourceText.From(content, encoding ?? Encoding.UTF8, checksumAlgorithm);
499private static SourceText CreateStreamText(string content, bool useBOM, bool useMemoryStream)
506return SourceText.From(stream, encoding, SourceHashAlgorithm.Sha1, throwIfBinaryDetected: true);
510return SourceText.From(bytes, bytes.Length, encoding, SourceHashAlgorithm.Sha1, throwIfBinaryDetected: true);
524var sourceText = CreateText(Guid.NewGuid().ToString());
558var sourceText = CreateText(Guid.NewGuid().ToString());
602ImmutableArray<(string, SourceText)>.Empty);
609ImmutableArray<(string, SourceText)>.Empty,
656ImmutableArray<(string, SourceText)>.Empty);
662var contents = CreateText(Guid.NewGuid().ToString());
670var contents = CreateText(Guid.NewGuid().ToString());
720return ImmutableArray.Create(("hint", SourceText.From($"// generated document {callCount}", Encoding.UTF8)));
742solution = solution.WithTextDocumentText(tempDocId, SourceText.From("// new contents"));
775var tempDoc = project.AddDocument("X.cs", SourceText.From("// "));
804return ImmutableArray.Create(("hint", SourceText.From($"// generated document {callCount}", Encoding.UTF8)));
859return ImmutableArray.Create(("hint", SourceText.From($"// generated document {callCount}", Encoding.UTF8)));
913var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
922var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
964var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
973var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
1005var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
1014var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
1048var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
1057var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
1100var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
1110var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
1153var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
1163var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
1206var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
1216var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
1251var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
1261var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
1296var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
1305var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
1339var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
1348var tempDoc = project2.AddDocument("X.cs", SourceText.From("// "));
1431Contract.ThrowIfFalse(workspace.TryApplyChanges(workspace.CurrentSolution.WithDocumentText(normalDocId, SourceText.From("// new text"))));
1545var tempDoc = project1.AddDocument("X.cs", SourceText.From("// "));
1624private static SourceText GetNewText(Document document, string csAddition, string vbAddition)
1628return SourceText.From(document.State.GetTextSynchronously(CancellationToken.None).ToString() + csAddition);
1631return SourceText.From(document.State.GetTextSynchronously(CancellationToken.None).ToString() + vbAddition);
1737solution = current.AddDocument($"Document{i}", SourceText.From(documents[i])).Project.Solution;
1743solution = current.AddAdditionalDocument($"AdditionalDocument{i}", SourceText.From(additionalDocuments[i])).Project.Solution;
Services\SolutionServiceTests.cs (18)
160await VerifySolutionUpdate(code, s => s.WithDocumentText(s.Projects.First().DocumentIds.First(), SourceText.From(code + " ")));
315project = project.AddDocument("newDocument", SourceText.From("// new text")).Project;
335loader: TextLoader.From(TextAndVersion.Create(SourceText.From("test"), VersionStamp.Create())));
346return s.WithAdditionalDocumentText(additionalDocumentId, SourceText.From("changed"));
367loader: TextLoader.From(TextAndVersion.Create(SourceText.From("root = true"), VersionStamp.Create(), filePath: configPath)),
379return s.WithAnalyzerConfigDocumentText(analyzerConfigDocumentId, SourceText.From("root = false"));
399loader: TextLoader.From(TextAndVersion.Create(SourceText.From("class A { }"), VersionStamp.Create())));
410return s.WithDocumentText(documentId, SourceText.From("class Changed { }"));
437var currentSolution = remoteSolution1.WithDocumentText(remoteSolution1.Projects.First().Documents.First().Id, SourceText.From(code + " class Test2 { }"));
446currentSolution = oopSolution2.WithDocumentText(oopSolution2.Projects.First().Documents.First().Id, SourceText.From(code + " class Test3 { }"));
522var frozenText1 = SourceText.From("// Hello, World!");
531var frozenText2 = SourceText.From("// Hello, World! A second time!");
835solution = solution.GetProject(project1.Id).AddDocument("X.cs", SourceText.From("// X")).Project.Solution;
836solution = solution.GetProject(project2.Id).AddDocument("Y.vb", SourceText.From("' Y")).Project.Solution;
890solution = solution.GetProject(project1.Id).AddDocument("X.cs", SourceText.From("// X")).Project.Solution;
891solution = 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 (11)
System.Windows.Forms.Analyzers.Tests (12)