Skip to content

Commit 9e12670

Browse files
committed
Fix bugs in VisitorUtils around LastIndexOf
Should have been just `IndexOf`, and also use `+` instead of `string.Concat()` for simplicity and speed.
1 parent 4c1538b commit 9e12670

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

src/PowerShellEditorServices/Utility/VisitorUtils.cs

+6-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ internal static (int startColumn, int startLine) GetNameStartColumnAndLineFromAs
106106
internal static (int startColumn, int startLine) GetNameStartColumnAndLineFromAst(FunctionMemberAst functionMemberAst)
107107
{
108108
// find name index to get offset even with attributes, static, hidden ++
109-
int nameStartIndex = functionMemberAst.Extent.Text.LastIndexOf(string.Concat(functionMemberAst.Name, '('), StringComparison.OrdinalIgnoreCase);
109+
int nameStartIndex = functionMemberAst.Extent.Text.IndexOf(
110+
functionMemberAst.Name + '(', StringComparison.OrdinalIgnoreCase);
110111
return GetNameStartColumnAndLineFromAst(functionMemberAst, nameStartIndex);
111112
}
112113

@@ -119,8 +120,10 @@ internal static (int startColumn, int startLine) GetNameStartColumnAndLineFromAs
119120
internal static (int startColumn, int startLine) GetNameStartColumnAndLineFromAst(PropertyMemberAst propertyMemberAst, bool isEnumMember)
120121
{
121122
// find name index to get offset even with attributes, static, hidden ++
122-
string searchString = isEnumMember ? propertyMemberAst.Name : string.Concat('$', propertyMemberAst.Name);
123-
int nameStartIndex = propertyMemberAst.Extent.Text.LastIndexOf(searchString, StringComparison.OrdinalIgnoreCase);
123+
string searchString = isEnumMember
124+
? propertyMemberAst.Name : '$' + propertyMemberAst.Name;
125+
int nameStartIndex = propertyMemberAst.Extent.Text.IndexOf(
126+
searchString, StringComparison.OrdinalIgnoreCase);
124127
return GetNameStartColumnAndLineFromAst(propertyMemberAst, nameStartIndex);
125128
}
126129

0 commit comments

Comments
 (0)