| 1 | import { IDE, Position } from "../.."; |
| 2 | import { GetLspDefinitionsFunction } from "../../autocomplete/types"; |
| 3 | import { ConfigHandler } from "../../config/ConfigHandler"; |
| 4 | import { NextEditProvider } from "../NextEditProvider"; |
| 5 | import { EditAggregator } from "./aggregateEdits"; |
| 6 | import { BeforeAfterDiff, createDiff, DiffFormatType } from "./diffFormatting"; |
| 7 | import { processNextEditData } from "./processNextEditData"; |
| 8 | |
| 9 | export const processSmallEdit = async ( |
| 10 | beforeAfterdiff: BeforeAfterDiff, |
| 11 | cursorPosBeforeEdit: Position, |
| 12 | cursorPosAfterPrevEdit: Position, |
| 13 | configHandler: ConfigHandler, |
| 14 | getDefsFromLspFunction: GetLspDefinitionsFunction, |
| 15 | ide: IDE, |
| 16 | ) => { |
| 17 | NextEditProvider.getInstance().addDiffToContext( |
| 18 | createDiff({ |
| 19 | beforeContent: beforeAfterdiff.beforeContent, |
| 20 | afterContent: beforeAfterdiff.afterContent, |
| 21 | filePath: beforeAfterdiff.filePath, |
| 22 | diffType: DiffFormatType.Unified, |
| 23 | contextLines: 5, // NOTE: This can change depending on experiments! |
| 24 | }), |
| 25 | ); |
| 26 | |
| 27 | // Get the current context data from the most recent message |
| 28 | const currentData = (EditAggregator.getInstance() as any) |
| 29 | .latestContextData || { |
| 30 | configHandler: configHandler, |
| 31 | getDefsFromLspFunction: getDefsFromLspFunction, |
| 32 | recentlyEditedRanges: [], |
| 33 | recentlyVisitedRanges: [], |
| 34 | }; |
| 35 | |
| 36 | void processNextEditData({ |
| 37 | filePath: beforeAfterdiff.filePath, |
| 38 | beforeContent: beforeAfterdiff.beforeContent, |
| 39 | afterContent: beforeAfterdiff.afterContent, |
| 40 | cursorPosBeforeEdit: cursorPosBeforeEdit, |
| 41 | cursorPosAfterPrevEdit: cursorPosAfterPrevEdit, |
| 42 | ide: ide, |
| 43 | configHandler: currentData.configHandler, |
| 44 | getDefinitionsFromLsp: currentData.getDefsFromLspFunction, |
| 45 | recentlyEditedRanges: currentData.recentlyEditedRanges, |
| 46 | recentlyVisitedRanges: currentData.recentlyVisitedRanges, |
| 47 | workspaceDir: currentData.workspaceDir, |
| 48 | }); |
| 49 | }; |