1167 instantiations of TextSpan
AnalyzerRunner (1)
CSharpSyntaxGenerator (1)
IdeBenchmarks (2)
IdeCoreBenchmarks (5)
Microsoft.Analyzers.Extra.Tests (1)
Microsoft.Analyzers.Local.Tests (1)
Microsoft.AspNetCore.App.Analyzers (20)
Infrastructure\VirtualChars\CSharpVirtualCharService.cs (6)
295charResults.Add((ch, new TextSpan(offset + index, 1)));
389result.Add((ch, new TextSpan(offset + index, 2)));
456result.Add(((char)uintChar, new TextSpan(startIndex + offset, 2 + 8)));
467result.Add(((char)highSurrogate, new TextSpan(pos, 0)));
468result.Add(((char)lowSurrogate, new TextSpan(pos, 2 + 8)));
496result.Add((character, new TextSpan(startIndex + offset, 2 + 4)));
Microsoft.AspNetCore.App.Analyzers.Test (1)
Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation.Test (3)
Microsoft.CodeAnalysis (40)
Syntax\SyntaxDiffer.cs (7)
45return new[] { new TextChange(new TextSpan(0, 0), after.GetText().ToString()) };
81return new[] { new TextSpan(0, after!.GetText().Length) };
112newSpans.Add(new TextSpan(start, change.Range.NewLength));
569RecordChange(new ChangeRecord(new TextChangeRange(new TextSpan(start, 0), newSpan.Length), null, insertedNodes));
581new TextChangeRange(new TextSpan(last.Range.Span.Start, last.Range.Span.Length + change.Range.Span.Length), last.Range.NewLength + change.Range.NewLength),
604new TextChangeRange(new TextSpan(last.Range.Span.Start, last.Range.Span.Length + textChangeRange.Span.Length), last.Range.NewLength + textChangeRange.NewLength),
763new TextSpan(range.Span.Start + commonLeadingCount, range.Span.Length - (commonLeadingCount + commonTrailingCount)),
Text\SourceText.cs (8)
534return this.GetSubText(new TextSpan(start, this.Length - start));
543this.Write(textWriter, new TextSpan(0, this.Length), cancellationToken);
710return ToString(new TextSpan(0, this.Length));
798var subText = this.GetSubText(new TextSpan(position, change.Span.Start - position));
821var subText = this.GetSubText(new TextSpan(position, this.Length - position));
869return this.Replace(new TextSpan(start, length), newText);
890return ImmutableArray.Create(new TextChangeRange(new TextSpan(0, oldText.Length), this.Length));
914var span = new TextSpan(newPos, range.NewLength);
Text\TextChangeRangeExtensions.cs (4)
225addAndAdjustOldDelta(builder, ref oldDelta, new TextChangeRange(new TextSpan(oldChange.Span.Start, oldChangeLeadingDeletion), oldChangeLeadingInsertion));
226oldChange = new TextChangeRange(new TextSpan(newChange.SpanStart - oldDelta, oldChange.Span.Length - oldChangeLeadingDeletion), oldChange.NewLength - oldChangeLeadingInsertion);
380add(builder, new TextChangeRange(new TextSpan(newChange.SpanStart - oldDelta, newChange.SpanLength), newChange.NewLength));
391builder[^1] = new TextChangeRange(new TextSpan(last.Span.Start, last.Span.Length + change.Span.Length), last.NewLength + change.NewLength);
Microsoft.CodeAnalysis.CodeStyle (39)
src\Analyzers\Core\Analyzers\ValidateFormatString\AbstractValidateFormatStringDiagnosticAnalyzer.cs (1)
354new Text.TextSpan(
src\Compilers\Core\Portable\Text\TextChangeRangeExtensions.cs (4)
225addAndAdjustOldDelta(builder, ref oldDelta, new TextChangeRange(new TextSpan(oldChange.Span.Start, oldChangeLeadingDeletion), oldChangeLeadingInsertion));
226oldChange = new TextChangeRange(new TextSpan(newChange.SpanStart - oldDelta, oldChange.Span.Length - oldChangeLeadingDeletion), oldChange.NewLength - oldChangeLeadingInsertion);
380add(builder, new TextChangeRange(new TextSpan(newChange.SpanStart - oldDelta, newChange.SpanLength), newChange.NewLength));
391builder[^1] = new TextChangeRange(new TextSpan(last.Span.Start, last.Span.Length + change.Span.Length), last.NewLength + change.NewLength);
Microsoft.CodeAnalysis.CodeStyle.Fixes (3)
Microsoft.CodeAnalysis.CSharp (11)
Microsoft.CodeAnalysis.CSharp.CodeStyle (6)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\EmbeddedLanguages\VirtualChars\CSharpVirtualCharService.cs (6)
278charResults.Add((ch, new TextSpan(offset + index, 1)));
382result.Add((ch, new TextSpan(offset + index, 2)));
449result.Add(((char)uintChar, new TextSpan(startIndex + offset, 2 + 8)));
460result.Add(((char)highSurrogate, new TextSpan(pos, 0)));
461result.Add(((char)lowSurrogate, new TextSpan(pos, 2 + 8)));
489result.Add((character, new TextSpan(startIndex + offset, 2 + 4)));
Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes (5)
Microsoft.CodeAnalysis.CSharp.CommandLine.UnitTests (1)
Microsoft.CodeAnalysis.CSharp.EditorFeatures (7)
Microsoft.CodeAnalysis.CSharp.EditorFeatures.UnitTests (44)
Classification\SyntacticClassifierTests.cs (29)
6052var classifications = await GetSyntacticClassificationsAsync(document, [new TextSpan(0, source.Length)]);
6055new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(0, 3)),
6056new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentText, new TextSpan(3, 1)),
6057new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(4, 1)),
6058new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentName, new TextSpan(5, 5)),
6059new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentAttributeName, new TextSpan(11, 4)),
6060new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(15, 1)),
6061new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentAttributeQuotes, new TextSpan(16, 1)),
6062new ClassifiedSpan(ClassificationTypeNames.Identifier, new TextSpan(17, 5)),
6063new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentAttributeQuotes, new TextSpan(22, 1)),
6064new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(23, 1)),
6065new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(24, 2)),
6066new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentName, new TextSpan(26, 5)),
6067new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(31, 1))
6082var classifications = await GetSyntacticClassificationsAsync(document, [new TextSpan(0, source.Length)]);
6085new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(2, 3)),
6086new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentText, new TextSpan(5, 1)),
6087new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(6, 1)),
6088new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentName, new TextSpan(7, 5)),
6089new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(14, 3)),
6090new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentAttributeName, new TextSpan(18, 4)),
6091new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(22, 1)),
6092new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentAttributeQuotes, new TextSpan(23, 1)),
6093new ClassifiedSpan(ClassificationTypeNames.Identifier, new TextSpan(24, 5)),
6094new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentAttributeQuotes, new TextSpan(29, 1)),
6095new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(30, 1)),
6096new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(31, 2)),
6097new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentName, new TextSpan(33, 5)),
6098new ClassifiedSpan(ClassificationTypeNames.XmlDocCommentDelimiter, new TextSpan(38, 1))
Diagnostics\DiagnosticAnalyzerDriver\DiagnosticAnalyzerDriverTests.cs (5)
65await DiagnosticProviderTestUtilities.GetAllDiagnosticsAsync(workspace, document, new TextSpan(0, document.GetTextAsync().Result.Length));
93await DiagnosticProviderTestUtilities.GetAllDiagnosticsAsync(ideEngineWorkspace, ideEngineDocument, new TextSpan(0, ideEngineDocument.GetTextAsync().Result.Length));
175await DiagnosticProviderTestUtilities.GetAllDiagnosticsAsync(workspace, sourceDocument, new TextSpan(0, sourceDocument.GetTextAsync().Result.Length));
205var diagnostics = await DiagnosticProviderTestUtilities.GetAllDiagnosticsAsync(workspace, ideEngineDocument, new TextSpan(0, ideEngineDocument.GetTextAsync().Result.Length));
261var diagnostics = await DiagnosticProviderTestUtilities.GetAllDiagnosticsAsync(ideEngineWorkspace, ideEngineDocument, new TextSpan(0, ideEngineDocument.GetTextAsync().Result.Length));
NavigateTo\NavigateToSearcherTests.cs (5)
124var results = ImmutableArray.Create<INavigateToSearchResult>(new TestNavigateToSearchResult(workspace, new TextSpan(0, 0)));
159var results = ImmutableArray.Create<INavigateToSearchResult>(new TestNavigateToSearchResult(workspace, new TextSpan(0, 0)));
236var results = ImmutableArray.Create<INavigateToSearchResult>(new TestNavigateToSearchResult(workspace, new TextSpan(0, 0)));
272var results = ImmutableArray.Create<INavigateToSearchResult>(new TestNavigateToSearchResult(workspace, new TextSpan(0, 0)));
320var results = ImmutableArray.Create<INavigateToSearchResult>(new TestNavigateToSearchResult(workspace, new TextSpan(0, 0)));
Microsoft.CodeAnalysis.CSharp.Emit.UnitTests (7)
CodeGen\CodeGenTupleTest.cs (7)
5799var loc1 = Location.Create(tree, new TextSpan(0, 1));
5910var loc1 = Location.Create(tree, new TextSpan(0, 1));
5911var loc2 = Location.Create(tree, new TextSpan(1, 1));
6351var loc1 = Location.Create(syntaxTree, new TextSpan(0, 1));
6387var loc1 = Location.Create(syntaxTree, new TextSpan(0, 1));
6388var loc2 = Location.Create(syntaxTree, new TextSpan(1, 1));
22617var newText = text.WithChanges(new TextChange(new TextSpan(pos, 0), " ")); // add space before closing-paren
Microsoft.CodeAnalysis.CSharp.Emit3.UnitTests (4)
Microsoft.CodeAnalysis.CSharp.Features (26)
Microsoft.CodeAnalysis.CSharp.Features.UnitTests (2)
Microsoft.CodeAnalysis.CSharp.Semantic.UnitTests (3)
Microsoft.CodeAnalysis.CSharp.Symbol.UnitTests (6)
Microsoft.CodeAnalysis.CSharp.Syntax.UnitTests (157)
Diagnostics\DiagnosticTest.cs (7)
83Location l1 = new SourceLocation(syntaxTree, new TextSpan(5, 8));
87Assert.Equal(new TextSpan(5, 8), d1.Location.SourceSpan);
98DiagnosticInfo di3 = new CustomErrorInfo(provider, "OtherSymbol", new SourceLocation(syntaxTree, new TextSpan(14, 8)));
99var d3 = new CSDiagnostic(di3, new SourceLocation(syntaxTree, new TextSpan(1, 1)));
101Assert.Equal(new TextSpan(1, 1), d3.Location.SourceSpan);
103Assert.Equal(new TextSpan(14, 8), d3.AdditionalLocations.First().SourceSpan);
2412return new TextSpan(index, textToFind.Length);
Diagnostics\LocationsTests.cs (11)
71return new TextSpan(index, textToFind.Length);
89TextSpan xSpan = new TextSpan(sampleProgram.IndexOf("x;", StringComparison.Ordinal), 2);
90TextSpan xToCloseBraceSpan = new TextSpan(xSpan.Start, sampleProgram.IndexOf('}') - xSpan.Start + 1);
429SourceLocation loc1 = new SourceLocation(syntaxTree, new TextSpan(3, 4));
430SourceLocation loc2 = new SourceLocation(syntaxTree, new TextSpan(3, 4));
431SourceLocation loc3 = new SourceLocation(syntaxTree, new TextSpan(3, 7));
432SourceLocation loc4 = new SourceLocation(tree2, new TextSpan(3, 4));
490TextSpan span1 = new TextSpan(sampleProgram.IndexOf("i;", StringComparison.Ordinal), 2);
491TextSpan span2 = new TextSpan(sampleProgram.IndexOf("c;", StringComparison.Ordinal), 2);
504Location location = Location.Create("test.txt", new TextSpan(), new LinePositionSpan(new LinePosition(2, 1), new LinePosition(3, 1)));
514var sourceSpan = new TextSpan();
IncrementalParsing\IncrementalParsingTests.cs (46)
496var span = new TextSpan(source.IndexOf("]") + 1, length: 1);
528var span = new TextSpan(source.IndexOf("."), length: 1);
573var prefixSpan = new TextSpan(source.IndexOf(prefix), length: prefix.Length);
574var suffixSpan = new TextSpan(source.IndexOf(suffix), length: suffix.Length);
965var newText = text.WithChanges(new TextChange(new TextSpan(0, 8), ""));
979var newText = text.WithChanges(new TextChange(new TextSpan(0, 8), ""));
2748new TextChange(new TextSpan(str.IndexOf(" abc", StringComparison.Ordinal), 0), "//"),
2749new TextChange(new TextSpan(str.IndexOf(" 123", StringComparison.Ordinal), 0), "//"),
2750new TextChange(new TextSpan(str.IndexOf(" def", StringComparison.Ordinal), 0), "//"));
2770var newText = oldText.WithChanges(new TextChange(new TextSpan(0, 0), "{"));
2786var newText = oldText.WithChanges(new TextChange(new TextSpan(0, 0), @"System.Console.WriteLine(false)
2845var newText = oldText.WithChanges(new TextChange(new TextSpan(0, 0), @"if (false)
2900var span = new TextSpan(oldIText.Length, 0);
2914span = new TextSpan(oldIText.Length, 0);
2983var span = new TextSpan(currLen, 0);
3020var span = new TextSpan(text.LastIndexOf('x'), 0);
3100var change = new TextChange(new TextSpan(0, 0), items[1]); // Prepend
3198var span = new TextSpan(source.IndexOf(" A[]?"), 0);
3219var span = new TextSpan(src.IndexOf(":"), 1);
3240var span = new TextSpan(source.IndexOf(";"), 0);
3261var span = new TextSpan(source.IndexOf(";") + 1, 0);
3282var span = new TextSpan(source.IndexOf(";") + 1, 0);
3304var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3328var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3352var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3376var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3400var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3424var span = new TextSpan(source.IndexOf(substring) + substring.Length, 1);
3450var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3475var span = new TextSpan(source.IndexOf(substring), 0);
3501var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3527var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3545var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3563var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3581var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3595var span = new TextSpan(start: 0, length: 1); // delete first character
3609var span = new TextSpan(start: 0, length: 0);
3624var span = new TextSpan(start: source.IndexOf(substring), length: 3); // Goo[Goo] -> [Goo]
3661var span = new TextSpan(start: source.IndexOf(":") + 1, length: 0);
3688new TextChange(new TextSpan(position1, 0), "n"),
3689new TextChange(new TextSpan(position2, 0), "n"),
3690new TextChange(new TextSpan(position3, 0), "n"));
3728new TextChange(new TextSpan(locationOfChange, 0), "/*"),
3729new TextChange(new TextSpan(locationOfChange + widthOfChange, 0), "*/")
3738var newText = oldText.WithChanges(new TextChange(new TextSpan(locationOfChange, widthOfChange), ""));
3764var newText = oldText.WithChanges(new TextChange(new TextSpan(oldText.Length, 0), newChar.ToString()));
LexicalAndXml\SyntaxTokenParserTests.cs (50)
39AssertToken(expectedKind: SyntaxKind.ClassKeyword, expectedContextualKind: SyntaxKind.None, new TextSpan(0, 22), """
44AssertToken(expectedKind: SyntaxKind.IdentifierToken, expectedContextualKind: SyntaxKind.None, new TextSpan(22, 3), """
49AssertToken(expectedKind: SyntaxKind.OpenBraceToken, expectedContextualKind: SyntaxKind.None, new TextSpan(25, 3), """
54AssertToken(expectedKind: SyntaxKind.CloseBraceToken, expectedContextualKind: SyntaxKind.None, new TextSpan(28, 3), """
59AssertToken(expectedKind: SyntaxKind.EndOfFileToken, expectedContextualKind: SyntaxKind.None, new TextSpan(31, 0), "", parser.ParseNextToken());
60AssertToken(expectedKind: SyntaxKind.EndOfFileToken, expectedContextualKind: SyntaxKind.None, new TextSpan(31, 0), "", parser.ParseNextToken());
78AssertToken(expectedKind: SyntaxKind.ClassKeyword, expectedContextualKind: SyntaxKind.None, new TextSpan(0, 54), """
89AssertToken(expectedKind: SyntaxKind.IdentifierToken, expectedContextualKind: SyntaxKind.None, new TextSpan(54, 3), """
94AssertToken(expectedKind: SyntaxKind.OpenBraceToken, expectedContextualKind: SyntaxKind.None, new TextSpan(57, 3), """
99AssertToken(expectedKind: SyntaxKind.CloseBraceToken, expectedContextualKind: SyntaxKind.None, new TextSpan(60, 3), """
104AssertToken(expectedKind: SyntaxKind.EndOfFileToken, expectedContextualKind: SyntaxKind.None, new TextSpan(63, 0), "", parser.ParseNextToken());
121AssertToken(expectedKind: SyntaxKind.ClassKeyword, expectedContextualKind: SyntaxKind.None, new TextSpan(0, 16), """
126AssertToken(expectedKind: SyntaxKind.IdentifierToken, expectedContextualKind: SyntaxKind.None, new TextSpan(16, 3), """
131AssertToken(expectedKind: SyntaxKind.OpenBraceToken, expectedContextualKind: SyntaxKind.None, new TextSpan(19, 3), """
136AssertToken(expectedKind: SyntaxKind.EndOfFileToken, expectedContextualKind: SyntaxKind.None, new TextSpan(22, 18), """
143AssertToken(expectedKind: SyntaxKind.EndOfFileToken, expectedContextualKind: SyntaxKind.None, new TextSpan(40, 0), "", parser.ParseNextToken());
162AssertToken(expectedKind: SyntaxKind.ClassKeyword, expectedContextualKind: SyntaxKind.None, new TextSpan(18, 22), """
169AssertToken(expectedKind: SyntaxKind.OpenBraceToken, expectedContextualKind: SyntaxKind.None, new TextSpan(43, 3), """
174AssertToken(expectedKind: SyntaxKind.CloseBraceToken, expectedContextualKind: SyntaxKind.None, new TextSpan(46, 3), """
187AssertToken(expectedKind: SyntaxKind.IdentifierToken, expectedContextualKind: SyntaxKind.None, new TextSpan(1, 4), """lass""", parser.ParseNextToken());
196AssertToken(expectedKind: SyntaxKind.EndOfFileToken, expectedContextualKind: SyntaxKind.None, new TextSpan(100, 0), "", parser.ParseNextToken());
205AssertToken(expectedKind: SyntaxKind.ClassKeyword, expectedContextualKind: SyntaxKind.None, new TextSpan(0, 6), "class ", parser.ParseNextToken());
223AssertToken(expectedKind: SyntaxKind.ClassKeyword, expectedContextualKind: SyntaxKind.None, new TextSpan(0, 16), """
229AssertToken(expectedKind: SyntaxKind.IdentifierToken, expectedContextualKind: SyntaxKind.None, new TextSpan(16, 3), """
244AssertToken(expectedKind: SyntaxKind.OpenBraceToken, expectedContextualKind: SyntaxKind.None, new TextSpan(19, 3), """
249AssertToken(expectedKind: SyntaxKind.EndOfFileToken, expectedContextualKind: SyntaxKind.None, new TextSpan(22, 18), """
264AssertToken(expectedKind: SyntaxKind.IdentifierToken, expectedContextualKind: SyntaxKind.WhenKeyword, new TextSpan(0, 5), "when ", parser.ParseNextToken());
265AssertToken(expectedKind: SyntaxKind.IdentifierToken, expectedContextualKind: SyntaxKind.None, new TextSpan(5, 11), "identifier ", parser.ParseNextToken());
266AssertToken(expectedKind: SyntaxKind.ClassKeyword, expectedContextualKind: SyntaxKind.None, new TextSpan(16, 5), "class", parser.ParseNextToken());
276AssertToken(expectedKind: SyntaxKind.None, expectedContextualKind: SyntaxKind.None, new TextSpan(0, 0), "", result);
281AssertToken(expectedKind: SyntaxKind.None, expectedContextualKind: SyntaxKind.None, new TextSpan(0, 0), "", result);
285AssertToken(expectedKind: SyntaxKind.ClassKeyword, expectedContextualKind: SyntaxKind.None, new TextSpan(0, 6), "class ", parser.ParseNextToken());
295AssertToken(expectedKind: SyntaxKind.None, expectedContextualKind: SyntaxKind.None, new TextSpan(0, 11), "/* test */ ", result);
302AssertToken(expectedKind: SyntaxKind.None, expectedContextualKind: SyntaxKind.None, new TextSpan(11, 0), "", intermediateResult);
307AssertToken(expectedKind: SyntaxKind.None, expectedContextualKind: SyntaxKind.None, new TextSpan(11, 0), "", intermediateResult);
311AssertToken(expectedKind: SyntaxKind.ClassKeyword, expectedContextualKind: SyntaxKind.None, new TextSpan(11, 6), "class ", parser.ParseNextToken());
314AssertToken(expectedKind: SyntaxKind.ClassKeyword, expectedContextualKind: SyntaxKind.None, new TextSpan(0, 17), "/* test */ class ", parser.ParseNextToken());
328AssertToken(expectedKind: SyntaxKind.None, expectedContextualKind: SyntaxKind.None, new TextSpan(0, 14), $"/* test */\r\n\r\n", result);
336AssertToken(expectedKind: SyntaxKind.None, expectedContextualKind: SyntaxKind.None, new TextSpan(14, 0), "", intermediateResult);
341AssertToken(expectedKind: SyntaxKind.None, expectedContextualKind: SyntaxKind.None, new TextSpan(14, 0), "", intermediateResult);
345AssertToken(expectedKind: SyntaxKind.ClassKeyword, expectedContextualKind: SyntaxKind.None, new TextSpan(14, 6), "class ", parser.ParseNextToken());
348AssertToken(expectedKind: SyntaxKind.ClassKeyword, expectedContextualKind: SyntaxKind.None, new TextSpan(0, 20), "/* test */\r\n\r\nclass ", parser.ParseNextToken());
358AssertToken(expectedKind: SyntaxKind.None, expectedContextualKind: SyntaxKind.None, new TextSpan(0, 0), "", result);
362AssertToken(expectedKind: SyntaxKind.ClassKeyword, expectedContextualKind: SyntaxKind.None, new TextSpan(0, 6), "class ", parser.ParseNextToken());
372AssertToken(expectedKind: SyntaxKind.None, expectedContextualKind: SyntaxKind.None, new TextSpan(0, 11), "/* test */ ", result);
378AssertToken(expectedKind: SyntaxKind.ClassKeyword, expectedContextualKind: SyntaxKind.None, new TextSpan(11, 6), "class ", parser.ParseNextToken());
381AssertToken(expectedKind: SyntaxKind.ClassKeyword, expectedContextualKind: SyntaxKind.None, new TextSpan(0, 17), "/* test */ class ", parser.ParseNextToken());
395AssertToken(expectedKind: SyntaxKind.None, expectedContextualKind: SyntaxKind.None, new TextSpan(0, 12), $"/* test */\r\n", result);
401AssertToken(expectedKind: SyntaxKind.ClassKeyword, expectedContextualKind: SyntaxKind.None, new TextSpan(12, 8), "\r\nclass ", parser.ParseNextToken());
404AssertToken(expectedKind: SyntaxKind.ClassKeyword, expectedContextualKind: SyntaxKind.None, new TextSpan(0, 20), "/* test */\r\n\r\nclass ", parser.ParseNextToken());
Syntax\SyntaxDiffingTests.cs (23)
33Assert.Equal(new TextSpan(0, 0), changes[0].Span);
53Assert.Equal(new TextSpan(6, 1), changes[0].Span);
75Assert.Equal(new TextSpan(6, 1), changes[0].Span);
77Assert.Equal(new TextSpan(18, 1), changes[1].Span);
90Assert.Equal(new TextSpan(0, 6), spans[0]);
95Assert.Equal(new TextSpan(0, 0), changes[0].Span);
108Assert.Equal(new TextSpan(0, 8), spans[0]);
113Assert.Equal(new TextSpan(0, 0), changes[0].Span);
127Assert.Equal(new TextSpan(11, 11), spans[0]); // its going to pick one of the two spans.
132Assert.Equal(new TextSpan(11, 0), changes[0].Span);
147Assert.Equal(new TextSpan(10, 12), spans[0]);
152Assert.Equal(new TextSpan(10, 0), changes[0].Span);
165Assert.Equal(new TextSpan(0, 14), spans[0]);
170Assert.Equal(new TextSpan(0, 0), changes[0].Span);
183Assert.Equal(new TextSpan(10, 7), spans[0]); // int X;
188Assert.Equal(new TextSpan(10, 0), changes[0].Span);
205Assert.Equal(new TextSpan(10, 7), changes[0].Span);
222Assert.Equal(new TextSpan(24, 7), changes[0].Span);
239Assert.Equal(new TextSpan(14, 1), changes[0].Span);
252Assert.Equal(new TextSpan(14, 6), spans[0]); // 'struct'
257Assert.Equal(new TextSpan(14, 5), changes[0].Span);
307var span = new TextSpan(index, 4);
372var span = new TextSpan(index, 6);
Syntax\SyntaxNodeTests.cs (13)
578var tokens = t1.GetCompilationUnitRoot().DescendantTokens(new TextSpan(0, 16)).ToList();
590var tokens = t1.GetCompilationUnitRoot().DescendantTokens(new TextSpan(1, 14)).ToList();
602var tokens = t1.GetCompilationUnitRoot().DescendantTokens(new TextSpan(7, 17)).ToList();
615var tokens = t1.GetCompilationUnitRoot().DescendantTokens(new TextSpan(8, 15)).ToList();
664var node = t1.GetCompilationUnitRoot().DescendantTokens(new TextSpan(6, 3)).First();
745var EOFSpan = new TextSpan(root.FullSpan.End, 0);
754var nodeEndPositionSpan = new TextSpan(classDecl.FullSpan.End, 0);
764var invalidSpan = new TextSpan(100, 100);
766invalidSpan = new TextSpan(root.FullSpan.End - 1, 2);
768invalidSpan = new TextSpan(classDecl2.FullSpan.Start - 1, root.FullSpan.End);
770invalidSpan = new TextSpan(classDecl.FullSpan.End, root.FullSpan.End);
920var tree2 = tree1.WithChangedText(tree1.GetText().WithChanges(new TextChange(new TextSpan(22, 0), " return; ")));
2092var textSpan = new TextSpan(5, 10);
Microsoft.CodeAnalysis.CSharp.Test.Utilities (2)
Microsoft.CodeAnalysis.CSharp.Workspaces (9)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\EmbeddedLanguages\VirtualChars\CSharpVirtualCharService.cs (6)
278charResults.Add((ch, new TextSpan(offset + index, 1)));
382result.Add((ch, new TextSpan(offset + index, 2)));
449result.Add(((char)uintChar, new TextSpan(startIndex + offset, 2 + 8)));
460result.Add(((char)highSurrogate, new TextSpan(pos, 0)));
461result.Add(((char)lowSurrogate, new TextSpan(pos, 2 + 8)));
489result.Add((character, new TextSpan(startIndex + offset, 2 + 4)));
Microsoft.CodeAnalysis.CSharp.Workspaces.UnitTests (2)
Formatting\CSharpFormattingTestBase.cs (2)
29return AssertFormatAsync(code, code, [new TextSpan(0, code.Length)], changedOptionSet, testWithTransformation, parseOptions);
39return AssertFormatAsync(expected, code, [new TextSpan(0, code.Length)], changedOptionSet, testWithTransformation, parseOptions);
Microsoft.CodeAnalysis.EditorFeatures (13)
EditorConfigSettings\Updater\SettingsUpdateHelper.cs (3)
306return (editorConfigText.WithChanges(new TextChange(new TextSpan(lastValidSpecificHeaderSpanEnd.Value.Span.End, 0), newEntry)), lastValidHeaderSpanEnd, lastValidSpecificHeaderSpanEnd);
315return (editorConfigText.WithChanges(new TextChange(new TextSpan(lastValidHeaderSpanEnd.Value.Span.End, 0), newEntry)), lastValidHeaderSpanEnd, lastValidSpecificHeaderSpanEnd);
349var result = editorConfigText.WithChanges(new TextChange(new TextSpan(editorConfigText.Length, 0), prefix + newEntry));
Microsoft.CodeAnalysis.EditorFeatures.Test.Utilities (19)
BraceHighlighting\MultiCharacterBraceHighlightingTests.cs (8)
59return new BraceMatchingResult(new TextSpan(position, 2), new TextSpan(secondAt, 2));
68return new BraceMatchingResult(new TextSpan(position - 1, 2), new TextSpan(secondAt, 2));
74return new BraceMatchingResult(new TextSpan(lessThan, 2), new TextSpan(position, 2));
83return new BraceMatchingResult(new TextSpan(lessThan, 2), new TextSpan(position - 1, 2));
Microsoft.CodeAnalysis.EditorFeatures.Text (6)
Microsoft.CodeAnalysis.EditorFeatures.UnitTests (106)
CommentSelection\CommentUncommentSelectionCommandHandlerTests.cs (78)
103new TextChange(new TextSpan(8, 0), "/*"),
104new TextChange(new TextSpan(14, 0), "*/"),
117new TextChange(new TextSpan(0, 0), "//"),
118new TextChange(new TextSpan(16, 0), "//"),
145new TextChange(new TextSpan(20, 0), "//"),
146new TextChange(new TextSpan(34, 0), "//"),
147new TextChange(new TextSpan(41, 0), "//"),
171new TextChange(new TextSpan(0, 0), "//"),
172new TextChange(new TextSpan(9, 0), "//"),
173new TextChange(new TextSpan(12, 0), "//"),
174new TextChange(new TextSpan(30, 0), "//"),
185new TextChange(new TextSpan(0, 0), "//"),
186new TextChange(new TextSpan(11, 0), "//"),
187new TextChange(new TextSpan(16, 0), "//"),
188new TextChange(new TextSpan(36, 0), "//"),
211new TextChange(new TextSpan(20, 0), "//"),
212new TextChange(new TextSpan(34, 0), "//"),
213new TextChange(new TextSpan(41, 0), "//"),
232new TextChange(new TextSpan(20, 0), "//"),
233new TextChange(new TextSpan(34, 0), "//"),
234new TextChange(new TextSpan(41, 0), "//"),
254new TextChange(new TextSpan(20, 0), "//"),
255new TextChange(new TextSpan(34, 0), "//"),
256new TextChange(new TextSpan(41, 0), "//"),
277new TextChange(new TextSpan(20, 0), "/*"),
278new TextChange(new TextSpan(21, 0), "*/"),
279new TextChange(new TextSpan(34, 0), "//"),
280new TextChange(new TextSpan(41, 0), "/*"),
281new TextChange(new TextSpan(42, 0), "*/"),
282new TextChange(new TextSpan(52, 0), "//"),
302new TextChange(new TextSpan(20, 0), "//"),
303new TextChange(new TextSpan(34, 0), "//"),
304new TextChange(new TextSpan(41, 0), "//"),
313UncommentSelection(code, new[] { new TextChange(new TextSpan(0, 2), string.Empty) }, Span.FromBounds(0, 6), supportBlockComments: true);
322new TextChange(new TextSpan(7, 2), string.Empty),
323new TextChange(new TextSpan(30, 2), string.Empty),
335new TextChange(new TextSpan(11, 2), string.Empty),
336new TextChange(new TextSpan(34, 2), string.Empty),
359new TextChange(new TextSpan(18, 2), string.Empty),
360new TextChange(new TextSpan(34, 2), string.Empty),
361new TextChange(new TextSpan(47, 2), string.Empty),
362new TextChange(new TextSpan(68, 2), string.Empty),
363new TextChange(new TextSpan(119, 2), string.Empty),
364new TextChange(new TextSpan(128, 2), string.Empty),
385new TextChange(new TextSpan(20, 2), string.Empty),
386new TextChange(new TextSpan(23, 2), string.Empty),
387new TextChange(new TextSpan(38, 2), string.Empty),
388new TextChange(new TextSpan(49, 2), string.Empty),
389new TextChange(new TextSpan(52, 2), string.Empty),
390new TextChange(new TextSpan(64, 2), string.Empty),
411new TextChange(new TextSpan(2, 2), string.Empty),
412new TextChange(new TextSpan(19, 2), string.Empty),
413new TextChange(new TextSpan(26, 2), string.Empty),
433new TextChange(new TextSpan(6, 2), string.Empty),
434new TextChange(new TextSpan(16, 2), string.Empty)
447new TextChange(new TextSpan(19, 2), string.Empty),
448new TextChange(new TextSpan(29, 2), string.Empty)
461new TextChange(new TextSpan(0, 2), string.Empty),
462new TextChange(new TextSpan(15, 2), string.Empty)
475new TextChange(new TextSpan(0, 2), string.Empty),
476new TextChange(new TextSpan(15, 2), string.Empty)
513new TextChange(new TextSpan(18, 2), string.Empty),
514new TextChange(new TextSpan(112, 2), string.Empty),
544new TextChange(new TextSpan(20, 2), string.Empty),
545new TextChange(new TextSpan(114, 2), string.Empty),
573new TextChange(new TextSpan(18, 2), string.Empty),
574new TextChange(new TextSpan(112, 2), string.Empty),
602new TextChange(new TextSpan(18, 2), string.Empty),
603new TextChange(new TextSpan(112, 2), string.Empty),
631new TextChange(new TextSpan(55, 2), string.Empty),
659new TextChange(new TextSpan(55, 2), string.Empty),
687new TextChange(new TextSpan(18, 2), string.Empty),
688new TextChange(new TextSpan(28, 2), string.Empty),
689new TextChange(new TextSpan(44, 2), string.Empty),
690new TextChange(new TextSpan(53, 2), string.Empty),
691new TextChange(new TextSpan(78, 2), string.Empty),
692new TextChange(new TextSpan(109, 2), string.Empty),
693new TextChange(new TextSpan(118, 2), string.Empty),
Diagnostics\DiagnosticDataTests.cs (10)
28await VerifyTextSpanAsync(code, 10, 10, 20, 20, new TextSpan(0, 0));
37await VerifyTextSpanAsync(code, 30, 30, 40, 40, new TextSpan(code.Length, 0));
46await VerifyTextSpanAsync(code, 0, 30, 40, 40, new TextSpan(code.Length, 0));
55await VerifyTextSpanAsync(code, 0, 30, 0, 40, new TextSpan(code.Length, 0));
64await VerifyTextSpanAsync(code, 1, 30, 1, 40, new TextSpan(code.Length, 0));
73await VerifyTextSpanAsync(code, 1, 30, 1, 40, new TextSpan(code.Length, 0));
82await VerifyTextSpanAsync(code, 1, 30, 2, 40, new TextSpan(code.Length, 0));
91await VerifyTextSpanAsync(code, 1, 0, 1, 2, new TextSpan(code.Length, 0));
106await VerifyTextSpanAsync(code, 3, 10, 3, 11, new TextSpan(28, 1));
189await VerifyTextSpanAsync(content, 3, 10, 3, 11, new TextSpan(28, 1));
Snippets\RoslynLSPSnippetConvertTests.cs (3)
404ImmutableArray<SnippetPlaceholder>.Empty, new TextChange(new TextSpan(8, 0), "quux"), triggerLocation: 12, CancellationToken.None).Result;
415ImmutableArray<SnippetPlaceholder>.Empty, new TextChange(new TextSpan(4, 4), "bar quux"), triggerLocation: 12, CancellationToken.None).Result;
492var textChange = new TextChange(new TextSpan(stringSpan.Start, 0), text.Substring(stringSpan.Start, stringSpan.Length));
Microsoft.CodeAnalysis.EditorFeatures2.UnitTests (9)
Microsoft.CodeAnalysis.Features (44)
Navigation\IDocumentNavigationService.cs (2)
37=> CanNavigateToSpanAsync(workspace, documentId, new TextSpan(position, 0), allowInvalidSpan: allowInvalidPosition, cancellationToken);
43=> GetLocationForSpanAsync(workspace, documentId, new TextSpan(position, 0), allowInvalidSpan: allowInvalidPosition, cancellationToken);
src\Analyzers\Core\Analyzers\ValidateFormatString\AbstractValidateFormatStringDiagnosticAnalyzer.cs (1)
354new Text.TextSpan(
Microsoft.CodeAnalysis.Features.Test.Utilities (3)
Microsoft.CodeAnalysis.LanguageServer (1)
Microsoft.CodeAnalysis.LanguageServer.Protocol (12)
Handler\InlineCompletions\InlineCompletionsHandler.cs (6)
204snippetEndPosition = GetAdjustedSpan(formattingChanges, new TextSpan(snippetEndPosition, 0)).Start;
238return new TextSpan(originalSpan.Start + amountToAdjust, originalSpan.Length);
243var offsetInSnippet = new TextSpan(positionInFullText - snippetPositionInFullText, length);
286part = await functionPart.WithSnippetFunctionResultAsync(documentWithDefaultSnippet, new TextSpan(locationInDefaultSnippet, part.DefaultText.Length), simplifierOptions, cancellationToken).ConfigureAwait(false);
292var fieldSpan = new TextSpan(locationInFinalSnippet, part.DefaultText.Length);
297caretSpan = new TextSpan(locationInFinalSnippet, cursorPart.DefaultText.Length);
Microsoft.CodeAnalysis.LanguageServer.Protocol.UnitTests (7)
Microsoft.CodeAnalysis.Remote.ServiceHub (1)
Microsoft.CodeAnalysis.Test.Utilities (3)
Microsoft.CodeAnalysis.UnitTests (302)
Text\StringText_LineTest.cs (11)
20var span = new TextSpan(0, 3);
53var line = TextLine.FromSpan(text, new TextSpan(0, 3));
62Assert.Throws<ArgumentOutOfRangeException>(() => TextLine.FromSpan(text, new TextSpan(0, 0)));
69Assert.Throws<ArgumentOutOfRangeException>(() => TextLine.FromSpan(text, new TextSpan(0, 3)));
76Assert.Throws<ArgumentOutOfRangeException>(() => TextLine.FromSpan(text, new TextSpan(1, 5)));
84var line = TextLine.FromSpan(text, new TextSpan(start, 0));
98var line = TextLine.FromSpan(text, new TextSpan(0, 0));
107Assert.Throws<ArgumentOutOfRangeException>(() => TextLine.FromSpan(text, new TextSpan(1, 10)));
114Assert.Throws<ArgumentOutOfRangeException>(() => TextLine.FromSpan(text, new TextSpan(-1, 2)));
121Assert.Throws<ArgumentOutOfRangeException>(() => TextLine.FromSpan(text, new TextSpan(7, 0)));
128Assert.Throws<ArgumentNullException>(() => TextLine.FromSpan(null, new TextSpan(0, 2)));
Text\TextChangeRangeTest.cs (8)
20() => { var notUsed = new TextChangeRange(new TextSpan(), -1); });
26var span = new TextSpan(2, 50);
39EqualityUnit.Create(new TextChangeRange(new TextSpan(42, 2), 13)).WithEqualValues(new TextChangeRange(new TextSpan(42, 2), 13)),
40EqualityUnit.Create(new TextChangeRange(new TextSpan(42, 2), 13)).WithNotEqualValues(new TextChangeRange(new TextSpan(42, 2), 5)),
41EqualityUnit.Create(new TextChangeRange(new TextSpan(42, 2), 13)).WithNotEqualValues(new TextChangeRange(new TextSpan(42, 4), 13)));
Text\TextChangeTests.cs (193)
41var subText = text.GetSubText(new TextSpan(0, 5));
49var subText = text.GetSubText(new TextSpan(6, 5));
57var subText = text.GetSubText(new TextSpan(4, 3));
88new TextChange(new TextSpan(0, 5), "Halo"),
89new TextChange(new TextSpan(6, 5), "Universe"));
100new TextChange(new TextSpan(0, 5), "Halo"),
101new TextChange(new TextSpan(3, 5), "Universe")
113new TextChange(new TextSpan(6, 5), "Universe"),
114new TextChange(new TextSpan(0, 5), "Halo")
127new TextChange(new TextSpan(6, 7), "Universe"),
128new TextChange(new TextSpan(0, 5), "Halo")
142new TextChange(new TextSpan(6, 0), "Super "),
143new TextChange(new TextSpan(6, 0), "Spectacular "));
154new TextChange(new TextSpan(6, 0), "Super "),
155new TextChange(new TextSpan(6, 2), "Vu"));
166new TextChange(new TextSpan(6, 2), "Vu"),
167new TextChange(new TextSpan(6, 0), "Super ")
180new TextChange(new TextSpan(4, 1), string.Empty),
181new TextChange(new TextSpan(5, 1), string.Empty));
191new TextChange(new TextSpan(4, 1), string.Empty),
192new TextChange(new TextSpan(6, 5), "Universe"));
194var subText = newText.GetSubText(new TextSpan(3, 4));
206new TextChange(new TextSpan(4, 1), string.Empty));
216new TextChange(new TextSpan(6, 5), "Universe"));
233new TextChange(new TextSpan(0, 1), "[1]"),
234new TextChange(new TextSpan(1, 1), "[2]"),
235new TextChange(new TextSpan(5, 0), "[3]"),
236new TextChange(new TextSpan(25, 2), "[4]")
278new TextChange(new TextSpan(8, 2), "IN"),
279new TextChange(new TextSpan(15, 2), "IN"));
286new TextChange(new TextSpan(8, 2), new string('a', 10)),
287new TextChange(new TextSpan(15, 2), new string('a', 10)));
294new TextChange(new TextSpan(8, 2), "\r\n"),
295new TextChange(new TextSpan(15, 2), "\r\n"));
302new TextChange(new TextSpan(6, 0), "aa\r"),
303new TextChange(new TextSpan(11, 0), "aa\r"));
310new TextChange(new TextSpan(6, 0), "aa\n"),
311new TextChange(new TextSpan(11, 0), "aa\n"));
318new TextChange(new TextSpan(4, 4), "aaaaaa"),
319new TextChange(new TextSpan(15, 4), "aaaaaa"));
326new TextChange(new TextSpan(5, 0), "aaaaaa"));
333new TextChange(new TextSpan(5, 0), "\naaaaaa\r"));
340new TextChange(new TextSpan(21, 0), "Line4\r\n"),
341new TextChange(new TextSpan(21, 0), "Line5\r\n"));
392var subtext = text.GetSubText(new TextSpan(5, 10));
403var newText = text.Replace(new TextSpan(0, 20), "");
414var newText = text.Replace(new TextSpan(10, 6), "");
426var newText = text.Replace(new TextSpan(10, 1), "");
442var textWithSegments = text.Replace(new TextSpan(10, 0), "*");
459var textWithSegments = text.Replace(new TextSpan(10, 0), "*");
463var textWithFewerSegments = textWithSegments.Replace(new TextSpan(9, 3), "");
479var textWithSegments = text.Replace(new TextSpan(0, text.Length), "");
636var change1 = original.WithChanges(new TextChange(new TextSpan(5, 6), string.Empty)); // prepare a ChangedText instance
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
657var change1 = original.WithChanges(new TextChange(new TextSpan(6, 0), "Cruel "));
658var change2 = change1.WithChanges(new TextChange(new TextSpan(7, 3), "oo"));
663Assert.Equal(new TextSpan(6, 0), changes[0].Span);
672var change1 = original.WithChanges(new TextChange(new TextSpan(1, 3), "aa"));
673var change2 = change1.WithChanges(new TextChange(new TextSpan(2, 0), "bb"));
678Assert.Equal(new[] { new TextChange(new TextSpan(1, 3), "abba") }, changes);
686var change1 = original.WithChanges(new TextChange(new TextSpan(1, 1), "aaa"));
687var change2 = change1.WithChanges(new TextChange(new TextSpan(3, 0), "bb"));
692Assert.Equal(new[] { new TextChange(new TextSpan(1, 1), "aabba") }, changes);
700var change1 = original.WithChanges(new TextChange(new TextSpan(1, 3), "aa"));
701var change2 = change1.WithChanges(new TextChange(new TextSpan(2, 1), "bb"));
706Assert.Equal(new[] { new TextChange(new TextSpan(1, 3), "abb") }, changes);
713var change1 = original.WithChanges(new TextChange(new TextSpan(6, 0), "Cruel "));
714var change2 = change1.WithChanges(new TextChange(new TextSpan(2, 14), "ar"));
719Assert.Equal(new TextSpan(2, 8), changes[0].Span);
727var change1 = original.WithChanges(new TextChange(new TextSpan(6, 0), "Cruel "));
728var change2 = change1.WithChanges(new TextChange(new TextSpan(4, 6), " Bel"));
733Assert.Equal(new TextSpan(4, 2), changes[0].Span);
741var change1 = original.WithChanges(new TextChange(new TextSpan(6, 0), "Cruel "));
742var change2 = change1.WithChanges(new TextChange(new TextSpan(7, 6), "wazy V"));
747Assert.Equal(new TextSpan(6, 1), changes[0].Span);
755var change1 = original.WithChanges(new TextChange(new TextSpan(1, 0), "aa"));
756var change2 = change1.WithChanges(new TextChange(new TextSpan(1, 0), "bb"));
761Assert.Equal(new[] { new TextChange(new TextSpan(1, 0), "bbaa") }, changes);
768var change1 = original.WithChanges(new TextChange(new TextSpan(1, 3), "aa"));
769var change2 = change1.WithChanges(new TextChange(new TextSpan(1, 0), "bb"));
774Assert.Equal(new[] { new TextChange(new TextSpan(1, 3), "bbaa") }, changes);
781var change1 = original.WithChanges(new TextChange(new TextSpan(1, 0), "aa"));
782var change2 = change1.WithChanges(new TextChange(new TextSpan(1, 1), "bb"));
787Assert.Equal(new[] { new TextChange(new TextSpan(1, 0), "bba") }, changes);
794var change1 = original.WithChanges(new TextChange(new TextSpan(1, 0), "aa"));
795var change2 = change1.WithChanges(new TextChange(new TextSpan(1, 2), "bb"));
800Assert.Equal(new[] { new TextChange(new TextSpan(1, 0), "bb") }, changes);
807var change1 = original.WithChanges(new TextChange(new TextSpan(1, 0), "aa"));
808var change2 = change1.WithChanges(new TextChange(new TextSpan(1, 3), "bb"));
813Assert.Equal(new[] { new TextChange(new TextSpan(1, 1), "bb") }, changes);
821var change1 = original.WithChanges(new TextChange(new TextSpan(1, 3), "aa"));
822var change2 = change1.WithChanges(new TextChange(new TextSpan(1, 1), "bb"));
827Assert.Equal(new[] { new TextChange(new TextSpan(1, 3), "bba") }, changes);
835var change1 = original.WithChanges(new TextChange(new TextSpan(1, 3), "aa"));
836var change2 = change1.WithChanges(new TextChange(new TextSpan(1, 3), "bb"));
847var change1 = original.WithChanges(new TextChange(new TextSpan(4, 0), "o "));
848var change2 = change1.WithChanges(new TextChange(new TextSpan(6, 0), "World"));
853Assert.Equal(new TextSpan(4, 0), changes[0].Span);
861var change1 = original.WithChanges(new TextChange(new TextSpan(4, 0), "o"));
862var change2 = change1.WithChanges(new TextChange(new TextSpan(6, 0), "World"));
867Assert.Equal(new TextSpan(4, 0), changes[0].Span);
869Assert.Equal(new TextSpan(5, 0), changes[1].Span);
877var change1 = original.WithChanges(new TextChange(new TextSpan(8, 0), "l"));
878var change2 = change1.WithChanges(new TextChange(new TextSpan(4, 0), "o"));
883Assert.Equal(new TextSpan(4, 0), changes[0].Span);
885Assert.Equal(new TextSpan(8, 0), changes[1].Span);
893var change1 = original.WithChanges(new TextChange(new TextSpan(4, 0), " World"));
895var change2 = change1.WithChanges(new TextChange(new TextSpan(4, 0), "o"));
900Assert.Equal(new TextSpan(4, 0), changes[0].Span);
911c => c.WithChanges(new TextChange(new TextSpan(4, 0), "o ")),
912c => c.WithChanges(new TextChange(new TextSpan(6, 0), "World")));
918Assert.Equal(new TextSpan(4, 0), changes[0].Span);
926new TextChangeRange(new TextSpan(919, 10), 466),
927new TextChangeRange(new TextSpan(936, 33), 29),
928new TextChangeRange(new TextSpan(1098, 0), 70),
929new TextChangeRange(new TextSpan(1125, 4), 34),
930new TextChangeRange(new TextSpan(1138, 0), 47));
932new TextChangeRange(new TextSpan(997, 0), 2),
933new TextChangeRange(new TextSpan(1414, 0), 2),
934new TextChangeRange(new TextSpan(1419, 0), 2),
935new TextChangeRange(new TextSpan(1671, 5), 5),
936new TextChangeRange(new TextSpan(1681, 0), 4));
941new TextChangeRange(new TextSpan(919, 10), 468),
942new TextChangeRange(new TextSpan(936, 33), 33),
943new TextChangeRange(new TextSpan(1098, 0), 70),
944new TextChangeRange(new TextSpan(1125, 4), 38),
945new TextChangeRange(new TextSpan(1138, 0), 47));
954Assert.Equal("new TextChange(new TextSpan(0, 1), \"abc\")", new TextChange(new TextSpan(0, 1), "abc").GetDebuggerDisplay());
955Assert.Equal("new TextChange(new TextSpan(0, 1), (NewLength = 10))", new TextChange(new TextSpan(0, 1), "0123456789").GetDebuggerDisplay());
979var newChange = new TextChange(new TextSpan(i, length: random.Next(originalText.Length - i)), newText);
999var newChange = new TextChange(new TextSpan(i, length: random.Next(editedLength - i)), newText);
1047var change1 = originalText.WithChanges(new TextChange(new TextSpan(0, 2), "a"));
1048var change2 = change1.WithChanges(new TextChange(new TextSpan(0, 2), "bb"));
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), ""));
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"));
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"));
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"));
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), ""));
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"));
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"));
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"));
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), ""));
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), ""));
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), ""));
1226new TextChange(new TextSpan(39, 0), " "),
1227new TextChange(new TextSpan(42, 0), " "),
1228new TextChange(new TextSpan(57, 0), " "),
1229new TextChange(new TextSpan(58, 0), "\r\n"),
1230new TextChange(new TextSpan(64, 2), " "),
1231new TextChange(new TextSpan(69, 0), " "),
1237new TextChange(new TextSpan(35, 4), string.Empty),
1238new TextChange(new TextSpan(46, 4), string.Empty),
1239new TextChange(new TextSpan(73, 4), string.Empty),
1240new TextChange(new TextSpan(88, 0), " "),
1241new TextChange(new TextSpan(90, 4), string.Empty),
1242new TextChange(new TextSpan(105, 4), string.Empty),
Text\TextSpanTest.cs (87)
21var span = new TextSpan(0, 42);
30var span = new TextSpan(1, 40);
42var span = new TextSpan(0, 0);
50var s1 = new TextSpan(1, 40);
51var s2 = new TextSpan(1, 40);
64var s1 = new TextSpan(1, 40);
65var s2 = new TextSpan(2, 40);
78var s1 = new TextSpan(1, 5);
79var s2 = new TextSpan(1, 40);
89TextSpan span = new TextSpan(0, 0);
100TextSpan span = new TextSpan(0, 1);
112TextSpan span = new TextSpan(15, 1485);
122TextSpan span = new TextSpan(0, int.MaxValue - 1);
131TextSpan span = new TextSpan(0, 10);
141TextSpan span_05_15 = new TextSpan(5, 10);
142TextSpan span_03_10 = new TextSpan(3, 7);
143TextSpan span_10_11 = new TextSpan(10, 1);
144TextSpan span_00_03 = new TextSpan(0, 3);
165Assert.False(new TextSpan(2, 5).Contains(new TextSpan(0, 0)));
166Assert.False(new TextSpan(2, 5).Contains(new TextSpan(10, 0)));
169Assert.True(new TextSpan(2, 5).Contains(new TextSpan(3, 0)));
172Assert.True(new TextSpan(2, 5).Contains(new TextSpan(2, 0)));
175Assert.True(new TextSpan(2, 5).Contains(new TextSpan(7, 0)));
178Assert.True(new TextSpan(2, 0).Contains(new TextSpan(2, 0)));
185Assert.False(new TextSpan(0, 0).Contains(new TextSpan(2, 5)));
186Assert.False(new TextSpan(10, 0).Contains(new TextSpan(2, 5)));
189Assert.False(new TextSpan(3, 0).Contains(new TextSpan(2, 5)));
192Assert.False(new TextSpan(2, 0).Contains(new TextSpan(2, 5)));
195Assert.False(new TextSpan(7, 0).Contains(new TextSpan(2, 5)));
201TextSpan span1 = new TextSpan(0, 10);
202TextSpan span2 = new TextSpan(0, 10);
218TextSpan span1 = new TextSpan(0, 10);
219TextSpan span2 = new TextSpan(0, 11);
220TextSpan span3 = new TextSpan(1, 11);
236TextSpan span1 = new TextSpan(10, 10); // 10..20
237TextSpan span2 = new TextSpan(5, 5); // 5..10
248TextSpan span1 = new TextSpan(10, 10); // 10..20
249TextSpan span2 = new TextSpan(5, 2); // 5..7
260TextSpan span1 = new TextSpan(10, 10); // 10..20
261TextSpan span2 = new TextSpan(5, 10); // 5..15
265Assert.Equal(span1.Overlap(span2), new TextSpan(10, 5));
266Assert.Equal(span2.Overlap(span1), new TextSpan(10, 5));
272TextSpan span1 = new TextSpan(10, 0); // [10, 10)
273TextSpan span2 = new TextSpan(10, 0); // [10, 10)
284TextSpan span1 = new TextSpan(10, 0); // [10, 10)
285TextSpan span2 = new TextSpan(5, 10); // [5, 15)
296TextSpan span1 = new TextSpan(10, 10); // 10..20
297TextSpan span2 = new TextSpan(5, 5); // 5..10
301Assert.Equal(span1.Intersection(span2), new TextSpan(10, 0));
302Assert.Equal(span2.Intersection(span1), new TextSpan(10, 0));
308TextSpan span1 = new TextSpan(10, 10); // 10..20
309TextSpan span2 = new TextSpan(5, 2); // 5..7
320TextSpan span1 = new TextSpan(10, 10); // 10..20
321TextSpan span2 = new TextSpan(5, 10); // 5..15
325Assert.Equal(span1.Intersection(span2), new TextSpan(10, 5));
326Assert.Equal(span2.Intersection(span1), new TextSpan(10, 5));
332TextSpan span1 = new TextSpan(10, 0); // [10, 10)
333TextSpan span2 = new TextSpan(10, 0); // [10, 10)
337Assert.Equal(span1.Intersection(span2), new TextSpan(10, 0));
338Assert.Equal(span2.Intersection(span1), new TextSpan(10, 0));
344TextSpan span1 = new TextSpan(2, 5); // [2, 7)
345TextSpan span2 = new TextSpan(7, 5); // [7, 12)
349Assert.Equal(span1.Intersection(span2), new TextSpan(7, 0));
350Assert.Equal(span2.Intersection(span1), new TextSpan(7, 0));
356TextSpan span1 = new TextSpan(2, 5); // [2, 7)
357TextSpan span2 = new TextSpan(3, 0); // [3, 3)
361Assert.Equal(span1.Intersection(span2), new TextSpan(3, 0));
362Assert.Equal(span2.Intersection(span1), new TextSpan(3, 0));
368TextSpan span1 = new TextSpan(2, 5); // [2, 7)
369TextSpan span2 = new TextSpan(2, 0); // [2, 2)
373Assert.Equal(span1.Intersection(span2), new TextSpan(2, 0));
374Assert.Equal(span2.Intersection(span1), new TextSpan(2, 0));
380TextSpan span1 = new TextSpan(2, 5); // [2, 7)
381TextSpan span2 = new TextSpan(7, 0); // [7, 0)
385Assert.Equal(span1.Intersection(span2), new TextSpan(7, 0));
386Assert.Equal(span2.Intersection(span1), new TextSpan(7, 0));
Microsoft.CodeAnalysis.VisualBasic (12)
Microsoft.CodeAnalysis.VisualBasic.CommandLine.UnitTests (3)
Microsoft.CodeAnalysis.VisualBasic.EditorFeatures (3)
Microsoft.CodeAnalysis.VisualBasic.Emit.UnitTests (5)
CodeGen\CodeGenTuples.vb (5)
6872Dim loc1 = Location.Create(tree, New TextSpan(0, 1))
6921Dim loc1 = Location.Create(tree, New TextSpan(0, 1))
6922Dim loc2 = Location.Create(tree, New TextSpan(1, 1))
7270Dim loc1 = Location.Create(tree, New TextSpan(0, 1))
7271Dim loc2 = Location.Create(tree, New TextSpan(1, 1))
Microsoft.CodeAnalysis.VisualBasic.Features (12)
Microsoft.CodeAnalysis.VisualBasic.Features.UnitTests (2)
Microsoft.CodeAnalysis.VisualBasic.Semantic.UnitTests (4)
Microsoft.CodeAnalysis.VisualBasic.Symbol.UnitTests (5)
Microsoft.CodeAnalysis.VisualBasic.Syntax.UnitTests (93)
IncrementalParser\IncrementalParser.vb (35)
90Dim span = New TextSpan(i, 10)
112Dim newText = text.WithChanges(New TextChange(New TextSpan(text.Length, 0), _s.Substring(i, 1)))
129Dim newText = oldText.WithChanges(New TextChange(New TextSpan(pos, 0), "'"))
138Dim anotherText = newText.WithChanges(New TextChange(New TextSpan(pos, 1), ""))
171.changeSpan = New TextSpan(code.Length, 0),
193.changeSpan = New TextSpan(code.Length, 0),
216.changeSpan = New TextSpan(code.Length, 0),
232.changeSpan = New TextSpan(code.Length, 0),
251.changeSpan = New TextSpan(code.Length, 0),
266.changeSpan = New TextSpan(code.Length, 0),
284.changeSpan = New TextSpan(0, 0),
303.changeSpan = New TextSpan(0, 0),
317.changeSpan = New TextSpan(0, 0),
329.changeSpan = New TextSpan(0, 0),
384.changeSpan = New TextSpan(0, 0),
397.changeSpan = New TextSpan(0, 0),
417.changeSpan = New TextSpan(0, 0),
432.changeSpan = New TextSpan(0, 0),
445.changeSpan = New TextSpan(0, 0),
459.changeSpan = New TextSpan(0, 0),
641.changeSpan = New TextSpan(0, 0),
653.changeSpan = New TextSpan(0, 10),
689.changeSpan = New TextSpan(0, 0),
705Dim newText = oldText.WithChanges(New TextChange(New TextSpan(22, 0), " Sub "))
744Dim newText = oldText.WithChanges(New TextChange(New TextSpan(103, 0), " "))
770Dim newText = oldText.WithChanges(New TextChange(New TextSpan(insertionPoint, 0), " "))
795Dim newText = oldText.WithChanges(New TextChange(New TextSpan(insertionPoint, replace.Length), "{"))
830Dim newText = oldText.WithChanges(New TextChange(New TextSpan(pos, 0), "'"))
852.changeSpan = New TextSpan(15, 0),
1160Dim span = New TextSpan(oldIText.Length, 0)
1166span = New TextSpan(0, code1.Length)
1206Dim span = New TextSpan(code.IndexOf("="c), 0)
1225Dim change = New TextChange(New TextSpan(position, 2), "End" + vbCrLf)
1243Dim change = New TextChange(New TextSpan(position, 0), " Select c" + vbCrLf)
1677Dim change = New TextChange(New TextSpan(position, 2), "71")
IncrementalParser\IPEndBlockStatements.vb (5)
35.changeSpan = New TextSpan(code.Length, 0),
164.changeSpan = New TextSpan(code.Length, 0),
302.changeSpan = New TextSpan(code.Length, 0),
448.changeSpan = New TextSpan(code.Length, 0),
550.changeSpan = New TextSpan(code.Length, 0),
TestSyntaxNodes.vb (47)
336VerifyListSpans(precedingTrivia, New TextSpan(tree.FullSpan.Start, (tree.SpanStart - tree.FullSpan.Start)))
342VerifyListSpans(followingTrivia, New TextSpan(tree.Span.End, (tree.FullSpan.End - tree.Span.End)))
361VerifyListSpans(precedingTrivia, New TextSpan(tree.FullSpan.Start, (tree.SpanStart - tree.FullSpan.Start)))
367VerifyListSpans(followingTrivia, New TextSpan(tree.Span.End, (tree.FullSpan.End - tree.Span.End)))
375Assert.Equal(New TextSpan(0, 1), dig1.Span)
376Assert.Equal(New TextSpan(0, 1), dig1.FullSpan)
381Assert.Equal(New TextSpan(0, 4), binop.Span)
382Assert.Equal(New TextSpan(1, 1), binop.OperatorToken.Span)
383Assert.Equal(New TextSpan(1, 2), binop.OperatorToken.FullSpan)
384Assert.Equal(New TextSpan(3, 1), binop.Right.Span)
385Assert.Equal(New TextSpan(3, 1), binop.Right.FullSpan)
388Assert.Equal(New TextSpan(0, 17), simpleTree.Span)
389Assert.Equal(New TextSpan(0, 18), simpleTree.FullSpan)
390Assert.Equal(New TextSpan(3, 14), DirectCast(simpleTree, BinaryExpressionSyntax).Right.Span)
393Assert.Equal(New TextSpan(6, 1), argList.Arguments(0).Span)
394Assert.Equal(New TextSpan(7, 1), argList.Arguments.GetWithSeparators(1).Span)
395Assert.Equal(New TextSpan(9, 4), argList.Arguments(1).Span)
396Assert.Equal(New TextSpan(13, 1), argList.Arguments.GetWithSeparators(3).Span)
397Assert.Equal(New TextSpan(15, 1), argList.Arguments(2).Span)
441Dim x As New TextSpan(-1, 0)
445Dim x As New TextSpan(0, -1)
449Dim x As New TextSpan(-1, -1)
453Dim x As New TextSpan(2, -4)
488VerifyListSpans(l, New TextSpan(0, 6))
527VerifyListSpans(l, New TextSpan(0, 21))
995CheckErrorList(kwModule, {17}, {New TextSpan(0, 6)})
1001CheckErrorList(kwModule, {17, 42}, {New TextSpan(0, 6), New TextSpan(0, 6)})
1007CheckErrorList(endModule, {101, 17, 42}, {New TextSpan(3, 3), New TextSpan(6, 6), New TextSpan(6, 6)})
1012CheckErrorList(endModule, {1, 101, 17, 42}, {New TextSpan(0, 12), New TextSpan(3, 3), New TextSpan(6, 6), New TextSpan(6, 6)})
1048{New TextSpan(26, 5), New TextSpan(26, 5), New TextSpan(71, 22), New TextSpan(94, 1), New TextSpan(96, 5)})
1825Dim resultList = identExpr.DescendantTokens(New TextSpan(3, 18))
2273Dim EOFSpan = New TextSpan(root.FullSpan.End, 0)
2283Dim nodeEndPositionSpan = New TextSpan(classDecl.FullSpan.End, 0)
2294Dim invalidSpan = New TextSpan(100, 100)
2296invalidSpan = New TextSpan(root.FullSpan.End - 1, 2)
2298invalidSpan = New TextSpan(classDecl2.FullSpan.Start - 1, root.FullSpan.End)
2300invalidSpan = New TextSpan(classDecl.FullSpan.End, root.FullSpan.End)
Microsoft.CodeAnalysis.VisualBasic.Test.Utilities (2)
Microsoft.CodeAnalysis.VisualBasic.Workspaces (5)
Microsoft.CodeAnalysis.VisualBasic.Workspaces.UnitTests (2)
Microsoft.CodeAnalysis.Workspaces (46)
src\Compilers\Core\Portable\Text\TextChangeRangeExtensions.cs (4)
225addAndAdjustOldDelta(builder, ref oldDelta, new TextChangeRange(new TextSpan(oldChange.Span.Start, oldChangeLeadingDeletion), oldChangeLeadingInsertion));
226oldChange = new TextChangeRange(new TextSpan(newChange.SpanStart - oldDelta, oldChange.Span.Length - oldChangeLeadingDeletion), oldChange.NewLength - oldChangeLeadingInsertion);
380add(builder, new TextChangeRange(new TextSpan(newChange.SpanStart - oldDelta, newChange.SpanLength), newChange.NewLength));
391builder[^1] = new TextChangeRange(new TextSpan(last.Span.Start, last.Span.Length + change.Span.Length), last.NewLength + change.NewLength);
Microsoft.CodeAnalysis.Workspaces.Test.Utilities (1)
Microsoft.CodeAnalysis.Workspaces.UnitTests (17)
Microsoft.Gen.ComplianceReports.Unit.Tests (1)
Microsoft.Gen.ContextualOptions.Unit.Tests (1)
Microsoft.Gen.Logging.Unit.Tests (1)
Microsoft.Gen.Metrics.Unit.Tests (1)
Microsoft.Gen.MetricsReports.Unit.Tests (1)
Microsoft.Maui.Controls.SourceGen (1)
Microsoft.VisualStudio.LanguageServices (6)
Microsoft.VisualStudio.LanguageServices.UnitTests (5)
Microsoft.VisualStudio.LanguageServices.Xaml (1)
Roslyn.VisualStudio.Next.UnitTests (1)
System.Text.RegularExpressions.Generator (1)
5392 references to TextSpan
ConfigurationSchemaGenerator (1)
CSharpSyntaxGenerator (1)
IdeBenchmarks (2)
IdeCoreBenchmarks (2)
Microsoft.Analyzers.Extra (1)
Microsoft.Analyzers.Extra.Tests (2)
Microsoft.Analyzers.Local.Tests (2)
Microsoft.AspNetCore.App.Analyzers (57)
Infrastructure\VirtualChars\CSharpVirtualCharService.cs (11)
218var lineSpan = currentLine.Span;
267var charResults = new List<(char ch, TextSpan span)>();
285if (!IsLegalBraceEscape(tokenText, index, offset, out var braceSpan))
304string tokenText, int offset, int startIndexInclusive, int endIndexExclusive, List<(char ch, TextSpan span)> charResults)
314private static void ConvertCharactersToRunes(List<(char ch, TextSpan span)> charResults, ImmutableList<VirtualChar>.Builder runeResults)
334runeResults.Add(VirtualChar.Create(rune, TextSpan.FromBounds(span.Start, nextSpan.End)));
348List<(char ch, TextSpan span)> result, string tokenText, int offset, int index)
361List<(char ch, TextSpan span)> result, string tokenText, int offset, int index)
394List<(char ch, TextSpan span)> result, string tokenText, int offset, int index)
413List<(char ch, TextSpan span)> result, string tokenText, int offset, int index, char character)
526result.Add((character, TextSpan.FromBounds(startIndex + offset, endIndex + offset)));
Microsoft.AspNetCore.App.Analyzers.Test (23)
RouteEmbeddedLanguage\Infrastructure\MarkupTestFile.cs (18)
53string input, out string output, out int? position, out IDictionary<string, List<TextSpan>> spans)
56var tempSpans = new Dictionary<string, List<TextSpan>>();
191IDictionary<string, List<TextSpan>> spans,
196var span = TextSpan.FromBounds(matchIndex, finalIndex);
197GetOrAdd(spans, name, _ => new List<TextSpan>()).Add(span);
210string input, out string output, out int? cursorPositionOpt, out ImmutableArray<TextSpan> spans)
214var builder = GetOrAdd(dictionary, string.Empty, _ => new List<TextSpan>());
220string input, out string output, out int? cursorPositionOpt, out IDictionary<string, ImmutableArray<TextSpan>> spans)
226public static void GetSpans(string input, out string output, out IDictionary<string, ImmutableArray<TextSpan>> spans)
229public static void GetPositionAndSpans(string input, out string output, out int cursorPosition, out ImmutableArray<TextSpan> spans)
236=> GetPositionAndSpans(input, out output, out cursorPosition, out ImmutableArray<TextSpan> spans);
241public static void GetPositionAndSpan(string input, out string output, out int? cursorPosition, out TextSpan? textSpan)
243GetPositionAndSpans(input, out output, out cursorPosition, out ImmutableArray<TextSpan> spans);
247public static void GetPositionAndSpan(string input, out string output, out int cursorPosition, out TextSpan textSpan)
253public static void GetSpans(string input, out string output, out ImmutableArray<TextSpan> spans)
258public static void GetSpan(string input, out string output, out TextSpan textSpan)
260GetSpans(input, out output, out ImmutableArray<TextSpan> spans);
Microsoft.AspNetCore.App.CodeFixes (2)
Microsoft.AspNetCore.Components.Analyzers (1)
Microsoft.AspNetCore.Components.SdkAnalyzers (1)
Microsoft.AspNetCore.Http.RequestDelegateGenerator (1)
Microsoft.AspNetCore.Mvc.Api.Analyzers (2)
Microsoft.CodeAnalysis (283)
DiagnosticAnalyzer\AnalysisScope.cs (12)
26public TextSpan? FilterSpanOpt { get; }
48public TextSpan? OriginalFilterSpan { get; }
118public static AnalysisScope Create(ImmutableArray<DiagnosticAnalyzer> analyzers, SourceOrAdditionalFile filterFile, TextSpan? filterSpan, bool isSyntacticSingleFileAnalysis, CompilationWithAnalyzers compilationWithAnalyzers)
121public static AnalysisScope Create(ImmutableArray<DiagnosticAnalyzer> analyzers, SourceOrAdditionalFile filterFile, TextSpan? filterSpan, SourceOrAdditionalFile originalFilterFile, TextSpan? originalFilterSpan, bool isSyntacticSingleFileAnalysis, CompilationWithAnalyzers compilationWithAnalyzers)
136TextSpan? filterSpanOpt,
138TextSpan? originalFilterSpan,
158private static TextSpan? GetEffectiveFilterSpan(TextSpan? filterSpan, SourceOrAdditionalFile? filterFile)
210public AnalysisScope WithFilterSpan(TextSpan? filterSpan)
282public bool ShouldInclude(TextSpan filterSpan)
287public bool ContainsSpan(TextSpan filterSpan)
DiagnosticAnalyzer\AnalyzerDriver.cs (7)
1327var span = root.FullSpan;
2141TextSpan? filterSpan,
2167async ValueTask<IGroupedAnalyzerActions> getAllActionsAsync(AnalyzerDriver driver, ISymbol symbol, DiagnosticAnalyzer analyzer, SyntaxTree? filterTree, TextSpan? filterSpan, CancellationToken cancellationToken)
2183async ValueTask<IGroupedAnalyzerActions> getInheritedActionsAsync(AnalyzerDriver driver, ISymbol symbol, DiagnosticAnalyzer analyzer, SyntaxTree? filterTree, TextSpan? filterSpan, CancellationToken cancellationToken)
2207static async ValueTask<AnalyzerActions> getSymbolActionsCoreAsync(AnalyzerDriver driver, ISymbol symbol, DiagnosticAnalyzer analyzer, SyntaxTree? filterTree, TextSpan? filterSpan, CancellationToken cancellationToken)
2331protected bool IsGeneratedOrHiddenCodeLocation(SyntaxTree syntaxTree, TextSpan span, CancellationToken cancellationToken)
2334protected bool IsHiddenSourceLocation(SyntaxTree syntaxTree, TextSpan span)
DiagnosticAnalyzer\AnalyzerExecutor.cs (24)
45private readonly Func<SyntaxTree, TextSpan, CancellationToken, bool> _isGeneratedCodeLocation;
108Func<SyntaxTree, TextSpan, CancellationToken, bool> isGeneratedCodeLocation,
140Func<SyntaxTree, TextSpan, CancellationToken, bool> isGeneratedCodeLocation,
251TextSpan? filterSpan,
360TextSpan? filterSpan,
415TextSpan? filterSpan,
452TextSpan? filterSpan,
469TextSpan? filterSpan,
515TextSpan? filterSpan,
561TextSpan? filterSpan,
608TextSpan? filterSpan,
642TextSpan? filterSpan,
668TextSpan? filterSpan,
698TextSpan? filterSpan,
735TextSpan? filterSpan,
756TextSpan? filterSpan,
880TextSpan? filterSpan,
959TextSpan spanForContainingTopmostNodeForAnalysis,
961TextSpan? filterSpan,
989TextSpan? filterSpan,
1061TextSpan spanForContainingOperationBlock,
1063TextSpan? filterSpan,
1089TextSpan? filterSpan,
1451private AnalyzerDiagnosticReporter GetAddSemanticDiagnostic(SyntaxTree tree, TextSpan? span, DiagnosticAnalyzer analyzer, CancellationToken cancellationToken)
DiagnosticAnalyzer\CompilationWithAnalyzers.cs (15)
411public async Task<ImmutableArray<Diagnostic>> GetAnalyzerSyntaxDiagnosticsAsync(SyntaxTree tree, TextSpan? filterSpan, CancellationToken cancellationToken)
445public async Task<ImmutableArray<Diagnostic>> GetAnalyzerSyntaxDiagnosticsAsync(SyntaxTree tree, TextSpan? filterSpan, ImmutableArray<DiagnosticAnalyzer> analyzers, CancellationToken cancellationToken)
474public Task<AnalysisResult> GetAnalysisResultAsync(SyntaxTree tree, TextSpan? filterSpan, CancellationToken cancellationToken)
505public Task<AnalysisResult> GetAnalysisResultAsync(SyntaxTree tree, TextSpan? filterSpan, ImmutableArray<DiagnosticAnalyzer> analyzers, CancellationToken cancellationToken)
552public async Task<AnalysisResult> GetAnalysisResultAsync(AdditionalText file, TextSpan? filterSpan, CancellationToken cancellationToken)
569public async Task<AnalysisResult> GetAnalysisResultAsync(AdditionalText file, TextSpan? filterSpan, ImmutableArray<DiagnosticAnalyzer> analyzers, CancellationToken cancellationToken)
577private async Task<AnalysisResult> GetAnalysisResultCoreAsync(SourceOrAdditionalFile file, ImmutableArray<DiagnosticAnalyzer> analyzers, TextSpan? filterSpan, CancellationToken cancellationToken)
584private async Task<ImmutableArray<Diagnostic>> GetAnalyzerSyntaxDiagnosticsCoreAsync(SyntaxTree tree, ImmutableArray<DiagnosticAnalyzer> analyzers, TextSpan? filterSpan, CancellationToken cancellationToken)
598public async Task<ImmutableArray<Diagnostic>> GetAnalyzerSemanticDiagnosticsAsync(SemanticModel model, TextSpan? filterSpan, CancellationToken cancellationToken)
613public async Task<ImmutableArray<Diagnostic>> GetAnalyzerSemanticDiagnosticsAsync(SemanticModel model, TextSpan? filterSpan, ImmutableArray<DiagnosticAnalyzer> analyzers, CancellationToken cancellationToken)
628public Task<AnalysisResult> GetAnalysisResultAsync(SemanticModel model, TextSpan? filterSpan, CancellationToken cancellationToken)
643public Task<AnalysisResult> GetAnalysisResultAsync(SemanticModel model, TextSpan? filterSpan, ImmutableArray<DiagnosticAnalyzer> analyzers, CancellationToken cancellationToken)
651private async Task<AnalysisResult> GetAnalysisResultCoreAsync(SemanticModel model, TextSpan? filterSpan, ImmutableArray<DiagnosticAnalyzer> analyzers, CancellationToken cancellationToken)
658private async Task<ImmutableArray<Diagnostic>> GetAnalyzerSemanticDiagnosticsCoreAsync(SemanticModel model, TextSpan? filterSpan, ImmutableArray<DiagnosticAnalyzer> analyzers, CancellationToken cancellationToken)
877TextSpan? originalSpan,
DiagnosticAnalyzer\DiagnosticAnalysisContext.cs (23)
714public TextSpan? FilterSpan { get; }
732TextSpan? filterSpan,
800public TextSpan? FilterSpan { get; }
828TextSpan? filterSpan,
896public TextSpan? FilterSpan { get; }
909internal SymbolStartAnalysisContext(ISymbol symbol, Compilation compilation, AnalyzerOptions options, bool isGeneratedCode, SyntaxTree? filterTree, TextSpan? filterSpan, CancellationToken cancellationToken)
1056public TextSpan? FilterSpan { get; }
1079TextSpan? filterSpan,
1166public TextSpan? FilterSpan { get; }
1191TextSpan? filterSpan,
1276public TextSpan? FilterSpan { get; }
1307TextSpan? filterSpan,
1418public TextSpan? FilterSpan { get; }
1453TextSpan? filterSpan,
1531public TextSpan? FilterSpan { get; }
1557TextSpan? filterSpan,
1609public TextSpan? FilterSpan { get; }
1627TextSpan? filterSpan,
1642/// which can be created using <see cref="Location.Create(string, TextSpan, LinePositionSpan)"/> API.
1703public TextSpan? FilterSpan { get; }
1734TextSpan? filterSpan,
1809public TextSpan? FilterSpan { get; }
1842TextSpan? filterSpan,
Syntax\SyntaxDiffer.cs (17)
22private readonly TextSpan _oldSpan;
71internal static IList<TextSpan> GetPossiblyDifferentTextSpans(SyntaxTree? before, SyntaxTree? after)
76return SpecializedCollections.EmptyList<TextSpan>();
94internal static IList<TextSpan> GetPossiblyDifferentTextSpans(SyntaxNode oldNode, SyntaxNode newNode)
99private IList<TextSpan> ComputeSpansInNew()
105var newSpans = new List<TextSpan>();
532var oldSpan = GetSpan(_oldNodes, 0, oldNodeCount);
544var oldSpan = removedNode.FullSpan;
547var newSpan = insertedNode.FullSpan;
553var oldSpan = GetSpan(_oldNodes, 0, oldNodeCount);
556var newSpan = GetSpan(_newNodes, 0, newNodeCount);
565var newSpan = GetSpan(_newNodes, 0, newNodeCount);
624private static TextSpan GetSpan(Stack<SyntaxNodeOrToken> stack, int first, int length)
646return TextSpan.FromBounds(start, end);
649private static TextSpan GetSpan(Queue<SyntaxNodeOrToken> queue, int first, int length)
671return TextSpan.FromBounds(start, end);
826var span = GetSpan(queue, 0, queue.Count);
Syntax\SyntaxNode.cs (12)
84public TextSpan FullSpan => new TextSpan(this.Position, this.Green.FullWidth);
91public TextSpan Span
113/// Same as accessing <see cref="TextSpan.Start"/> on <see cref="Span"/>.
884public IEnumerable<SyntaxNode> DescendantNodes(TextSpan span, Func<SyntaxNode, bool>? descendIntoChildren = null, bool descendIntoTrivia = false)
905public IEnumerable<SyntaxNode> DescendantNodesAndSelf(TextSpan span, Func<SyntaxNode, bool>? descendIntoChildren = null, bool descendIntoTrivia = false)
926public IEnumerable<SyntaxNodeOrToken> DescendantNodesAndTokens(TextSpan span, Func<SyntaxNode, bool>? descendIntoChildren = null, bool descendIntoTrivia = false)
947public IEnumerable<SyntaxNodeOrToken> DescendantNodesAndTokensAndSelf(TextSpan span, Func<SyntaxNode, bool>? descendIntoChildren = null, bool descendIntoTrivia = false)
962public SyntaxNode FindNode(TextSpan span, bool findInsideTrivia = false, bool getInnermostNodeForTie = false)
971!.FirstAncestorOrSelf<SyntaxNode, TextSpan>((a, span) => a.FullSpan.Contains(span), span);
1052public IEnumerable<SyntaxToken> DescendantTokens(TextSpan span, Func<SyntaxNode, bool>? descendIntoChildren = null, bool descendIntoTrivia = false)
1189public IEnumerable<SyntaxTrivia> DescendantTrivia(TextSpan span, Func<SyntaxNode, bool>? descendIntoChildren = null, bool descendIntoTrivia = false)
1533var span = token.Span;
Syntax\SyntaxNode.Iterators.cs (14)
17private IEnumerable<SyntaxNode> DescendantNodesImpl(TextSpan span, Func<SyntaxNode, bool>? descendIntoChildren, bool descendIntoTrivia, bool includeSelf)
24private IEnumerable<SyntaxNodeOrToken> DescendantNodesAndTokensImpl(TextSpan span, Func<SyntaxNode, bool>? descendIntoChildren, bool descendIntoTrivia, bool includeSelf)
31private IEnumerable<SyntaxTrivia> DescendantTriviaImpl(TextSpan span, Func<SyntaxNode, bool>? descendIntoChildren = null, bool descendIntoTrivia = false)
38private static bool IsInSpan(in TextSpan span, TextSpan childSpan)
69public bool TryGetNextInSpan(in TextSpan span, out SyntaxNodeOrToken value)
84public SyntaxNode? TryGetNextAsNodeInSpan(in TextSpan span)
222public bool TryGetNextInSpan(in TextSpan span, out SyntaxNodeOrToken value)
317public bool TryGetNextInSpan(in TextSpan span, out SyntaxNodeOrToken value)
390private IEnumerable<SyntaxNode> DescendantNodesOnly(TextSpan span, Func<SyntaxNode, bool>? descendIntoChildren, bool includeSelf)
415private IEnumerable<SyntaxNodeOrToken> DescendantNodesAndTokensOnly(TextSpan span, Func<SyntaxNode, bool>? descendIntoChildren, bool includeSelf)
444private IEnumerable<SyntaxNodeOrToken> DescendantNodesAndTokensIntoTrivia(TextSpan span, Func<SyntaxNode, bool>? descendIntoChildren, bool includeSelf)
532private IEnumerable<SyntaxTrivia> DescendantTriviaOnly(TextSpan span, Func<SyntaxNode, bool>? descendIntoChildren)
570private IEnumerable<SyntaxTrivia> DescendantTriviaIntoTrivia(TextSpan span, Func<SyntaxNode, bool>? descendIntoChildren)
Microsoft.CodeAnalysis.CodeStyle (384)
src\Analyzers\Core\Analyzers\SimplifyTypeNames\SimplifyTypeNamesDiagnosticAnalyzerBase.cs (5)
81out TextSpan issueSpan, out string diagnosticId, out bool inDeclaration,
118out var issueSpan, out var diagnosticId, out var inDeclaration,
135internal static Diagnostic CreateDiagnostic(SemanticModel model, TSimplifierOptions options, AnalyzerOptions analyzerOptions, TextSpan issueSpan, string diagnosticId, bool inDeclaration)
206/// indicate that <c>intervalTree</c> may be updated by adding a new non-overlapping <see cref="TextSpan"/>
249static bool TryProceedWithInterval(bool addIfAvailable, TextSpan span, StrongBox<bool> completed, TextSpanMutableIntervalTree intervalTree)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Collections\NormalizedTextSpanCollection.cs (42)
14internal sealed class NormalizedTextSpanCollection : ReadOnlyCollection<TextSpan>
21: base(new List<TextSpan>(0))
29public NormalizedTextSpanCollection(TextSpan span)
42public NormalizedTextSpanCollection(IEnumerable<TextSpan> spans)
93var span1 = left[index1];
94var span2 = right[index2];
122spans.Add(TextSpan.FromBounds(start, end));
161var span1 = left[index1];
162var span2 = right[index2];
221var span1 = left[index1];
222var span2 = right[index2];
283var span1 = left[index1];
284var span2 = right[index2];
296spans.Add(TextSpan.FromBounds(Math.Max(lastEnd, span1.Start), span1.End));
307spans.Add(TextSpan.FromBounds(Math.Max(lastEnd, span1.Start), span2.Start));
333var span1 = left[index1++];
334spans.Add(TextSpan.FromBounds(Math.Max(lastEnd, span1.Start), span1.End));
398var span1 = this[index1];
399var span2 = set[index2];
429public bool OverlapsWith(TextSpan span)
458var span1 = this[index1];
459var span2 = set[index2];
483public bool IntersectsWith(TextSpan span)
506foreach (var s in this)
533foreach (var s in this)
546private static IList<TextSpan> ListFromSpan(TextSpan span)
548IList<TextSpan> list = new List<TextSpan>(1)
564private static void UpdateSpanUnion(TextSpan span, IList<TextSpan> spans, ref int start, ref int end)
568spans.Add(TextSpan.FromBounds(start, end));
585private static IList<TextSpan> NormalizeSpans(IEnumerable<TextSpan> spans)
592var sorted = new List<TextSpan>(spans);
599sorted.Sort(delegate (TextSpan s1, TextSpan s2) { return s1.Start.CompareTo(s2.Start); });
601IList<TextSpan> normalized = new List<TextSpan>(sorted.Count);
611normalized.Add(TextSpan.FromBounds(oldStart, oldEnd));
621normalized.Add(TextSpan.FromBounds(oldStart, oldEnd));
626private sealed class OrderedSpanList : List<TextSpan>
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Diagnostics\IPragmaSuppressionsAnalyzer.cs (1)
24TextSpan? span,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\EmbeddedLanguages\Common\EmbeddedSyntaxTrivia.cs (1)
34public TextSpan GetSpan()
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\AnalysisContextExtensions.cs (13)
14private static bool ShouldAnalyze(TextSpan? contextFilterSpan, TextSpan span)
24public static bool ShouldAnalyzeSpan(this SyntaxTreeAnalysisContext context, TextSpan span)
34public static bool ShouldAnalyzeSpan(this SemanticModelAnalysisContext context, TextSpan span)
44public static bool ShouldAnalyzeSpan(this SymbolStartAnalysisContext context, TextSpan span, SyntaxTree tree)
64public static bool ShouldAnalyzeSpan(this SymbolAnalysisContext context, TextSpan span, SyntaxTree tree)
84public static bool ShouldAnalyzeSpan(this AdditionalFileAnalysisContext context, TextSpan span)
94public static bool ShouldAnalyzeSpan(this OperationBlockStartAnalysisContext context, TextSpan span)
104public static bool ShouldAnalyzeSpan(this OperationBlockAnalysisContext context, TextSpan span)
114public static bool ShouldAnalyzeSpan(this OperationAnalysisContext context, TextSpan span)
124public static bool ShouldAnalyzeSpan(this SyntaxNodeAnalysisContext context, TextSpan span)
134public static bool ShouldAnalyzeSpan<TSytnaxKind>(this CodeBlockStartAnalysisContext<TSytnaxKind> context, TextSpan span) where TSytnaxKind : struct
144public static bool ShouldAnalyzeSpan(this CodeBlockAnalysisContext context, TextSpan span)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\SourceTextExtensions_SharedWithCodeStyle.cs (2)
33this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden, CancellationToken cancellationToken)
45this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\TextSpanExtensions.cs (22)
18public static IEnumerable<TextSpan> ToNormalizedSpans(this IEnumerable<TextSpan> spans)
21public static ImmutableArray<TextSpan> ToNormalizedSpans(this ImmutableArray<TextSpan> spans)
24public static TextSpan Collapse(this IEnumerable<TextSpan> spans)
29foreach (var span in spans)
48return TextSpan.FromBounds(start, end);
54public static bool IsAround(this TextSpan span, SyntaxNodeOrToken node) => IsAround(span, node, node);
60public static bool IsAround(this TextSpan span, SyntaxNodeOrToken startNode, SyntaxNodeOrToken endNode)
62var innerSpan = TextSpan.FromBounds(startNode.Span.Start, endNode.Span.End);
63var outerSpan = TextSpan.FromBounds(startNode.FullSpan.Start, endNode.FullSpan.End);
67public static IEnumerable<TextSpan> Subtract(this TextSpan span, TextSpan except)
81yield return TextSpan.FromBounds(span.Start, startSegmentEnd);
85yield return TextSpan.FromBounds(endSegmentStart, span.End);
88public static IEnumerable<TextSpan> Subtract(this IEnumerable<TextSpan> spans, TextSpan except)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Formatting\Context\FormattingContext.IndentationData.cs (14)
18private abstract class IndentationData(TextSpan textSpan)
20public TextSpan TextSpan { get; } = textSpan;
23public IndentationData WithTextSpan(TextSpan span)
26protected abstract IndentationData WithTextSpanCore(TextSpan span);
29private sealed class SimpleIndentationData(TextSpan textSpan, int indentation) : IndentationData(textSpan)
33protected override IndentationData WithTextSpanCore(TextSpan span)
57public RelativeIndentationData(FormattingContext formattingContext, int inseparableRegionSpanStart, TextSpan textSpan, IndentBlockOperation operation, Func<FormattingContext, IndentBlockOperation, SyntaxToken> effectiveBaseTokenGetter, Func<FormattingContext, IndentBlockOperation, SyntaxToken, int> indentationDeltaGetter, Func<FormattingContext, SyntaxToken, int> baseIndentationGetter)
68this.InseparableRegionSpan = TextSpan.FromBounds(inseparableRegionSpanStart, textSpan.End);
71private RelativeIndentationData(FormattingContext formattingContext, int inseparableRegionSpanStart, TextSpan textSpan, IndentBlockOperation operation, Func<FormattingContext, IndentBlockOperation, SyntaxToken> effectiveBaseTokenGetter, Func<FormattingContext, IndentBlockOperation, SyntaxToken, int> indentationDeltaGetter, Func<FormattingContext, SyntaxToken, int> baseIndentationGetter, int lazyIndentationDelta)
82this.InseparableRegionSpan = TextSpan.FromBounds(inseparableRegionSpanStart, textSpan.End);
85public TextSpan InseparableRegionSpan { get; }
107protected override IndentationData WithTextSpanCore(TextSpan span)
119public AdjustedIndentationData(TextSpan textSpan, IndentationData baseIndentationData, int adjustment)
142protected override IndentationData WithTextSpanCore(TextSpan span)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Formatting\Rules\BaseIndentationFormattingRule.cs (10)
20private readonly TextSpan _span;
22public BaseIndentationFormattingRule(SyntaxNode root, TextSpan span, int baseIndentation, AbstractFormattingRule? vbHelperFormattingRule = null)
130private TextSpan AdjustTextSpan(TextSpan textSpan)
131=> TextSpan.FromBounds(Math.Max(_span.Start, textSpan.Start), Math.Min(_span.End, textSpan.End));
133private static void SetInnermostNodeForSpan(SyntaxNode root, ref TextSpan span, out SyntaxToken token1, out SyntaxToken token2, out SyntaxNode? commonNode)
149private static void GetTokens(SyntaxNode root, TextSpan span, out SyntaxToken token1, out SyntaxToken token2)
168private static TextSpan GetSpanFromTokens(TextSpan span, SyntaxToken token1, SyntaxToken token2)
217return TextSpan.FromBounds(start, end);
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Formatting\Rules\Operations\FormattingOperations.cs (8)
31=> CreateAnchorIndentationOperation(anchorToken, endToken, TextSpan.FromBounds(anchorToken.Span.End, endToken.Span.End));
36public static AnchorIndentationOperation CreateAnchorIndentationOperation(SyntaxToken anchorToken, SyntaxToken endToken, TextSpan textSpan)
43=> CreateSuppressOperation(startToken, endToken, TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End), option);
48private static SuppressOperation CreateSuppressOperation(SyntaxToken startToken, SyntaxToken endToken, TextSpan textSpan, SuppressOption option)
56var span = CommonFormattingHelpers.GetSpanIncludingTrailingAndLeadingTriviaOfAdjacentTokens(startToken, endToken);
63public static IndentBlockOperation CreateIndentBlockOperation(SyntaxToken startToken, SyntaxToken endToken, TextSpan textSpan, int indentationDelta, IndentBlockOption option)
71var span = CommonFormattingHelpers.GetSpanIncludingTrailingAndLeadingTriviaOfAdjacentTokens(startToken, endToken);
79public static IndentBlockOperation CreateRelativeIndentBlockOperation(SyntaxToken baseToken, SyntaxToken startToken, SyntaxToken endToken, TextSpan textSpan, int indentationDelta, IndentBlockOption option)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Formatting\TriviaEngine\AbstractTriviaFormatter.cs (13)
46private delegate void WhitespaceAppender<T>(LineColumn lineColumn, LineColumnDelta delta, TextSpan span, ArrayBuilder<T> changes);
388var span = GetTextSpan(trivia1, trivia2);
500var span = TextSpan.FromBounds(start, end);
716var insertionPoint = GetInsertionSpan(changes);
731private TextSpan GetInsertionSpan(ArrayBuilder<TextChange> changes)
766TextSpan notUsed,
823private TextChange GetWhitespaceTextChange(LineColumn lineColumn, LineColumnDelta delta, TextSpan span)
826private void AddWhitespaceTextChange(LineColumn lineColumn, LineColumnDelta delta, TextSpan span, ArrayBuilder<TextChange> changes)
832private TextSpan GetTextSpan(SyntaxTrivia trivia1, SyntaxTrivia trivia2)
836return TextSpan.FromBounds(this.StartPosition, trivia2.FullSpan.Start);
841return TextSpan.FromBounds(trivia1.FullSpan.End, this.EndPosition);
844return TextSpan.FromBounds(trivia1.FullSpan.End, trivia2.FullSpan.Start);
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\NamingStyles\NamingStyle.cs (19)
159var spanToCheck = TextSpan.FromBounds(0, name.Length - Suffix.Length);
173private WordSpanEnumerable GetWordSpans(string name, TextSpan nameSpan)
176private static string Substring(string name, TextSpan wordSpan)
179private static readonly Func<string, TextSpan, bool> s_firstCharIsLowerCase = (val, span) => !DoesCharacterHaveCasing(val[span.Start]) || char.IsLower(val[span.Start]);
180private static readonly Func<string, TextSpan, bool> s_firstCharIsUpperCase = (val, span) => !DoesCharacterHaveCasing(val[span.Start]) || char.IsUpper(val[span.Start]);
182private static readonly Func<string, TextSpan, bool> s_wordIsAllUpperCase = (val, span) =>
195private static readonly Func<string, TextSpan, bool> s_wordIsAllLowerCase = (val, span) =>
209string name, TextSpan nameSpan, Func<string, TextSpan, bool> wordCheck,
231private bool CheckPascalCase(string name, TextSpan nameSpan, out string reason)
236private bool CheckAllUpper(string name, TextSpan nameSpan, out string reason)
241private bool CheckAllLower(string name, TextSpan nameSpan, out string reason)
247string name, TextSpan nameSpan,
248Func<string, TextSpan, bool> firstWordCheck,
249Func<string, TextSpan, bool> restWordCheck,
290private bool CheckCamelCase(string name, TextSpan nameSpan, out string reason)
297private bool CheckFirstUpper(string name, TextSpan nameSpan, out string reason)
405using var parts = TemporaryArray<TextSpan>.Empty;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\SelectedMembers\AbstractSelectedMembers.cs (4)
35SyntaxTree tree, TextSpan textSpan, bool allowPartialSelection, CancellationToken cancellationToken)
39SyntaxTree tree, TextSpan textSpan, bool allowPartialSelection, CancellationToken cancellationToken)
43SyntaxTree tree, TextSpan textSpan, bool allowPartialSelection,
78SyntaxNode root, SourceText text, TextSpan textSpan,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\CommonFormattingHelpers.cs (10)
46public static IEnumerable<(SyntaxToken, SyntaxToken)> ConvertToTokenPairs(this SyntaxNode root, IReadOnlyList<TextSpan> spans)
82public static ValueTuple<SyntaxToken, SyntaxToken> ConvertToTokenPair(this SyntaxNode root, TextSpan textSpan)
158=> (token1.RawKind == 0) ? text.ToString(TextSpan.FromBounds(0, token2.SpanStart)) : text.ToString(TextSpan.FromBounds(token1.Span.End, token2.SpanStart));
260public static TextSpan GetSpanIncludingTrailingAndLeadingTriviaOfAdjacentTokens(SyntaxToken startToken, SyntaxToken endToken)
267return TextSpan.FromBounds(startPosition, endPosition);
325var fullSpan = node.FullSpan;
358public static TextSpan GetFormattingSpan(SyntaxNode root, TextSpan span)
368return TextSpan.FromBounds(startPosition, endPosition);
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\StringBreaker.cs (10)
16public static void AddWordParts(string identifier, ref TemporaryArray<TextSpan> parts)
19public static void AddCharacterParts(string identifier, ref TemporaryArray<TextSpan> parts)
22public static void AddParts(string text, bool word, ref TemporaryArray<TextSpan> parts)
26var span = StringBreaker.GenerateSpan(text, start, word);
40public static TextSpan GenerateSpan(string identifier, int wordStart, bool word)
80private static TextSpan ScanCharacterRun(string identifier, int length, int wordStart)
101private static TextSpan ScanWordRun(string identifier, int length, int wordStart)
150private static TextSpan ScanLowerCaseRun(string identifier, int length, int wordStart)
161private static TextSpan ScanNumber(string identifier, int length, int wordStart)
169return TextSpan.FromBounds(wordStart, current);
Microsoft.CodeAnalysis.CodeStyle.Fixes (56)
src\Analyzers\Core\CodeFixes\ConflictMarkerResolution\AbstractConflictMarkerCodeFixProvider.cs (8)
333edits.Add(new TextChange(TextSpan.FromBounds(startPos, startEnd), ""));
337edits.Add(new TextChange(TextSpan.FromBounds(firstMiddlePos, bottomEnd), ""));
346edits.Add(new TextChange(TextSpan.FromBounds(startPos, equalsEnd), ""));
350edits.Add(new TextChange(TextSpan.FromBounds(endPos, bottomEnd), ""));
359edits.Add(new TextChange(TextSpan.FromBounds(startPos, startEnd), ""));
365edits.Add(new TextChange(TextSpan.FromBounds(secondMiddlePos, equalsEnd), ""));
371edits.Add(new TextChange(TextSpan.FromBounds(firstMiddlePos, equalsEnd), ""));
376edits.Add(new TextChange(TextSpan.FromBounds(endPos, bottomEnd), ""));
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Simplification\Simplifiers\AbstractSimplifier.cs (1)
21out TextSpan issueSpan,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Utilities\NullableHelpers.cs (1)
56TextSpan span,
Microsoft.CodeAnalysis.CSharp (186)
Binder\BinderFactory.BinderFactoryVisitor.cs (5)
560private Symbol GetMemberSymbol(string memberName, TextSpan memberSpan, NamedTypeSymbol container, SymbolKind kind)
592bool checkSymbol(Symbol sym, TextSpan memberSpan, SymbolKind kind, out Symbol result)
640private static bool InSpan(Location location, SyntaxTree syntaxTree, TextSpan span)
649private static bool InSpan(ImmutableArray<Location> locations, SyntaxTree syntaxTree, TextSpan span)
1066TextSpan containingSpan = containingNode.Span;
Compilation\CSharpCompilation.cs (14)
254internal bool IsNullableAnalysisEnabledIn(CSharpSyntaxTree tree, TextSpan span)
268/// from <see cref="IsNullableAnalysisEnabledIn(CSharpSyntaxTree, TextSpan)"/>.
2663TextSpan infoSpan = info.Span;
2790public readonly TextSpan Span;
2792public ImportInfo(SyntaxTree tree, SyntaxKind kind, TextSpan span)
2977var location = syntaxTree.GetLocation(TextSpan.FromBounds(0, 0));
3071private static bool IsDefinedOrImplementedInSourceTree(Symbol symbol, SyntaxTree tree, TextSpan? span)
3087private ImmutableArray<Diagnostic> GetDiagnosticsForMethodBodiesInTree(SyntaxTree tree, TextSpan? span, CancellationToken cancellationToken)
3168void compileMethodBodiesAndDocComments(SyntaxTree? filterTree, TextSpan? filterSpan, BindingDiagnosticBag bindingDiagnostics, CancellationToken cancellationToken)
3219private ReadOnlyBindingDiagnostic<AssemblySymbol> GetSourceDeclarationDiagnostics(SyntaxTree? syntaxTree = null, TextSpan? filterSpanWithinTree = null, Func<IEnumerable<Diagnostic>, SyntaxTree, TextSpan?, IEnumerable<Diagnostic>>? locationFilterOpt = null, Predicate<Symbol>? symbolFilter = null, CancellationToken cancellationToken = default)
3268private ReadOnlyBindingDiagnostic<AssemblySymbol> GetClsComplianceDiagnostics(SyntaxTree? syntaxTree, TextSpan? filterSpanWithinTree, CancellationToken cancellationToken)
3291private static IEnumerable<Diagnostic> FilterDiagnosticsByLocation(IEnumerable<Diagnostic> diagnostics, SyntaxTree tree, TextSpan? filterSpanWithinTree)
3305TextSpan? filterSpanWithinTree,
Compilation\SyntaxTreeSemanticModel.cs (10)
106private void VerifySpanForGetDiagnostics(TextSpan? span)
114public override ImmutableArray<Diagnostic> GetSyntaxDiagnostics(TextSpan? span = null, CancellationToken cancellationToken = default(CancellationToken))
121public override ImmutableArray<Diagnostic> GetDeclarationDiagnostics(TextSpan? span = null, CancellationToken cancellationToken = default(CancellationToken))
128public override ImmutableArray<Diagnostic> GetMethodBodyDiagnostics(TextSpan? span = null, CancellationToken cancellationToken = default(CancellationToken))
135public override ImmutableArray<Diagnostic> GetDiagnostics(TextSpan? span = null, CancellationToken cancellationToken = default(CancellationToken))
848var span = node.Span;
1004private MemberSemanticModel GetOrAddModelForParameter(ParameterSyntax paramDecl, TextSpan span)
1045private MemberSemanticModel GetOrAddModelIfContains(CSharpSyntaxNode node, TextSpan span)
1720private NamespaceSymbol GetDeclaredNamespace(NamespaceOrTypeSymbol container, TextSpan declarationSpan, NameSyntax name)
1751private Symbol GetDeclaredMember(NamespaceOrTypeSymbol container, TextSpan declarationSpan, bool isKnownToBeANamespace, string name = null)
Lowering\Instrumentation\DebugInfoInjector_SequencePoints.cs (12)
22GetBreakpointSpan(declaratorSyntax, out _, out TextSpan? part);
33TextSpan part = TextSpan.FromBounds(start, end);
44TextSpan span = TextSpan.FromBounds(start, end);
48private static TextSpan CreateSpan(ParameterSyntax parameter)
53private static TextSpan CreateSpan(SyntaxTokenList startOpt, SyntaxNodeOrToken startFallbackOpt, SyntaxNodeOrToken endOpt)
81return TextSpan.FromBounds(startPos, endPos);
87internal static void GetBreakpointSpan(VariableDeclaratorSyntax declaratorSyntax, out SyntaxNode node, out TextSpan? part)
125part = TextSpan.FromBounds(declarationSyntax.SpanStart, declaratorSyntax.Span.End);
142internal static void GetFirstLocalOrFieldBreakpointSpan(SyntaxToken? firstToken, VariableDeclaratorSyntax declaratorSyntax, out SyntaxNode node, out TextSpan? part)
167part = TextSpan.FromBounds(start, end);
src\Compilers\CSharp\CSharpAnalyzerDriver\CSharpDeclarationComputer.cs (1)
24TextSpan span,
Microsoft.CodeAnalysis.CSharp.CodeStyle (99)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\EmbeddedLanguages\VirtualChars\CSharpVirtualCharService.cs (10)
207var lineSpan = currentLine.Span;
254using var _ = ArrayBuilder<(char ch, TextSpan span)>.GetInstance(out var charResults);
287string tokenText, int offset, int startIndexInclusive, int endIndexExclusive, ArrayBuilder<(char ch, TextSpan span)> charResults)
306private static void ConvertCharactersToRunes(ArrayBuilder<(char ch, TextSpan span)> charResults, ImmutableSegmentedList<VirtualChar>.Builder runeResults)
326runeResults.Add(VirtualChar.Create(rune, TextSpan.FromBounds(span.Start, nextSpan.End)));
340ArrayBuilder<(char ch, TextSpan span)> result, string tokenText, int offset, int index)
353ArrayBuilder<(char ch, TextSpan span)> result, string tokenText, int offset, int index)
387ArrayBuilder<(char ch, TextSpan span)> result, string tokenText, int offset, int index)
406ArrayBuilder<(char ch, TextSpan span)> result, string tokenText, int offset, int index, char character)
519result.Add((character, TextSpan.FromBounds(startIndex + offset, endIndex + offset)));
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Indentation\CSharpSmartTokenFormatter.cs (2)
67_root, [TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End)], _options.FormattingOptions, smartTokenformattingRules, cancellationToken);
121_root, [TextSpan.FromBounds(adjustedStartPosition, adjustedEndPosition)], _options.FormattingOptions, smartTokenFormattingRules, cancellationToken);
Microsoft.CodeAnalysis.CSharp.CodeStyle.Fixes (35)
Microsoft.CodeAnalysis.CSharp.CommandLine.UnitTests (1)
Microsoft.CodeAnalysis.CSharp.EditorFeatures (85)
StringCopyPaste\StringCopyPasteHelpers.cs (10)
183public static int GetLongestQuoteSequence(SourceText text, TextSpan span)
186public static int GetLongestOpenBraceSequence(SourceText text, TextSpan span)
189public static int GetLongestCloseBraceSequence(SourceText text, TextSpan span)
197private static int GetLongestCharacterSequence(SourceText text, TextSpan span, char character)
514commonIndentPrefix = GetCommonIndentationPrefix(commonIndentPrefix, text, TextSpan.FromBounds(line.Start, nonWhitespaceIndex));
521private static string? GetCommonIndentationPrefix(string? commonIndentPrefix, SourceText text, TextSpan lineWhitespaceSpan)
539public static TextSpan MapSpan(TextSpan span, ITextSnapshot from, ITextSnapshot to)
542public static bool RawContentMustBeMultiLine(SourceText text, ImmutableArray<TextSpan> spans)
558foreach (var span in spans)
StringCopyPaste\StringInfo.cs (26)
19TextSpan startDelimiterSpan,
20TextSpan endDelimiterSpan,
21TextSpan endDelimiterSpanWithoutSuffix,
22ImmutableArray<TextSpan> contentSpans)
40public readonly TextSpan StartDelimiterSpan = startDelimiterSpan;
45public readonly TextSpan EndDelimiterSpan = endDelimiterSpan;
50public readonly TextSpan EndDelimiterSpanWithoutSuffix = endDelimiterSpanWithoutSuffix;
60public readonly ImmutableArray<TextSpan> ContentSpans = contentSpans;
98var contentSpans = ImmutableArray.Create(TextSpan.FromBounds(start, end));
104startDelimiterSpan: TextSpan.FromBounds(literal.SpanStart, start),
105endDelimiterSpan: TextSpan.FromBounds(end, literal.Span.End),
106endDelimiterSpanWithoutSuffix: TextSpan.FromBounds(end, endBeforeU8Suffix),
145TextSpan.FromBounds(literal.SpanStart, rawStart),
146TextSpan.FromBounds(rawEnd, literal.Span.End),
147TextSpan.FromBounds(rawEnd, endBeforeU8Suffix),
148contentSpans: [TextSpan.FromBounds(start, end)]);
175startDelimiterSpan: TextSpan.FromBounds(literal.SpanStart, start),
176endDelimiterSpan: TextSpan.FromBounds(end, literal.Span.End),
177endDelimiterSpanWithoutSuffix: TextSpan.FromBounds(end, endBeforeU8Suffix),
178[TextSpan.FromBounds(start, end)]);
202using var result = TemporaryArray<TextSpan>.Empty;
209result.Add(TextSpan.FromBounds(currentPosition, content.SpanStart));
215result.Add(TextSpan.FromBounds(currentPosition, end));
219startDelimiterSpan: TextSpan.FromBounds(interpolatedString.SpanStart, interpolatedString.StringStartToken.Span.End),
220endDelimiterSpan: TextSpan.FromBounds(interpolatedString.StringEndToken.SpanStart, interpolatedString.Span.End),
221endDelimiterSpanWithoutSuffix: TextSpan.FromBounds(interpolatedString.StringEndToken.SpanStart, endBeforeU8Suffix),
Microsoft.CodeAnalysis.CSharp.EditorFeatures.UnitTests (75)
PdbSourceDocument\ImplementationAssemblyLookupServiceTests.cs (10)
36MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
74MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
114MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
159MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
219MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
280MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
335MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
386MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
451MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
509MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
PdbSourceDocument\PdbSourceDocumentTests.cs (13)
402MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
432MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
469MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
516MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
573MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
596MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
618MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
640MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
661MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
684MarkupTestFile.GetSpan(source, out var metadataSource, out var expectedSpan);
716MarkupTestFile.GetSpan(source1, out var metadataSource, out var expectedSpan);
754MarkupTestFile.GetSpan(source1, out var metadataSource, out var expectedSpan);
925MarkupTestFile.GetSpan(source2, out source2, out var expectedSpan);
QuickInfo\DiagnosticAnalyzerQuickInfoSourceTests.cs (7)
130""", GetFormattedIDEAnalyzerTitle(51, nameof(AnalyzersResources.Remove_unused_private_members)), ImmutableArray<TextSpan>.Empty);
175""", description, ImmutableArray<TextSpan>.Empty);
179ImmutableArray<TextSpan> relatedSpans)
186info.RelatedSpans.Select(actualSpan => new Action<TextSpan>(expectedSpan => Assert.Equal(expectedSpan, actualSpan))).ToArray());
206ImmutableArray<TextSpan> relatedSpans,
240private static Task TestInClassAsync(string code, string expectedDescription, params TextSpan[] relatedSpans)
249private static Task TestInMethodAsync(string code, string expectedDescription, params TextSpan[] relatedSpans)
Microsoft.CodeAnalysis.CSharp.EditorFeatures2.UnitTests (1)
Microsoft.CodeAnalysis.CSharp.Emit2.UnitTests (2)
Microsoft.CodeAnalysis.CSharp.Emit3.UnitTests (9)
Microsoft.CodeAnalysis.CSharp.Features (433)
Completion\CompletionProviders\DeclarationName\DeclarationNameRecommender.NameGenerator.cs (6)
25using var parts = TemporaryArray<TextSpan>.Empty;
42using var breaks = TemporaryArray<TextSpan>.Empty;
49in TemporaryArray<TextSpan> breaks, string baseName, bool pluralize)
67private static Words GetLongestBackwardSubsequence(int length, in TemporaryArray<TextSpan> breaks, string baseName, bool pluralize)
74private static Words GetLongestForwardSubsequence(int length, in TemporaryArray<TextSpan> breaks, string baseName, bool pluralize)
77private static Words GetWords(int start, int end, in TemporaryArray<TextSpan> breaks, string baseName, bool pluralize)
ConvertToRawString\ConvertInterpolatedStringToRawStringCodeRefactoringProvider.cs (17)
316builder.Append(text.ToString(TextSpan.FromBounds(line.End, line.EndIncludingLineBreak)));
336builder.Append(text.ToString(TextSpan.FromBounds(firstNonWhitespacePos, line.EndIncludingLineBreak)));
484private static (ImmutableIntervalTree<TextSpan> interpolationInteriorSpans, ImmutableIntervalTree<TextSpan> restrictedSpans) GetInterpolationSpans(
487var interpolationInteriorSpans = new SegmentedList<TextSpan>();
488var restrictedSpans = new SegmentedList<TextSpan>();
495interpolationInteriorSpans.Add(TextSpan.FromBounds(interpolation.OpenBraceToken.Span.End, interpolation.CloseBraceToken.Span.Start));
505var descendantSpan = descendant.Span;
516restrictedSpans.Add(TextSpan.FromBounds(start, descendantSpan.End));
524ImmutableIntervalTree<TextSpan>.CreateFromUnsorted(new TextSpanIntervalIntrospector(), interpolationInteriorSpans),
525ImmutableIntervalTree<TextSpan>.CreateFromUnsorted(new TextSpanIntervalIntrospector(), restrictedSpans));
581builder.Append(text.ToString(TextSpan.FromBounds(line.End, line.EndIncludingLineBreak)));
593var currentLineLeadingWhitespace = line.Text!.ToString(TextSpan.FromBounds(line.Start, pos));
596builder.Append(text.ToString(TextSpan.FromBounds(line.Start + commonWhitespacePrefix.Length, line.EndIncludingLineBreak)));
614builder.Append(text.ToString(TextSpan.FromBounds(line.Start + commonWhitespacePrefix.Length, line.EndIncludingLineBreak)));
639ImmutableIntervalTree<TextSpan> interpolationInteriorSpans)
668var currentLineLeadingWhitespace = line.Text!.ToString(TextSpan.FromBounds(line.Start, pos));
EditAndContinue\BreakpointSpans.cs (35)
18public static bool TryGetBreakpointSpan(SyntaxTree tree, int position, CancellationToken cancellationToken, out TextSpan breakpointSpan)
69public static bool TryGetClosestBreakpointSpan(SyntaxNode root, int position, int minLength, out TextSpan span)
72var candidate = (TextSpan?)null;
109private static TextSpan CreateSpan(SyntaxToken startToken, SyntaxToken endToken)
110=> TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End);
112private static TextSpan CreateSpan(SyntaxNode node)
115private static TextSpan CreateSpan(SyntaxNode node, SyntaxToken token)
116=> TextSpan.FromBounds(node.SpanStart, token.Span.End);
118private static TextSpan CreateSpan(SyntaxToken token)
119=> TextSpan.FromBounds(token.SpanStart, token.Span.End);
121private static TextSpan CreateSpan(SyntaxTokenList startOpt, SyntaxNodeOrToken startFallbackOpt, SyntaxNodeOrToken endOpt)
149return TextSpan.FromBounds(startPos, endPos);
164private static TextSpan? TryCreateSpanForNode(SyntaxNode node, int position)
299TextSpan createSpanForSwitchArm(SwitchExpressionArmSyntax switchArm)
439internal static TextSpan? CreateSpanForConstructorDeclaration(ConstructorDeclarationSyntax constructorSyntax, int position)
471internal static TextSpan CreateSpanForImplicitConstructorInitializer(ConstructorDeclarationSyntax constructor)
477internal static TextSpan CreateSpanForExplicitConstructorInitializer(ConstructorInitializerSyntax constructorInitializer)
483internal static TextSpan CreateSpanForImplicitPrimaryConstructorInitializer(TypeDeclarationSyntax typeDeclaration)
486return TextSpan.FromBounds(typeDeclaration.Identifier.SpanStart, typeDeclaration.ParameterList.Span.End);
505internal static TextSpan CreateSpanForExplicitPrimaryConstructorInitializer(PrimaryConstructorBaseTypeSyntax baseTypeSyntax)
511internal static TextSpan CreateSpanForCopyConstructor(RecordDeclarationSyntax recordDeclaration)
527internal static TextSpan CreateSpanForRecordParameter(ParameterSyntax parameter)
544internal static TextSpan CreateSpanForAutoPropertyAccessor(AccessorDeclarationSyntax accessor)
550private static TextSpan? TryCreateSpanForFieldDeclaration(BaseFieldDeclarationSyntax fieldDeclaration, int position)
553private static TextSpan? TryCreateSpanForSwitchLabel(SwitchLabelSyntax switchLabel, int position)
563private static TextSpan CreateSpanForBlock(BlockSyntax block, int position)
577private static TextSpan? TryCreateSpanForStatement(StatementSyntax statement, int position)
772private static TextSpan? TryCreateSpanForVariableDeclaration(VariableDeclarationSyntax declaration, int position)
781private static TextSpan? TryCreateSpanForVariableDeclaration(
795return default(TextSpan);
802return default(TextSpan);
816return default(TextSpan);
827internal static TextSpan CreateSpanForVariableDeclarator(
914private static TextSpan CreateSpanForCatchClause(CatchClauseSyntax catchClause)
974private static TextSpan? CreateSpanForAccessors(SyntaxList<AccessorDeclarationSyntax> accessors, int position)
EditAndContinue\CSharpEditAndContinueAnalyzer.cs (39)
77internal override bool TryFindMemberDeclaration(SyntaxNode? root, SyntaxNode node, TextSpan activeSpan, out OneOrMany<SyntaxNode> declarations)
206TextSpan span,
333private static TextSpan GetActiveSpan(BlockSyntax node, BlockPart part)
347private static TextSpan GetActiveSpan(ForEachStatementSyntax node, ForEachPart part)
351ForEachPart.VariableDeclaration => TextSpan.FromBounds(node.Type.SpanStart, node.Identifier.Span.End),
357private static TextSpan GetActiveSpan(ForEachVariableStatementSyntax node, ForEachPart part)
361ForEachPart.VariableDeclaration => TextSpan.FromBounds(node.Variable.SpanStart, node.Variable.Span.End),
367private static TextSpan GetActiveSpan(SwitchExpressionSyntax node, SwitchExpressionPart part)
371SwitchExpressionPart.SwitchBody => TextSpan.FromBounds(node.SwitchKeyword.SpanStart, node.CloseBraceToken.Span.End),
600protected override bool TryGetEnclosingBreakpointSpan(SyntaxToken token, out TextSpan span)
603protected override bool TryGetActiveSpan(SyntaxNode node, int statementPart, int minLength, out TextSpan span)
1604protected override TextSpan? TryGetDiagnosticSpan(SyntaxNode node, EditKind editKind)
1607internal static new TextSpan GetDiagnosticSpan(SyntaxNode node, EditKind editKind)
1610private static TextSpan? TryGetDiagnosticSpanImpl(SyntaxNode node, EditKind editKind)
1614internal static TextSpan? TryGetDiagnosticSpanImpl(SyntaxKind kind, SyntaxNode node, EditKind editKind)
1644return TextSpan.FromBounds(ns.NamespaceKeyword.SpanStart, ns.Name.Span.End);
1727return TextSpan.FromBounds(constraint.WhereKeyword.SpanStart, constraint.Constraints.Last().Span.End);
1768return TextSpan.FromBounds(usingStatement.UsingKeyword.SpanStart, usingStatement.CloseParenToken.Span.End);
1772return TextSpan.FromBounds(fixedStatement.FixedKeyword.SpanStart, fixedStatement.CloseParenToken.Span.End);
1776return TextSpan.FromBounds(lockStatement.LockKeyword.SpanStart, lockStatement.CloseParenToken.Span.End);
1799return TextSpan.FromBounds(ifStatement.IfKeyword.SpanStart, ifStatement.CloseParenToken.Span.End);
1806return TextSpan.FromBounds(switchStatement.SwitchKeyword.SpanStart,
1814return TextSpan.FromBounds(whileStatement.WhileKeyword.SpanStart, whileStatement.CloseParenToken.Span.End);
1821return TextSpan.FromBounds(forStatement.ForKeyword.SpanStart, forStatement.CloseParenToken.Span.End);
1826return TextSpan.FromBounds(
1939private static TextSpan GetDiagnosticSpan(SyntaxTokenList modifiers, SyntaxNodeOrToken start, SyntaxNodeOrToken end)
1940=> TextSpan.FromBounds((modifiers.Count != 0) ? modifiers.First().SpanStart : start.SpanStart, end.Span.End);
1942private static TextSpan CombineSpans(TextSpan first, TextSpan second, TextSpan defaultSpan)
1943=> (first.Length > 0 && second.Length > 0) ? TextSpan.FromBounds(first.Start, second.End) : (first.Length > 0) ? first : (second.Length > 0) ? second : defaultSpan;
1945internal override TextSpan GetLambdaParameterDiagnosticSpan(SyntaxNode lambda, int ordinal)
2294private readonly TextSpan? _span;
2303TextSpan? span = null)
2328private TextSpan GetSpan()
2633TextSpan newStatementSpan)
2680protected override TextSpan GetExceptionHandlingRegion(SyntaxNode node, out bool coversAllChildren)
2695return TextSpan.FromBounds(
ExtractMethod\CSharpSelectionValidator.cs (17)
25TextSpan textSpan,
149private static TextSpan GetControlFlowSpan(SelectionInfo selectionInfo)
150=> TextSpan.FromBounds(selectionInfo.FirstTokenInFinalSpan.SpanStart, selectionInfo.LastTokenInFinalSpan.Span.End);
276private static bool CheckTopLevel(SyntaxNode node, TextSpan span)
312private static bool ContainsInBlockBody(BlockSyntax block, TextSpan textSpan)
319var blockSpan = TextSpan.FromBounds(block.OpenBraceToken.Span.End, block.CloseBraceToken.SpanStart);
323private static bool ContainsInExpressionBodiedMemberBody(ArrowExpressionClauseSyntax expressionBodiedMember, TextSpan textSpan)
330var expressionBodiedMemberBody = TextSpan.FromBounds(expressionBodiedMember.Expression.SpanStart, expressionBodiedMember.Expression.Span.End);
407root, TextSpan.FromBounds(selectionInfo.FirstTokenInOriginalSpan.SpanStart, selectionInfo.LastTokenInOriginalSpan.Span.End),
454return selectionInfo.With(s => s.FinalSpan = GetAdjustedSpan(text, TextSpan.FromBounds(start, end)));
476SyntaxNode root, TextSpan textSpan,
529private static TextSpan GetAdjustedSpan(SourceText text, TextSpan textSpan)
552return TextSpan.FromBounds(textSpan.Start, previousLine.EndIncludingLineBreak);
555return TextSpan.FromBounds(textSpan.Start, previousLine.End);
SignatureHelp\TupleConstructionSignatureHelpProvider.cs (3)
37private SignatureHelpState? GetCurrentArgumentState(SyntaxNode root, int position, ISyntaxFactsService syntaxFacts, TextSpan currentSpan, CancellationToken cancellationToken)
64ISyntaxFactsService syntaxFacts, TextSpan currentSpan, CancellationToken cancellationToken, [NotNullWhen(true)] out TupleExpressionSyntax? result)
83ISyntaxFactsService syntaxFacts, TextSpan currentSpan, CancellationToken cancellationToken, [NotNullWhen(true)] out ParenthesizedExpressionSyntax? result)
src\Compilers\CSharp\CSharpAnalyzerDriver\CSharpDeclarationComputer.cs (1)
24TextSpan span,
Structure\CSharpStructureHelpers.cs (15)
153var span = TextSpan.FromBounds(startComment.SpanStart, endComment.Span.End);
256textSpan: TextSpan.FromBounds(startPosition, endPosition),
257hintSpan: TextSpan.FromBounds(startPosition, hintTextEndToken.Span.End),
297TextSpan textSpan, string bannerText, bool autoCollapse,
305TextSpan textSpan, TextSpan hintSpan,
356var span = TextSpan.FromBounds(GetCollapsibleStart(startToken), spanEndPos);
357var hintSpan = GetHintSpan(node, hintEndPos);
369private static TextSpan GetHintSpan(SyntaxNode node, int endPos)
379return TextSpan.FromBounds(child.SpanStart, endPos);
383return TextSpan.FromBounds(node.SpanStart, endPos);
461textSpan: TextSpan.FromBounds(spanStart, spanEnd),
462hintSpan: TextSpan.FromBounds(hintSpanStart, hintSpanEnd),
Microsoft.CodeAnalysis.CSharp.Features.UnitTests (16)
EditAndContinue\BreakpointSpansTests.cs (7)
38markup, out var source, out var position, out TextSpan? expectedSpan);
42tree, position.Value, CancellationToken.None, out var breakpointSpan);
85var expectedEnvelope = expectedSpans.IsEmpty ? default : TextSpan.FromBounds(expectedSpans[0].Start, expectedSpans[^1].End);
92public static IEnumerable<TextSpan> GetBreakpointSequence(SyntaxNode root, int position)
94TextSpan lastSpan = default;
98if (BreakpointSpans.TryGetClosestBreakpointSpan(root, p, minLength: 0, out var span) && span.Start > lastSpan.Start)
Microsoft.CodeAnalysis.CSharp.Semantic.UnitTests (26)
SourceGeneration\GeneratorDriverTests.cs (22)
1219new[] { (gen001, TextSpan.FromBounds(2, 5)) },
1226new[] { (gen001, TextSpan.FromBounds(27, 30)) },
1240new[] { (gen001, TextSpan.FromBounds(34, 37)) },
1249new[] { (gen001, TextSpan.FromBounds(34, 37)), (gen001, TextSpan.FromBounds(77, 80)) },
1253void verifyDiagnosticsWithSource(string source, (Diagnostic, TextSpan)[] reportDiagnostics, params DiagnosticDescription[] expected)
1263foreach ((var d, var l) in reportDiagnostics)
1360return x.Diagnostic.WithLocation(Location.Create(syntaxTree, TextSpan.FromBounds(start, end)));
3626location: Location.Create(syntaxTree, TextSpan.FromBounds(0, 2))));
3659location: Location.Create(validSyntaxTree, TextSpan.FromBounds(0, 2)),
3660additionalLocations: new[] { Location.Create(invalidSyntaxTree, TextSpan.FromBounds(0, 2)) }));
3690location: Location.Create(syntaxTree, TextSpan.FromBounds(0, 2))));
3720location: Location.Create(validSyntaxTree, TextSpan.FromBounds(0, 2)),
3721additionalLocations: new[] { Location.Create(invalidSyntaxTree, TextSpan.FromBounds(0, 2)) }));
3752location: Location.Create(syntaxTree, TextSpan.FromBounds(0, 100))));
3784location: Location.Create(syntaxTree, TextSpan.FromBounds(0, 2)),
3785additionalLocations: new[] { Location.Create(syntaxTree, TextSpan.FromBounds(0, 100)) }));
3815location: Location.Create(syntaxTree, TextSpan.FromBounds(0, 100))));
3844location: Location.Create(syntaxTree, TextSpan.FromBounds(0, 2)),
3845additionalLocations: new[] { Location.Create(syntaxTree, TextSpan.FromBounds(0, 100)) }));
3876location: Location.Create(syntaxTree, TextSpan.FromBounds(0, 2))));
3906location: Location.Create(syntaxTree, TextSpan.FromBounds(0, 2))));
Microsoft.CodeAnalysis.CSharp.Symbol.UnitTests (9)
Microsoft.CodeAnalysis.CSharp.Syntax.UnitTests (66)
IncrementalParsing\IncrementalParsingTests.cs (29)
496var span = new TextSpan(source.IndexOf("]") + 1, length: 1);
528var span = new TextSpan(source.IndexOf("."), length: 1);
573var prefixSpan = new TextSpan(source.IndexOf(prefix), length: prefix.Length);
574var suffixSpan = new TextSpan(source.IndexOf(suffix), length: suffix.Length);
2900var span = new TextSpan(oldIText.Length, 0);
2983var span = new TextSpan(currLen, 0);
3020var span = new TextSpan(text.LastIndexOf('x'), 0);
3198var span = new TextSpan(source.IndexOf(" A[]?"), 0);
3219var span = new TextSpan(src.IndexOf(":"), 1);
3240var span = new TextSpan(source.IndexOf(";"), 0);
3261var span = new TextSpan(source.IndexOf(";") + 1, 0);
3282var span = new TextSpan(source.IndexOf(";") + 1, 0);
3304var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3328var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3352var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3376var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3400var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3424var span = new TextSpan(source.IndexOf(substring) + substring.Length, 1);
3450var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3475var span = new TextSpan(source.IndexOf(substring), 0);
3501var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3527var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3545var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3563var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3581var span = new TextSpan(source.IndexOf(substring) + substring.Length, 0);
3595var span = new TextSpan(start: 0, length: 1); // delete first character
3609var span = new TextSpan(start: 0, length: 0);
3624var span = new TextSpan(start: source.IndexOf(substring), length: 3); // Goo[Goo] -> [Goo]
3661var span = new TextSpan(start: source.IndexOf(":") + 1, length: 0);
Microsoft.CodeAnalysis.CSharp.Test.Utilities (1)
Microsoft.CodeAnalysis.CSharp.Workspaces (131)
Classification\SyntaxClassification\FunctionPointerUnmanagedCallingConventionClassifier.cs (1)
23TextSpan textSpan,
Classification\Worker.cs (9)
26private readonly TextSpan _textSpan;
30private Worker(TextSpan textSpan, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
38IEnumerable<SyntaxToken> tokens, TextSpan textSpan, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
46SyntaxNode node, TextSpan textSpan, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
52private void AddClassification(TextSpan span, string type)
60private bool ShouldAddSpan(TextSpan span)
122var span = token.Span;
135AddClassification(TextSpan.FromBounds(token.Span.Start, token.Span.End - "u8".Length), type);
136AddClassification(TextSpan.FromBounds(token.Span.End - "u8".Length, token.Span.End), ClassificationTypeNames.Keyword);
Rename\CSharpRenameRewriterLanguageService.cs (15)
56private readonly ImmutableDictionary<TextSpan, RenameLocation> _renameLocations;
57private readonly ImmutableHashSet<TextSpan> _conflictLocations;
93private readonly ImmutableDictionary<TextSpan, ImmutableSortedSet<TextSpan>?> _stringAndCommentTextSpans;
105private List<(TextSpan oldSpan, TextSpan newSpan)>? _modifiedSubSpans;
109private void AddModifiedSpan(TextSpan oldSpan, TextSpan newSpan)
296var oldSpan = originalNode.Span;
311var newSpan = newNode.Span;
388var oldSpan = token.Span;
635private SyntaxToken RenameInStringLiteral(SyntaxToken oldToken, SyntaxToken newToken, ImmutableSortedSet<TextSpan>? subSpansToReplace, Func<SyntaxTriviaList, string, string, SyntaxTriviaList, SyntaxToken> createNewStringLiteral)
641var oldSpan = oldToken.Span;
669var oldSpan = trivia.Span;
680ImmutableSortedSet<TextSpan>? subSpansToReplace = null;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\EmbeddedLanguages\VirtualChars\CSharpVirtualCharService.cs (10)
207var lineSpan = currentLine.Span;
254using var _ = ArrayBuilder<(char ch, TextSpan span)>.GetInstance(out var charResults);
287string tokenText, int offset, int startIndexInclusive, int endIndexExclusive, ArrayBuilder<(char ch, TextSpan span)> charResults)
306private static void ConvertCharactersToRunes(ArrayBuilder<(char ch, TextSpan span)> charResults, ImmutableSegmentedList<VirtualChar>.Builder runeResults)
326runeResults.Add(VirtualChar.Create(rune, TextSpan.FromBounds(span.Start, nextSpan.End)));
340ArrayBuilder<(char ch, TextSpan span)> result, string tokenText, int offset, int index)
353ArrayBuilder<(char ch, TextSpan span)> result, string tokenText, int offset, int index)
387ArrayBuilder<(char ch, TextSpan span)> result, string tokenText, int offset, int index)
406ArrayBuilder<(char ch, TextSpan span)> result, string tokenText, int offset, int index, char character)
519result.Add((character, TextSpan.FromBounds(startIndex + offset, endIndex + offset)));
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\CSharp\Indentation\CSharpSmartTokenFormatter.cs (2)
67_root, [TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End)], _options.FormattingOptions, smartTokenformattingRules, cancellationToken);
121_root, [TextSpan.FromBounds(adjustedStartPosition, adjustedEndPosition)], _options.FormattingOptions, smartTokenFormattingRules, cancellationToken);
Microsoft.CodeAnalysis.CSharp.Workspaces.UnitTests (6)
Microsoft.CodeAnalysis.EditorFeatures (194)
CommentSelection\AbstractToggleBlockCommentBase.cs (39)
57protected abstract ImmutableArray<TextSpan> GetBlockCommentsInDocument(Document document, ITextSnapshot snapshot,
58TextSpan linesContainingSelections, CommentSelectionInfo commentInfo, CancellationToken cancellationToken);
98var linesContainingSelection = TextSpan.FromBounds(firstLineAroundSelection, lastLineAroundSelection);
132private static bool TryUncommentBlockComment(ImmutableArray<TextSpan> blockCommentedSpans,
138&& blockCommentSelection.TryGetBlockCommentOnSameLine(blockCommentedSpans, out var blockCommentOnSameLine))
148foreach (var spanToRemove in intersectingBlockComments)
153var trackingSpan = TextSpan.FromBounds(intersectingBlockComments.First().Start, intersectingBlockComments.Last().End);
174var spanToAdd = blockCommentSelection.SelectedSpan;
178spanToAdd = TextSpan.FromBounds(caretLocation, caretLocation);
205if (blockCommentSelection.IsSpanWhitespace(TextSpan.FromBounds(extent.Span.Start, extent.Span.End)))
220var selectedSpan = blockCommentSelection.SelectedSpan;
226foreach (var uncommentedSpan in blockCommentSelection.UncommentedSpansInSelection)
254private static void AddBlockComment(CommentSelectionInfo commentInfo, TextSpan span, ArrayBuilder<TextChange> textChanges)
260private static void DeleteBlockComment(BlockCommentSelectionHelper blockCommentSelection, TextSpan spanToRemove,
282public TextSpan SelectedSpan { get; }
284public ImmutableArray<TextSpan> IntersectingBlockComments { get; }
286public ImmutableArray<TextSpan> UncommentedSpansInSelection { get; }
288public BlockCommentSelectionHelper(ImmutableArray<TextSpan> allBlockComments, SnapshotSpan selectedSnapshotSpan)
293SelectedSpan = TextSpan.FromBounds(selectedSnapshotSpan.Start, selectedSnapshotSpan.End);
301public bool IsSpanWhitespace(TextSpan span)
360public bool TryGetBlockCommentOnSameLine(ImmutableArray<TextSpan> allBlockComments, out TextSpan commentedSpanOnSameLine)
364var lineStartToCaretIsWhitespace = IsSpanWhitespace(TextSpan.FromBounds(selectedLine.Start, SelectedSpan.Start));
365var caretToLineEndIsWhitespace = IsSpanWhitespace(TextSpan.FromBounds(SelectedSpan.Start, selectedLine.End));
366foreach (var blockComment in allBlockComments)
372if (IsSpanWhitespace(TextSpan.FromBounds(SelectedSpan.Start, blockComment.Start)))
382if (IsSpanWhitespace(TextSpan.FromBounds(blockComment.End, SelectedSpan.Start)))
398private static ImmutableArray<TextSpan> GetIntersectingBlockComments(ImmutableArray<TextSpan> allBlockComments, TextSpan span)
404private ImmutableArray<TextSpan> GetUncommentedSpansInSelection()
406var uncommentedSpans = new List<TextSpan>();
410foreach (var commentedSpan in IntersectingBlockComments)
415var possibleUncommentedSpan = TextSpan.FromBounds(spanStart, commentedSpan.Start);
429var uncommentedSpan = TextSpan.FromBounds(spanStart, SelectedSpan.End);
Extensibility\NavigationBar\SimpleNavigationBarItem.cs (1)
12internal sealed class SimpleNavigationBarItem(ITextVersion textVersion, string text, Glyph glyph, ImmutableArray<TextSpan> spans, ImmutableArray<NavigationBarItem> childItems, int indent, bool bolded, bool grayed) : NavigationBarItem(textVersion, text, glyph, spans, childItems, indent, bolded, grayed), IEquatable<SimpleNavigationBarItem>
Navigation\IDocumentNavigationServiceExtensions.cs (3)
31this IDocumentNavigationService service, IThreadingContext threadingContext, Workspace workspace, DocumentId documentId, TextSpan textSpan, NavigationOptions options, bool allowInvalidSpan, CancellationToken cancellationToken)
38this IDocumentNavigationService service, IThreadingContext threadingContext, Workspace workspace, DocumentId documentId, TextSpan textSpan, NavigationOptions options, CancellationToken cancellationToken)
45this IDocumentNavigationService service, IThreadingContext threadingContext, Workspace workspace, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken)
Microsoft.CodeAnalysis.EditorFeatures.Test.Utilities (75)
Formatting\CoreFormatterTestsBase.cs (4)
177private protected async Task AssertFormatAsync(string expected, string code, IEnumerable<TextSpan> spans, OptionsCollection options = null, int? baseIndentation = null)
213internal void AssertFormatWithTransformation(Workspace workspace, string expected, SyntaxFormattingOptions options, ImmutableArray<AbstractFormattingRule> rules, SyntaxNode root, IEnumerable<TextSpan> spans)
226internal void AssertFormat(Workspace workspace, string expected, SyntaxFormattingOptions options, ImmutableArray<AbstractFormattingRule> rules, ITextBuffer clonedBuffer, SyntaxNode root, IEnumerable<TextSpan> spans)
276TestFileMarkupParser.GetSpans(markupCode, out var code, out ImmutableArray<TextSpan> spans);
RefactoringHelpers\RefactoringHelpersTestBase.cs (12)
34text = GetSelectionAndResultSpans(text, out var selection, out var result);
43text = GetSelectionSpan(text, out var selection);
52text = GetSelectionAndResultSpans(text, out var selection, out var result);
65text = GetSelectionSpan(text, out var selection);
71private static string GetSelectionSpan(string text, out TextSpan selection)
73MarkupTestFile.GetSpans(text, out text, out IDictionary<string, ImmutableArray<TextSpan>> spans);
85private static string GetSelectionAndResultSpans(string text, out TextSpan selection, out TextSpan result)
87MarkupTestFile.GetSpans(text, out text, out IDictionary<string, ImmutableArray<TextSpan>> spans);
102private async Task<TNode?> GetNodeForSelectionAsync<TNode>(string text, TextSpan selection, Func<TNode, bool> predicate, bool allowEmptyNodes = false) where TNode : SyntaxNode
Workspaces\EditorTestWorkspace.cs (11)
67IDictionary<string, ImmutableArray<TextSpan>> spans,
265: ImmutableArray<TextSpan>.Empty;
266foreach (var span in document.SelectedSpans)
279mappedSpans[key] = mappedSpans.TryGetValue(key, out var textSpans) ? textSpans : ImmutableArray<TextSpan>.Empty;
314out Dictionary<string, ImmutableArray<TextSpan>> mappedMarkupSpans, out int? mappedCaretLocation)
368var matchingSpan = documentWithSpan.AnnotatedSpans[spanName].Single();
409IDictionary<string, ImmutableArray<TextSpan>> markupSpans,
410out Dictionary<string, ImmutableArray<TextSpan>> mappedMarkupSpans,
413var tempMappedMarkupSpans = new Dictionary<string, PooledObjects.ArrayBuilder<TextSpan>>();
417tempMappedMarkupSpans[key] = PooledObjects.ArrayBuilder<TextSpan>.GetInstance();
418foreach (var markupSpan in markupSpans[key])
Microsoft.CodeAnalysis.EditorFeatures.Test.Utilities2 (8)
Microsoft.CodeAnalysis.EditorFeatures.Text (14)
Microsoft.CodeAnalysis.EditorFeatures.UnitTests (74)
CodeFixes\CodeFixServiceTests.cs (15)
59document, TextSpan.FromBounds(0, 0), new DefaultCodeActionRequestPriorityProvider(), CancellationToken.None);
86_ = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), CancellationToken.None);
112var fixCollections = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), CancellationToken.None);
143_ = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0),
150_ = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0),
179_ = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0),
209var fixCollectionSet = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0),
296var fixes = await tuple.codeFixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), CancellationToken.None);
321document, TextSpan.FromBounds(0, 0), new DefaultCodeActionRequestPriorityProvider(), CancellationToken.None);
563c.ReportDiagnostic(Diagnostic.Create(descriptor, c.Tree.GetLocation(TextSpan.FromBounds(0, 0))));
783return await fixService.GetFixesAsync(document, TextSpan.FromBounds(0, 0), CancellationToken.None);
884var txtDocumentCodeFixes = await tuple.codeFixService.GetFixesAsync(txtDocument, TextSpan.FromBounds(0, 1), CancellationToken.None);
901var logDocumentCodeFixes = await tuple.codeFixService.GetFixesAsync(logDocument, TextSpan.FromBounds(0, 1), CancellationToken.None);
926var span = new TextSpan(line.Start, line.End);
1143static async Task VerifyCachedDiagnosticsAsync(Document sourceDocument, bool expectedCachedDiagnostic, TextSpan testSpan, DiagnosticIncrementalAnalyzer diagnosticIncrementalAnalyzer)
CodeRefactorings\CodeRefactoringServiceTest.cs (7)
50var refactorings = await refactoringService.GetRefactoringsAsync(document, TextSpan.FromBounds(0, 0), CancellationToken.None);
88var refactorings = await refactoringService.GetRefactoringsAsync(document, TextSpan.FromBounds(0, 0), CancellationToken.None);
109var result = await refactoringService.GetRefactoringsAsync(document, TextSpan.FromBounds(0, 0), CancellationToken.None);
172var txtRefactorings = await refactoringService.GetRefactoringsAsync(txtAdditionalDocument, TextSpan.FromBounds(0, 0), CancellationToken.None);
187var logRefactorings = await refactoringService.GetRefactoringsAsync(logAdditionalDocument, TextSpan.FromBounds(0, 0), CancellationToken.None);
211var editorConfigRefactorings = await refactoringService.GetRefactoringsAsync(editorConfig, TextSpan.FromBounds(0, 0), CancellationToken.None);
226var globalConfigRefactorings = await refactoringService.GetRefactoringsAsync(globalConfig, TextSpan.FromBounds(0, 0), CancellationToken.None);
CommentSelection\CommentUncommentSelectionCommandHandlerTests.cs (3)
87CommentSelection(code, new[] { new TextChange(TextSpan.FromBounds(0, 0), "//") }, supportBlockComments: true);
127CommentSelection(code, new[] { new TextChange(TextSpan.FromBounds(0, 0), "//") }, supportBlockComments: false);
423CommentSelection(code, new[] { new TextChange(TextSpan.FromBounds(0, 0), "//") }, new[] { new Span(0, 15) }, supportBlockComments: true);
Diagnostics\DiagnosticAnalyzerServiceTests.cs (4)
427var diagnosticSpan = new TextSpan(2, 2);
482public AdditionalFileAnalyzer2(bool registerFromInitialize, TextSpan diagnosticSpan, string id)
767async Task VerifyCallbackSpanAsync(TextSpan? filterSpan)
952=> Task.FromResult(ImmutableArray.Create(Diagnostic.Create(s_syntaxRule, Location.Create(document.FilePath, TextSpan.FromBounds(0, 0), new LinePositionSpan(new LinePosition(0, 0), new LinePosition(0, 0))))));
EditAndContinue\EditAndContinueLanguageServiceTests.cs (3)
163var documentDiagnostic = CodeAnalysis.Diagnostic.Create(diagnosticDescriptor1, Location.Create(syntaxTree, TextSpan.FromBounds(1, 2)), ["doc", "error 1"]);
165var syntaxError = CodeAnalysis.Diagnostic.Create(diagnosticDescriptor1, Location.Create(syntaxTree, TextSpan.FromBounds(1, 2)), ["doc", "syntax error 3"]);
166var rudeEditDiagnostic = new RudeEditDiagnostic(RudeEditKind.Delete, TextSpan.FromBounds(2, 3), arguments: ["x"]).ToDiagnostic(syntaxTree);
Microsoft.CodeAnalysis.EditorFeatures.Wpf (11)
Microsoft.CodeAnalysis.EditorFeatures2.UnitTests (44)
Classification\ClassificationTests.vb (5)
342Public Sub AddLexicalClassifications(text As SourceText, textSpan As TextSpan, result As SegmentedList(Of ClassifiedSpan), cancellationToken As CancellationToken) Implements IClassificationService.AddLexicalClassifications
345Public Sub AddSyntacticClassifications(services As SolutionServices, root As SyntaxNode, textSpans As ImmutableArray(Of TextSpan), result As SegmentedList(Of ClassifiedSpan), cancellationToken As CancellationToken) Implements IClassificationService.AddSyntacticClassifications
348Public Function AddSemanticClassificationsAsync(document As Document, textSpans As ImmutableArray(Of TextSpan), options As ClassificationOptions, result As SegmentedList(Of ClassifiedSpan), cancellationToken As CancellationToken) As Task Implements IClassificationService.AddSemanticClassificationsAsync
352Public Function AddSyntacticClassificationsAsync(document As Document, textSpans As ImmutableArray(Of TextSpan), result As SegmentedList(Of ClassifiedSpan), cancellationToken As CancellationToken) As Task Implements IClassificationService.AddSyntacticClassificationsAsync
367Public Function AddEmbeddedLanguageClassificationsAsync(document As Document, textSpans As ImmutableArray(Of TextSpan), options As ClassificationOptions, result As SegmentedList(Of ClassifiedSpan), cancellationToken As CancellationToken) As Task Implements IClassificationService.AddEmbeddedLanguageClassificationsAsync
CodeFixes\CodeFixServiceTests.vb (3)
297document, Text.TextSpan.FromBounds(0, 0), New DefaultCodeActionRequestPriorityProvider(), CancellationToken.None)
342Public Function AnalyzeDocumentAsync(document As Document, span As TextSpan?, promptTitle As String, cancellationToken As CancellationToken) As Task Implements ICopilotCodeAnalysisService.AnalyzeDocumentAsync
346Public Function GetCachedDocumentDiagnosticsAsync(document As Document, span As TextSpan?, promptTitles As ImmutableArray(Of String), cancellationToken As CancellationToken) As Task(Of ImmutableArray(Of Diagnostic)) Implements ICopilotCodeAnalysisService.GetCachedDocumentDiagnosticsAsync
FindReferences\FindReferencesTests.vb (11)
202Public ReadOnly Spans As List(Of TextSpan)
204Public Sub New(fileName As String, spans As List(Of TextSpan))
280Dim spans As ImmutableArray(Of TextSpan) = Nothing
281Dim expected = If(doc.AnnotatedSpans.TryGetValue(DefinitionKey, spans), spans, ImmutableArray(Of TextSpan).Empty).Order()
376Optional locationFilterOpt As Func(Of ReferenceLocation, Boolean) = Nothing) As Dictionary(Of String, List(Of TextSpan))
392Private Shared Function PrintSpans(expected As IOrderedEnumerable(Of TextSpan), actual As IOrderedEnumerable(Of TextSpan), doc As Document, prefix As String, suffix As String, Optional messageOnly As Boolean = False) As String
422Private Shared Function TextSpansMatch(expected As IOrderedEnumerable(Of TextSpan), actual As IOrderedEnumerable(Of TextSpan)) As Boolean
426Dim enumeratorExpected As IEnumerator(Of TextSpan) = Nothing
427Dim enumeratorActual As IEnumerator(Of TextSpan) = Nothing
IntelliSense\SignatureHelpControllerTests.vb (2)
66.Returns(Task.FromResult(New SignatureHelpItems(CreateItems(2), TextSpan.FromBounds(0, 0), selectedItem:=0, semanticParameterIndex:=0, syntacticArgumentCount:=0, argumentName:=Nothing)))
213New SignatureHelpItems(_items, TextSpan.FromBounds(position, position), selectedItem:=0, semanticParameterIndex:=0, syntacticArgumentCount:=0, argumentName:=Nothing),
Microsoft.CodeAnalysis.ExternalAccess.AspNetCore (7)
Microsoft.CodeAnalysis.ExternalAccess.Copilot (12)
Internal\Analyzer\AbstractCopilotCodeAnalysisService.cs (4)
39protected abstract Task<ImmutableArray<Diagnostic>> AnalyzeDocumentCoreAsync(Document document, TextSpan? span, string promptTitle, CancellationToken cancellationToken);
73public async Task AnalyzeDocumentAsync(Document document, TextSpan? span, string promptTitle, CancellationToken cancellationToken)
128public async Task<ImmutableArray<Diagnostic>> GetCachedDocumentDiagnosticsAsync(Document document, TextSpan? span, ImmutableArray<string> promptTitles, CancellationToken cancellationToken)
162protected virtual Task<ImmutableArray<Diagnostic>> GetDiagnosticsIntersectWithSpanAsync(Document document, IReadOnlyList<Diagnostic> diagnostics, TextSpan span, CancellationToken cancellationToken)
Internal\Analyzer\CSharp\CSharpCopilotCodeAnalysisService.ReflectionWrapper.cs (3)
17using AnalyzeDocumentAsyncDelegateType = Func<Document, TextSpan?, string, CancellationToken, Task<ImmutableArray<Diagnostic>>>;
108=> CreateDelegate<AnalyzeDocumentAsyncDelegateType>(AnalyzeDocumentAsyncMethodName, [typeof(Document), typeof(TextSpan?), typeof(string), typeof(CancellationToken)]);
138public async Task<ImmutableArray<Diagnostic>> AnalyzeDocumentAsync(Document document, TextSpan? span, string promptTitle, CancellationToken cancellationToken)
Microsoft.CodeAnalysis.ExternalAccess.FSharp (71)
Internal\Classification\FSharpClassificationService.cs (7)
35public void AddLexicalClassifications(SourceText text, TextSpan textSpan, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
42public async Task AddSemanticClassificationsAsync(Document document, ImmutableArray<TextSpan> textSpans, ClassificationOptions options, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
44foreach (var textSpan in textSpans)
52public async Task AddSyntacticClassificationsAsync(Document document, ImmutableArray<TextSpan> textSpans, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
54foreach (var textSpan in textSpans)
67public void AddSyntacticClassifications(SolutionServices services, SyntaxNode? root, ImmutableArray<TextSpan> textSpans, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
84public Task AddEmbeddedLanguageClassificationsAsync(Document document, ImmutableArray<TextSpan> textSpans, ClassificationOptions options, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
Internal\Editor\FSharpEditorFormattingService.cs (4)
44public Task<IList<TextChange>> GetFormattingChangesAsync(Document document, TextSpan? textSpan, CancellationToken cancellationToken)
54public Task<IList<TextChange>> GetFormattingChangesOnPasteAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken)
79async Task<ImmutableArray<TextChange>> IFormattingInteractionService.GetFormattingChangesAsync(Document document, ITextBuffer textBuffer, TextSpan? textSpan, CancellationToken cancellationToken)
91async Task<ImmutableArray<TextChange>> IFormattingInteractionService.GetFormattingChangesOnPasteAsync(Document document, ITextBuffer textBuffer, TextSpan textSpan, CancellationToken cancellationToken)
Structure\FSharpBlockSpan.cs (5)
23public TextSpan TextSpan { get; }
28public TextSpan HintSpan { get; }
50string type, bool isCollapsible, TextSpan textSpan, string bannerText = Ellipses, bool autoCollapse = false, bool isDefaultCollapsed = false)
58string type, bool isCollapsible, TextSpan textSpan, TextSpan hintSpan, string bannerText = Ellipses, bool autoCollapse = false, bool isDefaultCollapsed = false)
Microsoft.CodeAnalysis.ExternalAccess.OmniSharp (18)
Structure\OmniSharpBlockSpan.cs (5)
21public TextSpan TextSpan { get; }
26public TextSpan HintSpan { get; }
48string type, bool isCollapsible, TextSpan textSpan, string bannerText = Ellipses, bool autoCollapse = false, bool isDefaultCollapsed = false)
56string type, bool isCollapsible, TextSpan textSpan, TextSpan hintSpan, string bannerText = Ellipses, bool autoCollapse = false, bool isDefaultCollapsed = false)
Microsoft.CodeAnalysis.ExternalAccess.Razor (15)
Microsoft.CodeAnalysis.ExternalAccess.Xaml (2)
Microsoft.CodeAnalysis.Features (667)
AddImport\AbstractAddImportFeatureService.cs (5)
65Document document, TextSpan span, string diagnosticId, int maxResults,
89Document document, TextSpan span, string diagnosticId, int maxResults,
515Document document, TextSpan span, ImmutableArray<Diagnostic> diagnostics, int maxResultsPerDiagnostic,
538Document document, TextSpan span, ImmutableArray<string> diagnosticIds,
563TextSpan span,
AddImport\IAddImportFeatureService.cs (4)
25Document document, TextSpan span, string diagnosticId, int maxResults,
34Document document, TextSpan span, ImmutableArray<Diagnostic> diagnostics, int maxResultsPerDiagnostic,
48/// Similar to <see cref="GetFixesAsync(Document, TextSpan, string, int, ISymbolSearchService, AddImportOptions, ImmutableArray{PackageSource}, CancellationToken)"/>
52Document document, TextSpan span, ImmutableArray<string> diagnosticIds,
AddImport\Remote\IRemoteMissingImportDiscoveryService.cs (2)
27Checksum solutionChecksum, RemoteServiceCallbackId callbackId, DocumentId documentId, TextSpan span, string diagnosticId, int maxResults,
31Checksum solutionChecksum, RemoteServiceCallbackId callbackId, DocumentId id, TextSpan span, ImmutableArray<string> diagnosticIds,
ClassifiedSpansAndHighlightSpanFactory.cs (13)
32Document document, TextSpan sourceSpan, ClassificationOptions options, CancellationToken cancellationToken)
36var narrowSpan = sourceSpan;
37var lineSpan = GetLineSpanForReference(sourceText, narrowSpan);
44private static TextSpan GetLineSpanForReference(SourceText sourceText, TextSpan referenceSpan)
53return TextSpan.FromBounds(Math.Min(firstNonWhitespacePosition, referenceSpan.Start), sourceLine.End);
57Document document, TextSpan narrowSpan, TextSpan widenedSpan, ClassificationOptions options, CancellationToken cancellationToken)
59var highlightSpan = new TextSpan(
69Document document, TextSpan narrowSpan, TextSpan widenedSpan, ClassificationOptions options, CancellationToken cancellationToken)
83new ClassifiedSpan(ClassificationTypeNames.Text, TextSpan.FromBounds(widenedSpan.Start, narrowSpan.Start)),
85new ClassifiedSpan(ClassificationTypeNames.Text, TextSpan.FromBounds(narrowSpan.End, widenedSpan.End)),
CodeFixes\Suppression\AbstractSuppressionCodeFixProvider.cs (5)
142TextDocument textDocument, TextSpan span, IEnumerable<Diagnostic> diagnostics, CancellationToken cancellationToken)
150internal async Task<ImmutableArray<PragmaWarningCodeAction>> GetPragmaSuppressionsAsync(Document document, TextSpan span, IEnumerable<Diagnostic> diagnostics, CancellationToken cancellationToken)
159Document document, TextSpan span, IEnumerable<Diagnostic> diagnostics, bool skipSuppressMessage, bool skipUnsuppress, CancellationToken cancellationToken)
265private async Task<SuppressionTargetInfo> GetSuppressionTargetInfoAsync(Document document, TextSpan span, CancellationToken cancellationToken)
322TextSpan? minContainingSpan = null;
CodeFixes\Suppression\AbstractSuppressionCodeFixProvider.PragmaHelpers.cs (6)
26TextSpan diagnosticSpan,
28Func<SyntaxToken, TextSpan, SyntaxToken> getNewStartToken,
29Func<SyntaxToken, TextSpan, SyntaxToken> getNewEndToken,
65private static int GetPositionForPragmaInsertion(ImmutableArray<SyntaxTrivia> triviaList, TextSpan currentDiagnosticSpan, AbstractSuppressionCodeFixProvider fixer, bool isStartToken, out SyntaxTrivia triviaAtIndex)
104TextSpan currentDiagnosticSpan,
156TextSpan currentDiagnosticSpan,
CodeFixes\Suppression\AbstractSuppressionCodeFixProvider.RemoveSuppressionCodeAction_Pragma.cs (6)
87SyntaxToken getNewStartToken(SyntaxToken startToken, TextSpan currentDiagnosticSpan) => includeStartTokenChange
91SyntaxToken getNewEndToken(SyntaxToken endToken, TextSpan currentDiagnosticSpan) => includeEndTokenChange
124var diagnosticSpan = diagnostic.Location.SourceSpan;
158private SyntaxToken GetNewTokenWithModifiedPragma(SyntaxToken token, TextSpan currentDiagnosticSpan, bool add, bool toggle, int indexOfTriviaToRemoveOrToggle, bool isStartToken, CancellationToken cancellationToken)
165private SyntaxToken GetNewTokenWithAddedPragma(SyntaxToken token, TextSpan currentDiagnosticSpan, bool isStartToken, CancellationToken cancellationToken)
208var spanToCheck = new TextSpan(
CodeLens\IRemoteCodeLensReferencesService.cs (4)
16ValueTask<ReferenceCount?> GetReferenceCountAsync(Checksum solutionChecksum, DocumentId documentId, TextSpan textSpan, int maxResultCount, CancellationToken cancellationToken);
17ValueTask<ImmutableArray<ReferenceLocationDescriptor>?> FindReferenceLocationsAsync(Checksum solutionChecksum, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken);
18ValueTask<ImmutableArray<ReferenceMethodDescriptor>?> FindReferenceMethodsAsync(Checksum solutionChecksum, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken);
19ValueTask<string> GetFullyQualifiedNameAsync(Checksum solutionChecksum, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken);
CodeRefactorings\AddMissingImports\AbstractAddMissingImportsFeatureService.cs (5)
32public async Task<Document> AddMissingImportsAsync(Document document, TextSpan textSpan, IProgress<CodeAnalysisProgress> progressTracker, CancellationToken cancellationToken)
57public async Task<AddMissingImportsAnalysisResult> AnalyzeAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken)
155private async Task<Document> CleanUpNewLinesAsync(Document document, IEnumerable<TextSpan> insertSpans, SyntaxFormattingOptions formattingOptions, CancellationToken cancellationToken)
162foreach (var insertSpan in insertSpans)
170private async Task<Document> CleanUpNewLinesAsync(Document document, TextSpan insertSpan, SyntaxFormattingOptions options, CancellationToken cancellationToken)
CodeRefactorings\CodeRefactoringContextExtensions.cs (9)
21this CodeRefactoringContext context, ImmutableArray<TCodeAction> actions, TextSpan? applicableToSpan = null)
58public static async Task<TSyntaxNode?> TryGetRelevantNodeAsync<TSyntaxNode>(this Document document, TextSpan span, CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode
64public static TSyntaxNode? TryGetRelevantNode<TSyntaxNode>(this ParsedDocument document, TextSpan span, CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode
67public static TSyntaxNode? TryGetRelevantNode<TSyntaxNode>(this ParsedDocument document, TextSpan span, bool allowEmptyNode, CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode
75this Document document, TextSpan span, CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode
81this Document document, TextSpan span, bool allowEmptyNodes, CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode
88this ParsedDocument document, TextSpan span, CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode
92this ParsedDocument document, TextSpan span, bool allowEmptyNodes, CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode
101this ParsedDocument document, TextSpan span, bool allowEmptyNodes, int maxCount, ref TemporaryArray<TSyntaxNode> result, CancellationToken cancellationToken) where TSyntaxNode : SyntaxNode
CodeRefactorings\MoveType\AbstractMoveTypeService.cs (6)
30public abstract Task<Solution> GetModifiedSolutionAsync(Document document, TextSpan textSpan, MoveTypeOperationKind operationKind, CancellationToken cancellationToken);
31public abstract Task<ImmutableArray<CodeAction>> GetRefactoringAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken);
41protected abstract Task<TTypeDeclarationSyntax?> GetRelevantNodeAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken);
46Document document, TextSpan textSpan, CancellationToken cancellationToken)
52public override async Task<Solution> GetModifiedSolutionAsync(Document document, TextSpan textSpan, MoveTypeOperationKind operationKind, CancellationToken cancellationToken)
74private async Task<State?> CreateStateAsync(Document document, TextSpan textSpan, CancellationToken cancellationToken)
CodeRefactorings\SyncNamespace\AbstractSyncNamespaceCodeRefactoringProvider.State.cs (1)
69TextSpan textSpan,
Completion\Providers\AbstractPartialMethodCompletionProvider.cs (2)
83Document document, int position, TextSpan span, DeclarationModifiers modifiers, SyntaxToken token, CancellationToken cancellationToken)
105private CompletionItem CreateItem(IMethodSymbol method, int line, TextSpan span, SemanticModel semanticModel, DeclarationModifiers modifiers, SyntaxToken token)
ConvertTupleToStruct\AbstractConvertTupleToStructCodeRefactoringProvider.cs (6)
120TextSpan span,
170private CodeAction CreateAction(Document document, TextSpan span, Scope scope, bool isRecord)
184Document document, TextSpan span, CancellationToken cancellationToken)
217Document document, TextSpan span, Scope scope, bool isRecord, CancellationToken cancellationToken)
251(DocumentId documentId, TextSpan span) renamedToken,
263Document document, TextSpan span, Scope scope, bool isRecord, CancellationToken cancellationToken)
Diagnostics\IDiagnosticAnalyzerService.cs (4)
109TextDocument document, TextSpan? range, Func<string, bool>? shouldIncludeDiagnostic,
127TextDocument document, TextSpan? range, CancellationToken cancellationToken)
138TextDocument document, TextSpan? range, DiagnosticKind diagnosticKind, bool includeSuppressedDiagnostics, CancellationToken cancellationToken)
153TextDocument document, TextSpan? range, string? diagnosticId,
EditAndContinue\AbstractEditAndContinueAnalyzer.cs (36)
95internal abstract bool TryFindMemberDeclaration(SyntaxNode? root, SyntaxNode node, TextSpan activeSpan, out OneOrMany<SyntaxNode> declarations);
128protected abstract bool TryGetEnclosingBreakpointSpan(SyntaxToken token, out TextSpan span);
145protected abstract bool TryGetActiveSpan(SyntaxNode node, int statementPart, int minLength, out TextSpan span);
269protected abstract TextSpan? TryGetDiagnosticSpan(SyntaxNode node, EditKind editKind);
271internal TextSpan GetDiagnosticSpan(SyntaxNode node, EditKind editKind)
274protected virtual TextSpan GetBodyDiagnosticSpan(SyntaxNode node, EditKind editKind)
294internal abstract TextSpan GetLambdaParameterDiagnosticSpan(SyntaxNode lambda, int ordinal);
406protected abstract TextSpan GetExceptionHandlingRegion(SyntaxNode node, out bool coversAllChildren);
409internal abstract void ReportEnclosingExceptionHandlingRudeEdits(ArrayBuilder<RudeEditDiagnostic> diagnostics, IEnumerable<Edit<SyntaxNode>> exceptionHandlingEdits, SyntaxNode oldStatement, TextSpan newStatementSpan);
630using var _3 = ArrayBuilder<(SyntaxNode OldNode, SyntaxNode NewNode, TextSpan DiagnosticSpan)>.GetInstance(out var triviaEdits);
723lineText = text.ToString(TextSpan.FromBounds(diagnostic.Span.Start, Math.Min(diagnostic.Span.Start + 120, line.End)));
1188TextSpan newSpan;
1319var trackedSpan = text.Lines.GetTextSpan(trackedLineSpan);
1334private ActiveStatement GetActiveStatementWithSpan(UnmappedActiveStatement oldStatement, SyntaxTree newTree, TextSpan newSpan, ArrayBuilder<RudeEditDiagnostic> diagnostics, CancellationToken cancellationToken)
1357TextSpan newStatementSyntaxSpan,
1575public ActiveStatementExceptionRegions GetExceptionRegions(SyntaxNode root, TextSpan unmappedActiveStatementSpan, bool isNonLeaf, CancellationToken cancellationToken)
1615private TextSpan GetDeletedNodeDiagnosticSpan(
1640private TextSpan FindClosestActiveSpan(SyntaxNode statement, int statementPart)
1667internal TextSpan GetDeletedNodeActiveSpan(IReadOnlyDictionary<SyntaxNode, SyntaxNode> forwardMap, SyntaxNode deletedNode)
1685internal TextSpan GetDeletedDeclarationActiveSpan(IReadOnlyDictionary<SyntaxNode, SyntaxNode> forwardMap, SyntaxNode deletedDeclaration)
1707internal TextSpan GetDeletedNodeDiagnosticSpan(IReadOnlyDictionary<SyntaxNode, SyntaxNode> forwardMap, SyntaxNode deletedNode)
1767protected void AddAroundActiveStatementRudeDiagnostic(ArrayBuilder<RudeEditDiagnostic> diagnostics, SyntaxNode? oldNode, SyntaxNode? newNode, TextSpan newActiveStatementSpan)
1812protected void AddRudeDeleteAroundActiveStatement(ArrayBuilder<RudeEditDiagnostic> diagnostics, SyntaxNode oldNode, TextSpan newActiveStatementSpan)
2041[Out] ArrayBuilder<(SyntaxNode OldNode, SyntaxNode NewNode, TextSpan DiagnosticSpan)> triviaEdits,
2094var rudeEditSpan = default(TextSpan);
2227rudeEditSpan = TextSpan.FromBounds(newTokensEnum.Current.FullSpan.Start, newTokensEnum.Current.SpanStart);
2233rudeEditSpan = TextSpan.FromBounds(lastNewToken.Span.End, newTokensEnum.Current.SpanStart);
2501IReadOnlyList<(SyntaxNode OldNode, SyntaxNode NewNode, TextSpan DiagnosticSpan)> triviaEdits,
3101TextSpan? newActiveStatementSpan = null;
4828TextSpan diagnosticSpan)
4929public void Report(RudeEditKind kind, TextSpan span)
4956public void Report(RudeEditKind kind, CancellationToken cancellationToken, TextSpan? span = null, string?[]? arguments = null)
4959public RudeEditDiagnostic CreateRudeEdit(RudeEditKind kind, CancellationToken cancellationToken, TextSpan? span = null, string?[]? arguments = null)
5019private DiagnosticContext CreateDiagnosticContext(ArrayBuilder<RudeEditDiagnostic> diagnostics, ISymbol? oldSymbol, ISymbol? newSymbol, SyntaxNode? newNode, SemanticModel newModel, Match<SyntaxNode>? topMatch, TextSpan diagnosticSpan = default)
6052private TextSpan GetSymbolLocationSpan(ISymbol symbol, CancellationToken cancellationToken)
EmbeddedLanguages\Classification\AbstractEmbeddedLanguageClassificationService.cs (5)
39Document document, ImmutableArray<TextSpan> textSpans, ClassificationOptions options, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
52SolutionServices services, Project? project, SemanticModel semanticModel, ImmutableArray<TextSpan> textSpans, ClassificationOptions options, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
58foreach (var textSpan in textSpans)
70TextSpan textSpan,
79private readonly TextSpan _textSpan = textSpan;
EmbeddedLanguages\RegularExpressions\RegexParser.CaptureInfoAnalyzer.cs (12)
32private readonly ImmutableDictionary<int, TextSpan>.Builder _captureNumberToSpan;
33private readonly ImmutableDictionary<string, TextSpan>.Builder _captureNameToSpan;
41_captureNumberToSpan = ImmutableDictionary.CreateBuilder<int, TextSpan>();
42_captureNameToSpan = ImmutableDictionary.CreateBuilder<string, TextSpan>();
50public static (ImmutableDictionary<string, TextSpan>, ImmutableDictionary<int, TextSpan>) Analyze(
57private (ImmutableDictionary<string, TextSpan>, ImmutableDictionary<int, TextSpan>) Analyze(
139private readonly TextSpan GetGroupingSpan(RegexGroupingNode grouping)
181private readonly void RecordCapture(RegexToken token, TextSpan span)
197ImmutableDictionary<T, TextSpan>.Builder mapping,
199T val, TextSpan span)
EncapsulateField\AbstractEncapsulateFieldService.cs (7)
41protected abstract Task<ImmutableArray<IFieldSymbol>> GetFieldsAsync(Document document, TextSpan span, CancellationToken cancellationToken);
44public async Task<EncapsulateFieldResult?> EncapsulateFieldsInSpanAsync(Document document, TextSpan span, bool useDefaultBehavior, CancellationToken cancellationToken)
57public async Task<ImmutableArray<CodeAction>> GetEncapsulateFieldCodeActionsAsync(Document document, TextSpan span, CancellationToken cancellationToken)
279Func<DocumentId, TextSpan, bool> filter,
296private static bool IntersectsWithAny(DocumentId documentId, TextSpan span, ISet<(DocumentId documentId, TextSpan span)> constructorLocations)
310private ISet<(DocumentId documentId, TextSpan span)> GetConstructorLocations(Solution solution, INamedTypeSymbol containingType)
ExtractMethod\SelectionValidator.cs (8)
24TextSpan textSpan)
29protected readonly TextSpan OriginalSpan = textSpan;
35public abstract bool IsFinalSpanSemanticallyValidSpan(SyntaxNode node, TextSpan textSpan, IEnumerable<SyntaxNode> returnStatements, CancellationToken cancellationToken);
39SemanticModel semanticModel, TextSpan textSpan, (SyntaxNode, SyntaxNode) range, CancellationToken cancellationToken)
85SyntaxNode root, TextSpan textSpan, CancellationToken cancellationToken) where T : SyntaxNode
145SyntaxNode root, TextSpan textSpan, CancellationToken cancellationToken) where T : SyntaxNode
184public TextSpan OriginalSpan { get; set; }
185public TextSpan FinalSpan { get; set; }
GenerateConstructors\AbstractGenerateConstructorsCodeRefactoringProvider.cs (6)
77Document priorDocument, TextSpan priorSelection, Document currentDocument, IntentDataProvider intentDataProvider, CancellationToken cancellationToken)
152TextSpan textSpan,
153Action<CodeAction, TextSpan> registerSingleAction,
189private async Task<(CodeAction CodeAction, TextSpan ApplicableToSpan)?> HandleNonSelectionAsync(
191TextSpan textSpan,
265Document document, TextSpan textSpan, bool addNullChecks, Accessibility? desiredAccessibility, CancellationToken cancellationToken)
GenerateEqualsAndGetHashCodeFromMembers\GenerateEqualsAndGetHashCodeFromMembersCodeRefactoringProvider.cs (1)
171TextSpan textSpan,
Highlighting\Keywords\AbstractKeywordHighlighter.cs (8)
20protected sealed override void AddHighlightsForNode(SyntaxNode node, List<TextSpan> highlights, CancellationToken cancellationToken)
23protected abstract void AddHighlights(TNode node, List<TextSpan> highlights, CancellationToken cancellationToken);
30private static readonly ObjectPool<List<TextSpan>> s_textSpanListPool = new(() => []);
38SyntaxNode root, int position, List<TextSpan> highlights, CancellationToken cancellationToken)
66private static bool AnyIntersects(int position, List<TextSpan> highlights)
68foreach (var highlight in highlights)
77protected abstract void AddHighlightsForNode(SyntaxNode node, List<TextSpan> highlights, CancellationToken cancellationToken);
79protected static TextSpan EmptySpan(int position)
Navigation\IDocumentNavigationService.cs (6)
19Task<bool> CanNavigateToSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, bool allowInvalidSpan, CancellationToken cancellationToken);
27Task<INavigableLocation?> GetLocationForSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, bool allowInvalidSpan, CancellationToken cancellationToken);
33public virtual Task<bool> CanNavigateToSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, bool allowInvalidSpan, CancellationToken cancellationToken)
39public virtual Task<INavigableLocation?> GetLocationForSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, bool allowInvalidSpan, CancellationToken cancellationToken)
48public static Task<bool> CanNavigateToSpanAsync(this IDocumentNavigationService service, Workspace workspace, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken)
54public static Task<INavigableLocation?> GetLocationForSpanAsync(this IDocumentNavigationService service, Workspace workspace, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken)
ReplaceDocCommentTextWithTag\AbstractReplaceDocCommentTextWithTagCodeRefactoringProvider.cs (8)
41var singleWordSpan = ExpandSpan(sourceText, span, fullyQualifiedName: false);
63var fullyQualifiedSpan = ExpandSpan(sourceText, span, fullyQualifiedName: true);
110CodeRefactoringContext context, SemanticModel semanticModel, SyntaxToken token, TextSpan replacementSpan, CancellationToken cancellationToken)
141CodeRefactoringContext context, TextSpan expandedSpan, string replacement)
152Document document, TextSpan span, string replacement, CancellationToken cancellationToken)
160private static TextSpan ExpandSpan(SourceText sourceText, TextSpan span, bool fullyQualifiedName)
181return TextSpan.FromBounds(startInclusive, endExclusive);
SimplifyTypeNames\AbstractSimplifyTypeNamesCodeFixProvider.cs (4)
45SyntaxNode root, SemanticModel model, TextSpan span,
78var span = context.Span;
124private bool CanSimplifyTypeNameExpression(SemanticModel model, SyntaxNode node, TSimplifierOptions options, TextSpan span, out string diagnosticId, CancellationToken cancellationToken)
129model, node, options, out var issueSpan, out diagnosticId, out _, cancellationToken))
Snippets\SnippetFunctionService.cs (9)
38public static async Task<string?> GetSimplifiedTypeNameAsync(Document document, TextSpan fieldSpan, string fullyQualifiedTypeName, SimplifierOptions simplifierOptions, CancellationToken cancellationToken)
41var updatedTextSpan = new TextSpan(fieldSpan.Start, fullyQualifiedTypeName.Length);
56public async Task<string?> GetSwitchExpansionAsync(Document document, TextSpan caseGenerationLocation, TextSpan switchExpressionLocation, SimplifierOptions simplifierOptions, CancellationToken cancellationToken)
120protected abstract Task<ITypeSymbol?> GetEnumSymbolAsync(Document document, TextSpan switchExpressionSpan, CancellationToken cancellationToken);
122protected abstract Task<(Document, TextSpan)> GetDocumentWithEnumCaseAsync(Document document, string fullyQualifiedTypeName, string firstEnumMemberName, TextSpan caseGenerationLocation, CancellationToken cancellationToken);
128TextSpan caseGenerationLocation,
140private static async Task<string?> GetSimplifiedTypeNameAtSpanAsync(Document documentWithFullyQualifiedTypeName, TextSpan fullyQualifiedTypeSpan, SimplifierOptions simplifierOptions, CancellationToken cancellationToken)
SplitOrMergeIfStatements\AbstractMergeIfStatementsCodeRefactoringProvider.cs (7)
23protected abstract bool IsApplicableSpan(SyntaxNode node, TextSpan span, out SyntaxNode ifOrElseIf);
53void RegisterRefactoring(MergeDirection direction, TextSpan upperIfOrElseIfSpan, TextSpan lowerIfOrElseIfSpan)
60TextSpan.FromBounds(upperIfOrElseIfSpan.Start, lowerIfOrElseIfSpan.End));
65private async Task<Document> RefactorAsync(Document document, TextSpan upperIfOrElseIfSpan, TextSpan lowerIfOrElseIfSpan, CancellationToken cancellationToken)
80static SyntaxNode FindIfOrElseIf(TextSpan span, IIfLikeStatementGenerator ifGenerator, SyntaxNode root)
src\Analyzers\Core\Analyzers\SimplifyTypeNames\SimplifyTypeNamesDiagnosticAnalyzerBase.cs (5)
81out TextSpan issueSpan, out string diagnosticId, out bool inDeclaration,
118out var issueSpan, out var diagnosticId, out var inDeclaration,
135internal static Diagnostic CreateDiagnostic(SemanticModel model, TSimplifierOptions options, AnalyzerOptions analyzerOptions, TextSpan issueSpan, string diagnosticId, bool inDeclaration)
206/// indicate that <c>intervalTree</c> may be updated by adding a new non-overlapping <see cref="TextSpan"/>
249static bool TryProceedWithInterval(bool addIfAvailable, TextSpan span, StrongBox<bool> completed, TextSpanMutableIntervalTree intervalTree)
src\Analyzers\Core\CodeFixes\ConflictMarkerResolution\AbstractConflictMarkerCodeFixProvider.cs (8)
333edits.Add(new TextChange(TextSpan.FromBounds(startPos, startEnd), ""));
337edits.Add(new TextChange(TextSpan.FromBounds(firstMiddlePos, bottomEnd), ""));
346edits.Add(new TextChange(TextSpan.FromBounds(startPos, equalsEnd), ""));
350edits.Add(new TextChange(TextSpan.FromBounds(endPos, bottomEnd), ""));
359edits.Add(new TextChange(TextSpan.FromBounds(startPos, startEnd), ""));
365edits.Add(new TextChange(TextSpan.FromBounds(secondMiddlePos, equalsEnd), ""));
371edits.Add(new TextChange(TextSpan.FromBounds(firstMiddlePos, equalsEnd), ""));
376edits.Add(new TextChange(TextSpan.FromBounds(endPos, bottomEnd), ""));
Structure\BlockSpan.cs (14)
13TextSpan textSpan,
14TextSpan hintSpan,
15ImmutableArray<(TextSpan textSpan, TextSpan hintSpan, string type)> subHeadings = default,
30public TextSpan TextSpan { get; } = textSpan;
35public TextSpan HintSpan { get; } = hintSpan;
50/// The primary span representing "else" statement block would be the same as the <see cref="TextSpan"/> of
54public ImmutableArray<(TextSpan textSpan, TextSpan hintSpan, string type)> SubHeadings { get; } = subHeadings;
77string type, bool isCollapsible, TextSpan textSpan, string bannerText = Ellipses, bool autoCollapse = false, bool isDefaultCollapsed = false)
97Optional<TextSpan> textSpan = default,
98Optional<TextSpan> hintSpan = default,
99Optional<ImmutableArray<(TextSpan textSpan, TextSpan hintSpan, string type)>> subHeadings = default,
Microsoft.CodeAnalysis.Features.Test.Utilities (40)
Microsoft.CodeAnalysis.Features.UnitTests (18)
EditAndContinue\ActiveStatementsMapTests.cs (9)
48var span = TextSpan.FromBounds(8, 11);
51TextSpan.FromBounds(1, 6), // does not overlap
52TextSpan.FromBounds(3, 9), // overlaps
53TextSpan.FromBounds(4, 5), // does not overlap
54TextSpan.FromBounds(6, 7), // does not overlap
55TextSpan.FromBounds(7, 9), // overlaps
56TextSpan.FromBounds(10, 12), // overlaps
57TextSpan.FromBounds(13, 15)); // does not overlap
EditAndContinue\RemoteEditAndContinueServiceTests.cs (3)
121var diagnostic = Diagnostic.Create(diagnosticDescriptor, Location.Create(syntaxTree, TextSpan.FromBounds(1, 1)));
199var documentDiagnostic = Diagnostic.Create(diagnosticDescriptor1, Location.Create(syntaxTree, TextSpan.FromBounds(1, 2)), new[] { "doc", "some error" });
201var syntaxError = Diagnostic.Create(diagnosticDescriptor1, Location.Create(syntaxTree, TextSpan.FromBounds(1, 2)), new[] { "doc", "syntax error" });
EditAndContinue\RudeEditDiagnosticTests.cs (4)
85var re = new RudeEditDiagnostic(kind, TextSpan.FromBounds(1, 2));
91var re = new RudeEditDiagnostic(kind, TextSpan.FromBounds(1, 2), syntaxNode, ["<1>", "<2>"]);
99var re = new RudeEditDiagnostic(kind, TextSpan.FromBounds(1, 2), syntaxNode, ["<1>", "<2>", "<3>"]);
108var re = new RudeEditDiagnostic(kind, TextSpan.FromBounds(1, 2), syntaxNode, ["<1>"]);
Microsoft.CodeAnalysis.LanguageServer (2)
Microsoft.CodeAnalysis.LanguageServer.Protocol (125)
Features\CodeFixes\CodeFixService.cs (19)
102TextDocument document, TextSpan range, ICodeActionRequestPriorityProvider priorityProvider, CancellationToken cancellationToken)
124var spanToErrorDiagnostics = new SortedDictionary<TextSpan, List<DiagnosticData>>();
125var spanToOtherDiagnostics = new SortedDictionary<TextSpan, List<DiagnosticData>>();
151SortedDictionary<TextSpan, List<DiagnosticData>> spanToDiagnostics,
171TextSpan range,
246TextSpan range,
256private static SortedDictionary<TextSpan, List<DiagnosticData>> ConvertToMap(
263var spanToDiagnostics = new SortedDictionary<TextSpan, List<DiagnosticData>>();
281TextDocument document, TextSpan range, string diagnosticId, CancellationToken cancellationToken)
285TextDocument document, TextSpan range, string diagnosticId, DiagnosticSeverity minimumSeverity, CancellationToken cancellationToken)
304var spanToDiagnostics = new SortedDictionary<TextSpan, List<DiagnosticData>>
338var textSpan = new TextSpan(0, text.Length);
437SortedDictionary<TextSpan, List<DiagnosticData>> spanToDiagnostics,
456using var _1 = PooledDictionary<CodeFixProvider, List<(TextSpan range, List<DiagnosticData> diagnostics)>>.GetInstance(out var fixerToRangesAndDiagnostics);
583TextSpan range,
586PooledDictionary<CodeFixProvider, List<(TextSpan range, List<DiagnosticData> diagnostics)>> fixerToRangesAndDiagnostics)
618TextDocument document, TextSpan span, CodeFixProvider fixer, CodeChangeProviderMetadata? fixerMetadata,
699TextSpan diagnosticsSpan,
734TextSpan fixesSpan,
Features\CodeFixes\ICodeFixService.cs (6)
18IAsyncEnumerable<CodeFixCollection> StreamFixesAsync(TextDocument document, TextSpan textSpan, ICodeActionRequestPriorityProvider priorityProvider, CancellationToken cancellationToken);
25Task<CodeFixCollection?> GetMostSevereFixAsync(TextDocument document, TextSpan range, ICodeActionRequestPriorityProvider priorityProvider, CancellationToken cancellationToken);
27Task<CodeFixCollection?> GetDocumentFixAllForIdInSpanAsync(TextDocument document, TextSpan textSpan, string diagnosticId, DiagnosticSeverity severity, CancellationToken cancellationToken);
35public static IAsyncEnumerable<CodeFixCollection> StreamFixesAsync(this ICodeFixService service, TextDocument document, TextSpan range, CancellationToken cancellationToken)
38public static Task<ImmutableArray<CodeFixCollection>> GetFixesAsync(this ICodeFixService service, TextDocument document, TextSpan range, CancellationToken cancellationToken)
41public static Task<ImmutableArray<CodeFixCollection>> GetFixesAsync(this ICodeFixService service, TextDocument document, TextSpan textSpan, ICodeActionRequestPriorityProvider priorityProvider, CancellationToken cancellationToken)
Features\Diagnostics\EngineV2\DiagnosticIncrementalAnalyzer.IncrementalMemberEditAnalyzer.cs (10)
131ImmutableArray<TextSpan> oldMemberSpans,
138var span = spanBased ? changedMember.FullSpan : (TextSpan?)null;
146ImmutableArray<TextSpan> oldMemberSpans,
158ImmutableArray<TextSpan> oldMemberSpans,
171ImmutableArray<TextSpan> oldMemberSpans,
201private async Task<(SyntaxNode changedMember, int changedMemberId, ImmutableArray<TextSpan> memberSpans, Document lastDocument)?> TryGetChangedMemberAsync(
243ImmutableArray<TextSpan> oldMemberSpans,
290ImmutableArray<TextSpan> oldMemberSpans,
299var oldSpan = oldMemberSpans[memberId];
393var newSpan = new TextSpan(start, end - start);
Features\UnifiedSuggestions\UnifiedSuggestedActionsSource.cs (15)
39TextSpan selection,
344static (TextSpan? span, string category) CombineSpansAndCategory(ArrayBuilder<UnifiedSuggestedActionSet> sets)
381var combinedSpan = minStart >= 0 ? TextSpan.FromBounds(minStart, maxEnd) : (TextSpan?)null;
437TextSpan selection,
463TextSpan selection,
469TextSpan selection,
479bool IsActionAndSpanApplicable((CodeAction action, TextSpan? applicableSpan) actionAndSpan)
507TextSpan selection,
539async Task<IUnifiedSuggestedAction> GetUnifiedSuggestedActionSetAsync(CodeAction codeAction, TextSpan? applicableToSpan, TextSpan selection, CancellationToken cancellationToken)
581TextSpan selection,
642TextSpan? selectionOpt,
661TextSpan? selectionOpt,
705ImmutableArray<UnifiedSuggestedActionSet> actionSets, TextSpan? selectionOpt)
Handler\InlineCompletions\InlineCompletionsHandler.cs (20)
174TextSpan snippetShortcut,
192var spanToFormat = TextSpan.FromBounds(textChange.Span.Start, snippetEndPosition);
205var spanContainingFormattedSnippet = TextSpan.FromBounds(snippetShortcut.Start, snippetEndPosition);
212foreach (var span in spans)
215var fieldInFormattedText = GetAdjustedSpan(formattingChanges, span);
216var fieldInSnippetContext = GetTextSpanInContextOfSnippet(fieldInFormattedText.Start, spanContainingFormattedSnippet.Start, fieldInFormattedText.Length);
224var caretInFormattedText = GetAdjustedSpan(formattingChanges, caretSpan.Value);
225var caretInSnippetContext = GetTextSpanInContextOfSnippet(caretInFormattedText.Start, spanContainingFormattedSnippet.Start, caretInFormattedText.Length);
234static TextSpan GetAdjustedSpan(ImmutableArray<TextChange> textChanges, TextSpan originalSpan)
241static TextSpan GetTextSpanInContextOfSnippet(int positionInFullText, int snippetPositionInFullText, int length)
243var offsetInSnippet = new TextSpan(positionInFullText - snippetPositionInFullText, length);
252private static async Task<(string ReplacedSnippetText, ImmutableDictionary<SnippetFieldPart, ImmutableArray<TextSpan>> Fields, TextSpan? CaretSpan)> GetReplacedSnippetTextAsync(
255TextSpan snippetSpan,
267var fieldOffsets = new Dictionary<SnippetFieldPart, ImmutableArray<TextSpan>>();
269TextSpan? caretSpan = null;
292var fieldSpan = new TextSpan(locationInFinalSnippet, part.DefaultText.Length);
Microsoft.CodeAnalysis.LanguageServer.Protocol.UnitTests (15)
Microsoft.CodeAnalysis.Remote.ServiceHub (19)
Services\CodeLensReferences\RemoteCodeLensReferencesService.cs (5)
28private static async ValueTask<SyntaxNode?> TryFindNodeAsync(Solution solution, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken)
43public async ValueTask<ReferenceCount?> GetReferenceCountAsync(Checksum solutionChecksum, DocumentId documentId, TextSpan textSpan, int maxResultCount, CancellationToken cancellationToken)
66public async ValueTask<ImmutableArray<ReferenceLocationDescriptor>?> FindReferenceLocationsAsync(Checksum solutionChecksum, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken)
84public async ValueTask<ImmutableArray<ReferenceMethodDescriptor>?> FindReferenceMethodsAsync(Checksum solutionChecksum, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken)
102public ValueTask<string?> GetFullyQualifiedNameAsync(Checksum solutionChecksum, DocumentId documentId, TextSpan textSpan, CancellationToken cancellationToken)
Microsoft.CodeAnalysis.Test.Utilities (33)
MarkedSource\MarkupTestFile.cs (19)
53string input, bool treatPositionIndicatorsAsCode, out string output, out int? position, out IDictionary<string, ArrayBuilder<TextSpan>> spans)
56var tempSpans = new Dictionary<string, ArrayBuilder<TextSpan>>();
193IDictionary<string, ArrayBuilder<TextSpan>> spans,
198var span = TextSpan.FromBounds(matchIndex, finalIndex);
199GetOrAdd(spans, name, _ => ArrayBuilder<TextSpan>.GetInstance()).Add(span);
212string input, out string output, out int? cursorPositionOpt, out ImmutableArray<TextSpan> spans,
217var builder = GetOrAdd(dictionary, string.Empty, _ => ArrayBuilder<TextSpan>.GetInstance());
223string input, out string output, out int? cursorPositionOpt, out IDictionary<string, ImmutableArray<TextSpan>> spans,
230public static void GetSpans(string input, out string output, out IDictionary<string, ImmutableArray<TextSpan>> spans,
234public static void GetPositionAndSpans(string input, out string output, out int cursorPosition, out ImmutableArray<TextSpan> spans)
241=> GetPositionAndSpans(input, out output, out cursorPosition, out ImmutableArray<TextSpan> spans);
246public static void GetPositionAndSpan(string input, out string output, out int? cursorPosition, out TextSpan? textSpan)
248GetPositionAndSpans(input, out output, out cursorPosition, out ImmutableArray<TextSpan> spans);
249textSpan = spans.Length == 0 ? null : (TextSpan?)spans.Single();
252public static void GetPositionAndSpan(string input, out string output, out int cursorPosition, out TextSpan textSpan)
258public static void GetSpans(string input, out string output, out ImmutableArray<TextSpan> spans)
263public static void GetSpan(string input, out string output, out TextSpan textSpan)
265GetSpans(input, out output, out ImmutableArray<TextSpan> spans);
Microsoft.CodeAnalysis.UnitTests (69)
Text\TextSpanTest.cs (49)
21var span = new TextSpan(0, 42);
30var span = new TextSpan(1, 40);
42var span = new TextSpan(0, 0);
50var s1 = new TextSpan(1, 40);
51var s2 = new TextSpan(1, 40);
64var s1 = new TextSpan(1, 40);
65var s2 = new TextSpan(2, 40);
78var s1 = new TextSpan(1, 5);
79var s2 = new TextSpan(1, 40);
89TextSpan span = new TextSpan(0, 0);
100TextSpan span = new TextSpan(0, 1);
112TextSpan span = new TextSpan(15, 1485);
122TextSpan span = new TextSpan(0, int.MaxValue - 1);
131TextSpan span = new TextSpan(0, 10);
141TextSpan span_05_15 = new TextSpan(5, 10);
142TextSpan span_03_10 = new TextSpan(3, 7);
143TextSpan span_10_11 = new TextSpan(10, 1);
144TextSpan span_00_03 = new TextSpan(0, 3);
201TextSpan span1 = new TextSpan(0, 10);
202TextSpan span2 = new TextSpan(0, 10);
218TextSpan span1 = new TextSpan(0, 10);
219TextSpan span2 = new TextSpan(0, 11);
220TextSpan span3 = new TextSpan(1, 11);
236TextSpan span1 = new TextSpan(10, 10); // 10..20
237TextSpan span2 = new TextSpan(5, 5); // 5..10
248TextSpan span1 = new TextSpan(10, 10); // 10..20
249TextSpan span2 = new TextSpan(5, 2); // 5..7
260TextSpan span1 = new TextSpan(10, 10); // 10..20
261TextSpan span2 = new TextSpan(5, 10); // 5..15
272TextSpan span1 = new TextSpan(10, 0); // [10, 10)
273TextSpan span2 = new TextSpan(10, 0); // [10, 10)
284TextSpan span1 = new TextSpan(10, 0); // [10, 10)
285TextSpan span2 = new TextSpan(5, 10); // [5, 15)
296TextSpan span1 = new TextSpan(10, 10); // 10..20
297TextSpan span2 = new TextSpan(5, 5); // 5..10
308TextSpan span1 = new TextSpan(10, 10); // 10..20
309TextSpan span2 = new TextSpan(5, 2); // 5..7
320TextSpan span1 = new TextSpan(10, 10); // 10..20
321TextSpan span2 = new TextSpan(5, 10); // 5..15
332TextSpan span1 = new TextSpan(10, 0); // [10, 10)
333TextSpan span2 = new TextSpan(10, 0); // [10, 10)
344TextSpan span1 = new TextSpan(2, 5); // [2, 7)
345TextSpan span2 = new TextSpan(7, 5); // [7, 12)
356TextSpan span1 = new TextSpan(2, 5); // [2, 7)
357TextSpan span2 = new TextSpan(3, 0); // [3, 3)
368TextSpan span1 = new TextSpan(2, 5); // [2, 7)
369TextSpan span2 = new TextSpan(2, 0); // [2, 2)
380TextSpan span1 = new TextSpan(2, 5); // [2, 7)
381TextSpan span2 = new TextSpan(7, 0); // [7, 0)
Microsoft.CodeAnalysis.VisualBasic (158)
Compilation\VisualBasicCompilation.vb (11)
1706Dim unusedBuilder As ArrayBuilder(Of TextSpan) = Nothing
1731unusedBuilder = ArrayBuilder(Of TextSpan).GetInstance()
1760Private Sub AddImportsDependencies(diagnostics As BindingDiagnosticBag, infoTree As SyntaxTree, clauseSpan As TextSpan)
1832Public ReadOnly StatementSpan As TextSpan
1833Public ReadOnly ClauseSpans As ImmutableArray(Of TextSpan)
1843Dim builder = ArrayBuilder(Of TextSpan).GetInstance()
2179Dim location = tree.GetLocation(TextSpan.FromBounds(0, 0))
2212Private Sub AddClsComplianceDiagnostics(diagnostics As BindingDiagnosticBag, cancellationToken As CancellationToken, Optional filterTree As SyntaxTree = Nothing, Optional filterSpanWithinTree As TextSpan? = Nothing)
2233Private Shared Iterator Function FilterDiagnosticsByLocation(diagnostics As IEnumerable(Of Diagnostic), tree As SyntaxTree, filterSpanWithinTree As TextSpan?) As IEnumerable(Of Diagnostic)
2243filterSpanWithinTree As TextSpan?,
2300Private Sub GetDiagnosticsForMethodBodiesInTree(tree As SyntaxTree, filterSpanWithinTree As TextSpan?, hasDeclarationErrors As Boolean, diagnostics As BindingDiagnosticBag, cancellationToken As CancellationToken)
src\Compilers\VisualBasic\BasicAnalyzerDriver\VisualBasicDeclarationComputer.vb (1)
16span As TextSpan,
Microsoft.CodeAnalysis.VisualBasic.CodeStyle (42)
src\Workspaces\VisualBasic\Portable\Formatting\Rules\BaseFormattingRule.vb (8)
28Optional textSpan As TextSpan = Nothing,
38Protected Shared Sub SetAlignmentBlockOperation(operations As List(Of IndentBlockOperation), baseToken As SyntaxToken, startToken As SyntaxToken, endToken As SyntaxToken, span As TextSpan, Optional [option] As IndentBlockOption = IndentBlockOption.RelativePosition)
46Protected Shared Sub AddAbsolutePositionIndentBlockOperation(operations As List(Of IndentBlockOperation), startToken As SyntaxToken, endToken As SyntaxToken, indentation As Integer, span As TextSpan, Optional [option] As IndentBlockOption = IndentBlockOption.AbsolutePosition)
50Private Shared Function GetAlignmentSpan(startToken As SyntaxToken, endToken As SyntaxToken) As TextSpan
52Return TextSpan.FromBounds(previousToken.Span.End, endToken.FullSpan.End)
55Private Shared Function GetIndentBlockSpan(startToken As SyntaxToken, endToken As SyntaxToken) As TextSpan
64Return TextSpan.FromBounds(spanStart, trivia.FullSpan.Start)
68Return TextSpan.FromBounds(spanStart, nextToken.SpanStart)
src\Workspaces\VisualBasic\Portable\Formatting\Rules\NodeBasedFormattingRule.vb (2)
79AddIndentBlockOperation(operations, baseToken, startToken, endToken, TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End))
157operations.Add(FormattingOperations.CreateIndentBlockOperation(caseBlockLastToken, nextTokenAfterCase, TextSpan.FromBounds(caseBlockLastToken.Span.End, nextTokenAfterCase.SpanStart), 1, IndentBlockOption.RelativePosition))
Microsoft.CodeAnalysis.VisualBasic.CodeStyle.Fixes (13)
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\VisualBasic\Indentation\SpecialFormattingOperation.vb (5)
72TextSpan.FromBounds(startToken.FullSpan.Start, node.FullSpan.End), indentationDelta:=1, [option]:=IndentBlockOption.RelativePosition))
110baseToken, startToken, endToken, TextSpan.FromBounds(baseToken.Span.End, closeBrace.Span.End), indentationDelta, IndentBlockOption.RelativePosition))
148Dim span As TextSpan
156span = TextSpan.FromBounds(baseToken.Span.End, firstToken.SpanStart)
159span = TextSpan.FromBounds(baseToken.Span.End, closeBrace.Span.End)
Microsoft.CodeAnalysis.VisualBasic.CommandLine.UnitTests (1)
Microsoft.CodeAnalysis.VisualBasic.EditorFeatures (7)
Microsoft.CodeAnalysis.VisualBasic.Features (219)
EditAndContinue\BreakpointSpans.vb (28)
13Friend Function TryGetBreakpointSpan(tree As SyntaxTree, position As Integer, cancellationToken As CancellationToken, <Out> ByRef breakpointSpan As TextSpan) As Boolean
58Public Function TryGetClosestBreakpointSpan(root As SyntaxNode, position As Integer, minLength As Integer, <Out> ByRef span As TextSpan) As Boolean
61Dim candidate As TextSpan? = Nothing
91Private Function CreateSpan(node As SyntaxNode) As TextSpan
92Return TextSpan.FromBounds(node.SpanStart, node.Span.End)
95Private Function TryCreateSpan(Of TNode As SyntaxNode)(list As SeparatedSyntaxList(Of TNode)) As TextSpan?
100Return TextSpan.FromBounds(list.First.SpanStart, list.Last.Span.End)
103Private Function TryCreateSpanForNode(node As SyntaxNode, position As Integer) As TextSpan?
174Return TextSpan.FromBounds(asSingleLine.IfKeyword.SpanStart, asSingleLine.ThenKeyword.Span.End)
235Private Function CreateSpanForMethodBase(methodBase As MethodBaseSyntax) As TextSpan
237Return TextSpan.FromBounds(methodBase.DeclarationKeyword.SpanStart, methodBase.Span.End)
240Return TextSpan.FromBounds(methodBase.Modifiers.First().SpanStart, methodBase.Span.End)
243Private Function TryCreateSpanForPropertyStatement(node As PropertyStatementSyntax) As TextSpan?
250Return TextSpan.FromBounds(node.Identifier.Span.Start, node.Initializer.Span.End)
254Return TextSpan.FromBounds(node.Identifier.Span.Start, node.AsClause.Span.End)
260Private Function TryCreateSpanForVariableDeclaration(modifiers As SyntaxTokenList, declarators As SeparatedSyntaxList(Of VariableDeclaratorSyntax), position As Integer) As TextSpan?
334Private Function TryCreateSpanForFromClause(fromClause As FromClauseSyntax, position As Integer) As TextSpan?
352Private Function TryCreateSpanForFunctionAggregation(functionAggregation As FunctionAggregationSyntax) As TextSpan?
360Private Function TryCreateSpanForOrderByClause(orderByClause As OrderByClauseSyntax, position As Integer) As TextSpan?
368Private Function TryCreateSpanForOrderingSyntax(orderingSyntax As OrderingSyntax) As TextSpan?
372Private Function TryCreateSpanForPartitionWhileClauseSyntax(partitionWhileClause As PartitionWhileClauseSyntax) As TextSpan?
376Private Function TryCreateSpanForCollectionRangeVariable(collectionRangeVariable As CollectionRangeVariableSyntax) As TextSpan?
392Private Function TryCreateSpanForWhereClause(clause As WhereClauseSyntax) As TextSpan?
396Private Function TryCreateSpanForGroupByClause(clause As GroupByClauseSyntax, position As Integer) As TextSpan?
417Return TextSpan.FromBounds(clause.Keys.First.SpanStart, clause.Span.End)
420Private Function TryCreateSpanForSelectClause(clause As SelectClauseSyntax) As TextSpan?
428Private Function TryCreateSpanForLetClause(clause As LetClauseSyntax, position As Integer) As TextSpan?
432Private Function TryCreateSpanForExpression(expression As ExpressionSyntax) As TextSpan?
EditAndContinue\VisualBasicEditAndContinueAnalyzer.vb (31)
43Friend Overrides Function TryFindMemberDeclaration(rootOpt As SyntaxNode, node As SyntaxNode, activeSpan As TextSpan, <Out> ByRef declarations As OneOrMany(Of SyntaxNode)) As Boolean
130span As TextSpan,
331Protected Overrides Function TryGetEnclosingBreakpointSpan(token As SyntaxToken, <Out> ByRef span As TextSpan) As Boolean
335Protected Overrides Function TryGetActiveSpan(node As SyntaxNode, statementPart As Integer, minLength As Integer, <Out> ByRef span As TextSpan) As Boolean
1069Protected Overrides Function TryGetDiagnosticSpan(node As SyntaxNode, editKind As EditKind) As TextSpan?
1073Protected Overloads Shared Function GetDiagnosticSpan(node As SyntaxNode, editKind As EditKind) As TextSpan
1077Private Shared Function TryGetDiagnosticSpanImpl(node As SyntaxNode, editKind As EditKind) As TextSpan?
1081Protected Overrides Function GetBodyDiagnosticSpan(node As SyntaxNode, editKind As EditKind) As TextSpan
1086Friend Shared Function TryGetDiagnosticSpanImpl(kind As SyntaxKind, node As SyntaxNode, editKind As EditKind) As TextSpan?
1257Return TextSpan.FromBounds(newWith.NewKeyword.Span.Start,
1289Return TextSpan.FromBounds(groupJoin.GroupKeyword.SpanStart, groupJoin.JoinKeyword.Span.End)
1304Return TextSpan.FromBounds(partition.SkipOrTakeKeyword.SpanStart, partition.WhileKeyword.Span.End)
1318Private Overloads Shared Function GetDiagnosticSpan(ifKeyword As SyntaxToken, condition As SyntaxNode, thenKeywordOpt As SyntaxToken) As TextSpan
1319Return TextSpan.FromBounds(ifKeyword.Span.Start,
1323Private Overloads Shared Function GetDiagnosticSpan(node As NamespaceStatementSyntax) As TextSpan
1324Return TextSpan.FromBounds(node.NamespaceKeyword.SpanStart, node.Name.Span.End)
1327Private Overloads Shared Function GetDiagnosticSpan(node As TypeStatementSyntax) As TextSpan
1333Private Overloads Shared Function GetDiagnosticSpan(modifiers As SyntaxTokenList, start As SyntaxNodeOrToken, endNode As SyntaxNodeOrToken) As TextSpan
1334Return TextSpan.FromBounds(If(modifiers.Count <> 0, modifiers.First.SpanStart, start.SpanStart),
1338Private Overloads Shared Function GetDiagnosticSpan(header As MethodBaseSyntax) As TextSpan
1399Return TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End)
1402Private Overloads Shared Function GetDiagnosticSpan(lambda As LambdaHeaderSyntax) As TextSpan
1412Return TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End)
1415Friend Overrides Function GetLambdaParameterDiagnosticSpan(lambda As SyntaxNode, ordinal As Integer) As TextSpan
1709Private ReadOnly _span As TextSpan?
1717Optional span As TextSpan? = Nothing)
1736Private Function GetSpan() As TextSpan
2095newStatementSpan As TextSpan)
2127Protected Overrides Function GetExceptionHandlingRegion(node As SyntaxNode, <Out> ByRef coversAllChildren As Boolean) As TextSpan
2135Return TextSpan.FromBounds(tryBlock.FinallyBlock.SpanStart, tryBlock.EndTryStatement.Span.End)
2138Return TextSpan.FromBounds(tryBlock.CatchBlocks.First().SpanStart, tryBlock.EndTryStatement.Span.End)
src\Compilers\VisualBasic\BasicAnalyzerDriver\VisualBasicDeclarationComputer.vb (1)
16span As TextSpan,
Microsoft.CodeAnalysis.VisualBasic.Features.UnitTests (11)
Microsoft.CodeAnalysis.VisualBasic.Semantic.UnitTests (23)
SourceGeneration\GeneratorDriverTests.vb (20)
224gen001, TextSpan.FromBounds(1, 4),
229gen001, TextSpan.FromBounds(19, 22),
239gen001, TextSpan.FromBounds(26, 29),
246gen001, TextSpan.FromBounds(60, 63),
312location:=Location.Create(syntaxTree, TextSpan.FromBounds(2, 4))))
343location:=Location.Create(validSyntaxTree, TextSpan.FromBounds(2, 4)),
344additionalLocations:={Location.Create(invalidSyntaxTree, TextSpan.FromBounds(2, 4))}))
374location:=Location.Create(syntaxTree, TextSpan.FromBounds(2, 4))))
404location:=Location.Create(validSyntaxTree, TextSpan.FromBounds(2, 4)),
405additionalLocations:={Location.Create(invalidSyntaxTree, TextSpan.FromBounds(2, 4))}))
434location:=Location.Create(syntaxTree, TextSpan.FromBounds(2, 100))))
464location:=Location.Create(syntaxTree, TextSpan.FromBounds(2, 4)),
465additionalLocations:={Location.Create(syntaxTree, TextSpan.FromBounds(2, 100))}))
495location:=Location.Create(syntaxTree, TextSpan.FromBounds(2, 100))))
524location:=Location.Create(syntaxTree, TextSpan.FromBounds(2, 4)),
525additionalLocations:={Location.Create(syntaxTree, TextSpan.FromBounds(2, 100))}))
554location:=Location.Create(syntaxTree, TextSpan.FromBounds(2, 4))))
584location:=Location.Create(syntaxTree, TextSpan.FromBounds(2, 4))))
662Shared Sub VerifyDiagnosticsWithSource(source As String, diag As Diagnostic, location As TextSpan, ParamArray expected As DiagnosticDescription())
703Return x.Diagnostic.WithLocation(Location.Create(syntaxTree, TextSpan.FromBounds(start, endpoint)))
Microsoft.CodeAnalysis.VisualBasic.Symbol.UnitTests (8)
Microsoft.CodeAnalysis.VisualBasic.Syntax.UnitTests (12)
TestSyntaxNodes.vb (8)
219Private Sub VerifyListSpans(Of T As VisualBasicSyntaxNode)(list As SyntaxList(Of T), expectedFullSpan As TextSpan)
241Private Sub VerifyListSpans(list As ChildSyntaxList, expectedFullSpan As TextSpan)
263Private Sub VerifyListSpans(list As SyntaxNodeOrTokenList, expectedFullSpan As TextSpan)
287Private Sub VerifyListSpans(list As SyntaxTokenList, expectedFullSpan As TextSpan)
306Private Sub VerifyListSpans(list As SyntaxTriviaList, expectedFullSpan As TextSpan)
411VerifyListSpans(statements, TextSpan.FromBounds(statements(0).FullSpan.Start, statements(statements.Count - 1).FullSpan.End))
942Private Sub CheckErrorList(node As VisualBasicSyntaxNode, expectedErrorCodes As Integer(), expectedSpans As TextSpan())
964Private Sub CheckErrorList(node As SyntaxToken, expectedErrorCodes As Integer(), expectedSpans As TextSpan())
Microsoft.CodeAnalysis.VisualBasic.Test.Utilities (7)
Microsoft.CodeAnalysis.VisualBasic.Workspaces (134)
CodeCleanup\Providers\AbstractTokensCodeCleanupProvider.vb (4)
20document As Document, root As SyntaxNode, spans As ImmutableArray(Of TextSpan), cancellationToken As CancellationToken) As Task(Of Rewriter)
22Public Async Function CleanupAsync(document As Document, spans As ImmutableArray(Of TextSpan), options As CodeCleanupOptions, cancellationToken As CancellationToken) As Task(Of Document) Implements ICodeCleanupProvider.CleanupAsync
30Public Async Function CleanupAsync(root As SyntaxNode, spans As ImmutableArray(Of TextSpan), options As SyntaxFormattingOptions, services As SolutionServices, cancellationToken As CancellationToken) As Task(Of SyntaxNode) Implements ICodeCleanupProvider.CleanupAsync
44Public Sub New(spans As ImmutableArray(Of TextSpan), cancellationToken As CancellationToken)
CodeCleanup\Providers\RemoveUnnecessaryLineContinuationCodeCleanupProvider.vb (6)
32Public Async Function CleanupAsync(document As Document, spans As ImmutableArray(Of TextSpan), options As CodeCleanupOptions, cancellationToken As CancellationToken) As Task(Of Document) Implements ICodeCleanupProvider.CleanupAsync
45Public Function CleanupAsync(root As SyntaxNode, spans As ImmutableArray(Of TextSpan), options As SyntaxFormattingOptions, services As SolutionServices, cancellationToken As CancellationToken) As Task(Of SyntaxNode) Implements ICodeCleanupProvider.CleanupAsync
55Private ReadOnly _spans As ImmutableArray(Of TextSpan)
57Public Shared Function Process(root As SyntaxNode, spans As ImmutableArray(Of TextSpan), cancellationToken As CancellationToken) As SyntaxNode
62Private Sub New(root As SyntaxNode, spans As ImmutableArray(Of TextSpan))
102Private Sub Cleanup(root As SyntaxNode, span As TextSpan, cancellationToken As CancellationToken)
Formatting\Rules\BaseFormattingRule.vb (8)
28Optional textSpan As TextSpan = Nothing,
38Protected Shared Sub SetAlignmentBlockOperation(operations As List(Of IndentBlockOperation), baseToken As SyntaxToken, startToken As SyntaxToken, endToken As SyntaxToken, span As TextSpan, Optional [option] As IndentBlockOption = IndentBlockOption.RelativePosition)
46Protected Shared Sub AddAbsolutePositionIndentBlockOperation(operations As List(Of IndentBlockOperation), startToken As SyntaxToken, endToken As SyntaxToken, indentation As Integer, span As TextSpan, Optional [option] As IndentBlockOption = IndentBlockOption.AbsolutePosition)
50Private Shared Function GetAlignmentSpan(startToken As SyntaxToken, endToken As SyntaxToken) As TextSpan
52Return TextSpan.FromBounds(previousToken.Span.End, endToken.FullSpan.End)
55Private Shared Function GetIndentBlockSpan(startToken As SyntaxToken, endToken As SyntaxToken) As TextSpan
64Return TextSpan.FromBounds(spanStart, trivia.FullSpan.Start)
68Return TextSpan.FromBounds(spanStart, nextToken.SpanStart)
Formatting\Rules\NodeBasedFormattingRule.vb (2)
79AddIndentBlockOperation(operations, baseToken, startToken, endToken, TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End))
157operations.Add(FormattingOperations.CreateIndentBlockOperation(caseBlockLastToken, nextTokenAfterCase, TextSpan.FromBounds(caseBlockLastToken.Span.End, nextTokenAfterCase.SpanStart), 1, IndentBlockOption.RelativePosition))
Rename\VisualBasicRenameRewriterLanguageService.vb (14)
45Private ReadOnly _renameLocations As ImmutableDictionary(Of TextSpan, RenameLocation)
46Private ReadOnly _conflictLocations As ImmutableHashSet(Of TextSpan)
80Private ReadOnly _stringAndCommentTextSpans As ImmutableDictionary(Of TextSpan, ImmutableSortedSet(Of TextSpan))
90Private _modifiedSubSpans As List(Of ValueTuple(Of TextSpan, TextSpan))
93Private ReadOnly _complexifiedSpans As HashSet(Of TextSpan) = New HashSet(Of TextSpan)
95Private Sub AddModifiedSpan(oldSpan As TextSpan, newSpan As TextSpan)
185Me._modifiedSubSpans = New List(Of ValueTuple(Of TextSpan, TextSpan))()
589Private Function RenameInStringLiteral(oldToken As SyntaxToken, newToken As SyntaxToken, subSpansToReplace As ImmutableSortedSet(Of TextSpan), createNewStringLiteral As Func(Of SyntaxTriviaList, String, String, SyntaxTriviaList, SyntaxToken)) As SyntaxToken
626Dim subSpansToReplace As ImmutableSortedSet(Of TextSpan) = Nothing
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\VisualBasic\Indentation\SpecialFormattingOperation.vb (5)
72TextSpan.FromBounds(startToken.FullSpan.Start, node.FullSpan.End), indentationDelta:=1, [option]:=IndentBlockOption.RelativePosition))
110baseToken, startToken, endToken, TextSpan.FromBounds(baseToken.Span.End, closeBrace.Span.End), indentationDelta, IndentBlockOption.RelativePosition))
148Dim span As TextSpan
156span = TextSpan.FromBounds(baseToken.Span.End, firstToken.SpanStart)
159span = TextSpan.FromBounds(baseToken.Span.End, closeBrace.Span.End)
Microsoft.CodeAnalysis.VisualBasic.Workspaces.UnitTests (5)
Microsoft.CodeAnalysis.Workspaces (794)
CaseCorrection\AbstractCaseCorrectionService.cs (4)
20protected abstract void AddReplacements(SemanticModel? semanticModel, SyntaxNode root, ImmutableArray<TextSpan> spans, ConcurrentDictionary<SyntaxToken, SyntaxToken> replacements, CancellationToken cancellationToken);
22public async Task<Document> CaseCorrectAsync(Document document, ImmutableArray<TextSpan> spans, CancellationToken cancellationToken)
41public SyntaxNode CaseCorrect(SyntaxNode root, ImmutableArray<TextSpan> spans, CancellationToken cancellationToken)
44private SyntaxNode CaseCorrect(SemanticModel? semanticModel, SyntaxNode root, ImmutableArray<TextSpan> spans, CancellationToken cancellationToken)
Classification\AbstractClassificationService.cs (10)
31public abstract void AddLexicalClassifications(SourceText text, TextSpan textSpan, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken);
35Document document, ImmutableArray<TextSpan> textSpans, ClassificationOptions options, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
41Document document, ImmutableArray<TextSpan> textSpans, ClassificationOptions options, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
48ImmutableArray<TextSpan> textSpans,
109ImmutableArray<TextSpan> textSpans,
139ImmutableArray<TextSpan> textSpans,
158foreach (var span in reassignedVariableSpans)
166foreach (var span in obsoleteSymbolSpans)
202public async Task AddSyntacticClassificationsAsync(Document document, ImmutableArray<TextSpan> textSpans, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
209SolutionServices services, SyntaxNode? root, ImmutableArray<TextSpan> textSpans, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
Classification\ClassifierHelper.cs (16)
31TextSpan span,
54ImmutableArray<TextSpan> spans,
92var widenedSpan = new TextSpan(spans[0].Start, spans[^1].End);
110TextSpan widenedSpan)
155private static void AdjustSpans(SegmentedList<ClassifiedSpan> spans, TextSpan widenedSpan)
203TextSpan.FromBounds(
236Func<TClassifiedSpan, TextSpan> getSpan,
237Func<TClassifiedSpan, TextSpan, TClassifiedSpan> createSpan)
262var syntacticPartSpan = getSpan(syntacticPart);
286var firstSemanticPartSpan = getSpan(firstSemanticPart);
287var lastSemanticPartSpan = getSpan(lastSemanticPart);
294finalParts.Add(createSpan(syntacticPart, TextSpan.FromBounds(
304var semanticPart1Span = getSpan(semanticPart1);
305var semanticPart2Span = getSpan(semanticPart2);
312finalParts.Add(createSpan(syntacticPart, TextSpan.FromBounds(
320finalParts.Add(createSpan(syntacticPart, TextSpan.FromBounds(
Classification\IClassificationService.cs (5)
28void AddLexicalClassifications(SourceText text, TextSpan textSpan, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken);
34void AddSyntacticClassifications(SolutionServices services, SyntaxNode? root, ImmutableArray<TextSpan> textSpans, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken);
46Task AddSyntacticClassificationsAsync(Document document, ImmutableArray<TextSpan> textSpans, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken);
63Task AddSemanticClassificationsAsync(Document document, ImmutableArray<TextSpan> textSpans, ClassificationOptions options, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken);
74Task AddEmbeddedLanguageClassificationsAsync(Document document, ImmutableArray<TextSpan> textSpans, ClassificationOptions options, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken);
Classification\SyntaxClassification\AbstractNameSyntaxClassifier.cs (1)
31TextSpan span,
Classification\SyntaxClassification\AbstractSyntaxClassifier.cs (2)
22public virtual void AddClassifications(SyntaxNode syntax, TextSpan textSpan, SemanticModel semanticModel, ClassificationOptions options, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
26public virtual void AddClassifications(SyntaxToken syntax, TextSpan textSpan, SemanticModel semanticModel, ClassificationOptions options, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken)
Classification\SyntaxClassification\ISyntaxClassifier.cs (2)
29void AddClassifications(SyntaxNode node, TextSpan textSpan, SemanticModel semanticModel, ClassificationOptions options, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken);
34void AddClassifications(SyntaxToken token, TextSpan textSpan, SemanticModel semanticModel, ClassificationOptions options, SegmentedList<ClassifiedSpan> result, CancellationToken cancellationToken);
CodeCleanup\AbstractCodeCleanerService.cs (30)
27protected abstract ImmutableArray<TextSpan> GetSpansToAvoid(SyntaxNode root);
29public async Task<Document> CleanupAsync(Document document, ImmutableArray<TextSpan> spans, CodeCleanupOptions options, ImmutableArray<ICodeCleanupProvider> providers, CancellationToken cancellationToken)
73public async Task<SyntaxNode> CleanupAsync(SyntaxNode root, ImmutableArray<TextSpan> spans, SyntaxFormattingOptions options, SolutionServices services, ImmutableArray<ICodeCleanupProvider> providers, CancellationToken cancellationToken)
114private static ImmutableArray<TextSpan> GetTextSpansFromAnnotation(
120var builder = ArrayBuilder<TextSpan>.GetInstance();
137out var span))
152out TextSpan span)
219span = TextSpan.FromBounds(node.SpanStart, GetNextTokenEndPosition(nextTokenMarker.Type, nextToken));
226span = TextSpan.FromBounds(GetPreviousTokenStartPosition(previousTokenMarker.Type, previousToken), node.Span.End);
270SyntaxNode root, ImmutableArray<TextSpan> spans, CancellationToken cancellationToken)
278foreach (var span in nonOverlappingSpans)
320private static ImmutableArray<TextSpan> GetNonOverlappingSpans(
321SyntaxNode root, ImmutableArray<TextSpan> spans, CancellationToken cancellationToken)
327var tokenSpans = new List<TextSpan>();
328foreach (var span in spans)
347tokenSpans.Add(TextSpan.FromBounds(start, end));
359SyntaxNode root, TextSpan span,
381private static TextSpan GetSpanAlignedToTokens(
382SyntaxNode root, TextSpan span,
391return TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End);
444private static bool CleanupWholeNode(TextSpan nodeSpan, ImmutableArray<TextSpan> spans)
458Func<SyntaxNode, ImmutableArray<TextSpan>> spanGetter,
466var spans = ImmutableArray<TextSpan>.Empty;
520private ImmutableArray<TextSpan> GetSpans(
521SyntaxNode root, Func<SyntaxNode, ImmutableArray<TextSpan>> spanGetter)
539Func<SyntaxNode, ImmutableArray<TextSpan>> spanGetter,
548var spans = ImmutableArray<TextSpan>.Empty;
599private static bool TryCreateTextSpan(int start, int end, out TextSpan span)
608span = TextSpan.FromBounds(start, end);
CodeCleanup\CodeCleaner.cs (4)
70public static Task<Document> CleanupAsync(Document document, TextSpan span, CodeCleanupOptions options, ImmutableArray<ICodeCleanupProvider> providers = default, CancellationToken cancellationToken = default)
77public static async Task<Document> CleanupAsync(Document document, ImmutableArray<TextSpan> spans, CodeCleanupOptions options, ImmutableArray<ICodeCleanupProvider> providers = default, CancellationToken cancellationToken = default)
87public static Task<SyntaxNode> CleanupAsync(SyntaxNode root, TextSpan span, SyntaxFormattingOptions options, SolutionServices services, ImmutableArray<ICodeCleanupProvider> providers = default, CancellationToken cancellationToken = default)
94public static Task<SyntaxNode> CleanupAsync(SyntaxNode root, ImmutableArray<TextSpan> spans, SyntaxFormattingOptions options, SolutionServices services, ImmutableArray<ICodeCleanupProvider> providers = default, CancellationToken cancellationToken = default)
CodeRefactorings\CodeRefactoringContext.cs (12)
49public TextSpan Span { get; }
56private readonly Action<CodeAction, TextSpan?> _registerRefactoring;
64TextSpan span,
75TextSpan span,
86TextSpan span,
87Action<CodeAction, TextSpan?> registerRefactoring,
108/// <param name="applicableToSpan">The <see cref="TextSpan"/> within original document the <paramref name="action"/> is applicable to.</param>
111/// applicable to. It doesn't have to precisely represent the exact <see cref="TextSpan"/> that will get changed.
113internal void RegisterRefactoring(CodeAction action, TextSpan applicableToSpan) => RegisterRefactoring(action, new Nullable<TextSpan>(applicableToSpan));
115private void RegisterRefactoring(CodeAction action, TextSpan? applicableToSpan)
125internal void Deconstruct(out Document document, out TextSpan span, out CancellationToken cancellationToken)
CodeRefactorings\FixAllOccurences\FixAllProvider.cs (4)
58public static FixAllProvider Create(Func<FixAllContext, Document, Optional<ImmutableArray<TextSpan>>, Task<Document?>> fixAllAsync)
78Func<FixAllContext, Document, Optional<ImmutableArray<TextSpan>>, Task<Document?>> fixAllAsync,
94Func<FixAllContext, Document, Optional<ImmutableArray<TextSpan>>, Task<Document?>> fixAllAsync,
97protected override Task<Document?> FixAllAsync(FixAllContext context, Document document, Optional<ImmutableArray<TextSpan>> fixAllSpans)
Diagnostics\CompilationWithAnalyzersPair.cs (3)
82public async Task<AnalysisResultPair?> GetAnalysisResultAsync(SyntaxTree tree, TextSpan? filterSpan, ImmutableArray<DiagnosticAnalyzer> projectAnalyzers, ImmutableArray<DiagnosticAnalyzer> hostAnalyzers, CancellationToken cancellationToken)
94public async Task<AnalysisResultPair?> GetAnalysisResultAsync(AdditionalText file, TextSpan? filterSpan, ImmutableArray<DiagnosticAnalyzer> projectAnalyzers, ImmutableArray<DiagnosticAnalyzer> hostAnalyzers, CancellationToken cancellationToken)
106public async Task<AnalysisResultPair?> GetAnalysisResultAsync(SemanticModel model, TextSpan? filterSpan, ImmutableArray<DiagnosticAnalyzer> projectAnalyzers, ImmutableArray<DiagnosticAnalyzer> hostAnalyzers, CancellationToken cancellationToken)
Editing\ImportAdder.cs (7)
19private static async ValueTask<IEnumerable<TextSpan>> GetSpansAsync(Document document, CancellationToken cancellationToken)
25private static async ValueTask<IEnumerable<TextSpan>> GetSpansAsync(Document document, SyntaxAnnotation annotation, CancellationToken cancellationToken)
40public static Task<Document> AddImportsAsync(Document document, TextSpan span, OptionSet? options = null, CancellationToken cancellationToken = default)
52public static Task<Document> AddImportsAsync(Document document, IEnumerable<TextSpan> spans, OptionSet? options = null, CancellationToken cancellationToken = default)
55private static async Task<Document> AddImportsFromSyntaxesAsync(Document document, IEnumerable<TextSpan> spans, OptionSet? _, CancellationToken cancellationToken)
83internal static Task<Document> AddImportsFromSyntaxesAsync(Document document, IEnumerable<TextSpan> spans, AddImportPlacementOptions options, CancellationToken cancellationToken)
98internal static Task<Document> AddImportsFromSymbolAnnotationAsync(Document document, IEnumerable<TextSpan> spans, AddImportPlacementOptions options, CancellationToken cancellationToken)
Formatting\Formatter.cs (17)
63public static Task<Document> FormatAsync(Document document, TextSpan span, OptionSet? options = null, CancellationToken cancellationToken = default)
68internal static Task<Document> FormatAsync(Document document, TextSpan span, SyntaxFormattingOptions options, CancellationToken cancellationToken)
79public static async Task<Document> FormatAsync(Document document, IEnumerable<TextSpan>? spans, OptionSet? options = null, CancellationToken cancellationToken = default)
91internal static async Task<Document> FormatAsync(Document document, IEnumerable<TextSpan>? spans, SyntaxFormattingOptions? options, ImmutableArray<AbstractFormattingRule> rules, CancellationToken cancellationToken)
203public static SyntaxNode Format(SyntaxNode node, TextSpan span, Workspace workspace, OptionSet? options = null, CancellationToken cancellationToken = default)
206internal static SyntaxNode Format(SyntaxNode node, TextSpan span, SolutionServices services, SyntaxFormattingOptions options, CancellationToken cancellationToken)
218public static SyntaxNode Format(SyntaxNode node, IEnumerable<TextSpan>? spans, Workspace workspace, OptionSet? options = null, CancellationToken cancellationToken = default)
221private static SyntaxNode Format(SyntaxNode node, IEnumerable<TextSpan>? spans, Workspace workspace, OptionSet? options, ImmutableArray<AbstractFormattingRule> rules, CancellationToken cancellationToken)
227internal static SyntaxNode Format(SyntaxNode node, IEnumerable<TextSpan>? spans, SolutionServices services, SyntaxFormattingOptions options, ImmutableArray<AbstractFormattingRule> rules, CancellationToken cancellationToken)
230private static IFormattingResult? GetFormattingResult(SyntaxNode node, IEnumerable<TextSpan>? spans, Workspace workspace, OptionSet? options, ImmutableArray<AbstractFormattingRule> rules, CancellationToken cancellationToken)
254internal static IFormattingResult GetFormattingResult(SyntaxNode node, IEnumerable<TextSpan>? spans, SolutionServices services, SyntaxFormattingOptions options, ImmutableArray<AbstractFormattingRule> rules, CancellationToken cancellationToken)
283public static IList<TextChange> GetFormattedTextChanges(SyntaxNode node, TextSpan span, Workspace workspace, OptionSet? options = null, CancellationToken cancellationToken = default)
286internal static IList<TextChange> GetFormattedTextChanges(SyntaxNode node, TextSpan span, SolutionServices services, SyntaxFormattingOptions options, CancellationToken cancellationToken = default)
298public static IList<TextChange> GetFormattedTextChanges(SyntaxNode node, IEnumerable<TextSpan>? spans, Workspace workspace, OptionSet? options = null, CancellationToken cancellationToken = default)
301internal static IList<TextChange> GetFormattedTextChanges(SyntaxNode node, IEnumerable<TextSpan>? spans, SolutionServices services, SyntaxFormattingOptions options, CancellationToken cancellationToken = default)
304private static IList<TextChange> GetFormattedTextChanges(SyntaxNode node, IEnumerable<TextSpan>? spans, Workspace workspace, OptionSet? options, ImmutableArray<AbstractFormattingRule> rules, CancellationToken cancellationToken)
312internal static IList<TextChange> GetFormattedTextChanges(SyntaxNode node, IEnumerable<TextSpan>? spans, SolutionServices services, SyntaxFormattingOptions options, ImmutableArray<AbstractFormattingRule> rules, CancellationToken cancellationToken = default)
LanguageServices\FixAllSpanMappingService\AbstractFixAllSpanMappingService.cs (8)
19protected abstract Task<ImmutableDictionary<Document, ImmutableArray<TextSpan>>> GetFixAllSpansIfWithinGlobalStatementAsync(
20Document document, TextSpan span, CancellationToken cancellationToken);
22public Task<ImmutableDictionary<Document, ImmutableArray<TextSpan>>> GetFixAllSpansAsync(
23Document document, TextSpan triggerSpan, FixAllScope fixAllScope, CancellationToken cancellationToken)
31private async Task<ImmutableDictionary<Document, ImmutableArray<TextSpan>>> GetFixAllSpansAsync(
32Document document, TextSpan span, bool fixAllInContainingMember, CancellationToken cancellationToken)
49var builder = PooledDictionary<Document, ArrayBuilder<TextSpan>>.GetInstance();
74TextSpan span,
PatternMatching\AllLowerCamelCaseMatcher.cs (12)
38in TemporaryArray<TextSpan> candidateHumps, out ImmutableArray<TextSpan> matchedSpans)
65private static PatternMatchKind GetKind(CamelCaseResult result, in TemporaryArray<TextSpan> candidateHumps)
69int patternIndex, int candidateHumpIndex, bool? contiguous, in TemporaryArray<TextSpan> candidateHumps)
75var matchedSpansInReverse = includeMatchedSpans ? ArrayBuilder<TextSpan>.GetInstance() : null;
95var candidateHump = candidateHumps[humpIndex];
149int patternIndex, int humpIndex, bool contiguous, in TemporaryArray<TextSpan> candidateHumps)
153var candidateHump = candidateHumps[humpIndex];
191var matchSpanToAdd = new TextSpan(candidateHump.Start, possibleHumpMatchLength);
211CamelCaseResult result, ref CamelCaseResult? bestResult, TextSpan? matchSpanToAdd, in TemporaryArray<TextSpan> candidateHumps)
240private static bool IsBetter(CamelCaseResult result, CamelCaseResult? currentBestResult, in TemporaryArray<TextSpan> candidateHumps)
PatternMatching\PatternMatcher.cs (15)
166using var candidateHumps = TemporaryArray<TextSpan>.Empty;
256var hump = TextSpan.FromBounds(candidateHumps[i].Start, candidateLength);
306private TextSpan? GetMatchedSpan(int start, int length)
428private bool PartStartsWith(string candidate, TextSpan candidatePart, string pattern, TextSpan patternPart, CompareOptions compareOptions)
449private bool PartStartsWith(string candidate, TextSpan candidatePart, string pattern, CompareOptions compareOptions)
457in TemporaryArray<TextSpan> candidateHumps)
504in TemporaryArray<TextSpan> candidateHumps,
506out ImmutableArray<TextSpan> matchedSpans)
514in TemporaryArray<TextSpan> candidateHumps,
517out ImmutableArray<TextSpan> matchedSpans)
534using var matchSpans = TemporaryArray<TextSpan>.Empty;
559var candidateHump = candidateHumps[currentCandidateHump];
568var patternChunkCharacterSpan = patternHumps[currentPatternHump];
Rename\ConflictEngine\RenamedSpansTracker.cs (23)
25private readonly Dictionary<DocumentId, List<(TextSpan oldSpan, TextSpan newSpan)>> _documentToModifiedSpansMap = [];
31internal void AddModifiedSpan(DocumentId documentId, TextSpan oldSpan, TextSpan newSpan)
42internal void AddComplexifiedSpan(DocumentId documentId, TextSpan oldSpan, TextSpan newSpan, List<(TextSpan oldSpan, TextSpan newSpan)> modifiedSubSpans)
70var appliedTextSpans = new HashSet<TextSpan>();
122TextSpan originalSpan, TextSpan newSpan, List<(TextSpan oldSpan, TextSpan newSpan)> modifiedSubSpans)
124public TextSpan OriginalSpan = originalSpan;
125public TextSpan NewSpan = newSpan;
126public List<(TextSpan oldSpan, TextSpan newSpan)> ModifiedSubSpans = modifiedSubSpans;
189var modifiedSubSpans = new List<(TextSpan oldSpan, TextSpan newSpan)>();
224public ImmutableDictionary<DocumentId, ImmutableArray<(TextSpan oldSpan, TextSpan newSpan)>> GetDocumentToModifiedSpansMap()
226var builder = ImmutableDictionary.CreateBuilder<DocumentId, ImmutableArray<(TextSpan oldSpan, TextSpan newSpan)>>();
Rename\ConflictResolution.cs (16)
49private readonly ImmutableDictionary<DocumentId, ImmutableArray<(TextSpan oldSpan, TextSpan newSpan)>> _documentToModifiedSpansMap;
65_documentToModifiedSpansMap = ImmutableDictionary<DocumentId, ImmutableArray<(TextSpan oldSpan, TextSpan newSpan)>>.Empty;
76ImmutableDictionary<DocumentId, ImmutableArray<(TextSpan oldSpan, TextSpan newSpan)>> documentToModifiedSpansMap,
98public ImmutableArray<(TextSpan oldSpan, TextSpan newSpan)> GetComplexifiedSpans(DocumentId documentId)
101: ImmutableArray<(TextSpan oldSpan, TextSpan newSpan)>.Empty;
103public ImmutableDictionary<TextSpan, TextSpan> GetModifiedSpanMap(DocumentId documentId)
105var result = ImmutableDictionary.CreateBuilder<TextSpan, TextSpan>();
129internal TextSpan GetResolutionTextSpan(TextSpan originalSpan, DocumentId documentId)
Simplification\Simplifier.cs (4)
203public static Task<Document> ReduceAsync(Document document, TextSpan span, OptionSet? optionSet = null, CancellationToken cancellationToken = default)
215internal static Task<Document> ReduceAsync(Document document, TextSpan span, SimplifierOptions options, CancellationToken cancellationToken)
222public static async Task<Document> ReduceAsync(Document document, IEnumerable<TextSpan> spans, OptionSet? optionSet = null, CancellationToken cancellationToken = default)
240internal static Task<Document> ReduceAsync(Document document, IEnumerable<TextSpan> spans, SimplifierOptions options, CancellationToken cancellationToken)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Collections\NormalizedTextSpanCollection.cs (42)
14internal sealed class NormalizedTextSpanCollection : ReadOnlyCollection<TextSpan>
21: base(new List<TextSpan>(0))
29public NormalizedTextSpanCollection(TextSpan span)
42public NormalizedTextSpanCollection(IEnumerable<TextSpan> spans)
93var span1 = left[index1];
94var span2 = right[index2];
122spans.Add(TextSpan.FromBounds(start, end));
161var span1 = left[index1];
162var span2 = right[index2];
221var span1 = left[index1];
222var span2 = right[index2];
283var span1 = left[index1];
284var span2 = right[index2];
296spans.Add(TextSpan.FromBounds(Math.Max(lastEnd, span1.Start), span1.End));
307spans.Add(TextSpan.FromBounds(Math.Max(lastEnd, span1.Start), span2.Start));
333var span1 = left[index1++];
334spans.Add(TextSpan.FromBounds(Math.Max(lastEnd, span1.Start), span1.End));
398var span1 = this[index1];
399var span2 = set[index2];
429public bool OverlapsWith(TextSpan span)
458var span1 = this[index1];
459var span2 = set[index2];
483public bool IntersectsWith(TextSpan span)
506foreach (var s in this)
533foreach (var s in this)
546private static IList<TextSpan> ListFromSpan(TextSpan span)
548IList<TextSpan> list = new List<TextSpan>(1)
564private static void UpdateSpanUnion(TextSpan span, IList<TextSpan> spans, ref int start, ref int end)
568spans.Add(TextSpan.FromBounds(start, end));
585private static IList<TextSpan> NormalizeSpans(IEnumerable<TextSpan> spans)
592var sorted = new List<TextSpan>(spans);
599sorted.Sort(delegate (TextSpan s1, TextSpan s2) { return s1.Start.CompareTo(s2.Start); });
601IList<TextSpan> normalized = new List<TextSpan>(sorted.Count);
611normalized.Add(TextSpan.FromBounds(oldStart, oldEnd));
621normalized.Add(TextSpan.FromBounds(oldStart, oldEnd));
626private sealed class OrderedSpanList : List<TextSpan>
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Diagnostics\IPragmaSuppressionsAnalyzer.cs (1)
24TextSpan? span,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\EmbeddedLanguages\Common\EmbeddedSyntaxTrivia.cs (1)
34public TextSpan GetSpan()
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\AnalysisContextExtensions.cs (13)
14private static bool ShouldAnalyze(TextSpan? contextFilterSpan, TextSpan span)
24public static bool ShouldAnalyzeSpan(this SyntaxTreeAnalysisContext context, TextSpan span)
34public static bool ShouldAnalyzeSpan(this SemanticModelAnalysisContext context, TextSpan span)
44public static bool ShouldAnalyzeSpan(this SymbolStartAnalysisContext context, TextSpan span, SyntaxTree tree)
64public static bool ShouldAnalyzeSpan(this SymbolAnalysisContext context, TextSpan span, SyntaxTree tree)
84public static bool ShouldAnalyzeSpan(this AdditionalFileAnalysisContext context, TextSpan span)
94public static bool ShouldAnalyzeSpan(this OperationBlockStartAnalysisContext context, TextSpan span)
104public static bool ShouldAnalyzeSpan(this OperationBlockAnalysisContext context, TextSpan span)
114public static bool ShouldAnalyzeSpan(this OperationAnalysisContext context, TextSpan span)
124public static bool ShouldAnalyzeSpan(this SyntaxNodeAnalysisContext context, TextSpan span)
134public static bool ShouldAnalyzeSpan<TSytnaxKind>(this CodeBlockStartAnalysisContext<TSytnaxKind> context, TextSpan span) where TSytnaxKind : struct
144public static bool ShouldAnalyzeSpan(this CodeBlockAnalysisContext context, TextSpan span)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\SourceTextExtensions_SharedWithCodeStyle.cs (2)
33this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden, CancellationToken cancellationToken)
45this SourceText text, TextSpan span, Func<int, CancellationToken, bool> isPositionHidden,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Extensions\TextSpanExtensions.cs (22)
18public static IEnumerable<TextSpan> ToNormalizedSpans(this IEnumerable<TextSpan> spans)
21public static ImmutableArray<TextSpan> ToNormalizedSpans(this ImmutableArray<TextSpan> spans)
24public static TextSpan Collapse(this IEnumerable<TextSpan> spans)
29foreach (var span in spans)
48return TextSpan.FromBounds(start, end);
54public static bool IsAround(this TextSpan span, SyntaxNodeOrToken node) => IsAround(span, node, node);
60public static bool IsAround(this TextSpan span, SyntaxNodeOrToken startNode, SyntaxNodeOrToken endNode)
62var innerSpan = TextSpan.FromBounds(startNode.Span.Start, endNode.Span.End);
63var outerSpan = TextSpan.FromBounds(startNode.FullSpan.Start, endNode.FullSpan.End);
67public static IEnumerable<TextSpan> Subtract(this TextSpan span, TextSpan except)
81yield return TextSpan.FromBounds(span.Start, startSegmentEnd);
85yield return TextSpan.FromBounds(endSegmentStart, span.End);
88public static IEnumerable<TextSpan> Subtract(this IEnumerable<TextSpan> spans, TextSpan except)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Formatting\Context\FormattingContext.IndentationData.cs (14)
18private abstract class IndentationData(TextSpan textSpan)
20public TextSpan TextSpan { get; } = textSpan;
23public IndentationData WithTextSpan(TextSpan span)
26protected abstract IndentationData WithTextSpanCore(TextSpan span);
29private sealed class SimpleIndentationData(TextSpan textSpan, int indentation) : IndentationData(textSpan)
33protected override IndentationData WithTextSpanCore(TextSpan span)
57public RelativeIndentationData(FormattingContext formattingContext, int inseparableRegionSpanStart, TextSpan textSpan, IndentBlockOperation operation, Func<FormattingContext, IndentBlockOperation, SyntaxToken> effectiveBaseTokenGetter, Func<FormattingContext, IndentBlockOperation, SyntaxToken, int> indentationDeltaGetter, Func<FormattingContext, SyntaxToken, int> baseIndentationGetter)
68this.InseparableRegionSpan = TextSpan.FromBounds(inseparableRegionSpanStart, textSpan.End);
71private RelativeIndentationData(FormattingContext formattingContext, int inseparableRegionSpanStart, TextSpan textSpan, IndentBlockOperation operation, Func<FormattingContext, IndentBlockOperation, SyntaxToken> effectiveBaseTokenGetter, Func<FormattingContext, IndentBlockOperation, SyntaxToken, int> indentationDeltaGetter, Func<FormattingContext, SyntaxToken, int> baseIndentationGetter, int lazyIndentationDelta)
82this.InseparableRegionSpan = TextSpan.FromBounds(inseparableRegionSpanStart, textSpan.End);
85public TextSpan InseparableRegionSpan { get; }
107protected override IndentationData WithTextSpanCore(TextSpan span)
119public AdjustedIndentationData(TextSpan textSpan, IndentationData baseIndentationData, int adjustment)
142protected override IndentationData WithTextSpanCore(TextSpan span)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Formatting\Rules\BaseIndentationFormattingRule.cs (10)
20private readonly TextSpan _span;
22public BaseIndentationFormattingRule(SyntaxNode root, TextSpan span, int baseIndentation, AbstractFormattingRule? vbHelperFormattingRule = null)
130private TextSpan AdjustTextSpan(TextSpan textSpan)
131=> TextSpan.FromBounds(Math.Max(_span.Start, textSpan.Start), Math.Min(_span.End, textSpan.End));
133private static void SetInnermostNodeForSpan(SyntaxNode root, ref TextSpan span, out SyntaxToken token1, out SyntaxToken token2, out SyntaxNode? commonNode)
149private static void GetTokens(SyntaxNode root, TextSpan span, out SyntaxToken token1, out SyntaxToken token2)
168private static TextSpan GetSpanFromTokens(TextSpan span, SyntaxToken token1, SyntaxToken token2)
217return TextSpan.FromBounds(start, end);
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Formatting\Rules\Operations\FormattingOperations.cs (8)
31=> CreateAnchorIndentationOperation(anchorToken, endToken, TextSpan.FromBounds(anchorToken.Span.End, endToken.Span.End));
36public static AnchorIndentationOperation CreateAnchorIndentationOperation(SyntaxToken anchorToken, SyntaxToken endToken, TextSpan textSpan)
43=> CreateSuppressOperation(startToken, endToken, TextSpan.FromBounds(startToken.SpanStart, endToken.Span.End), option);
48private static SuppressOperation CreateSuppressOperation(SyntaxToken startToken, SyntaxToken endToken, TextSpan textSpan, SuppressOption option)
56var span = CommonFormattingHelpers.GetSpanIncludingTrailingAndLeadingTriviaOfAdjacentTokens(startToken, endToken);
63public static IndentBlockOperation CreateIndentBlockOperation(SyntaxToken startToken, SyntaxToken endToken, TextSpan textSpan, int indentationDelta, IndentBlockOption option)
71var span = CommonFormattingHelpers.GetSpanIncludingTrailingAndLeadingTriviaOfAdjacentTokens(startToken, endToken);
79public static IndentBlockOperation CreateRelativeIndentBlockOperation(SyntaxToken baseToken, SyntaxToken startToken, SyntaxToken endToken, TextSpan textSpan, int indentationDelta, IndentBlockOption option)
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Formatting\TriviaEngine\AbstractTriviaFormatter.cs (13)
46private delegate void WhitespaceAppender<T>(LineColumn lineColumn, LineColumnDelta delta, TextSpan span, ArrayBuilder<T> changes);
388var span = GetTextSpan(trivia1, trivia2);
500var span = TextSpan.FromBounds(start, end);
716var insertionPoint = GetInsertionSpan(changes);
731private TextSpan GetInsertionSpan(ArrayBuilder<TextChange> changes)
766TextSpan notUsed,
823private TextChange GetWhitespaceTextChange(LineColumn lineColumn, LineColumnDelta delta, TextSpan span)
826private void AddWhitespaceTextChange(LineColumn lineColumn, LineColumnDelta delta, TextSpan span, ArrayBuilder<TextChange> changes)
832private TextSpan GetTextSpan(SyntaxTrivia trivia1, SyntaxTrivia trivia2)
836return TextSpan.FromBounds(this.StartPosition, trivia2.FullSpan.Start);
841return TextSpan.FromBounds(trivia1.FullSpan.End, this.EndPosition);
844return TextSpan.FromBounds(trivia1.FullSpan.End, trivia2.FullSpan.Start);
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\NamingStyles\NamingStyle.cs (19)
159var spanToCheck = TextSpan.FromBounds(0, name.Length - Suffix.Length);
173private WordSpanEnumerable GetWordSpans(string name, TextSpan nameSpan)
176private static string Substring(string name, TextSpan wordSpan)
179private static readonly Func<string, TextSpan, bool> s_firstCharIsLowerCase = (val, span) => !DoesCharacterHaveCasing(val[span.Start]) || char.IsLower(val[span.Start]);
180private static readonly Func<string, TextSpan, bool> s_firstCharIsUpperCase = (val, span) => !DoesCharacterHaveCasing(val[span.Start]) || char.IsUpper(val[span.Start]);
182private static readonly Func<string, TextSpan, bool> s_wordIsAllUpperCase = (val, span) =>
195private static readonly Func<string, TextSpan, bool> s_wordIsAllLowerCase = (val, span) =>
209string name, TextSpan nameSpan, Func<string, TextSpan, bool> wordCheck,
231private bool CheckPascalCase(string name, TextSpan nameSpan, out string reason)
236private bool CheckAllUpper(string name, TextSpan nameSpan, out string reason)
241private bool CheckAllLower(string name, TextSpan nameSpan, out string reason)
247string name, TextSpan nameSpan,
248Func<string, TextSpan, bool> firstWordCheck,
249Func<string, TextSpan, bool> restWordCheck,
290private bool CheckCamelCase(string name, TextSpan nameSpan, out string reason)
297private bool CheckFirstUpper(string name, TextSpan nameSpan, out string reason)
405using var parts = TemporaryArray<TextSpan>.Empty;
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Services\SelectedMembers\AbstractSelectedMembers.cs (4)
35SyntaxTree tree, TextSpan textSpan, bool allowPartialSelection, CancellationToken cancellationToken)
39SyntaxTree tree, TextSpan textSpan, bool allowPartialSelection, CancellationToken cancellationToken)
43SyntaxTree tree, TextSpan textSpan, bool allowPartialSelection,
78SyntaxNode root, SourceText text, TextSpan textSpan,
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\CommonFormattingHelpers.cs (10)
46public static IEnumerable<(SyntaxToken, SyntaxToken)> ConvertToTokenPairs(this SyntaxNode root, IReadOnlyList<TextSpan> spans)
82public static ValueTuple<SyntaxToken, SyntaxToken> ConvertToTokenPair(this SyntaxNode root, TextSpan textSpan)
158=> (token1.RawKind == 0) ? text.ToString(TextSpan.FromBounds(0, token2.SpanStart)) : text.ToString(TextSpan.FromBounds(token1.Span.End, token2.SpanStart));
260public static TextSpan GetSpanIncludingTrailingAndLeadingTriviaOfAdjacentTokens(SyntaxToken startToken, SyntaxToken endToken)
267return TextSpan.FromBounds(startPosition, endPosition);
325var fullSpan = node.FullSpan;
358public static TextSpan GetFormattingSpan(SyntaxNode root, TextSpan span)
368return TextSpan.FromBounds(startPosition, endPosition);
src\Workspaces\SharedUtilitiesAndExtensions\Compiler\Core\Utilities\StringBreaker.cs (10)
16public static void AddWordParts(string identifier, ref TemporaryArray<TextSpan> parts)
19public static void AddCharacterParts(string identifier, ref TemporaryArray<TextSpan> parts)
22public static void AddParts(string text, bool word, ref TemporaryArray<TextSpan> parts)
26var span = StringBreaker.GenerateSpan(text, start, word);
40public static TextSpan GenerateSpan(string identifier, int wordStart, bool word)
80private static TextSpan ScanCharacterRun(string identifier, int length, int wordStart)
101private static TextSpan ScanWordRun(string identifier, int length, int wordStart)
150private static TextSpan ScanLowerCaseRun(string identifier, int length, int wordStart)
161private static TextSpan ScanNumber(string identifier, int length, int wordStart)
169return TextSpan.FromBounds(wordStart, current);
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Simplification\Simplifiers\AbstractSimplifier.cs (1)
21out TextSpan issueSpan,
src\Workspaces\SharedUtilitiesAndExtensions\Workspace\Core\Utilities\NullableHelpers.cs (1)
56TextSpan span,
Workspace\Host\DocumentService\IDocumentExcerptService.cs (8)
21/// return <see cref="ExcerptResult"/> of given <see cref="Document"/> and <see cref="TextSpan"/>
25Task<ExcerptResult?> TryExcerptAsync(Document document, TextSpan span, ExcerptMode mode, ClassificationOptions classificationOptions, CancellationToken cancellationToken);
40internal readonly struct ExcerptResult(SourceText content, TextSpan mappedSpan, ImmutableArray<ClassifiedSpan> classifiedSpans, Document document, TextSpan span)
50public readonly TextSpan MappedSpan = mappedSpan;
60/// should be same document in <see cref="IDocumentExcerptService.TryExcerptAsync(Document, TextSpan, ExcerptMode, ClassificationOptions, CancellationToken)" />
67/// should be same text span in <see cref="IDocumentExcerptService.TryExcerptAsync(Document, TextSpan, ExcerptMode, ClassificationOptions, CancellationToken)" />
69public readonly TextSpan Span = span;
Microsoft.CodeAnalysis.Workspaces.Test.Utilities (19)
Formatting\FormattingTestBase.cs (8)
36IEnumerable<TextSpan> spans,
67SolutionServices services, string expected, SyntaxNode root, IEnumerable<TextSpan> spans, SyntaxFormattingOptions options, bool treeCompare = true, ParseOptions? parseOptions = null)
83private static async Task AssertFormatAsync(SolutionServices services, string expected, SyntaxNode root, ImmutableArray<TextSpan> spans, SyntaxFormattingOptions options, SourceText sourceText)
99private static bool TryAdjustSpans(SourceText inputText, IList<TextChange> changes, SourceText outputText, ImmutableArray<TextSpan> inputSpans, out ImmutableArray<TextSpan> outputSpans)
107var outputBuilder = ImmutableArray.CreateBuilder<TextSpan>(inputSpans.Length);
110var span = inputSpans[i];
114outputBuilder.Add(TextSpan.FromBounds(0, outputText.Length));
Microsoft.CodeAnalysis.Workspaces.UnitTests (219)
CodeCleanup\MockCodeCleanupProvider.cs (5)
21public IEnumerable<TextSpan> ExpectedResult = null!;
23public Func<MockCodeCleanupProvider, Document, ImmutableArray<TextSpan>, SyntaxFormattingOptions, CancellationToken, Task<Document>>? CleanupDocumentAsyncImpl { get; set; }
24public Func<SyntaxNode, ImmutableArray<TextSpan>, SyntaxFormattingOptions, SolutionServices, SyntaxNode>? CleanupNodeImpl { get; set; }
28public Task<Document> CleanupAsync(Document document, ImmutableArray<TextSpan> spans, CodeCleanupOptions options, CancellationToken cancellationToken)
31public Task<SyntaxNode> CleanupAsync(SyntaxNode root, ImmutableArray<TextSpan> spans, SyntaxFormattingOptions options, SolutionServices services, CancellationToken cancellationToken)
EditorConfigParsing\EditorConfigFileParserTests.cs (72)
15internal static EditorConfigFile<EditorConfigOption> CreateParseResults(string editorconfigFilePath, params (string headerText, TextSpan span, bool isGlobal)[] sections)
32(string.Empty, TextSpan.FromBounds(0, 9), true),
33("*.cs", TextSpan.FromBounds(10, 19), false),
34("*.vb", TextSpan.FromBounds(20, 29), false),
35("*.{cs,vb}", TextSpan.FromBounds(30, 39), false),
36("*.{cs,csx,vb,vbx}", TextSpan.FromBounds(40, 49), false));
55(string.Empty, TextSpan.FromBounds(0, 9), true),
56("*.vb", TextSpan.FromBounds(20, 29), false),
57("*.{cs,vb}", TextSpan.FromBounds(30, 39), false),
58("*.{cs,csx,vb,vbx}", TextSpan.FromBounds(40, 49), false),
59("*s", TextSpan.FromBounds(50, 59), false),
60("*", TextSpan.FromBounds(60, 69), false),
61("*.{cs,csx}", TextSpan.FromBounds(70, 79), false));
70(string.Empty, TextSpan.FromBounds(0, 9), true),
71("*.vb", TextSpan.FromBounds(20, 29), false),
72("*.{cs,vb}", TextSpan.FromBounds(30, 39), false),
73("*.{cs,csx,vb,vbx}", TextSpan.FromBounds(40, 49), false),
74("*s", TextSpan.FromBounds(50, 59), false),
75("*", TextSpan.FromBounds(60, 69), false),
76("*.{cs,csx}", TextSpan.FromBounds(70, 79), false));
87(string.Empty, TextSpan.FromBounds(0, 9), true),
88("*.vb", TextSpan.FromBounds(20, 29), false),
89("*.{cs,csx,vb,vbx}", TextSpan.FromBounds(40, 49), false),
90("*s", TextSpan.FromBounds(50, 59), false),
91("*", TextSpan.FromBounds(60, 69), false),
92("*.{cs,csx}", TextSpan.FromBounds(70, 79), false));
111(string.Empty, TextSpan.FromBounds(0, 9), true),
112("*.cs", TextSpan.FromBounds(10, 19), false),
113("*.vb", TextSpan.FromBounds(20, 29), false),
114("*.{cs,vb}", TextSpan.FromBounds(30, 39), false),
115("*.{cs,csx,vb,vbx}", TextSpan.FromBounds(40, 49), false),
116("*s", TextSpan.FromBounds(50, 59), false),
117("*", TextSpan.FromBounds(60, 69), false),
118("*.{cs,csx}", TextSpan.FromBounds(70, 79), false));
133(string.Empty, TextSpan.FromBounds(0, 9), true),
134("sources/**/*.cs", TextSpan.FromBounds(10, 19), false),
135("sources/**/*.vb", TextSpan.FromBounds(20, 29), false),
136("*.{cs,vb}", TextSpan.FromBounds(30, 39), false),
137("*.{cs,csx,vb,vbx}", TextSpan.FromBounds(40, 49), false),
138("*s", TextSpan.FromBounds(50, 59), false),
139("*", TextSpan.FromBounds(60, 69), false),
140("*.{cs,csx}", TextSpan.FromBounds(70, 79), false));
150(string.Empty, TextSpan.FromBounds(0, 9), true),
151("sources/**/*.cs", TextSpan.FromBounds(10, 19), false),
152("sources/**/*.vb", TextSpan.FromBounds(20, 29), false),
153("*.{cs,vb}", TextSpan.FromBounds(30, 39), false),
154("*.{cs,csx,vb,vbx}", TextSpan.FromBounds(40, 49), false),
155("*s", TextSpan.FromBounds(50, 59), false),
156("*", TextSpan.FromBounds(60, 69), false),
157("*.{cs,csx}", TextSpan.FromBounds(70, 79), false));
172(string.Empty, TextSpan.FromBounds(0, 9), true),
173("*.{cs,csx,vbx}", TextSpan.FromBounds(30, 39), false),
174("*.{cs,csx,vb,vbx}", TextSpan.FromBounds(40, 49), false),
175("*s", TextSpan.FromBounds(50, 59), false),
176("*", TextSpan.FromBounds(60, 69), false));
191(string.Empty, TextSpan.FromBounds(0, 9), true),
192("*.*b", TextSpan.FromBounds(30, 39), false),
193("*.*b", TextSpan.FromBounds(80, 89), false),
194("*.*b", TextSpan.FromBounds(130, 139), false),
195("*.*s", TextSpan.FromBounds(40, 49), false),
196("*.*s", TextSpan.FromBounds(90, 99), false),
197("*.*s", TextSpan.FromBounds(120, 129), false),
198("*s", TextSpan.FromBounds(50, 59), false),
199("*s", TextSpan.FromBounds(100, 109), false),
200("*", TextSpan.FromBounds(60, 69), false),
201("*b", TextSpan.FromBounds(70, 79), false),
202("*b", TextSpan.FromBounds(110, 119), false));
217(string.Empty, TextSpan.FromBounds(0, 9), true),
218("*s", TextSpan.FromBounds(100, 109), false),
219("*", TextSpan.FromBounds(60, 69), false));
234(string.Empty, TextSpan.FromBounds(0, 9), true),
235("*s", TextSpan.FromBounds(100, 109), false));
EditorConfigParsing\NamingStyleParserTests.cs (48)
59Assert.Equal(TextSpan.FromBounds(2155, 2260), rule0.NamingScheme.OptionName.Span);
67Assert.Equal(TextSpan.FromBounds(2562, 2641), rule0.NamingScheme.Capitalization.Span);
70Assert.Equal(TextSpan.FromBounds(2338, 2481), rule0.ApplicableSymbolInfo.Accessibilities.Span);
77Assert.Equal(TextSpan.FromBounds(2338, 2481), rule0.ApplicableSymbolInfo.Accessibilities.Span);
80Assert.Equal(TextSpan.FromBounds(2483, 2558), rule0.ApplicableSymbolInfo.Modifiers.Span);
83Assert.Equal(TextSpan.FromBounds(2338, 2481), rule0.ApplicableSymbolInfo.Accessibilities.Span);
86Assert.Equal(TextSpan.FromBounds(1961, 2049), rule0.Severity.Span);
94Assert.Equal(TextSpan.FromBounds(5078, 5149), rule1.NamingScheme.OptionName.Span);
102Assert.Equal(TextSpan.FromBounds(5236, 5300), rule1.NamingScheme.Capitalization.Span);
105Assert.Equal(TextSpan.FromBounds(4998, 5076), rule1.ApplicableSymbolInfo.OptionName.Span);
120Assert.Equal(TextSpan.FromBounds(5153, 5232), rule1.ApplicableSymbolInfo.SymbolKinds.Span);
123Assert.Equal(TextSpan.FromBounds(4928, 4996), rule1.Severity.Span);
132Assert.Equal(TextSpan.FromBounds(5925, 5999), rule2.NamingScheme.OptionName.Span);
140Assert.Equal(TextSpan.FromBounds(6061, 6127), rule2.NamingScheme.Capitalization.Span);
143Assert.Equal(TextSpan.FromBounds(5853, 5923), rule2.ApplicableSymbolInfo.OptionName.Span);
170Assert.Equal(TextSpan.FromBounds(6003, 6057), rule2.ApplicableSymbolInfo.SymbolKinds.Span);
173Assert.Equal(TextSpan.FromBounds(5781, 5851), rule2.Severity.Span);
181Assert.Equal(TextSpan.FromBounds(2891, 3000), rule3.NamingScheme.OptionName.Span);
189Assert.Equal(TextSpan.FromBounds(3310, 3391), rule3.NamingScheme.Capitalization.Span);
192Assert.Equal(TextSpan.FromBounds(2783, 2889), rule3.ApplicableSymbolInfo.OptionName.Span);
199Assert.Equal(TextSpan.FromBounds(3080, 3225), rule3.ApplicableSymbolInfo.Accessibilities.Span);
202Assert.Equal(TextSpan.FromBounds(3227, 3306), rule3.ApplicableSymbolInfo.Modifiers.Span);
205Assert.Equal(TextSpan.FromBounds(3004, 3078), rule3.ApplicableSymbolInfo.SymbolKinds.Span);
208Assert.Equal(TextSpan.FromBounds(2691, 2781), rule3.Severity.Span);
216Assert.Equal(TextSpan.FromBounds(5502, 5587), rule4.NamingScheme.OptionName.Span);
224Assert.Equal(TextSpan.FromBounds(5666, 5735), rule4.NamingScheme.Capitalization.Span);
227Assert.Equal(TextSpan.FromBounds(5418, 5500), rule4.ApplicableSymbolInfo.OptionName.Span);
241Assert.Equal(TextSpan.FromBounds(5591, 5662), rule4.ApplicableSymbolInfo.SymbolKinds.Span);
244Assert.Equal(TextSpan.FromBounds(5338, 5416), rule4.Severity.Span);
252Assert.Equal(TextSpan.FromBounds(3569, 3642), rule5.NamingScheme.OptionName.Span);
260Assert.Equal(TextSpan.FromBounds(3773, 3836), rule5.NamingScheme.Capitalization.Span);
263Assert.Equal(TextSpan.FromBounds(3497, 3567), rule5.ApplicableSymbolInfo.OptionName.Span);
275Assert.Equal(TextSpan.FromBounds(3711, 3769), rule5.ApplicableSymbolInfo.Modifiers.Span);
279Assert.Equal(TextSpan.FromBounds(3646, 3709), rule5.ApplicableSymbolInfo.SymbolKinds.Span);
282Assert.Equal(TextSpan.FromBounds(3423, 3495), rule5.Severity.Span);
290Assert.Equal(TextSpan.FromBounds(4601, 4685), rule6.NamingScheme.OptionName.Span);
292Assert.Equal(TextSpan.FromBounds(4825, 4885), rule6.NamingScheme.Prefix.Span);
298Assert.Equal(TextSpan.FromBounds(4755, 4823), rule6.NamingScheme.Capitalization.Span);
301Assert.Equal(TextSpan.FromBounds(4518, 4599), rule6.ApplicableSymbolInfo.OptionName.Span);
315Assert.Equal(TextSpan.FromBounds(4689, 4751), rule6.ApplicableSymbolInfo.SymbolKinds.Span);
318Assert.Equal(TextSpan.FromBounds(4439, 4516), rule6.Severity.Span);
326Assert.Equal(TextSpan.FromBounds(4045, 4125), rule7.NamingScheme.OptionName.Span);
328Assert.Equal(TextSpan.FromBounds(4326, 4385), rule7.NamingScheme.Prefix.Span);
334Assert.Equal(TextSpan.FromBounds(4258, 4324), rule7.NamingScheme.Capitalization.Span);
337Assert.Equal(TextSpan.FromBounds(3966, 4043), rule7.ApplicableSymbolInfo.OptionName.Span);
349Assert.Equal(TextSpan.FromBounds(4191, 4254), rule7.ApplicableSymbolInfo.Modifiers.Span);
352Assert.Equal(TextSpan.FromBounds(4129, 4189), rule7.ApplicableSymbolInfo.SymbolKinds.Span);
355Assert.Equal(TextSpan.FromBounds(3889, 3964), rule7.Severity.Span);
EditorConfigParsing\SectionParserTests.cs (17)
20var section = new Section(null, false, default(TextSpan), headerText, $"[{headerText}]");
30var section = new Section(null, false, default(TextSpan), headerText, $"[{headerText}]");
39var section = new Section(null, false, default(TextSpan), headerText, $"[{headerText}]");
49var section = new Section(null, false, default(TextSpan), headerText, $"[{headerText}]");
59var section = new Section(null, false, default(TextSpan), headerText, $"[{headerText}]");
69var section = new Section(null, true, default(TextSpan), headerText, $"[{headerText}]");
79var section = new Section(null, true, default(TextSpan), string.Empty, string.Empty);
92var section = new Section(null, false, default(TextSpan), headerText, $"[{headerText}]");
103var section = new Section(null, false, default(TextSpan), headerText, $"[{headerText}]");
112var section = new Section(null, false, default(TextSpan), headerText, $"[{headerText}]");
121var section = new Section(null, false, default(TextSpan), headerText, $"[{headerText}]");
135var section = new Section(null, false, default(TextSpan), headerText, $"[{headerText}]");
152var section = new Section(null, false, default(TextSpan), headerText, $"[{headerText}]");
187var section = new Section(editorconfigFilePath, false, default(TextSpan), headerText, $"[{headerText}]");
210var section = new Section(editorconfigFilePath, false, default(TextSpan), headerText, $"[{headerText}]");
219var section = new Section(editorconfigFilePath, false, default(TextSpan), headerText, $"[{headerText}]");
230var section = new Section(editorconfigFilePath, false, default(TextSpan), headerText, $"[{headerText}]");
Shared\Extensions\TextSpanExtensions\SubtractTests.cs (59)
28private static TextSpan LongSpan { get; } = TextSpan.FromBounds(10, 20);
29private static TextSpan UnitSpan { get; } = TextSpan.FromBounds(10, 11);
30private static TextSpan EmptySpan { get; } = TextSpan.FromBounds(10, 10);
32private static int RightBeforeStart(TextSpan span) => span.Start - 1;
33private static int AtStart(TextSpan span) => span.Start;
34private static int RightAfterStart(TextSpan span) => span.Start + 1;
35private static int RightBeforeEnd(TextSpan span) => span.End - 1;
36private static int AtEnd(TextSpan span) => span.End;
37private static int RightAfterEnd(TextSpan span) => span.End + 1;
44LongSpan.Subtract(TextSpan.FromBounds(RightBeforeStart(LongSpan), RightBeforeStart(LongSpan))));
52LongSpan.Subtract(TextSpan.FromBounds(RightBeforeStart(LongSpan), AtStart(LongSpan))));
59[TextSpan.FromBounds(RightAfterStart(LongSpan), AtEnd(LongSpan))],
60LongSpan.Subtract(TextSpan.FromBounds(RightBeforeStart(LongSpan), RightAfterStart(LongSpan))));
67[TextSpan.FromBounds(RightBeforeEnd(LongSpan), AtEnd(LongSpan))],
68LongSpan.Subtract(TextSpan.FromBounds(RightBeforeStart(LongSpan), RightBeforeEnd(LongSpan))));
75LongSpan.Subtract(TextSpan.FromBounds(RightBeforeStart(LongSpan), AtEnd(LongSpan))));
82LongSpan.Subtract(TextSpan.FromBounds(RightBeforeStart(LongSpan), RightAfterEnd(LongSpan))));
90LongSpan.Subtract(TextSpan.FromBounds(AtStart(LongSpan), AtStart(LongSpan))));
97[TextSpan.FromBounds(RightAfterStart(LongSpan), AtEnd(LongSpan))],
98LongSpan.Subtract(TextSpan.FromBounds(AtStart(LongSpan), RightAfterStart(LongSpan))));
105[TextSpan.FromBounds(RightBeforeEnd(LongSpan), AtEnd(LongSpan))],
106LongSpan.Subtract(TextSpan.FromBounds(AtStart(LongSpan), RightBeforeEnd(LongSpan))));
113LongSpan.Subtract(TextSpan.FromBounds(AtStart(LongSpan), AtEnd(LongSpan))));
120LongSpan.Subtract(TextSpan.FromBounds(AtStart(LongSpan), RightAfterEnd(LongSpan))));
128LongSpan.Subtract(TextSpan.FromBounds(RightAfterStart(LongSpan), RightAfterStart(LongSpan))));
136TextSpan.FromBounds(AtStart(LongSpan), RightAfterStart(LongSpan)),
137TextSpan.FromBounds(RightBeforeEnd(LongSpan), AtEnd(LongSpan))
139LongSpan.Subtract(TextSpan.FromBounds(RightAfterStart(LongSpan), RightBeforeEnd(LongSpan))));
146[TextSpan.FromBounds(AtStart(LongSpan), RightAfterStart(LongSpan))],
147LongSpan.Subtract(TextSpan.FromBounds(RightAfterStart(LongSpan), AtEnd(LongSpan))));
154[TextSpan.FromBounds(AtStart(LongSpan), RightAfterStart(LongSpan))],
155LongSpan.Subtract(TextSpan.FromBounds(RightAfterStart(LongSpan), RightAfterEnd(LongSpan))));
163LongSpan.Subtract(TextSpan.FromBounds(RightBeforeEnd(LongSpan), RightBeforeEnd(LongSpan))));
170[TextSpan.FromBounds(AtStart(LongSpan), RightBeforeEnd(LongSpan))],
171LongSpan.Subtract(TextSpan.FromBounds(RightBeforeEnd(LongSpan), AtEnd(LongSpan))));
178[TextSpan.FromBounds(AtStart(LongSpan), RightBeforeEnd(LongSpan))],
179LongSpan.Subtract(TextSpan.FromBounds(RightBeforeEnd(LongSpan), RightAfterEnd(LongSpan))));
187LongSpan.Subtract(TextSpan.FromBounds(AtEnd(LongSpan), AtEnd(LongSpan))));
195LongSpan.Subtract(TextSpan.FromBounds(AtEnd(LongSpan), RightAfterEnd(LongSpan))));
203LongSpan.Subtract(TextSpan.FromBounds(RightAfterEnd(LongSpan), RightAfterEnd(LongSpan))));
211UnitSpan.Subtract(TextSpan.FromBounds(RightBeforeStart(UnitSpan), RightBeforeStart(UnitSpan))));
219UnitSpan.Subtract(TextSpan.FromBounds(RightBeforeStart(UnitSpan), AtStart(UnitSpan))));
226UnitSpan.Subtract(TextSpan.FromBounds(RightBeforeStart(UnitSpan), AtEnd(UnitSpan))));
233UnitSpan.Subtract(TextSpan.FromBounds(RightBeforeStart(UnitSpan), RightAfterEnd(UnitSpan))));
241UnitSpan.Subtract(TextSpan.FromBounds(AtStart(UnitSpan), AtStart(UnitSpan))));
248UnitSpan.Subtract(TextSpan.FromBounds(AtStart(UnitSpan), AtEnd(UnitSpan))));
255UnitSpan.Subtract(TextSpan.FromBounds(AtStart(UnitSpan), RightAfterEnd(UnitSpan))));
263UnitSpan.Subtract(TextSpan.FromBounds(AtEnd(UnitSpan), AtEnd(UnitSpan))));
271UnitSpan.Subtract(TextSpan.FromBounds(AtEnd(UnitSpan), RightAfterEnd(UnitSpan))));
279UnitSpan.Subtract(TextSpan.FromBounds(RightAfterEnd(UnitSpan), RightAfterEnd(UnitSpan))));
287EmptySpan.Subtract(TextSpan.FromBounds(RightBeforeStart(EmptySpan), RightBeforeStart(EmptySpan))));
294EmptySpan.Subtract(TextSpan.FromBounds(RightBeforeStart(EmptySpan), EmptySpan.Start)));
301EmptySpan.Subtract(TextSpan.FromBounds(RightBeforeStart(EmptySpan), RightAfterEnd(EmptySpan))));
308EmptySpan.Subtract(TextSpan.FromBounds(EmptySpan.Start, EmptySpan.Start)));
315EmptySpan.Subtract(TextSpan.FromBounds(EmptySpan.Start, RightAfterEnd(EmptySpan))));
323EmptySpan.Subtract(TextSpan.FromBounds(RightAfterEnd(EmptySpan), RightAfterEnd(EmptySpan))));
Microsoft.Gen.ComplianceReports.Unit.Tests (2)
Microsoft.Gen.ContextualOptions.Unit.Tests (2)
Microsoft.Gen.Logging.Unit.Tests (2)
Microsoft.Gen.Metrics.Unit.Tests (2)
Microsoft.Gen.MetricsReports.Unit.Tests (2)
Microsoft.Maui.Controls.BindingSourceGen (1)
Microsoft.ML.InternalCodeAnalyzer (1)
Microsoft.VisualStudio.LanguageServices (121)
Venus\ContainedDocument.cs (47)
238var editorVisibleSpansInOriginal = SharedPools.Default<List<TextSpan>>().AllocateAndClear();
257SharedPools.Default<List<TextSpan>>().ClearAndFree(editorVisibleSpansInOriginal);
261private IEnumerable<TextChange> FilterTextChanges(SourceText originalText, List<TextSpan> editorVisibleSpansInOriginal, IEnumerable<TextChange> changes)
279var visibleSpan = editorVisibleSpansInOriginal[spanIndex];
280var visibleTextSpan = GetVisibleTextSpan(originalText, visibleSpan, uptoFirstAndLastLine: true);
328private static bool WhitespaceOnEdges(TextSpan visibleTextSpan, TextChange change)
348private IEnumerable<TextChange> GetSubTextChanges(SourceText originalText, TextChange changeInOriginalText, TextSpan visibleSpanInOriginalText)
365SourceText originalText, TextSpan visibleSpanInOriginalText, string leftText, string rightText, int offsetInOriginalText, List<TextChange> changes)
368using var leftPool = SharedPools.Default<List<TextSpan>>().GetPooledObject();
369using var rightPool = SharedPools.Default<List<TextSpan>>().GetPooledObject();
385var spanInOriginalText = new TextSpan(offsetInOriginalText + spanInLeftText.Start, spanInLeftText.Length);
399SourceText originalText, TextSpan visibleSpanInOriginalText, string leftText, string rightText, int offsetInOriginalText)
416var spanInOriginalText = new TextSpan(offsetInOriginalText + spanInLeftText.Start, spanInLeftText.Length);
424private static bool TryGetWhitespaceOnlyChanges(string leftText, string rightText, List<TextSpan> spansInLeftText, List<TextSpan> spansInRightText)
427private static bool TryGetWhitespaceGroup(string text, List<TextSpan> groups)
454groups.Add(TextSpan.FromBounds(0, 0));
458groups.Add(TextSpan.FromBounds(start, i));
462groups.Add(TextSpan.FromBounds(start, i));
475groups.Add(TextSpan.FromBounds(start, text.Length));
503SourceText originalText, TextSpan visibleSpanInOriginalText,
504string rightText, TextSpan spanInOriginalText, TextSpan spanInRightText, out TextChange textChange)
548TextSpan.FromBounds(visibleFirstLineInOriginalText.EndIncludingLineBreak, visibleLastLineInOriginalText.Start),
569TextSpan.FromBounds(visibleFirstLineInOriginalText.EndIncludingLineBreak, spanInOriginalText.End),
586TextSpan.FromBounds(spanInOriginalText.Start, visibleLastLineInOriginalText.Start),
700public IEnumerable<TextSpan> GetEditorVisibleSpans()
721IList<TextSpan> visibleSpansInOriginal,
775using var pooledObject = SharedPools.Default<List<TextSpan>>().GetPooledObject();
794Document document, ITextEdit edit, TextSpan visibleSpan, AbstractFormattingRule baseIndentationRule, SyntaxFormattingOptions options)
799using var spanPool = SharedPools.Default<List<TextSpan>>().GetPooledObject();
824public BaseIndentationFormattingRule GetBaseIndentationRule(SyntaxNode root, SourceText text, List<TextSpan> spans, int spanIndex)
829GetVisibleAndTextSpan(text, spans, currentSpanIndex, out var visibleSpan, out var visibleTextSpan);
841return new BaseIndentationFormattingRule(root, TextSpan.FromBounds(visibleSpan.Start, end), baseIndentation, _vbHelperFormattingRule);
851return new BaseIndentationFormattingRule(root, TextSpan.FromBounds(visibleSpan.Start, end), baseIndentation, _vbHelperFormattingRule);
867var span = spans[spanIndex];
872private static void GetVisibleAndTextSpan(SourceText text, List<TextSpan> spans, int spanIndex, out TextSpan visibleSpan, out TextSpan visibleTextSpan)
884private int GetBaseIndentation(SyntaxNode root, SourceText text, TextSpan span)
911private static TextSpan GetVisibleTextSpan(SourceText text, TextSpan visibleSpan, bool uptoFirstAndLastLine = false)
946return (start <= end) ? TextSpan.FromBounds(start, end + 1) : default;
949private int GetAdditionalIndentation(SyntaxNode root, SourceText text, TextSpan span, int hostIndentationSize)
969var textSpan = GetVisibleTextSpan(text, span);
988var textSpan = GetVisibleTextSpan(text, span);
Venus\ContainedDocument.DocumentServiceProvider.cs (9)
85IEnumerable<TextSpan> spans,
102foreach (var span in spans)
135public async Task<ExcerptResult?> TryExcerptAsync(Document document, TextSpan span, ExcerptMode mode, ClassificationOptions classificationOptions, CancellationToken cancellationToken)
214var spanOnContentSpan = GetSpanOnContent(mappedSpan.Value.Span.ToTextSpan(), contentSpan);
264private static SnapshotSpan? MapRoslynSpanToPrimarySpan(IProjectionSnapshot primarySnapshot, ITextSnapshot roslynSnapshot, TextSpan span)
276private static (SourceText, TextSpan) GetContentAndMappedSpan(ExcerptMode mode, SnapshotSpan primarySpan, SnapshotSpan contentSpan)
317private static TextSpan GetSpanOnContent(TextSpan targetSpan, TextSpan excerptSpan)
Workspace\VisualStudioDocumentNavigationService.cs (14)
29using TextSpan = Microsoft.CodeAnalysis.Text.TextSpan;
52public async Task<bool> CanNavigateToSpanAsync(Workspace workspace, DocumentId documentId, TextSpan textSpan, bool allowInvalidSpan, CancellationToken cancellationToken)
101Workspace workspace, DocumentId documentId, TextSpan textSpan, bool allowInvalidSpan, CancellationToken cancellationToken)
127static async Task<TextSpan> GetTextSpanFromPositionAsync(Document document, int position, int virtualSpace, CancellationToken cancellationToken)
159Func<Document, Task<TextSpan>> getTextSpanForMappingAsync,
161Func<SourceText, TextSpan, VsTextSpan> getVsTextSpanForMapping,
183Func<Document, Task<TextSpan>> getTextSpanForMappingAsync,
185Func<SourceText, TextSpan, VsTextSpan> getVsTextSpanForMapping,
323ISpanMappingService spanMappingService, Document generatedDocument, TextSpan textSpan, CancellationToken cancellationToken)
351private static VsTextSpan GetVsTextSpan(SourceText text, TextSpan textSpan, bool allowInvalidSpan)
369/// It is unclear why, but we are sometimes asked to navigate to a <see cref="TextSpan"/>
376private static TextSpan GetSpanWithinDocumentBounds(TextSpan span, int documentLength)
377=> TextSpan.FromBounds(GetPositionWithinDocumentBounds(span.Start, documentLength), GetPositionWithinDocumentBounds(span.End, documentLength));
Microsoft.VisualStudio.LanguageServices.CSharp (12)
Microsoft.VisualStudio.LanguageServices.CSharp.UnitTests (1)
Microsoft.VisualStudio.LanguageServices.LiveShare (1)
Microsoft.VisualStudio.LanguageServices.UnitTests (7)
Microsoft.VisualStudio.LanguageServices.VisualBasic (9)
Microsoft.VisualStudio.LanguageServices.Xaml (17)
Roslyn.VisualStudio.Next.UnitTests (3)
System.Windows.Forms.Analyzers.CodeFixes.CSharp (1)
System.Windows.Forms.Analyzers.CodeFixes.VisualBasic (1)