You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix(parser): Resolve compilation error and improve command type handling
Corrected a compilation error in CommandParser.kt caused by duplicate
declarations of `MatchResultPlaceholder`.
Additionally, refactored `processTextInternal` to:
- Store `CommandTypeEnum` directly with parsed command matches using a new
`ProcessedMatch` data class.
- Use this directly stored `commandType` for single-instance command checks,
eliminating a previous, less reliable method of comparing command builder lambdas.
- Removed the `MatchResultPlaceholder` variable as it's no longer needed.
These changes make the parser more robust and fix the build failure.
Log.d(TAG, "Found raw match: Start=${matchResult.range.first}, End=${matchResult.range.last}, Command=${command}, Type=${patternInfo.commandType}, Pattern=${patternInfo.id}")
235
237
} catch (e:Exception) {
236
238
Log.e(TAG, "Error building command for pattern ${patternInfo.id} with match ${matchResult.value}: ${e.message}", e)
237
239
}
@@ -242,58 +244,43 @@ object CommandParser {
242
244
}
243
245
244
246
// Sort matches by start index
245
-
foundRawMatches.sortBy { it.first }
247
+
foundRawMatches.sortBy { it.startIndex }
246
248
Log.d(TAG, "Sorted raw matches (${foundRawMatches.size}): $foundRawMatches")
247
249
248
250
var currentPosition =0
249
-
for ((startIndex, endIndex, command) in foundRawMatches) {
251
+
for (processedMatch in foundRawMatches) {
252
+
val (startIndex, endIndex, command, commandTypeFromMatch) = processedMatch // Destructure
250
253
if (startIndex >= currentPosition) {
251
-
// Handle single-instance commands
252
-
val commandType =ALL_PATTERNS.find { it.commandBuilder(MatchResultPlaceholder) == command || (it.commandBuilder(MatchResultPlaceholder)::class== command::class&& command isCommand.WriteText) }?.commandType // This is a bit hacky for comparison
253
-
254
254
var canAdd =true
255
-
if (commandType !=null) {
256
-
val isSingleInstanceType =when (commandType) {
257
-
CommandTypeEnum.TAKE_SCREENSHOT,
258
-
CommandTypeEnum.PRESS_HOME,
259
-
CommandTypeEnum.PRESS_BACK,
260
-
CommandTypeEnum.SHOW_RECENT_APPS,
261
-
CommandTypeEnum.USE_HIGH_REASONING_MODEL,
262
-
CommandTypeEnum.USE_LOW_REASONING_MODEL,
263
-
CommandTypeEnum.PRESS_ENTER_KEY->true
264
-
else->false
265
-
}
266
-
if (isSingleInstanceType) {
267
-
if (addedSingleInstanceCommands.contains(commandType)) {
else->false// For non-parameterized or unique types, this won't prevent addition
287
-
}
288
-
}
289
-
290
-
if (!isLikelyDuplicate || commandType ==null||!addedSingleInstanceCommands.contains(commandType)) { // Ensure single instance types are not re-added due to this check
291
-
finalCommands.add(command)
292
-
currentPosition = endIndex +1
293
-
Log.d(TAG, "Added command: $command. New currentPosition: $currentPosition")
0 commit comments