-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(agent): move calcReplaceRange to a postprocess filter. (#1138)
* refactor(agent): Refactor calcReplaceRange to a postprocess filter. Fallback to non-syntax based filter when syntax error. * fix: remove console.log.
- Loading branch information
Showing
14 changed files
with
325 additions
and
383 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
clients/tabby-agent/src/postprocess/calculateReplaceRange.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { AgentConfig } from "../AgentConfig"; | ||
import { isBrowser } from "../env"; | ||
import { PostprocessChoiceFilter, logger } from "./base"; | ||
import { calculateReplaceRangeByBracketStack } from "./calculateReplaceRangeByBracketStack"; | ||
import { calculateReplaceRangeBySyntax } from "./calculateReplaceRangeBySyntax"; | ||
|
||
export function calculateReplaceRange( | ||
config: AgentConfig["postprocess"]["calculateReplaceRange"], | ||
): PostprocessChoiceFilter { | ||
return async (choice, context) => { | ||
const preferSyntaxParser = | ||
!isBrowser && // syntax parser is not supported in browser yet | ||
config.experimentalSyntax; | ||
|
||
if (preferSyntaxParser) { | ||
try { | ||
return await calculateReplaceRangeBySyntax(choice, context); | ||
} catch (error) { | ||
logger.debug({ error }, "Failed to calculate replace range by syntax parser"); | ||
} | ||
} | ||
return calculateReplaceRangeByBracketStack(choice, context); | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.