Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion src/api/schemas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const AutocompleteResponseSchema = z.object({
export const SuggestionTypeSchema = z.enum([
"GHOST_TEXT",
"POPUP",
"JUMP",
"JUMP_TO_EDIT",
"MULTI",
]);

Expand Down
8 changes: 4 additions & 4 deletions src/editor/edit-display-classifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ export interface EditDisplayClassification {
reason:
| "far-from-cursor"
| "before-cursor-multiline"
| "before-cursor-single-line-same-row"
| "before-cursor-single-line"
| "single-newline-boundary"
| "inline-safe";
}
Expand Down Expand Up @@ -51,10 +51,10 @@ export function classifyEditDisplay(
};
}

if (isBeforeCursor && input.editStartLine === input.cursorLine) {
if (isBeforeCursor) {
return {
decision: "SUPPRESS",
reason: "before-cursor-single-line-same-row",
decision: "JUMP",
reason: "before-cursor-single-line",
};
}

Expand Down
17 changes: 11 additions & 6 deletions src/editor/inline-edit-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -412,9 +412,6 @@ export class InlineEditProvider implements vscode.InlineCompletionItemProvider {
const startPosition = document.positionAt(result.startIndex);
const endPosition = document.positionAt(result.endIndex);
const editRange = new vscode.Range(startPosition, endPosition);
const metricsPayload = buildMetricsPayload(document, result, {
suggestionType: "GHOST_TEXT",
});

console.log("[Sweep] Creating inline edit:", {
id: result.id,
Expand All @@ -428,12 +425,20 @@ export class InlineEditProvider implements vscode.InlineCompletionItemProvider {
});

if (result.startIndex < cursorOffset) {
console.log("[Sweep] Edit before cursor cannot be shown as ghost text", {
id: result.id,
});
console.log(
"[Sweep] Edit before cursor cannot be shown as ghost text; falling back to jump edit",
{
id: result.id,
},
);
this.jumpEditManager.setPendingJumpEdit(document, result);
return undefined;
}

const metricsPayload = buildMetricsPayload(document, result, {
suggestionType: "GHOST_TEXT",
});

if (this.lastInlineEdit?.payload.id !== metricsPayload.id) {
void this.clearInlineEdit("replaced by new inline edit", {
hideSuggestion: false,
Expand Down
2 changes: 1 addition & 1 deletion src/editor/jump-edit-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ export class JumpEditManager implements vscode.Disposable {
editEndPos,
originCursorLine: editor.selection.active.line,
metricsPayload: buildMetricsPayload(document, result, {
suggestionType: "JUMP",
suggestionType: "JUMP_TO_EDIT",
}),
};

Expand Down
22 changes: 18 additions & 4 deletions src/telemetry/document-tracker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,10 @@ export class DocumentTracker implements vscode.Disposable {

for (const change of event.contentChanges) {
if (!change.text && change.rangeLength === 0) continue;
const actionPosition = this.getPostChangePosition(event.document, change);

this.cursorPositions.set(uri, {
line: change.range.start.line,
line: actionPosition.line,
timestamp: now,
});

Expand All @@ -122,14 +123,14 @@ export class DocumentTracker implements vscode.Disposable {
}

if (undoRedoActionType) {
undoRedoPosition = change.range.start;
undoRedoPosition = actionPosition;
} else {
const actionType = this.getActionType(change);
const offset = utf8ByteOffsetAt(event.document, change.range.start);
const offset = utf8ByteOffsetAt(event.document, actionPosition);

this.userActions.push({
action_type: actionType,
line_number: change.range.start.line,
line_number: actionPosition.line,
offset,
file_path: filepath,
timestamp: now,
Expand Down Expand Up @@ -221,6 +222,19 @@ export class DocumentTracker implements vscode.Disposable {
return isMultiChar ? "INSERT_SELECTION" : "INSERT_CHAR";
}

private getPostChangePosition(
document: vscode.TextDocument,
change: vscode.TextDocumentContentChangeEvent,
): vscode.Position {
const insertionEndOffset = change.rangeOffset + change.text.length;
const documentLength = document.getText().length;
const clampedOffset = Math.max(
0,
Math.min(insertionEndOffset, documentLength),
);
return document.positionAt(clampedOffset);
}

private getUndoRedoActionType(
reason: vscode.TextDocumentChangeReason | undefined,
): Extract<ActionType, "UNDO" | "REDO"> | null {
Expand Down
6 changes: 3 additions & 3 deletions test/edit-display-classifier.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe("classifyEditDisplay", () => {
});
});

test("returns SUPPRESS for same-line single-line edits before cursor", () => {
test("returns JUMP for same-line single-line edits before cursor", () => {
const result = classifyEditDisplay({
cursorLine: 10,
editStartLine: 10,
Expand All @@ -49,8 +49,8 @@ describe("classifyEditDisplay", () => {
});

expect(result).toEqual({
decision: "SUPPRESS",
reason: "before-cursor-single-line-same-row",
decision: "JUMP",
reason: "before-cursor-single-line",
});
});

Expand Down