Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to using index operator #72911

Merged
merged 43 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
2975b86
improve asset hints to speed up searching
CyrusNajmabadi Apr 6, 2024
9204f25
update pinning
CyrusNajmabadi Apr 6, 2024
51681b6
in progress
CyrusNajmabadi Apr 6, 2024
f685cb1
in progress
CyrusNajmabadi Apr 6, 2024
c04ebe7
In progress
CyrusNajmabadi Apr 6, 2024
3290c29
special test value
CyrusNajmabadi Apr 6, 2024
1a2ee5a
fix'
CyrusNajmabadi Apr 6, 2024
df48653
Update tests
CyrusNajmabadi Apr 6, 2024
60bdda6
Update docs
CyrusNajmabadi Apr 6, 2024
b76ced5
fix
CyrusNajmabadi Apr 6, 2024
d312052
in progress
CyrusNajmabadi Apr 6, 2024
65befaa
Simplify
CyrusNajmabadi Apr 6, 2024
9b71463
Simplify
CyrusNajmabadi Apr 6, 2024
aa3c405
Simplify
CyrusNajmabadi Apr 6, 2024
7163426
comment
CyrusNajmabadi Apr 6, 2024
616478a
restore
CyrusNajmabadi Apr 6, 2024
4a27911
docs
CyrusNajmabadi Apr 6, 2024
5a20b41
Simplify
CyrusNajmabadi Apr 6, 2024
d729f63
lint
CyrusNajmabadi Apr 6, 2024
502fccb
remove
CyrusNajmabadi Apr 6, 2024
63665c9
Switch to using index operator
CyrusNajmabadi Apr 6, 2024
98eec08
revert
CyrusNajmabadi Apr 6, 2024
39900f7
make readonly
CyrusNajmabadi Apr 6, 2024
800ed1d
rename type
CyrusNajmabadi Apr 6, 2024
805d0ea
rename type
CyrusNajmabadi Apr 6, 2024
4b7c554
Use enum
CyrusNajmabadi Apr 6, 2024
dfe6eec
revert
CyrusNajmabadi Apr 7, 2024
f32087a
Slight change to AssetPath
ToddGrun Apr 7, 2024
f30f0ae
Feedback
CyrusNajmabadi Apr 7, 2024
30a40a7
Merge branch 'main' into indexOperator
CyrusNajmabadi Apr 7, 2024
11e6ec2
shift left
CyrusNajmabadi Apr 7, 2024
8f007b6
IN progress
CyrusNajmabadi Apr 7, 2024
0e1ef0a
fixups
CyrusNajmabadi Apr 7, 2024
241a51d
Cleanup
CyrusNajmabadi Apr 7, 2024
e268200
Docs
CyrusNajmabadi Apr 7, 2024
6b1802d
Docs
CyrusNajmabadi Apr 7, 2024
d63de5a
Add docs
CyrusNajmabadi Apr 7, 2024
ab2ba2e
Bulk sync
CyrusNajmabadi Apr 7, 2024
6d4249b
Simplify
CyrusNajmabadi Apr 7, 2024
b604aa5
Merge remote-tracking branch 'upstream/main' into assetHints
CyrusNajmabadi Apr 7, 2024
00e0831
Doc
CyrusNajmabadi Apr 7, 2024
47c491f
Doc
CyrusNajmabadi Apr 7, 2024
e4d590e
Merge branch 'assetHints' into indexOperator
CyrusNajmabadi Apr 7, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ private static void CheckCharacters(VirtualCharSequence virtualChars, ref int po

private static string And(params string[] regexes)
{
var conj = $"({regexes[regexes.Length - 1]})";
var conj = $"({regexes[^1]})";
for (var i = regexes.Length - 2; i >= 0; i--)
conj = $"(?({regexes[i]}){conj}|[0-[0]])";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ private static async Task<ContainerElement> BuildInteractiveContentAsync(

// Stack the first paragraph of the documentation comments with the last line of the description
// to avoid vertical padding between the two.
var lastElement = elements[elements.Count - 1];
elements[elements.Count - 1] = new ContainerElement(
var lastElement = elements[^1];
elements[^1] = new ContainerElement(
ContainerElementStyle.Stacked,
lastElement,
element);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ private static void ProcessNodeList<T>(SyntaxList<T> children, ArrayBuilder<Text
{
if (!seenSeparator)
{
var nextToLast = children[children.Count - 2];
var nextToLast = children[^2];
AddLineSeparatorSpanForNode(nextToLast, spans, cancellationToken);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public RegexBraceMatcher()
return null;

var firstChar = trivia.Value.VirtualChars[0];
var lastChar = trivia.Value.VirtualChars[trivia.Value.VirtualChars.Length - 1];
var lastChar = trivia.Value.VirtualChars[^1];
return firstChar != '(' || lastChar != ')'
? null
: new BraceMatchingResult(firstChar.Span, lastChar.Span);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public string GetDisplayName()

public bool HasKeyName()
{
return Index >= 0 && Name != null && Name.Length >= 2 && Name[0] == '[' && Name[Name.Length - 1] == ']';
return Index >= 0 && Name != null && Name.Length >= 2 && Name[0] == '[' && Name[^1] == ']';
}

public bool AppendAsCollectionEntry(Builder result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ private void FormatMultidimensionalArrayElements(Builder result, Array array, bo
string _;
FormatObjectRecursive(result, array.GetValue(indices), isRoot: false, debuggerDisplayName: out _);

indices[indices.Length - 1]++;
indices[^1]++;
flatIndex++;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/VisualStudio/Core/Def/Library/VsNavInfo/NavInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public NavInfo(
_basePresentationNodes = CreateNodes(expandDottedNames: false);

_symbolType = _basePresentationNodes.Length > 0
? _basePresentationNodes[_basePresentationNodes.Length - 1].ListType
? _basePresentationNodes[^1].ListType
: 0;
}

Expand Down
2 changes: 1 addition & 1 deletion src/VisualStudio/Core/Def/Preview/FileChange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ private static string GetDisplayText(string excerpt)
var split = excerpt.Split(new[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries);
if (split.Length > 1)
{
return string.Format("{0} ... {1}", split[0].Trim(), split[split.Length - 1].Trim());
return string.Format("{0} ... {1}", split[0].Trim(), split[^1].Trim());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ private TreeViewItemBase GetPreviousItem()
{
if (ValueTrackingTreeView.SelectedItem is null)
{
return (TreeViewItemBase)ValueTrackingTreeView.Items[ValueTrackingTreeView.Items.Count - 1];
return (TreeViewItemBase)ValueTrackingTreeView.Items[^1];
}

var item = (TreeViewItemBase)ValueTrackingTreeView.SelectedItem;
Expand Down
2 changes: 1 addition & 1 deletion src/VisualStudio/Core/Def/Venus/ContainedDocument.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ private bool IsCodeBlock(ITextSnapshot surfaceSnapshot, int position, char ch)

private static bool CheckCode(ITextSnapshot snapshot, int position, char ch, string tag, bool checkAt = true)
{
if (ch != tag[tag.Length - 1] || position < tag.Length)
if (ch != tag[^1] || position < tag.Length)
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected abstract class AbstractNodeNameGenerator
protected static void AppendDotIfNeeded(StringBuilder builder)
{
if (builder.Length > 0 &&
char.IsLetterOrDigit(builder[builder.Length - 1]))
char.IsLetterOrDigit(builder[^1]))
{
builder.Append('.');
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ private async Task UpdatePathsToRemoteFilesAsync(CollaborationSession session)
#pragma warning disable CS8602 // Dereference of a possibly null reference. (Can localRoot be null here?)
var splitRoot = localRoot.TrimEnd('\\').Split('\\');
#pragma warning restore CS8602 // Dereference of a possibly null reference.
splitRoot[splitRoot.Length - 1] = "~external";
splitRoot[^1] = "~external";
var externalPath = string.Join("\\", splitRoot) + "\\";

remoteRootPaths.Add(localRoot);
Expand Down
4 changes: 2 additions & 2 deletions src/Workspaces/MSBuildTest/MSBuildWorkspaceTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ protected static int GetMethodInsertionPoint(VB.Syntax.ClassBlockSyntax classBlo
{
if (classBlock.Implements.Count > 0)
{
return classBlock.Implements[classBlock.Implements.Count - 1].FullSpan.End;
return classBlock.Implements[^1].FullSpan.End;
}
else if (classBlock.Inherits.Count > 0)
{
return classBlock.Inherits[classBlock.Inherits.Count - 1].FullSpan.End;
return classBlock.Inherits[^1].FullSpan.End;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ private static bool HasLeadingWhitespace(string tokenText)
=> tokenText.Length > 0 && char.IsWhiteSpace(tokenText[0]);

private static bool HasTrailingWhitespace(string tokenText)
=> tokenText.Length > 0 && char.IsWhiteSpace(tokenText[tokenText.Length - 1]);
=> tokenText.Length > 0 && char.IsWhiteSpace(tokenText[^1]);

public string GetBannerText(SyntaxNode documentationCommentTriviaSyntax, int maxBannerLength, CancellationToken cancellationToken)
=> GetBannerText((TDocumentationCommentTriviaSyntax)documentationCommentTriviaSyntax, maxBannerLength, cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ public void PushMethod(IMethodSymbol method)
public void PopMethod(IMethodSymbol method)
{
Contract.ThrowIfTrue(_methodSymbolStack.Count == 0);
Contract.ThrowIfFalse(method.Equals(_methodSymbolStack[_methodSymbolStack.Count - 1]));
Contract.ThrowIfFalse(method.Equals(_methodSymbolStack[^1]));
_methodSymbolStack.RemoveAt(_methodSymbolStack.Count - 1);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private static int GetEditDistanceWorker(ReadOnlySpan<char> source, ReadOnlySpan
// First:
// Determine the common prefix/suffix portions of the strings. We don't even need to
// consider them as they won't add anything to the edit cost.
while (source.Length > 0 && source[source.Length - 1] == target[target.Length - 1])
while (source.Length > 0 && source[^1] == target[^1])
{
source = source[..^1];
target = target[..^1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ internal static EnumDeclarationSyntax AddEnumMemberTo(EnumDeclarationSyntax dest
{
var lastMember = members.Last();
var trailingTrivia = lastMember.GetTrailingTrivia();
members[members.Count - 1] = lastMember.WithTrailingTrivia();
members[^1] = lastMember.WithTrailingTrivia();
members.Add(SyntaxFactory.Token(SyntaxKind.CommaToken).WithTrailingTrivia(trailingTrivia));
members.Add(member);
}
Expand Down
Loading