Skip to content

Commit

Permalink
chore(audoedit): simplify diff utils and data structures
Browse files Browse the repository at this point in the history
  • Loading branch information
valerybugakov committed Nov 21, 2024
1 parent ec6d617 commit 9a81f49
Show file tree
Hide file tree
Showing 8 changed files with 817 additions and 526 deletions.
69 changes: 39 additions & 30 deletions vscode/src/autoedits/renderer/decorators/base.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import type * as vscode from 'vscode'
import type { ModifiedRange } from '../diff-utils'

/**
* Represents a decorator that manages VS Code editor decorations for auto-edit suggestions.
Expand All @@ -8,14 +7,14 @@ import type { ModifiedRange } from '../diff-utils'
* that visualize proposed text changes in the editor.
*
* Lifecycle:
* - Single instance should be created per decoration session and disposed of when the decorations
* - A single instance should be created per decoration session and disposed of when the decorations
* are no longer needed.
* - Always call dispose() when the decorator is no longer needed to clean up resources.
* - Dispose should always clear the decorations.
*
* Usage Pattern:
* ```typescript
* const decorator = createAutoeditsDecorator(...);
* const decorator = createAutoEditsDecorator(...);
* try {
* decorator.setDecorations(decorationInfo);
* ...
Expand All @@ -25,46 +24,56 @@ import type { ModifiedRange } from '../diff-utils'
* }
* ```
*/
export interface AutoeditsDecorator extends vscode.Disposable {
export interface AutoEditsDecorator extends vscode.Disposable {
/**
* Applies decorations to the editor based on the provided decoration information.
*
* @param decorationInformation Contains the line-by-line information about text changes
* @param decorationInfo Contains the line-by-line information about text changes
* and how they should be decorated in the editor.
*/
setDecorations(decorationInformation: DecorationInformation): void
setDecorations(decorationInfo: DecorationInfo): void
}

/**
* Represents the different types of line decorations that can be applied.
* Represents a line of text with its change type and content.
*/
export enum DecorationLineType {
/** Line has been modified from its original state */
Modified = 0,
/** New line has been added */
Added = 1,
/** Line has been removed */
Removed = 2,
/** Line remains unchanged */
Unchanged = 3,
export type DecorationLineInfo = AddedLineInfo | RemovedLineInfo | ModifiedLineInfo | UnchangedLineInfo

export interface AddedLineInfo {
type: 'added'
text: string
lineNumber: number // `lineNumber` in the modified text
}

export interface RemovedLineInfo {
type: 'removed'
text: string
lineNumber: number // `lineNumber` in the original text
}

export interface DecorationLineInformation {
lineType: DecorationLineType
// Line number in the original text. The line number can be null if the line was added.
oldLineNumber: number | null
// Line number in the new predicted text. The line number can be null if the line was removed.
newLineNumber: number | null
// The text of the line in the original text.
export interface ModifiedLineInfo {
type: 'modified'
oldText: string
// The text of the line in the new predicted text.
newText: string
// The ranges of text that were modified in the line.
modifiedRanges: ModifiedRange[]
changes: LineChange[]
lineNumber: number // `lineNumber` in the modified text
}

export interface UnchangedLineInfo {
type: 'unchanged'
text: string
lineNumber: number // `lineNumber` in the modified text
}

export type LineChange = {
type: 'insert' | 'delete'
range: vscode.Range
text: string
}

export interface DecorationInformation {
lines: DecorationLineInformation[]
oldLines: string[]
newLines: string[]
export interface DecorationInfo {
modifiedLines: ModifiedLineInfo[]
removedLines: RemovedLineInfo[]
addedLines: AddedLineInfo[]
unchangedLines: UnchangedLineInfo[]
}
51 changes: 0 additions & 51 deletions vscode/src/autoedits/renderer/decorators/common.ts

This file was deleted.

Loading

0 comments on commit 9a81f49

Please sign in to comment.