Skip to content

Commit c9ea664

Browse files
CopilotToddGrun
andcommitted
Optimize attribute existence check by inverting condition
Co-authored-by: ToddGrun <6785178+ToddGrun@users.noreply.github.com>
1 parent e344faa commit c9ea664

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

src/Razor/src/Microsoft.CodeAnalysis.Razor.Workspaces/Completion/BlazorDataAttributeCompletionItemProvider.cs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -82,30 +82,33 @@ public ImmutableArray<RazorCompletionItem> GetCompletionItems(RazorCompletionCon
8282
continue;
8383
}
8484

85-
// Check if the attribute already exists on the element
86-
var alreadyExists = false;
87-
foreach (var attribute in attributes)
85+
// If not currently editing this attribute, check if it already exists
86+
if (selectedAttributeName != attributeName)
8887
{
89-
var existingAttributeName = attribute switch
88+
var alreadyExists = false;
89+
foreach (var attribute in attributes)
9090
{
91-
MarkupAttributeBlockSyntax attributeBlock => attributeBlock.Name.GetContent(),
92-
MarkupMinimizedAttributeBlockSyntax minimizedAttributeBlock => minimizedAttributeBlock.Name.GetContent(),
93-
_ => null
94-
};
91+
var existingAttributeName = attribute switch
92+
{
93+
MarkupAttributeBlockSyntax attributeBlock => attributeBlock.Name.GetContent(),
94+
MarkupMinimizedAttributeBlockSyntax minimizedAttributeBlock => minimizedAttributeBlock.Name.GetContent(),
95+
_ => null
96+
};
97+
98+
if (existingAttributeName == attributeName)
99+
{
100+
alreadyExists = true;
101+
break;
102+
}
103+
}
95104

96-
if (existingAttributeName == attributeName)
105+
if (alreadyExists)
97106
{
98-
alreadyExists = true;
99-
break;
107+
// Attribute already exists and is not the one currently being edited
108+
continue;
100109
}
101110
}
102111

103-
if (alreadyExists && selectedAttributeName != attributeName)
104-
{
105-
// Attribute already exists and is not the one currently being edited
106-
continue;
107-
}
108-
109112
var insertText = attributeName;
110113
var isSnippet = false;
111114

0 commit comments

Comments
 (0)