8 types derived from SourceText
Microsoft.CodeAnalysis (6)
Microsoft.CodeAnalysis.EditorFeatures.Text (1)
Microsoft.CodeAnalysis.Test.Utilities (1)
3674 references to SourceText
BuildValidator (4)
IdeCoreBenchmarks (11)
Microsoft.CodeAnalysis (232)
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);
266public void AddSource(string hintName, string source) => AddSource(hintName, SourceText.From(source, Encoding.UTF8));
269/// Adds a <see cref="SourceText"/> to the compilation that will be available during subsequent phases
272/// <param name="sourceText">The <see cref="SourceText"/> to add to the compilation</param>
276public void AddSource(string hintName, SourceText sourceText) => _additionalSources.Add(hintName, sourceText);
SourceGeneration\IncrementalContexts.cs (8)
109public void AddSource(string hintName, string source) => AddSource(hintName, SourceText.From(source, Encoding.UTF8));
112/// Adds a <see cref="SourceText"/> to the compilation that will be available during subsequent phases
115/// <param name="sourceText">The <see cref="SourceText"/> to add to the compilation</param>
119public void AddSource(string hintName, SourceText sourceText) => AdditionalSources.Add(hintName, sourceText);
144public void AddSource(string hintName, string source) => AddSource(hintName, SourceText.From(source, Encoding.UTF8));
147/// Adds a <see cref="SourceText"/> to the compilation
150/// <param name="sourceText">The <see cref="SourceText"/> to add to the compilation</param>
154public void AddSource(string hintName, SourceText sourceText) => Sources.Add(hintName, sourceText);
Text\ChangedText.cs (21)
17private readonly SourceText _newText;
20public ChangedText(SourceText oldText, SourceText newText, ImmutableArray<TextChangeRange> changeRanges)
31_info = new ChangeInfo(changeRanges, new WeakReference<SourceText>(oldText), (oldText as ChangedText)?._info);
35SourceText oldText, SourceText newText, ImmutableArray<TextChangeRange> changeRanges)
66public WeakReference<SourceText> WeakOldText { get; }
70public ChangeInfo(ImmutableArray<TextChangeRange> changeRanges, WeakReference<SourceText> weakOldText, ChangeInfo? previous)
85SourceText? tmp;
123internal override ImmutableArray<SourceText> Segments
128internal override SourceText StorageKey
143public override SourceText GetSubText(TextSpan span)
153public override SourceText WithChanges(IEnumerable<TextChange> changes)
170public override IReadOnlyList<TextChangeRange> GetChangeRanges(SourceText oldText)
183SourceText? actualOldText;
210private bool IsChangedFrom(SourceText oldText)
214SourceText? text;
224private static IReadOnlyList<ImmutableArray<TextChangeRange>> GetChangesBetween(SourceText oldText, ChangedText newText)
233SourceText? actualOldText;
271SourceText? oldText;
325var text = GetSubText(new TextSpan(changeStart, change.NewLength));
Text\CompositeText.cs (27)
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)
62internal override ImmutableArray<SourceText> Segments
78public override SourceText GetSubText(TextSpan span)
89var newSegments = ArrayBuilder<SourceText>.GetInstance();
94var segment = _segments[segIndex];
152var segment = _segments[segIndex];
164internal static void AddSegments(ArrayBuilder<SourceText> segments, SourceText text)
177internal static SourceText ToSourceText(ArrayBuilder<SourceText> segments, SourceText original, bool adjustSegments)
187return SourceText.From(string.Empty, original.Encoding, original.ChecksumAlgorithm);
207private static void ReduceSegmentCountIfNecessary(ArrayBuilder<SourceText> segments)
228private static int GetMinimalSegmentSizeToUseForCombining(ArrayBuilder<SourceText> segments)
248private static int GetSegmentCountIfCombined(ArrayBuilder<SourceText> segments, int segmentSize)
281private static void CombineSegments(ArrayBuilder<SourceText> segments, int segmentSize)
315var newText = writer.ToSourceText();
323private static readonly ObjectPool<HashSet<SourceText>> s_uniqueSourcesPool
324= new ObjectPool<HashSet<SourceText>>(() => new HashSet<SourceText>(), 5);
329private static void ComputeLengthAndStorageSize(IReadOnlyList<SourceText> segments, out int length, out int size)
336var segment = segments[i];
342foreach (var segment in uniqueSources)
354private static void TrimInaccessibleText(ArrayBuilder<SourceText> segments)
366foreach (var segment in segments)
Text\LargeText.cs (7)
17/// A <see cref="SourceText"/> optimized for very large sources. The text is stored as
25internal const int ChunkSize = SourceText.LargeObjectHeapLimitInChars; // 40K Unicode chars is 80KB which is less than the large object heap limit.
54internal static SourceText Decode(Stream stream, Encoding encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected, bool canBeEmbedded)
61return SourceText.From(string.Empty, encoding, checksumAlgorithm);
80internal static SourceText Decode(TextReader reader, int length, Encoding? encodingOpt, SourceHashAlgorithm checksumAlgorithm)
84return SourceText.From(string.Empty, encodingOpt, checksumAlgorithm);
226/// Called from <see cref="SourceText.Lines"/> to initialize the <see cref="TextLineCollection"/>. Thereafter,
Text\SourceText.cs (47)
80/// Constructs a <see cref="SourceText"/> from text in a string.
86/// If the encoding is not specified the resulting <see cref="SourceText"/> isn't debuggable.
87/// If an encoding-less <see cref="SourceText"/> is written to a file a <see cref="Encoding.UTF8"/> shall be used as a default.
94public static SourceText From(string text, Encoding? encoding = null, SourceHashAlgorithm checksumAlgorithm = SourceHashAlgorithm.Sha1)
105/// Constructs a <see cref="SourceText"/> from text in a string.
112/// If the encoding is not specified the resulting <see cref="SourceText"/> isn't debuggable.
113/// If an encoding-less <see cref="SourceText"/> is written to a file a <see cref="Encoding.UTF8"/> shall be used as a default.
120public static SourceText From(
143public static SourceText From(Stream stream, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected)
147/// Constructs a <see cref="SourceText"/> from stream content.
169public static SourceText From(
214public static SourceText From(byte[] buffer, int length, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm, bool throwIfBinaryDetected)
218/// Constructs a <see cref="SourceText"/> from a byte array.
238public static SourceText From(
381/// If an encoding-less <see cref="SourceText"/> is written to a file a <see cref="Encoding.UTF8"/> shall be used as a default.
399internal virtual ImmutableArray<SourceText> Segments
401get { return ImmutableArray<SourceText>.Empty; }
404internal virtual SourceText StorageKey
460/// The container of this <see cref="SourceText"/>.
486/// Gets a <see cref="SourceText"/> that contains the characters in the specified span of this text.
488public virtual SourceText GetSubText(TextSpan span)
495return SourceText.From(string.Empty, this.Encoding, this.ChecksumAlgorithm);
508/// Returns a <see cref="SourceText"/> that has the contents of this text including and after the start position.
510public SourceText GetSubText(int start)
528/// Write this <see cref="SourceText"/> to a text writer.
638public virtual SourceText WithChanges(IEnumerable<TextChange> changes)
650var segments = ArrayBuilder<SourceText>.GetInstance();
688var subText = this.GetSubText(new TextSpan(position, change.Span.Start - position));
694var segment = SourceText.From(change.NewText!, this.Encoding, this.ChecksumAlgorithm);
711var subText = this.GetSubText(new TextSpan(position, this.Length - position));
715var newText = CompositeText.ToSourceText(segments, this, adjustSegments: true);
739/// <exception cref="ArgumentException">If any changes are not in bounds of this <see cref="SourceText"/>.</exception>
741public SourceText WithChanges(params TextChange[] changes)
749public SourceText Replace(TextSpan span, string newText)
757public SourceText Replace(int start, int length, string newText)
767public virtual IReadOnlyList<TextChangeRange> GetChangeRanges(SourceText oldText)
789public virtual IReadOnlyList<TextChange> GetTextChanges(SourceText oldText)
854private readonly SourceText _text;
858public LineInfo(SourceText text, int[] lineStarts)
1025/// Compares the content with content of another <see cref="SourceText"/>.
1027public bool ContentEquals(SourceText other)
1046/// Implements equality comparison of the content of two different instances of <see cref="SourceText"/>.
1048protected virtual bool ContentEqualsImpl(SourceText other)
1147private readonly SourceText _text;
1149public StaticContainer(SourceText text)
1154public override SourceText CurrentText => _text;
Microsoft.CodeAnalysis.CodeStyle (52)
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)
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 (35)
AbstractConflictMarkerCodeFixProvider.cs (15)
73var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
83SyntaxNode root, SourceText text, int position,
144SourceText text, int position,
208var text = startLine.Text!;
226var text = startLine.Text!;
244var text = currentLine.Text!;
302Action<SourceText, ArrayBuilder<TextChange>, int, int, int, int> addEdits,
305var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
310var finalText = text.WithChanges(edits);
315SourceText text, ArrayBuilder<TextChange> edits,
328SourceText text, ArrayBuilder<TextChange> edits,
341SourceText text, ArrayBuilder<TextChange> edits,
375private static int GetEndIncludingLineBreak(SourceText text, int position)
391var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
430var finalText = text.WithChanges(edits);
Microsoft.CodeAnalysis.CodeStyle.LegacyTestFramework.UnitTestUtilities (5)
Microsoft.CodeAnalysis.CodeStyle.UnitTestUtilities (5)
Microsoft.CodeAnalysis.CSharp (48)
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)
920SourceText text,
937=> ParseText(SourceText.From(text, encoding, SourceHashAlgorithm.Sha1), options, path, diagnosticOptions, isGeneratedCode: null, cancellationToken);
Syntax\SyntaxFactory.cs (9)
1561return CSharpSyntaxTree.ParseText(SourceText.From(text, encoding, SourceHashAlgorithm.Sha1), (CSharpParseOptions?)options, path, diagnosticOptions: null, isGeneratedCode: null, cancellationToken);
1565/// <inheritdoc cref="CSharpSyntaxTree.ParseText(SourceText, CSharpParseOptions?, string, CancellationToken)"/>
1567SourceText text,
1899private static SourceText MakeSourceText(string text, int offset)
1901return SourceText.From(text, Encoding.UTF8).GetSubText(offset);
2778return ParseSyntaxTree(SourceText.From(text, encoding), options, path, diagnosticOptions, isGeneratedCode: null, cancellationToken);
2785SourceText text,
2806return ParseSyntaxTree(SourceText.From(text, encoding), options, path, diagnosticOptions, isGeneratedCode, cancellationToken);
2813SourceText text,
Microsoft.CodeAnalysis.CSharp.CodeStyle (15)
Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes (27)
Microsoft.CodeAnalysis.CSharp.CommandLine.UnitTests (2)
Microsoft.CodeAnalysis.CSharp.EditorFeatures (44)
StringCopyPaste\StringCopyPasteHelpers.cs (11)
32public static char SafeCharAt(SourceText text, int index)
107public static int GetFirstNonWhitespaceIndex(SourceText text, TextLine line)
172public static int SkipU8Suffix(SourceText text, int end)
186public static int GetLongestQuoteSequence(SourceText text, TextSpan span)
189public static int GetLongestOpenBraceSequence(SourceText text, TextSpan span)
192public static int GetLongestCloseBraceSequence(SourceText text, TextSpan span)
200private static int GetLongestCharacterSequence(SourceText text, TextSpan span, char character)
506var text = SourceText.From(change.NewText);
524private static string? GetCommonIndentationPrefix(string? commonIndentPrefix, SourceText text, TextSpan lineWhitespaceSpan)
545public static bool RawContentMustBeMultiLine(SourceText text, ImmutableArray<TextSpan> spans)
Microsoft.CodeAnalysis.CSharp.EditorFeatures.UnitTests (125)
EditAndContinue\CSharpEditAndContinueAnalyzerTests.cs (13)
47AddDocument("test.cs", SourceText.From(source, Encoding.UTF8), filePath: Path.Combine(TempRoot.Root, "test.cs")).Project.Solution;
305var oldText = await oldDocument.GetTextAsync();
308var newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2));
310var newText = await newDocument.GetTextAsync();
373var newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2));
435var newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2));
517var newSolution = workspace.CurrentSolution.WithDocumentText(documentId, SourceText.From(source2));
586var newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2));
625var newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2));
666var newSolution = oldSolution.AddDocument(newDocId, "goo.cs", SourceText.From(source2), filePath: Path.Combine(TempRoot.Root, "goo.cs"));
712var newSolution = oldSolution.AddDocument(newDocId, "goo.cs", SourceText.From(source2), filePath: Path.Combine(TempRoot.Root, "goo.cs"));
745var newSolution = oldSolution.AddDocument(documentId, "goo.cs", SourceText.From(source2), filePath: filePath);
800var newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2));
PdbSourceDocument\AbstractPdbSourceDocumentTests.cs (8)
123protected static async Task<(SourceText?, TextSpan)> GetGeneratedSourceTextAsync(
168var actual = await document.GetTextAsync();
191var sourceText = SourceText.From(source, encoding: encoding ?? Encoding.UTF8);
199SourceText source,
241protected static void CompileTestSource(string path, SourceText source, Project project, Location pdbLocation, Location sourceLocation, bool buildReferenceAssembly, bool windowsPdb, Encoding? fallbackEncoding = null)
251protected 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)
256protected 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)
PdbSourceDocument\ImplementationAssemblyLookupServiceTests.cs (28)
43var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
80var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
121var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
158var sourceText = SourceText.From(metadataSource, Encoding.UTF8);
182sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
218var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
241sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
278var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
301sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
332var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
355sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
382var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
405sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
446var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
469sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
503var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
526var typeForwardSourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
PdbSourceDocument\PdbSourceDocumentTests.cs (19)
407var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
436var sourceText = SourceText.From(metadataSource, encoding: Encoding.UTF8);
472var sourceText = SourceText.From(metadataSource, Encoding.UTF8);
519var sourceText = SourceText.From(metadataSource, Encoding.UTF8);
545sourceText = SourceText.From(typeForwardSource, Encoding.UTF8);
714CompileTestSource(path, SourceText.From(source2, Encoding.UTF8), project, Location.OnDisk, Location.OnDisk, buildReferenceAssembly: false, windowsPdb: false);
780var encodedSourceText = EncodedStringText.Create(ms, encoding, canBeEmbedded: true);
809var encodedSourceText = EncodedStringText.Create(ms, encoding, canBeEmbedded: true);
838var encodedSourceText = EncodedStringText.Create(ms, encoding, canBeEmbedded: true);
862var sourceText = SourceText.From(source, Encoding.UTF8);
914var sourceText1 = SourceText.From(source1, Encoding.UTF8);
915var sourceText2 = SourceText.From(source2, Encoding.UTF8);
Microsoft.CodeAnalysis.CSharp.EditorFeatures2.UnitTests (5)
Microsoft.CodeAnalysis.CSharp.Emit.UnitTests (9)
PDB\PDBTests.cs (4)
40var tree3 = SyntaxFactory.ParseSyntaxTree(SourceText.From("class C { }", encoding: null), path: "Bar.cs");
61var tree4 = SyntaxFactory.ParseSyntaxTree(SourceText.From("class D { public void F() { } }", new UTF8Encoding(false, false)), path: "Baz.cs");
97context.AddSource("hint2", SourceText.From("class G2 { void F() {} }", Encoding.UTF8, checksumAlgorithm: SourceHashAlgorithm.Sha256));
99Assert.Throws<ArgumentException>(() => context.AddSource("hint3", SourceText.From("class G3 { void F() {} }", encoding: null, checksumAlgorithm: SourceHashAlgorithm.Sha256)));
Microsoft.CodeAnalysis.CSharp.ExpressionEvaluator.ExpressionCompiler (11)
SyntaxHelpers.cs (11)
61var text = SourceText.From(expr, encoding: null, SourceHashAlgorithms.Default);
75var targetSyntax = ParseDebuggerExpressionInternal(SourceText.From(target, encoding: null, SourceHashAlgorithms.Default), consumeFullText: true);
83return assignment.MakeDebuggerExpression(SourceText.From(assignment.ToString(), encoding: null, SourceHashAlgorithms.Default));
199var source = SourceText.From(text, encoding: null, SourceHashAlgorithms.Default);
204private static InternalSyntax.ExpressionSyntax ParseDebuggerExpressionInternal(SourceText source, bool consumeFullText)
217var source = SourceText.From(text, encoding: null, SourceHashAlgorithms.Default);
226private static SyntaxTree CreateSyntaxTree(this InternalSyntax.CSharpSyntaxNode root, SourceText text)
231private static ExpressionSyntax MakeDebuggerExpression(this InternalSyntax.ExpressionSyntax expression, SourceText text)
Microsoft.CodeAnalysis.CSharp.Features (114)
Completion\CompletionProviders\CompletionUtilities.cs (8)
20internal static TextSpan GetCompletionItemSpan(SourceText text, int position)
60internal static bool IsTriggerCharacter(SourceText text, int characterPosition, in CompletionOptions options)
99internal static bool IsCompilerDirectiveTriggerCharacter(SourceText text, int characterPosition)
117internal static bool IsTriggerCharacterOrArgumentListCharacter(SourceText text, int characterPosition, in CompletionOptions options)
120private static bool IsArgumentListCharacter(SourceText text, int characterPosition)
126internal static bool IsTriggerAfterSpaceOrStartOfWordCharacter(SourceText text, int characterPosition, in CompletionOptions options)
136private static bool SpaceTypedNotBeforeWord(char ch, SourceText text, int characterPosition)
139public static bool IsStartingNewWord(SourceText text, int characterPosition)
StringIndentation\CSharpStringIndentationService.cs (6)
33var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
44SourceText text,
87SourceText text, SyntaxToken token, ArrayBuilder<StringIndentationRegion> result, CancellationToken cancellationToken)
101private static void ProcessInterpolatedStringExpression(SourceText text, InterpolatedStringExpressionSyntax interpolatedString, ArrayBuilder<StringIndentationRegion> result, CancellationToken cancellationToken)
144private static bool IgnoreInterpolation(SourceText text, int offset, InterpolationSyntax interpolation)
165private static bool TryGetIndentSpan(SourceText text, ExpressionSyntax expression, out int offset, out TextSpan indentSpan)
Microsoft.CodeAnalysis.CSharp.Scripting (3)
CSharpScript.cs (2)
37return Script.CreateInitialScript<T>(CSharpScriptCompiler.Instance, SourceText.From(code, options?.FileEncoding, SourceHashAlgorithms.Default), options, globalsType, assemblyLoader);
54return Script.CreateInitialScript<T>(CSharpScriptCompiler.Instance, SourceText.From(code, options?.FileEncoding), options, globalsType, assemblyLoader);
Microsoft.CodeAnalysis.CSharp.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)
472sgc.AddSource("test", SourceText.From("public class D{}", Encoding.UTF8));
475Assert.Throws<ArgumentException>("hintName", () => sgc.AddSource("test", SourceText.From("public class D{}", Encoding.UTF8)));
478Assert.Throws<ArgumentException>("hintName", () => sgc.AddSource("test.cs", SourceText.From("public class D{}", Encoding.UTF8)));
503spc.AddSource("test", SourceText.From("public class D{}", Encoding.UTF8));
506Assert.Throws<ArgumentException>("hintName", () => spc.AddSource("test", SourceText.From("public class D{}", Encoding.UTF8)));
509Assert.Throws<ArgumentException>("hintName", () => spc.AddSource("test.cs", SourceText.From("public class D{}", Encoding.UTF8)));
516spc.AddSource("test", SourceText.From("public class D{}", Encoding.UTF8));
578var generator = new CallbackGenerator((ic) => { }, (sgc) => { sgc.AddSource("test", SourceText.From("public class D {}", Encoding.UTF8)); });
608var 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)); });
748e.AddSource("a", SourceText.From("public class E {}", Encoding.UTF8));
772var generator = new CallbackGenerator((ic) => { }, (sgc) => { sgc.AddSource("a", SourceText.From("")); });
Microsoft.CodeAnalysis.CSharp.Symbol.UnitTests (5)
Microsoft.CodeAnalysis.CSharp.Syntax.UnitTests (296)
IncrementalParsing\IncrementalParsingTests.cs (221)
27var itext = SourceText.From(text);
34var itext = SourceText.From(text);
586var text = SourceText.From(@"partial class C{}");
590var newText = text.WithChanges(new TextChange(new TextSpan(0, 8), ""));
600var text = SourceText.From(@"partial class C{}");
604var newText = text.WithChanges(new TextChange(new TextSpan(0, 8), ""));
614SourceText oldText = SourceText.From(@"
630SourceText oldText = SourceText.From(@"
646SourceText oldText = SourceText.From(@"
663SourceText oldText = SourceText.From(@"
679SourceText oldText = SourceText.From(@"
692SourceText oldText = SourceText.From(@"
708SourceText oldText = SourceText.From(@"
720SourceText oldText = SourceText.From(@"
732SourceText oldText = SourceText.From(@" class A
748SourceText oldText = SourceText.From(@"public class TestClass
761SourceText oldText = SourceText.From(@"using System;
776SourceText oldText = SourceText.From(@"public class MyClass {
788SourceText oldText = SourceText.From(@"
802SourceText startingText = SourceText.From(@"
823SourceText startingText = SourceText.From(@"
842SourceText startingText = SourceText.From(@"
862SourceText oldText = SourceText.From(@"class MyClass
882SourceText oldText = SourceText.From(@"
906SourceText oldText = SourceText.From(@"
930SourceText oldText = SourceText.From(@"interface IGoo
954SourceText oldText = SourceText.From(@"interface IGoo
978SourceText oldText = SourceText.From(@"using System.Runtime.CompilerServices;
1000SourceText oldText = SourceText.From(@"class A
1024SourceText oldText = SourceText.From(@"public class MyClass {
1046SourceText oldText = SourceText.From(@"public class MyClass {
1137SourceText oldText = SourceText.From(@"class filesystem{
1156SourceText oldText = SourceText.From(@"class CSTR020mod{ public static void CSTR020() { ON ERROR GOTO ErrorTrap; } }");
1172SourceText oldText = SourceText.From(@"class A
1192SourceText oldText = SourceText.From(@"public class DynClassDrived
1214SourceText oldText = SourceText.From(@"public class MemberClass
1234SourceText oldText = SourceText.From(@"public class MemberClass
1253SourceText oldText = SourceText.From(@"class Test
1275SourceText oldText = SourceText.From(
1302SourceText oldText = SourceText.From(
1328SourceText oldText = SourceText.From(
1353SourceText oldText = SourceText.From(
1375SourceText oldText = SourceText.From(
1430SourceText oldText = SourceText.From(
1452SourceText oldText = SourceText.From(
1473SourceText oldText = SourceText.From(
1494SourceText oldText = SourceText.From(
1517SourceText oldText = SourceText.From(
1538SourceText oldText = SourceText.From(
1558SourceText oldText = SourceText.From(
1576SourceText oldText = SourceText.From(
1597SourceText oldText = SourceText.From(
1620SourceText oldText = SourceText.From(
1637SourceText oldText = SourceText.From(
1655SourceText oldText = SourceText.From(
1673SourceText oldText = SourceText.From(
1694SourceText oldText = SourceText.From(
1729SourceText oldText = SourceText.From(
1753SourceText oldText = SourceText.From(
1771SourceText oldText = SourceText.From(
1789SourceText oldText = SourceText.From(
1808SourceText oldText = SourceText.From(
1839SourceText oldText = SourceText.From(
1864SourceText oldText = SourceText.From(
1883SourceText oldText = SourceText.From(
1901SourceText oldText = SourceText.From(
1920SourceText oldText = SourceText.From(
1939SourceText oldText = SourceText.From(
1960SourceText oldText = SourceText.From(
1979SourceText oldText = SourceText.From(
2006SourceText oldText = SourceText.From(
2034SourceText oldText = SourceText.From(
2056SourceText oldText = SourceText.From(
2075SourceText oldText = SourceText.From(
2107SourceText oldText = SourceText.From(
2140SourceText oldText = SourceText.From(
2166SourceText oldText = SourceText.From(
2191SourceText oldText = SourceText.From(
2221SourceText oldText = SourceText.From(
2250SourceText oldText = SourceText.From(
2271SourceText oldText = SourceText.From(
2303SourceText oldText = SourceText.From(
2331SourceText oldText = SourceText.From(
2369var text = SourceText.From(str);
2372var text2 = text.WithChanges(
2387SourceText oldText = SourceText.From(@"
2395var newText = oldText.WithChanges(new TextChange(new TextSpan(0, 0), "{"));
2405SourceText oldText = SourceText.From(@"System.Console.WriteLine(true)
2411var newText = oldText.WithChanges(new TextChange(new TextSpan(0, 0), @"System.Console.WriteLine(false)
2434SourceText oldText = SourceText.From(@"System.Console.WriteLine(true)
2440var newText = oldText.WithInsertAt(
2464SourceText oldText = SourceText.From(@"System.Console.WriteLine(true)
2470var newText = oldText.WithChanges(new TextChange(new TextSpan(0, 0), @"if (false)
2524var oldIText = oldTree.GetText();
2528var newIText = oldIText.WithChanges(change);
2602var currIText = currTree.GetText();
2642var currIText = currTree.GetText();
2722var oldText = SourceText.From(items[0]);
2726var newText = oldText.WithChanges(change); // f is a method decl parameter
2753var oldText = SourceText.From(@"
2779var newText = SourceText.From(@"
2822var text = tree.GetText();
2843var text = tree.GetText();
2864var text = tree.GetText();
2885var text = tree.GetText();
2906var text = tree.GetText();
2927var text = tree.GetText();
2951var text = tree.GetText();
2975var text = tree.GetText();
2999var text = tree.GetText();
3023var text = tree.GetText();
3047var text = tree.GetText();
3073var text = tree.GetText();
3099var text = tree.GetText();
3124var text = tree.GetText();
3150var text = tree.GetText();
3168var text = tree.GetText();
3186var text = tree.GetText();
3204var text = tree.GetText();
3219var text = tree.GetText();
3233var text = tree.GetText();
3247var text = tree.GetText();
3285var text = tree.GetText();
3312private static void CommentOutText(SourceText oldText, int locationOfChange, int widthOfChange, out SyntaxTree incrementalTree, out SyntaxTree parsedTree)
3314var newText = oldText.WithChanges(
3324private static void RemoveText(SourceText oldText, int locationOfChange, int widthOfChange, out SyntaxTree incrementalTree, out SyntaxTree parsedTree)
3326var newText = oldText.WithChanges(new TextChange(new TextSpan(locationOfChange, widthOfChange), ""));
3346private static void CharByCharIncrementalParse(SourceText oldText, char newChar, out SyntaxTree incrementalTree, out SyntaxTree parsedTree)
3352var newText = oldText.WithChanges(new TextChange(new TextSpan(oldText.Length, 0), newChar.ToString()));
3357private static void TokenByTokenBottomUp(SourceText oldText, string token, out SyntaxTree incrementalTree, out SyntaxTree parsedTree)
3360SourceText 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 (28)
Microsoft.CodeAnalysis.CSharp.Workspaces.UnitTests (3)
Microsoft.CodeAnalysis.EditorFeatures (132)
DocumentationComments\AbstractDocumentationCommentCommandHandler.cs (5)
60private static DocumentationCommentSnippet? InsertOnCharacterTyped(IDocumentationCommentSnippetService service, SyntaxTree syntaxTree, SourceText text, int position, DocumentationCommentOptions options, CancellationToken cancellationToken)
63private static DocumentationCommentSnippet? InsertOnEnterTyped(IDocumentationCommentSnippetService service, SyntaxTree syntaxTree, SourceText text, int position, DocumentationCommentOptions options, CancellationToken cancellationToken)
66private static DocumentationCommentSnippet? InsertOnCommandInvoke(IDocumentationCommentSnippetService service, SyntaxTree syntaxTree, SourceText text, int position, DocumentationCommentOptions options, CancellationToken cancellationToken)
79Func<IDocumentationCommentSnippetService, SyntaxTree, SourceText, int, DocumentationCommentOptions, CancellationToken, DocumentationCommentSnippet?> getSnippetAction,
215var text = syntaxTree.GetText(c.UserCancellationToken);
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 (10)
24protected abstract SourceText? GetNewText(SourceText analyzerConfigDocument, IReadOnlyList<(TOption option, TValue value)> settingsToUpdate, CancellationToken token);
50public async Task<SourceText?> GetChangedEditorConfigAsync(AnalyzerConfigDocument? analyzerConfigDocument, CancellationToken token)
55var originalText = await analyzerConfigDocument.GetTextAsync(token).ConfigureAwait(false);
58var newText = GetNewText(originalText, _queue, token);
78var newText = await GetChangedEditorConfigAsync(analyzerConfigDocument, token).ConfigureAwait(false);
84var originalText = await analyzerConfigDocument!.GetTextAsync(token).ConfigureAwait(false);
88public async Task<SourceText?> GetChangedEditorConfigAsync(SourceText originalText, CancellationToken token)
92var newText = GetNewText(originalText, _queue, token);
Microsoft.CodeAnalysis.EditorFeatures.Cocoa (3)
Microsoft.CodeAnalysis.EditorFeatures.DiagnosticsTests.Utilities (10)
Microsoft.CodeAnalysis.EditorFeatures.Test.Utilities (49)
Workspaces\TestWorkspace.cs (10)
329protected override void ApplyDocumentTextChanged(DocumentId document, SourceText newText)
335protected override void ApplyDocumentAdded(DocumentInfo info, SourceText text)
354protected override void ApplyAdditionalDocumentTextChanged(DocumentId document, SourceText newText)
360protected override void ApplyAdditionalDocumentAdded(DocumentInfo info, SourceText text)
376protected override void ApplyAnalyzerConfigDocumentTextChanged(DocumentId document, SourceText newText)
382protected override void ApplyAnalyzerConfigDocumentAdded(DocumentInfo info, SourceText text)
754public void ChangeDocument(DocumentId documentId, SourceText text)
759public Task ChangeDocumentAsync(DocumentId documentId, SourceText text)
780public void ChangeAdditionalDocument(DocumentId documentId, SourceText text)
787public void ChangeAnalyzerConfigDocument(DocumentId documentId, SourceText text)
Microsoft.CodeAnalysis.EditorFeatures.Text (20)
Microsoft.CodeAnalysis.EditorFeatures.UnitTests (116)
Diagnostics\DiagnosticAnalyzerServiceTests.cs (10)
194project = project.AddAnalyzerConfigDocument(".editorconfig", filePath: "z:\\.editorconfig", text: SourceText.From(editorconfigText)).Project;
197var document = project.AddDocument("test.cs", SourceText.From("class A {}"), filePath: "z:\\test.cs");
299var document = workspace.AddDocument(project.Id, "Empty.cs", SourceText.From(""));
365loader: TextLoader.From(TextAndVersion.Create(SourceText.From(""), VersionStamp.Create(), filePath)),
488loader: TextLoader.From(TextAndVersion.Create(SourceText.From("class A {}"), VersionStamp.Create(), filePath: "test.cs")),
556text: SourceText.From(analyzerConfigText),
586loader: TextLoader.From(TextAndVersion.Create(SourceText.From("class A {}"), VersionStamp.Create(), filePath: "test.cs")),
706var text = await additionalDoc.GetTextAsync();
899var text = await document.GetTextAsync();
1199return workspace.AddDocument(project.Id, "Empty.cs", SourceText.From("class A { B B {get} }"));
EditAndContinue\CompileTimeSolutionProviderTests.cs (5)
51AddAdditionalDocument(additionalDocumentId, "additional", SourceText.From(""), filePath: additionalFilePath).
52AddAnalyzerConfigDocument(analyzerConfigId, "config", SourceText.From(""), filePath: "RazorSourceGenerator.razorencconfig").
110context.AddSource("hint", SourceText.From(s));
122AddAdditionalDocument(additionalDocumentId, "additional", SourceText.From(""), filePath: "additional.razor").
123AddAnalyzerConfigDocument(analyzerConfigId, "config", SourceText.From(analyzerConfigText), filePath: "Z:\\RazorSourceGenerator.razorencconfig"),
EditAndContinue\EditAndContinueWorkspaceServiceTests.cs (32)
101private static SourceText GetAnalyzerConfigText((string key, string value)[] analyzerConfig)
314var sourceText = SourceText.From(new MemoryStream(encoding.GetBytesWithPreamble(source.content)), encoding, checksumAlgorithm);
363private static SourceText CreateText(string source)
364=> SourceText.From(source, Encoding.UTF8, SourceHashAlgorithms.Default);
366private static SourceText CreateTextFromFile(string path)
369return SourceText.From(stream, Encoding.UTF8, SourceHashAlgorithms.Default);
395var sourceText = CreateText("class DTO {}");
513var sourceTreeA1 = SyntaxFactory.ParseSyntaxTree(SourceText.From(sourceBytesA1, sourceBytesA1.Length, encodingA, SourceHashAlgorithms.Default), TestOptions.Regular, sourceFileA.Path);
514var sourceTreeB1 = SyntaxFactory.ParseSyntaxTree(SourceText.From(sourceBytesB1, sourceBytesB1.Length, encodingB, SourceHashAlgorithms.Default), TestOptions.Regular, sourceFileB.Path);
515var sourceTreeC1 = SyntaxFactory.ParseSyntaxTree(SourceText.From(sourceBytesC1, sourceBytesC1.Length, encodingC, SourceHashAlgorithm.Sha1), TestOptions.Regular, sourceFileC.Path);
752var sourceText = CreateText("class D {}");
817solution = solution.AddDocument(designTimeOnlyDocumentId, designTimeOnlyFileName, SourceText.From(sourceDesignTimeOnly, Encoding.UTF8), filePath: designTimeOnlyFilePath);
837solution = solution.AddDocument(designTimeOnlyDocumentId, designTimeOnlyFileName, SourceText.From(sourceDesignTimeOnly, Encoding.UTF8), filePath: designTimeOnlyFilePath);
1035AddDocument("a.cs", SourceText.From(source1, Encoding.UTF8, SourceHashAlgorithm.Sha1), filePath: sourceFile.Path);
1318public SourceText Text { get; set; }
1320public override SourceText CurrentText => Text;
1346AddDocument(documentId, "test.cs", SourceText.From(source1, encoding, SourceHashAlgorithm.Sha1), filePath: sourceFile.Path);
1368var text = await document.GetTextAsync();
2365solution = solution.WithDocumentText(document1.Id, SourceText.From("class C1 { void M() { System.Console.WriteLine(2); } }", encoding: null, SourceHashAlgorithms.Default));
2599var sourceText1 = CreateText(source1);
3552var sourceTextV1 = document1.GetTextSynchronously(CancellationToken.None);
3553var sourceTextV2 = CreateText(sourceV2);
3645var sourceTextV1 = await document1.GetTextAsync(CancellationToken.None);
3646var sourceTextV2 = CreateText(sourceV2);
3713var sourceText = CreateText("dummy1");
3784var text1 = await doc1.GetTextAsync();
3785var text2 = await doc2.GetTextAsync();
3787DocumentId AddProjectAndLinkDocument(string projectName, Document doc, SourceText text)
4708var document1 = await solution.GetDocument(documentId).GetTextAsync();
4716Text = SourceText.From(source3, Encoding.UTF8, SourceHashAlgorithm.Sha1)
4729var text = await document.GetTextAsync();
SolutionCrawler\WorkCoordinatorTests.cs (11)
348project = project.AddAdditionalDocument("a1", SourceText.From("")).Project;
706var worker = await ExecuteOperation(workspace, w => w.ChangeDocument(document.Id, SourceText.From("//")));
743worker = await ExecuteOperation(workspace, w => w.ChangeAdditionalDocument(ncfile.Id, SourceText.From("//")));
785worker = await ExecuteOperation(workspace, w => w.ChangeAnalyzerConfigDocument(analyzerConfigFile.Id, SourceText.From("//")));
833workspace.ChangeDocument(document.Id, SourceText.From("//"));
841workspace.ChangeDocument(document.Id, SourceText.From("// "));
888workspace.ChangeDocument(document.Id, SourceText.From("//"));
895workspace.ChangeDocument(document.Id, SourceText.From("// "));
903workspace.ChangeDocument(document.Id, SourceText.From("// "));
933workspace.ChangeDocument(id, SourceText.From("//"));
943workspace.ChangeDocument(id, SourceText.From("// "));
Microsoft.CodeAnalysis.EditorFeatures.Wpf (8)
Microsoft.CodeAnalysis.EditorFeatures2.UnitTests (25)
IntelliSense\CSharpCompletionCommandHandlerTests.vb (8)
4167Public Overrides Function IsInsertionTrigger(text As SourceText, characterPosition As Integer, options As CompletionOptions) As Boolean
8204Public Overrides Function ShouldTriggerCompletion(text As SourceText, caretPosition As Integer, trigger As CompletionTrigger, options As OptionSet) As Boolean
8249Public Overrides Function ShouldTriggerCompletion(text As SourceText, caretPosition As Integer, trigger As CompletionTrigger, options As OptionSet) As Boolean
9591Public Overrides Function ShouldTriggerCompletion(text As SourceText, caretPosition As Integer, trigger As CompletionTrigger, options As OptionSet) As Boolean
10252Public Overrides Function IsInsertionTrigger(text As SourceText, characterPosition As Integer, options As CompletionOptions) As Boolean
10325Public Overrides Function IsInsertionTrigger(text As SourceText, characterPosition As Integer, options As CompletionOptions) As Boolean
10618Public Overrides Function IsInsertionTrigger(text As SourceText, characterPosition As Integer, options As CompletionOptions) As Boolean
10754Public Overrides Function ShouldTriggerCompletion(text As SourceText, caretPosition As Integer, trigger As CompletionTrigger, options As OptionSet) As Boolean
Microsoft.CodeAnalysis.ExternalAccess.FSharp (13)
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 (3)
Microsoft.CodeAnalysis.ExternalAccess.Razor (2)
Microsoft.CodeAnalysis.Features (225)
AbstractConflictMarkerCodeFixProvider.cs (15)
73var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
83SyntaxNode root, SourceText text, int position,
144SourceText text, int position,
208var text = startLine.Text!;
226var text = startLine.Text!;
244var text = currentLine.Text!;
302Action<SourceText, ArrayBuilder<TextChange>, int, int, int, int> addEdits,
305var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
310var finalText = text.WithChanges(edits);
315SourceText text, ArrayBuilder<TextChange> edits,
328SourceText text, ArrayBuilder<TextChange> edits,
341SourceText text, ArrayBuilder<TextChange> edits,
375private static int GetEndIncludingLineBreak(SourceText text, int position)
391var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
430var finalText = text.WithChanges(edits);
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)
29public static TextSpan GetWordSpan(SourceText text, int position,
35public static TextSpan GetWordSpan(SourceText text, int position,
62public static bool IsStartingNewWord(SourceText text, int characterPosition, Func<char, bool> isWordStartCharacter, Func<char, bool> isWordCharacter)
209internal static bool IsTextualTriggerString(SourceText text, int characterPosition, string value)
DocumentationComments\AbstractDocumentationCommentSnippetService.cs (8)
43SourceText text,
80private List<string>? GetDocumentationCommentLines(SyntaxToken token, SourceText text, in DocumentationCommentOptions options, out string? indentText, out int caretOffset, out int spanToReplaceLength)
129public bool IsValidTargetMember(SyntaxTree syntaxTree, SourceText text, int position, CancellationToken cancellationToken)
132private TMemberNode? GetTargetMember(SyntaxTree syntaxTree, SourceText text, int position, CancellationToken cancellationToken)
189public DocumentationCommentSnippet? GetDocumentationCommentSnippetOnEnterTyped(SyntaxTree syntaxTree, SourceText text, int position, in DocumentationCommentOptions options, CancellationToken cancellationToken)
207private DocumentationCommentSnippet? GenerateDocumentationCommentAfterEnter(SyntaxTree syntaxTree, SourceText text, int position, in DocumentationCommentOptions options, CancellationToken cancellationToken)
249public DocumentationCommentSnippet? GetDocumentationCommentSnippetOnCommandInvoke(SyntaxTree syntaxTree, SourceText text, int position, in DocumentationCommentOptions options, CancellationToken cancellationToken)
286private DocumentationCommentSnippet? GenerateExteriorTriviaAfterEnter(SyntaxTree syntaxTree, SourceText text, int position, in DocumentationCommentOptions options, CancellationToken cancellationToken)
EditAndContinue\AbstractEditAndContinueAnalyzer.cs (10)
498private static readonly SourceText s_emptySource = SourceText.From("");
527SourceText oldText;
551var newText = await newDocument.GetTextAsync(cancellationToken).ConfigureAwait(false);
700static void LogRudeEdits(ArrayBuilder<RudeEditDiagnostic> diagnostics, SourceText text, string filePath)
794SourceText newText,
951SourceText newText,
1263private bool TryGetTrackedStatement(ImmutableArray<LinePositionSpan> activeStatementSpans, int index, SourceText text, SyntaxNode declaration, SyntaxNode body, [NotNullWhen(true)] out SyntaxNode? trackedStatement, out int trackedStatementPart)
2411SourceText newText,
2846var oldSyntaxText = await oldSyntaxDocument.GetTextAsync(cancellationToken).ConfigureAwait(false);
EditAndContinue\CommittedSolution.cs (13)
224var sourceText = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
283var matchingSourceText = maybeMatchingSourceText.Value;
310private async ValueTask<(Optional<SourceText?> matchingSourceText, bool? hasDocument)> TryGetMatchingSourceTextAsync(Document document, SourceText sourceText, Document? currentDocument, CancellationToken cancellationToken)
322private static async ValueTask<Optional<SourceText?>> TryGetMatchingSourceTextAsync(
323SourceText sourceText, string filePath, Document? currentDocument, IPdbMatchingSourceTextProvider sourceTextProvider, ImmutableArray<byte> requiredChecksum, SourceHashAlgorithm checksumAlgorithm, CancellationToken cancellationToken)
332var currentDocumentSourceText = await currentDocument.GetTextAsync(cancellationToken).ConfigureAwait(false);
342return SourceText.From(text, sourceText.Encoding, checksumAlgorithm);
386var sourceText = await documentState.GetTextAsync(cancellationToken).ConfigureAwait(false);
437private static bool IsMatchingSourceText(SourceText sourceText, ImmutableArray<byte> requiredChecksum, SourceHashAlgorithm checksumAlgorithm)
440private static Optional<SourceText?> TryGetPdbMatchingSourceTextFromDisk(string sourceFilePath, Encoding? encoding, ImmutableArray<byte> requiredChecksum, SourceHashAlgorithm checksumAlgorithm)
450var 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);
Microsoft.CodeAnalysis.LanguageServer.Protocol (100)
Microsoft.CodeAnalysis.LanguageServer.Protocol.UnitTests (45)
Workspaces\LspWorkspaceManagerTests.cs (7)
74await testLspServer.TestWorkspace.ChangeDocumentAsync(firstDocument.Id, SourceText.From($"Some more text{markupOne}", System.Text.Encoding.UTF8, SourceHashAlgorithms.Default));
108await testLspServer.TestWorkspace.ChangeDocumentAsync(secondDocument.Id, SourceText.From("Two is now three!", System.Text.Encoding.UTF8, SourceHashAlgorithms.Default));
182var newSolution = testLspServer.TestWorkspace.CurrentSolution.AddDocument(newDocumentId, "NewDoc.cs", SourceText.From("New Doc", System.Text.Encoding.UTF8, SourceHashAlgorithms.Default), filePath: @"C:\NewDoc.cs");
220var miscText = await miscDocument.GetTextAsync(CancellationToken.None);
232var documentText = await document.GetTextAsync(CancellationToken.None);
353var changedFirstDocumentText = await changedFirstDocument.GetTextAsync(CancellationToken.None);
354var firstDocumentText = await firstDocument.GetTextAsync(CancellationToken.None);
Microsoft.CodeAnalysis.LanguageServerIndexFormat.Generator (3)
Microsoft.CodeAnalysis.Rebuild (9)
Microsoft.CodeAnalysis.Rebuild.UnitTests (3)
Microsoft.CodeAnalysis.Remote.ServiceHub (5)
Microsoft.CodeAnalysis.Remote.Workspaces (1)
Microsoft.CodeAnalysis.Scripting (12)
Hosting\CommandLine\CommandLineRunner.cs (5)
105SourceText code = null;
192private int RunScript(ScriptOptions options, SourceText code, ErrorLogger errorLogger, CancellationToken cancellationToken)
223var script = Script.CreateInitialScript<object>(_scriptCompiler, SourceText.From(initialScriptCodeOpt), options, globals.GetType(), assemblyLoaderOpt: null);
250var tree = _scriptCompiler.ParseSubmission(SourceText.From(input.ToString()), options.ParseOptions, cancellationToken);
275newScript = Script.CreateInitialScript<object>(_scriptCompiler, SourceText.From(code ?? string.Empty), options, globals.GetType(), assemblyLoaderOpt: null);
Script.cs (6)
39internal Script(ScriptCompiler compiler, ScriptBuilder builder, SourceText sourceText, ScriptOptions options, Type globalsTypeOpt, Script previousOpt)
54internal static Script<T> CreateInitialScript<T>(ScriptCompiler compiler, SourceText sourceText, ScriptOptions optionsOpt, Type globalsTypeOpt, InteractiveAssemblyLoader assemblyLoaderOpt)
79internal SourceText SourceText { get; }
117return new Script<TResult>(Compiler, Builder, SourceText.From(code ?? "", options.FileEncoding), options, GlobalsType, this);
130return new Script<TResult>(Compiler, Builder, SourceText.From(code, options.FileEncoding), options, GlobalsType, this);
318internal Script(ScriptCompiler compiler, ScriptBuilder builder, SourceText sourceText, ScriptOptions options, Type globalsTypeOpt, Script previousOpt)
Microsoft.CodeAnalysis.Scripting.TestUtilities (3)
Microsoft.CodeAnalysis.Test.Utilities (23)
Microsoft.CodeAnalysis.TestAnalyzerReference (5)
Microsoft.CodeAnalysis.UnitTests (501)
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 (88)
28TestIsEmpty(SourceText.From(string.Empty));
29TestIsEmpty(SourceText.From(new byte[0], 0));
30TestIsEmpty(SourceText.From(new MemoryStream()));
33private static void TestIsEmpty(SourceText text)
46Assert.Same(s_utf8, SourceText.From(HelloWorld, s_utf8).Encoding);
47Assert.Same(s_unicode, SourceText.From(HelloWorld, s_unicode).Encoding);
50Assert.Same(s_unicode, SourceText.From(bytes, bytes.Length, s_unicode).Encoding);
51Assert.Equal(utf8NoBOM, SourceText.From(bytes, bytes.Length, null).Encoding);
54Assert.Same(s_unicode, SourceText.From(stream, s_unicode).Encoding);
55Assert.Equal(utf8NoBOM, SourceText.From(stream, null).Encoding);
64Assert.Equal(utf8BOM, SourceText.From(bytes, bytes.Length, s_unicode).Encoding);
65Assert.Equal(utf8BOM, SourceText.From(bytes, bytes.Length, null).Encoding);
68Assert.Equal(utf8BOM, SourceText.From(stream, s_unicode).Encoding);
69Assert.Equal(utf8BOM, SourceText.From(stream, null).Encoding);
75Assert.Equal(SourceHashAlgorithm.Sha1, SourceText.From(HelloWorld).ChecksumAlgorithm);
78Assert.Equal(SourceHashAlgorithm.Sha1, SourceText.From(bytes, bytes.Length).ChecksumAlgorithm);
81Assert.Equal(SourceHashAlgorithm.Sha1, SourceText.From(stream).ChecksumAlgorithm);
89Assert.Equal(algorithm, SourceText.From(HelloWorld, checksumAlgorithm: algorithm).ChecksumAlgorithm);
92Assert.Equal(algorithm, SourceText.From(bytes, bytes.Length, checksumAlgorithm: algorithm).ChecksumAlgorithm);
95Assert.Equal(algorithm, SourceText.From(stream, checksumAlgorithm: algorithm).ChecksumAlgorithm);
111VerifyChecksum(SourceText.From(source, encodingNoBOM, checksumAlgorithm), checksumNoBOM);
112VerifyChecksum(SourceText.From(source, encodingBOM, checksumAlgorithm), checksumBOM);
121VerifyChecksum(SourceText.From(bytesNoBOM, bytesNoBOM.Length, null, checksumAlgorithm), checksumNoBOM);
122VerifyChecksum(SourceText.From(bytesNoBOM, bytesNoBOM.Length, encodingNoBOM, checksumAlgorithm), checksumNoBOM);
123VerifyChecksum(SourceText.From(bytesNoBOM, bytesNoBOM.Length, encodingBOM, checksumAlgorithm), checksumNoBOM);
126VerifyChecksum(SourceText.From(bytesBOM, bytesBOM.Length, null, checksumAlgorithm), checksumBOM);
127VerifyChecksum(SourceText.From(bytesBOM, bytesBOM.Length, encodingNoBOM, checksumAlgorithm), checksumBOM);
128VerifyChecksum(SourceText.From(bytesBOM, bytesBOM.Length, encodingBOM, checksumAlgorithm), checksumBOM);
131VerifyChecksum(SourceText.From(streamNoBOM, null, checksumAlgorithm), checksumNoBOM);
132VerifyChecksum(SourceText.From(streamNoBOM, encodingNoBOM, checksumAlgorithm), checksumNoBOM);
133VerifyChecksum(SourceText.From(streamNoBOM, encodingBOM, checksumAlgorithm), checksumNoBOM);
136VerifyChecksum(SourceText.From(streamBOM, null, checksumAlgorithm), checksumBOM);
137VerifyChecksum(SourceText.From(streamBOM, encodingNoBOM, checksumAlgorithm), checksumBOM);
138VerifyChecksum(SourceText.From(streamBOM, encodingBOM, checksumAlgorithm), checksumBOM);
156VerifyChecksum(FromChanges(SourceText.From(source, encodingNoBOM, checksumAlgorithm)), checksumNoBOM);
157VerifyChecksum(FromChanges(SourceText.From(source, encodingBOM, checksumAlgorithm)), checksumBOM);
162VerifyChecksum(FromChanges(SourceText.From(streamNoBOM, encodingNoBOM, checksumAlgorithm)), checksumNoBOM);
163VerifyChecksum(FromChanges(SourceText.From(streamNoBOM, encodingBOM, checksumAlgorithm)), checksumBOM);
166VerifyChecksum(FromChanges(SourceText.From(streamBOM, encodingNoBOM, checksumAlgorithm)), checksumBOM);
167VerifyChecksum(FromChanges(SourceText.From(streamBOM, encodingBOM, checksumAlgorithm)), checksumBOM);
170private static SourceText FromLargeTextWriter(string source, Encoding encoding, SourceHashAlgorithm checksumAlgorithm)
179private static SourceText FromChanges(SourceText text)
183var changed = text.WithChanges(change);
188private static void VerifyChecksum(SourceText text, ImmutableArray<byte> expectedChecksum)
197var f = SourceText.From(HelloWorld, s_utf8);
199Assert.True(f.ContentEquals(SourceText.From(HelloWorld, s_utf8)));
200Assert.False(f.ContentEquals(SourceText.From(HelloWorld + "o", s_utf8)));
201Assert.True(SourceText.From(HelloWorld, s_utf8).ContentEquals(SourceText.From(HelloWorld, s_utf8)));
203var e1 = EncodedStringText.Create(new MemoryStream(s_unicode.GetBytes(HelloWorld)), s_unicode);
204var e2 = EncodedStringText.Create(new MemoryStream(s_utf8.GetBytes(HelloWorld)), s_utf8);
218Assert.False(SourceText.IsBinary(""));
220Assert.False(SourceText.IsBinary("\0abc"));
221Assert.False(SourceText.IsBinary("a\0bc"));
222Assert.False(SourceText.IsBinary("abc\0"));
223Assert.False(SourceText.IsBinary("a\0b\0c"));
225Assert.True(SourceText.IsBinary("\0\0abc"));
226Assert.True(SourceText.IsBinary("a\0\0bc"));
227Assert.True(SourceText.IsBinary("abc\0\0"));
230Assert.False(SourceText.IsBinary(encoding.GetString(new byte[] { 0x81, 0x8D, 0x8F, 0x90, 0x9D })));
232Assert.False(SourceText.IsBinary("abc def baz aeiouy \u00E4\u00EB\u00EF\u00F6\u00FC\u00FB"));
233Assert.True(SourceText.IsBinary(encoding.GetString(TestMetadata.ResourcesNet451.System)));
240Assert.Throws<InvalidDataException>(() => SourceText.From(bytes, bytes.Length, throwIfBinaryDetected: true));
243Assert.Throws<InvalidDataException>(() => SourceText.From(stream, throwIfBinaryDetected: true));
250var expectedSourceText = SourceText.From(expected);
253var actualSourceText = SourceText.From(actual, expected.Length);
257Assert.Same(s_utf8, SourceText.From(actual, expected.Length, s_utf8).Encoding);
258Assert.Same(s_unicode, SourceText.From(actual, expected.Length, s_unicode).Encoding);
259Assert.Null(SourceText.From(actual, expected.Length, null).Encoding);
265var expected = new string('l', SourceText.LargeObjectHeapLimitInChars);
266var expectedSourceText = SourceText.From(expected);
269var actualSourceText = SourceText.From(actual, expected.Length);
276Assert.Same(s_utf8, SourceText.From(actual, expected.Length, s_utf8).Encoding);
277Assert.Same(s_unicode, SourceText.From(actual, expected.Length, s_unicode).Encoding);
278Assert.Null(SourceText.From(actual, expected.Length, null).Encoding);
289Encoding actualEncoding = SourceText.TryReadByteOrderMark(data, validLength, out actualPreambleLength);
322var sourceText = SourceText.From("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
341var sourceText = SourceText.From(Text);
353SourceText.From("ABC").Write(TextWriter.Null, TextSpan.FromBounds(4, 4)));
362SourceText.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 (1)
Microsoft.CodeAnalysis.VisualBasic.CodeStyle.UnitTests (1)
Microsoft.CodeAnalysis.VisualBasic.EditorFeatures (4)
Microsoft.CodeAnalysis.VisualBasic.EditorFeatures.UnitTests (14)
EditAndContinue\VisualBasicEditAndContinueAnalyzerTests.vb (6)
36AddDocument("test.vb", SourceText.From(source, Encoding.UTF8), filePath:=Path.Combine(TempRoot.Root, "test.vb")).Project.Solution
476Dim newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2))
561Dim newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2))
619Dim newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2))
650Dim newSolution = oldSolution.WithDocumentText(documentId, SourceText.From(source2))
681Dim newSolution = oldSolution.AddDocument(newDocId, "goo.vb", SourceText.From(source2), filePath:=Path.Combine(TempRoot.Root, "goo.vb"))
Microsoft.CodeAnalysis.VisualBasic.Emit.UnitTests (2)
Microsoft.CodeAnalysis.VisualBasic.ExpressionEvaluator.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 (32)
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)
CompilationTestUtils.vb (4)
22Return source.Select(Function(s) VisualBasicSyntaxTree.ParseText(SourceText.From(s, encoding:=Nothing, SourceHashAlgorithms.Default), parseOptions))
623Return VisualBasicSyntaxTree.ParseText(SourceText.From(FilterString(programElement.Value), Encoding.UTF8, SourceHashAlgorithms.Default), path:=If(programElement.@name, ""))
640Dim text = SourceText.From(codeWithoutMarker, Encoding.UTF8)
1011Private Function GetLineText(text As SourceText, position As Integer, ByRef offsetInLine As Integer) As String
Microsoft.CodeAnalysis.VisualBasic.Workspaces (13)
Microsoft.CodeAnalysis.VisualBasic.Workspaces.UnitTests (5)
Microsoft.CodeAnalysis.Workspaces (334)
CodeFixesAndRefactorings\DocumentBasedFixAllProviderHelpers.cs (5)
30Func<TFixAllContext, IProgressTracker, Task<Dictionary<DocumentId, (SyntaxNode? node, SourceText? text)>>> getFixedDocumentsAsync)
59Func<TFixAllContext, IProgressTracker, Task<Dictionary<DocumentId, (SyntaxNode? node, SourceText? text)>>> getFixedDocumentsAsync)
79Dictionary<DocumentId, (SyntaxNode? node, SourceText? text)> docIdToNewRootOrText,
104using var _2 = ArrayBuilder<Task<(DocumentId docId, SourceText sourceText)>>.GetInstance(out var tasks);
114var cleanedText = await cleanedDocument.GetTextAsync(cancellationToken).ConfigureAwait(false);
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)
Shared\Extensions\SourceTextExtensions.cs (12)
19public static void GetLineAndOffset(this SourceText text, int position, out int lineNumber, out int offset)
27public static int GetOffset(this SourceText text, int position)
34this SourceText text,
45public static TextChangeRange GetEncompassingTextChangeRange(this SourceText newText, SourceText oldText)
62public static int IndexOf(this SourceText text, string value, int startIndex, bool caseSensitive)
93public static int LastIndexOf(this SourceText text, string value, int startIndex, bool caseSensitive)
129public static bool ContentEquals(this SourceText text, int position, string value)
147public static int IndexOfNonWhiteSpace(this SourceText text, int start, int length)
163public static void WriteTo(this SourceText sourceText, ObjectWriter writer, CancellationToken cancellationToken)
181private static void WriteChunksTo(SourceText sourceText, ObjectWriter writer, int length, CancellationToken cancellationToken)
226public static SourceText ReadFrom(ITextFactoryService textService, ObjectReader reader, Encoding? encoding, SourceHashAlgorithm checksumAlgorithm, CancellationToken cancellationToken)
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 (12)
153var text = textAndVersion.Text;
226var newText = newTextAndVersion.Text;
229var oldText = oldTree.GetText(cancellationToken);
237private static TreeAndVersion MakeNewTreeAndVersion(SyntaxTree oldTree, SourceText oldText, VersionStamp oldVersion, SyntaxTree newTree, SourceText newText, VersionStamp newVersion)
246private static bool TopLevelChanged(SyntaxTree oldTree, SourceText oldText, SyntaxTree newTree, SourceText newText)
449public new DocumentState UpdateText(SourceText newText, PreservationMode mode)
509else if (TryGetText(out var priorText))
548new AsyncLazy<SourceText>(
688SourceText newText,
690SourceText? oldText = null)
Workspace\Solution\FileTextLoader.cs (7)
70GetType(), _ => new StrongBox<bool>(new Func<Stream, Workspace, SourceText>(CreateText).Method.DeclaringType != typeof(FileTextLoader))).Value;
74/// Creates <see cref="SourceText"/> from <see cref="Stream"/>.
78protected virtual SourceText CreateText(Stream stream, Workspace? workspace)
82/// Creates <see cref="SourceText"/> from <see cref="Stream"/>.
85private protected virtual SourceText CreateText(Stream stream, LoadTextOptions options, CancellationToken cancellationToken)
181var text = CreateText(readStream, options, cancellationToken);
216var text = CreateText(stream, options, cancellationToken);
Workspace\Solution\Solution.cs (15)
1005var sourceText = SourceText.From(text, encoding: null, checksumAlgorithm: project.ChecksumAlgorithm);
1014public Solution AddDocument(DocumentId documentId, string name, SourceText text, IEnumerable<string>? folders = null, string? filePath = null, bool isGenerated = false)
1045var sourceText = SourceText.From(string.Empty, encoding: null, project.ChecksumAlgorithm);
1051private Solution AddDocumentImpl(ProjectState project, DocumentId documentId, string name, SourceText text, IReadOnlyList<string>? folders, string? filePath, bool isGenerated)
1114=> this.AddAdditionalDocument(documentId, name, SourceText.From(text), folders, filePath);
1120public Solution AddAdditionalDocument(DocumentId documentId, string name, SourceText text, IEnumerable<string>? folders = null, string? filePath = null)
1159public Solution AddAnalyzerConfigDocument(DocumentId documentId, string name, SourceText text, IEnumerable<string>? folders = null, string? filePath = null)
1183private DocumentInfo CreateDocumentInfo(DocumentId documentId, string name, SourceText text, IEnumerable<string>? folders, string? filePath)
1370public Solution WithDocumentText(DocumentId documentId, SourceText text, PreservationMode mode = PreservationMode.PreserveValue)
1397public Solution WithAdditionalDocumentText(DocumentId documentId, SourceText text, PreservationMode mode = PreservationMode.PreserveValue)
1424public Solution WithAnalyzerConfigDocumentText(DocumentId documentId, SourceText text, PreservationMode mode = PreservationMode.PreserveValue)
1727public Solution WithDocumentText(IEnumerable<DocumentId?> documentIds, SourceText text, PreservationMode mode = PreservationMode.PreserveValue)
1758internal Document WithFrozenSourceGeneratedDocument(SourceGeneratedDocumentIdentity documentIdentity, SourceText text)
Workspace\Workspace.cs (17)
922protected internal void OnDocumentTextChanged(DocumentId documentId, SourceText newText, PreservationMode mode)
936protected internal void OnAdditionalDocumentTextChanged(DocumentId documentId, SourceText newText, PreservationMode mode)
950protected internal void OnAnalyzerConfigDocumentTextChanged(DocumentId documentId, SourceText newText, PreservationMode mode)
1650var text = document.GetTextSynchronously(CancellationToken.None);
1659var text = document.GetTextSynchronously(CancellationToken.None);
1668var text = document.GetTextSynchronously(CancellationToken.None);
1685var currentText = newDoc.GetTextSynchronously(CancellationToken.None); // needs wait
1695var currentText = newDoc.GetTextSynchronously(CancellationToken.None); // needs wait
1712if (!oldDoc.TryGetText(out var oldText))
1717var currentText = newDoc.GetTextSynchronously(CancellationToken.None); // needs wait
1720else if (!newDoc.TryGetText(out var newText))
1935protected virtual void ApplyDocumentAdded(DocumentInfo info, SourceText text)
1957protected virtual void ApplyDocumentTextChanged(DocumentId id, SourceText text)
1979protected virtual void ApplyAdditionalDocumentAdded(DocumentInfo info, SourceText text)
2001protected virtual void ApplyAdditionalDocumentTextChanged(DocumentId id, SourceText text)
2012protected virtual void ApplyAnalyzerConfigDocumentAdded(DocumentInfo info, SourceText text)
2034protected virtual void ApplyAnalyzerConfigDocumentTextChanged(DocumentId id, SourceText text)
Workspace\Workspace_Editor.cs (11)
372var newText = data.textContainer.CurrentText;
373if (oldDocument.TryGetText(out var oldText) &&
462private static TextAndVersion GetProperTextAndVersion(SourceText oldText, SourceText newText, VersionStamp version, string? filePath)
471private void SignupForTextChanges(DocumentId documentId, SourceTextContainer textContainer, bool isCurrentContext, Action<Workspace, DocumentId, SourceText, PreservationMode> onChangedHandler)
523Func<Solution, DocumentId, SourceText, PreservationMode, Solution> withDocumentText,
525Action<Workspace, DocumentId, SourceText, PreservationMode> onDocumentTextChanged)
538var oldText = oldDocument.GetTextSynchronously(CancellationToken.None);
541var newText = data.textContainer.CurrentText;
734private SourceText GetOpenDocumentText(Solution solution, DocumentId documentId)
739Contract.ThrowIfFalse(doc.TryGetText(out var text));
Microsoft.CodeAnalysis.Workspaces.MSBuild (6)
Microsoft.CodeAnalysis.Workspaces.MSBuild.UnitTests (43)
Microsoft.CodeAnalysis.Workspaces.Test.Utilities (13)
Formatting\FormattingTestBase.cs (6)
54var document = project.AddDocument("Document", SourceText.From(code));
89private static async Task AssertFormatAsync(SolutionServices services, string expected, SyntaxNode root, ImmutableArray<TextSpan> spans, SyntaxFormattingOptions options, SourceText sourceText)
96var resultText = sourceText.WithChanges(result);
105private static bool TryAdjustSpans(SourceText inputText, IList<TextChange> changes, SourceText outputText, ImmutableArray<TextSpan> inputSpans, out ImmutableArray<TextSpan> outputSpans)
133protected static void AssertResult(string expected, SourceText sourceText, IList<TextChange> result)
Microsoft.CodeAnalysis.Workspaces.UnitTests (275)
Formatter\FormatterTests.cs (7)
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();
71var document = workspace.AddDocument(project.Id, "File.dummy", SourceText.From("dummy"));
96var formattedText = await formattedDocument.GetTextAsync();
116var csDocument = workspace.AddDocument(csProject.Id, "File.cs", SourceText.From("class C { }"));
117var vbDocument = workspace.AddDocument(vbProject.Id, "File.vb", SourceText.From("Class C : End Class"));
SolutionTests\SolutionTests.cs (111)
56.AddDocument(DocumentId.CreateNewId(projectId), "goo.cs", SourceText.From("public class Goo { }", Encoding.UTF8, SourceHashAlgorithms.Default))
57.AddAdditionalDocument(DocumentId.CreateNewId(projectId), "add.txt", SourceText.From("text", Encoding.UTF8, SourceHashAlgorithms.Default))
58.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId), "editorcfg", SourceText.From("config", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "/a/b")));
78.AddDocument(DocumentId.CreateNewId(projectId1), "goo.cs", SourceText.From(docContents, Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "goo.cs")
79.AddAdditionalDocument(DocumentId.CreateNewId(projectId1), "add.txt", SourceText.From("text", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "add.txt")
80.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId1), "editorcfg", SourceText.From("config", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "/a/b")
82.AddDocument(DocumentId.CreateNewId(projectId2), "goo.cs", SourceText.From(docContents, Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "goo.cs")
83.AddAdditionalDocument(DocumentId.CreateNewId(projectId2), "add.txt", SourceText.From("text", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "add.txt")
84.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId2), "editorcfg", SourceText.From("config", Encoding.UTF8, SourceHashAlgorithms.Default), filePath: "/a/b")));
310.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId), "editorcfg", SourceText.From("config"));
326var text = SourceText.From("new text", encoding: null, SourceHashAlgorithm.Sha1);
331Assert.True(newDocument1.TryGetText(out var actualText));
337Assert.Throws<ArgumentNullException>(() => solution.WithDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity));
350var textAndVersion = TextAndVersion.Create(SourceText.From("new text"), VersionStamp.Default);
353Assert.True(newSolution1.GetDocument(documentId)!.TryGetText(out var actualText));
361Assert.Throws<ArgumentNullException>(() => solution.WithDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity));
374var text = SourceText.From("new text");
377Assert.True(newSolution1.GetDocument(documentId)!.TryGetText(out var actualText));
413var text1 = await document1.GetTextAsync();
414var text2 = await document2.GetTextAsync();
427var text = SourceText.From("new text", encoding: null, SourceHashAlgorithm.Sha1);
472private static Solution UpdateSolution(PreservationMode mode, TextUpdateType updateType, Solution solution, DocumentId documentId1, SourceText text, TextAndVersion textAndVersion)
501var text1 = await document1.GetTextAsync();
502var text2 = await document2.GetTextAsync();
515var text = SourceText.From("new text", encoding: null, SourceHashAlgorithm.Sha1);
580var text1 = await document1.GetTextAsync();
581var text2 = await document2.GetTextAsync();
598var text = SourceText.From("new text without pp directives", encoding: null, SourceHashAlgorithm.Sha1);
666var text1 = await document1.GetTextAsync();
667var text2 = await document2.GetTextAsync();
681var text = SourceText.From("#if true", encoding: null, SourceHashAlgorithm.Sha1);
743var text1 = await document1.GetTextAsync();
744var text2 = await document2.GetTextAsync();
757var text = SourceText.From("new text", encoding: null, SourceHashAlgorithm.Sha1);
808var text = SourceText.From("new text");
811Assert.True(newSolution1.GetAdditionalDocument(documentId)!.TryGetText(out var actualText));
817Assert.Throws<ArgumentNullException>(() => solution.WithAdditionalDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity));
830var textAndVersion = TextAndVersion.Create(SourceText.From("new text"), VersionStamp.Default);
833Assert.True(newSolution1.GetAdditionalDocument(documentId)!.TryGetText(out var actualText));
841Assert.Throws<ArgumentNullException>(() => solution.WithAdditionalDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity));
854var text = SourceText.From("new text");
857Assert.True(newSolution1.GetAnalyzerConfigDocument(documentId)!.TryGetText(out var actualText));
863Assert.Throws<ArgumentNullException>(() => solution.WithAnalyzerConfigDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity));
876var textAndVersion = TextAndVersion.Create(SourceText.From("new text"), VersionStamp.Default);
879Assert.True(newSolution1.GetAnalyzerConfigDocument(documentId)!.TryGetText(out var actualText));
887Assert.Throws<ArgumentNullException>(() => solution.WithAnalyzerConfigDocumentText(documentId, (SourceText)null!, PreservationMode.PreserveIdentity));
1114var textC = SourceText.From("class C {}", encoding: null, checksumAlgorithm: SourceHashAlgorithm.Sha1);
1750var sourceText = document.GetTextSynchronously(default);
1775var sourceText = SourceText.From("text", checksumAlgorithm: SourceHashAlgorithms.Default);
1789Assert.Throws<ArgumentNullException>("text", () => solution.AddDocument(documentId, "name", text: (SourceText)null!));
1836var root = CSharp.SyntaxFactory.ParseSyntaxTree(SourceText.From("class C {}", encoding: null, SourceHashAlgorithm.Sha1)).GetRoot();
1841var sourceText = document2.GetTextSynchronously(default);
1870var sourceText = document2.GetTextSynchronously(default);
2513.AddDocument(documentId, "DocumentName", SourceText.From("class Class{}"));
2553var text2 = tree2.GetText();
2676var observedText2 = sol.GetDocument(did).GetTextAsync().Result;
2694var docText = doc.GetTextAsync().Result;
2716var docText = doc.GetTextAsync().Result;
2741var docText = doc.GetTextAsync().Result;
2887private static ObjectReference<SourceText> GetObservedText(Solution solution, DocumentId documentId, string expectedText = null)
2889var observedText = solution.GetDocument(documentId).GetTextAsync().Result;
2896return new ObjectReference<SourceText>(observedText);
2918private static ObjectReference<SourceText> GetObservedTextAsync(Solution solution, DocumentId documentId, string expectedText = null)
2920var observedText = solution.GetDocument(documentId).GetTextAsync().Result;
2927return new ObjectReference<SourceText>(observedText);
3135.AddDocument(did, "test", SourceText.From(language == LanguageNames.CSharp ? "class C {}" : "Class C : End Class", Encoding.UTF8, SourceHashAlgorithm.Sha256), filePath: "old path");
3277var text = await doc.GetTextAsync().ConfigureAwait(false);
3339var solution2 = solution.WithDocumentText(did3, SourceText.From(text4));
3352var doc = ws.AddDocument(proj.Id, "a.cs", SourceText.From("public class c { }", Encoding.UTF32));
3413workspace.AddDocument(project1.Id, "Broken.cs", SourceText.From("class "));
3435project = project.AddDocument("Extra.cs", SourceText.From("class Extra { }")).Project;
3437var documentToFreeze = project.AddDocument("DocumentToFreeze.cs", SourceText.From(""));
3460project = project.AddDocument("Extra.cs", SourceText.From("class Extra { }")).Project;
3462var documentToFreezeOriginal = project.AddDocument("DocumentToFreeze.cs", SourceText.From("class DocumentToFreeze { void M() { } }"));
3466var solution = project.Solution.WithDocumentText(documentToFreezeOriginal.Id, SourceText.From("class DocumentToFreeze { void M() { /*no top level change*/ } }"));
3505project = project.AddDocument("Extra.cs", SourceText.From("class Extra { }")).Project;
3507var documentToFreezeOriginal = project.AddDocument("DocumentToFreeze.cs", SourceText.From("class DocumentToFreeze { void M() { } }"));
3511var solution = project.Solution.WithDocumentText(documentToFreezeOriginal.Id, SourceText.From("class DocumentToFreeze { void M() { } public void NewMethod() { } }"));
3569var document = workspace.AddDocument(project2.Id, "Test.cs", SourceText.From(""));
3668document = document.WithText(SourceText.From("// Source File with Changes"));
3695.WithDocumentText(documentId1, SourceText.From("// Document 1 Changed"))
3696.WithDocumentText(documentId2, SourceText.From("// Document 2 Changed"))
3697.WithDocumentText(documentId3, SourceText.From("// Document 3 Changed"));
3799var text = SourceText.From("// empty", encoding: null, SourceHashAlgorithms.Default);
3802var sourceText = strongTree.GetText();
3935loader: TextLoader.From(TextAndVersion.Create(SourceText.From("[*.*]\r\n\r\ndotnet_diagnostic.CA1234.severity = error"), VersionStamp.Default)))));
3969loader: TextLoader.From(TextAndVersion.Create(SourceText.From("[*.*]\r\n\r\ndotnet_diagnostic.CA1234.severity = error"), VersionStamp.Default)))));
4011loader: TextLoader.From(TextAndVersion.Create(SourceText.From("[*.*]\r\n\r\ndotnet_diagnostic.CA1234.severity = error"), VersionStamp.Default)))));
4023TextLoader.From(TextAndVersion.Create(SourceText.From("[*.*]\r\n\r\ndotnet_diagnostic.CA6789.severity = error"), VersionStamp.Default)),
4059loader: TextLoader.From(TextAndVersion.Create(SourceText.From("is_global = true\r\n\r\ndotnet_diagnostic.CA1234.severity = error"), VersionStamp.Default)))));
4105loader: TextLoader.From(TextAndVersion.Create(SourceText.From("[*.*]\r\n\r\ngenerated_code = true"), VersionStamp.Default)))));
4292var text = SourceText.From("public class C { }");
4313var newDocText = await newDoc.GetTextAsync();
4314var sameText = await newDoc.GetTextAsync();
4318var treeText = newDocTree.GetText();
4340var sourceTextToRelease = ObjectReference.CreateFromFactory(static () => SourceText.From(Guid.NewGuid().ToString()));
4388.AddDocument(documentId, "test.cs", SourceText.From("public class C { }"), filePath: sourcePath)
4389.AddAnalyzerConfigDocument(DocumentId.CreateNewId(projectId), ".editorconfig", SourceText.From($"[{pattern}]\nindent_style = tab"), filePath: configPath);
SolutionTests\SolutionWithSourceGeneratorTests.cs (18)
196project = project.AdditionalDocuments.First().WithAdditionalDocumentText(SourceText.From("Changed text!")).Project;
220project = project.AddDocument("Source.cs", SourceText.From("")).Project;
253project = project.Solution.WithDocumentText(documentId, SourceText.From("// Changed Source File")).Projects.Single();
296project = project.Solution.WithAdditionalDocumentText(additionalDocumentId, SourceText.From("Hello, everyone!")).Projects.Single();
301project = project.Solution.WithAdditionalDocumentText(additionalDocumentId, SourceText.From("Good evening, everyone!")).Projects.Single();
357SourceText.From("Hello, world!!!!")).Projects.Single();
470project = project.Documents.Single().WithText(SourceText.From("// Change")).Project;
546var existingText = await project.Documents.Single().GetTextAsync();
547var newText = existingText.WithChanges(new TextChange(new TextSpan(existingText.Length, length: 0), " With Change"));
576var differentOpenTextContainer = SourceText.From("// Open Text").Container;
600var differentOpenTextContainer = SourceText.From("// StaticContent", Encoding.UTF8).Container;
615.AddAdditionalDocument("Test.txt", SourceText.From(""));
620var differentOpenTextContainer = SourceText.From("// Open Text").Container;
651var differentOpenTextContainer = SourceText.From("// Open Text").Container;
678var differentOpenTextContainer = SourceText.From("// Open Text").Container;
715documentToFreeze = documentToFreeze.WithText(SourceText.From("// Changed Source File"));
744document = document.WithText(SourceText.From("// Something else"));
776document = document.WithText(SourceText.From("// Something else"));
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)
76var doc = ws.AddDocument(project.Id, name, SourceText.From(source));
158loader: TextLoader.From(TextAndVersion.Create(SourceText.From(""), VersionStamp.Create())));
216var text = SourceText.From("public class C { }");
230Assert.False(doc.TryGetText(out var currentText));
250var text = SourceText.From("public class C { }");
264Assert.False(doc.TryGetText(out var currentText));
284var text = SourceText.From("public class C { }");
304Assert.False(doc.TryGetText(out var currentText));
344var text = SourceText.From("public class C { }");
358Assert.False(doc.TryGetText(out var currentText));
390var actualText = await newDoc.GetTextAsync();
402var docid1 = ws.AddDocument(projid, "A.cs", SourceText.From("public class A { }")).Id;
403var docid2 = ws.AddDocument(projid, "B.cs", SourceText.From("public class B { }")).Id;
439var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
470var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
506var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
538var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
569var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
WorkspaceTests\WorkspaceTests.cs (7)
28var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
30var changedDoc = originalDoc.WithText(SourceText.From("new"));
41var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
57var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
76var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
93var originalDoc = ws.AddDocument(projectId, "TestDocument", SourceText.From(""));
150public Document AddDocument(ProjectId projectId, string name, SourceText text)
Microsoft.VisualStudio.LanguageServices (121)
ProjectSystem\VisualStudioWorkspaceImpl.AddAdditionalDocumentUndoUnit.cs (1)
18SourceText text)
ProjectSystem\VisualStudioWorkspaceImpl.AddAnalyzerConfigDocumentUndoUnit.cs (1)
17SourceText text)
ProjectSystem\VisualStudioWorkspaceImpl.cs (12)
766protected override void ApplyDocumentAdded(DocumentInfo info, SourceText text)
769protected override void ApplyAdditionalDocumentAdded(DocumentInfo info, SourceText text)
772protected override void ApplyAnalyzerConfigDocumentAdded(DocumentInfo info, SourceText text)
775private void AddDocumentCore(DocumentInfo info, SourceText initialText, TextDocumentKind documentKind)
883SourceText? initialText = null,
902SourceText? initialText = null,
922SourceText? initialText,
959var text = document.GetTextSynchronously(CancellationToken.None);
1129protected override void ApplyDocumentTextChanged(DocumentId documentId, SourceText newText)
1132protected override void ApplyAdditionalDocumentTextChanged(DocumentId documentId, SourceText newText)
1135protected override void ApplyAnalyzerConfigDocumentTextChanged(DocumentId documentId, SourceText newText)
1138private void ApplyTextDocumentChange(DocumentId documentId, SourceText newText)
Venus\ContainedDocument.cs (13)
211public void UpdateText(SourceText newText)
213var originalText = SubjectBuffer.CurrentSnapshot.AsText();
236private ITextSnapshot ApplyChanges(SourceText originalText, IEnumerable<TextChange> changes)
264private IEnumerable<TextChange> FilterTextChanges(SourceText originalText, List<TextSpan> editorVisibleSpansInOriginal, IEnumerable<TextChange> changes)
351private IEnumerable<TextChange> GetSubTextChanges(SourceText originalText, TextChange changeInOriginalText, TextSpan visibleSpanInOriginalText)
368SourceText originalText, TextSpan visibleSpanInOriginalText, string leftText, string rightText, int offsetInOriginalText, List<TextChange> changes)
402SourceText originalText, TextSpan visibleSpanInOriginalText, string leftText, string rightText, int offsetInOriginalText)
506SourceText originalText, TextSpan visibleSpanInOriginalText,
827public BaseIndentationFormattingRule GetBaseIndentationRule(SyntaxNode root, SourceText text, List<TextSpan> spans, int spanIndex)
875private static void GetVisibleAndTextSpan(SourceText text, List<TextSpan> spans, int spanIndex, out TextSpan visibleSpan, out TextSpan visibleTextSpan)
887private int GetBaseIndentation(SyntaxNode root, SourceText text, TextSpan span)
914private static TextSpan GetVisibleTextSpan(SourceText text, TextSpan visibleSpan, bool uptoFirstAndLastLine = false)
952private int GetAdditionalIndentation(SyntaxNode root, SourceText text, TextSpan span, int hostIndentationSize)
Workspace\VisualStudioDocumentNavigationService.cs (12)
71var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
89var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
107var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
156var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
162static VsTextSpan GetVsTextSpan(SourceText text, int lineNumber, int offset)
182var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
191static VsTextSpan GetVsTextSpan(SourceText text, int position, int virtualSpace)
213Func<SourceText, VsTextSpan> getVsTextSpan,
236Func<SourceText, VsTextSpan> getVsTextSpan,
296Func<SourceText, VsTextSpan> getVsTextSpan)
317var text = await document.GetTextAsync(cancellationToken).ConfigureAwait(false);
397private static VsTextSpan GetVsTextSpan(SourceText text, TextSpan textSpan, bool allowInvalidSpan)
Microsoft.VisualStudio.LanguageServices.CSharp (41)
CodeModel\CSharpCodeModelService.NodeLocator.cs (31)
34protected override VirtualTreePoint? GetStartPoint(SourceText text, LineFormattingOptions options, SyntaxNode node, EnvDTE.vsCMPart part)
85protected override VirtualTreePoint? GetEndPoint(SourceText text, LineFormattingOptions options, SyntaxNode node, EnvDTE.vsCMPart part)
136private static VirtualTreePoint GetBodyStartPoint(SourceText text, SyntaxToken openBrace)
148private static VirtualTreePoint GetBodyStartPoint(SourceText text, LineFormattingOptions options, SyntaxToken openBrace, SyntaxToken closeBrace, int memberStartColumn)
212private static VirtualTreePoint GetBodyEndPoint(SourceText text, SyntaxToken closeBrace)
222private static VirtualTreePoint GetStartPoint(SourceText text, ArrowExpressionClauseSyntax node, EnvDTE.vsCMPart part)
243private static VirtualTreePoint GetStartPoint(SourceText text, AttributeSyntax node, EnvDTE.vsCMPart part)
276private static VirtualTreePoint GetStartPoint(SourceText text, AttributeArgumentSyntax node, EnvDTE.vsCMPart part)
306private static VirtualTreePoint GetStartPoint(SourceText text, BaseTypeDeclarationSyntax node, EnvDTE.vsCMPart part)
354private static VirtualTreePoint GetStartPoint(SourceText text, LineFormattingOptions options, BaseMethodDeclarationSyntax node, EnvDTE.vsCMPart part)
443private static VirtualTreePoint GetStartPoint(SourceText text, LineFormattingOptions options, BasePropertyDeclarationSyntax node, EnvDTE.vsCMPart part)
508private static VirtualTreePoint GetStartPoint(SourceText text, LineFormattingOptions options, AccessorDeclarationSyntax node, EnvDTE.vsCMPart part)
557private static VirtualTreePoint GetStartPoint(SourceText text, BaseNamespaceDeclarationSyntax node, EnvDTE.vsCMPart part)
606private static VirtualTreePoint GetStartPoint(SourceText text, DelegateDeclarationSyntax node, EnvDTE.vsCMPart part)
646private static VirtualTreePoint GetStartPoint(SourceText text, UsingDirectiveSyntax node, EnvDTE.vsCMPart part)
679private static VirtualTreePoint GetStartPoint(SourceText text, VariableDeclaratorSyntax node, EnvDTE.vsCMPart part)
720private static VirtualTreePoint GetStartPoint(SourceText text, EnumMemberDeclarationSyntax node, EnvDTE.vsCMPart part)
760private static VirtualTreePoint GetStartPoint(SourceText text, ParameterSyntax node, EnvDTE.vsCMPart part)
800private static VirtualTreePoint GetEndPoint(SourceText text, ArrowExpressionClauseSyntax node, EnvDTE.vsCMPart part)
818private static VirtualTreePoint GetEndPoint(SourceText text, AttributeSyntax node, EnvDTE.vsCMPart part)
851private static VirtualTreePoint GetEndPoint(SourceText text, AttributeArgumentSyntax node, EnvDTE.vsCMPart part)
881private static VirtualTreePoint GetEndPoint(SourceText text, BaseTypeDeclarationSyntax node, EnvDTE.vsCMPart part)
922private static VirtualTreePoint GetEndPoint(SourceText text, BaseMethodDeclarationSyntax node, EnvDTE.vsCMPart part)
996private static VirtualTreePoint GetEndPoint(SourceText text, BasePropertyDeclarationSyntax node, EnvDTE.vsCMPart part)
1056private static VirtualTreePoint GetEndPoint(SourceText text, AccessorDeclarationSyntax node, EnvDTE.vsCMPart part)
1095private static VirtualTreePoint GetEndPoint(SourceText text, DelegateDeclarationSyntax node, EnvDTE.vsCMPart part)
1136private static VirtualTreePoint GetEndPoint(SourceText text, BaseNamespaceDeclarationSyntax node, EnvDTE.vsCMPart part)
1185private static VirtualTreePoint GetEndPoint(SourceText text, UsingDirectiveSyntax node, EnvDTE.vsCMPart part)
1218private static VirtualTreePoint GetEndPoint(SourceText text, EnumMemberDeclarationSyntax node, EnvDTE.vsCMPart part)
1259private static VirtualTreePoint GetEndPoint(SourceText text, VariableDeclaratorSyntax node, EnvDTE.vsCMPart part)
1301private static VirtualTreePoint GetEndPoint(SourceText text, ParameterSyntax node, EnvDTE.vsCMPart part)
Microsoft.VisualStudio.LanguageServices.CSharp.UnitTests (8)
Microsoft.VisualStudio.LanguageServices.Implementation (7)
Microsoft.VisualStudio.LanguageServices.LiveShare (7)
Microsoft.VisualStudio.LanguageServices.Test.Utilities2 (1)
Microsoft.VisualStudio.LanguageServices.UnitTests (5)
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 (15)
Roslyn.VisualStudio.DiagnosticsWindow (3)
Roslyn.VisualStudio.Next.UnitTests (39)
Remote\SnapshotSerializationTests.cs (14)
59var document1 = project1.AddDocument("Document1", SourceText.From(csCode));
63var document2 = project2.AddDocument("Document2", SourceText.From(vbCode));
69.AddAdditionalDocument("Additional", SourceText.From("hello"), ImmutableArray.Create("test"), @".\Add").Project.Solution;
78loader: TextLoader.From(TextAndVersion.Create(SourceText.From("root = true"), VersionStamp.Create())))));
159var document = workspace.CurrentSolution.AddProject("Project", "Project.dll", LanguageNames.CSharp).AddDocument("Document", SourceText.From(code));
182var document = solution.AddProject("Project", "Project.dll", LanguageNames.CSharp).AddDocument("Document", SourceText.From(code));
531var document = CreateWorkspace().CurrentSolution.AddProject("empty", "empty", LanguageNames.CSharp).AddDocument("empty", SourceText.From(""));
605var sourceText = SourceText.From("Hello", Encoding.UTF8);
619var newText = serializer.Deserialize<SourceText>(sourceText.GetWellKnownSynchronizationKind(), objectReader, CancellationToken.None);
624sourceText = SourceText.From("Hello", new NotSerializableEncoding());
638var newText = serializer.Deserialize<SourceText>(sourceText.GetWellKnownSynchronizationKind(), objectReader, CancellationToken.None);
Services\SolutionServiceTests.cs (15)
156await VerifySolutionUpdate(code, s => s.WithDocumentText(s.Projects.First().DocumentIds.First(), SourceText.From(code + " ")));
227project = project.AddDocument("newDocument", SourceText.From("// new text")).Project;
247loader: TextLoader.From(TextAndVersion.Create(SourceText.From("test"), VersionStamp.Create())));
258return s.WithAdditionalDocumentText(additionalDocumentId, SourceText.From("changed"));
279loader: TextLoader.From(TextAndVersion.Create(SourceText.From("root = true"), VersionStamp.Create(), filePath: configPath)),
291return s.WithAnalyzerConfigDocumentText(analyzerConfigDocumentId, SourceText.From("root = false"));
311loader: TextLoader.From(TextAndVersion.Create(SourceText.From("class A { }"), VersionStamp.Create())));
322return s.WithDocumentText(documentId, SourceText.From("class Changed { }"));
370remoteSolution = remoteSolution.WithDocumentText(remoteSolution.Projects.First().Documents.First().Id, SourceText.From(code + " class Test2 { }"));
396var currentSolution = remoteSolution1.WithDocumentText(remoteSolution1.Projects.First().Documents.First().Id, SourceText.From(code + " class Test2 { }"));
405currentSolution = oopSolution2.WithDocumentText(oopSolution2.Projects.First().Documents.First().Id, SourceText.From(code + " class Test3 { }"));
500var frozenText1 = SourceText.From("// Hello, World!");
509var frozenText2 = SourceText.From("// Hello, World! A second time!");
StackDepthTest (1)