Skip to content
Merged
Changes from all commits
Commits
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
19 changes: 18 additions & 1 deletion Sources/Extensions/Widgets/HAAppEntityAppIntentEntity.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,24 @@ struct HAAppEntityAppIntentEntityQuery: EntityQuery, EntityStringQuery {
.init(sections: getEntities().map { (key: Server, value: [HAAppEntityAppIntentEntity]) in
.init(
.init(stringLiteral: key.info.name),
items: value.filter({ $0.displayString.lowercased().contains(string.lowercased()) })
items: value.filter({ entity in
let matchDisplayString = entity.displayString.range(
of: string,
options: [.caseInsensitive, .diacriticInsensitive]
) != nil
let matchEntityId = entity.entityId.range(
of: string,
options: [.caseInsensitive, .diacriticInsensitive]
) != nil
let matchAreaName = {
if let area = entity.area {
return area.range(of: string, options: [.caseInsensitive, .diacriticInsensitive]) != nil
Comment on lines +54 to +64
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The implementation uses range(of:options:) with case-insensitive options, but the codebase consistently uses the simpler .lowercased().contains() pattern for case-insensitive string matching in similar contexts. Consider using the established pattern for consistency:

let matchDisplayString = entity.displayString.lowercased().contains(string.lowercased())
let matchEntityId = entity.entityId.lowercased().contains(string.lowercased())

This pattern is used in other similar EntityQuery implementations like IntentCoverEntity, IntentLightEntity, IntentSwitchEntity, and ScriptAppIntent.

Suggested change
let matchDisplayString = entity.displayString.range(
of: string,
options: [.caseInsensitive, .diacriticInsensitive]
) != nil
let matchEntityId = entity.entityId.range(
of: string,
options: [.caseInsensitive, .diacriticInsensitive]
) != nil
let matchAreaName = {
if let area = entity.area {
return area.range(of: string, options: [.caseInsensitive, .diacriticInsensitive]) != nil
let matchDisplayString = entity.displayString.lowercased().contains(string.lowercased())
let matchEntityId = entity.entityId.lowercased().contains(string.lowercased())
let matchAreaName = {
if let area = entity.area {
return area.lowercased().contains(string.lowercased())

Copilot uses AI. Check for mistakes.
} else {
return false
}
}()
Comment on lines +62 to +68
Copy link

Copilot AI Dec 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The immediately-invoked closure pattern for matchAreaName adds unnecessary complexity. Consider simplifying using optional chaining for better readability:

let matchAreaName = entity.area?.lowercased().contains(string.lowercased()) ?? false

This is more concise and follows Swift idiomatic practices for handling optionals.

Suggested change
let matchAreaName = {
if let area = entity.area {
return area.range(of: string, options: [.caseInsensitive, .diacriticInsensitive]) != nil
} else {
return false
}
}()
let matchAreaName = entity.area?.range(of: string, options: [.caseInsensitive, .diacriticInsensitive]) != nil

Copilot uses AI. Check for mistakes.
return matchDisplayString || matchEntityId || matchAreaName
})
)
})
}
Expand Down
Loading