Changesets · Branches · Tags · Compare
| Changeset | 935a14819b15637cacfdd84a5f27ab64b28e5a098bcee56675839a88d08ccad1 |
|---|---|
| Author | Jacob Kim <jacob@continue.dev> · 2025-08-15 12:18 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-08-15 15:18 -04:00 |
| Parents | e8c57a7b5386 |
8 files changed
modified .github/actions/build-vscode-extension/action.yml +4 −2
| @@ -105,7 +105,9 @@ | ||
| 105 | 105 | shell: bash |
| 106 | 106 | run: | |
| 107 | 107 | cd gui |
| 108 | - npm run build | |
| 108 | + npm run build --max-old-space-size=4096 | |
| 109 | + env: | |
| 110 | + NODE_OPTIONS: "--max-old-space-size=4096" | |
| 109 | 111 | |
| 110 | 112 | - name: Prepackage the extension |
| 111 | 113 | shell: bash |
| @@ -156,4 +158,4 @@ | ||
| 156 | 158 | npx vsce package --pre-release --no-dependencies --target ${{ steps.set-target.outputs.target }} |
| 157 | 159 | else |
| 158 | 160 | npx vsce package --no-dependencies --target ${{ steps.set-target.outputs.target }} |
| 159 | - fi | |
| No newline at the end of the file | ||
| 161 | + fi |
modified core/codeRenderer/CodeRenderer.ts +36 −16
| @@ -243,7 +243,10 @@ | ||
| 243 | 243 | ); |
| 244 | 244 | const backgroundColor = this.getBackgroundColor(highlightedCodeHtml); |
| 245 | 245 | |
| 246 | - const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${options.dimensions.width}" height="${options.dimensions.height}" shape-rendering="crispEdges"> | |
| 246 | + const lines = code.split("\n"); | |
| 247 | + const actualHeight = lines.length * options.lineHeight; | |
| 248 | + | |
| 249 | + const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${options.dimensions.width}" height="${actualHeight}" shape-rendering="crispEdges"> | |
| 247 | 250 | <style> |
| 248 | 251 | :root { |
| 249 | 252 | --purple: rgb(112, 114, 209); |
| @@ -252,7 +255,7 @@ | ||
| 252 | 255 | } |
| 253 | 256 | </style> |
| 254 | 257 | <g> |
| 255 | - <rect x="0" y="0" rx="10" ry="10" width="${options.dimensions.width}" height="${options.dimensions.height}" fill="${this.editorBackground}" shape-rendering="crispEdges" /> | |
| 258 | + <rect x="0" y="0" rx="10" ry="10" width="${options.dimensions.width}" height="${actualHeight}" fill="${this.editorBackground}" shape-rendering="crispEdges" /> | |
| 256 | 259 | ${lineBackgrounds} |
| 257 | 260 | ${guts} |
| 258 | 261 | </g> |
| @@ -317,29 +320,46 @@ | ||
| 317 | 320 | const y = index * options.lineHeight; |
| 318 | 321 | const isFirst = index === 0; |
| 319 | 322 | const isLast = index === lines.length - 1; |
| 323 | + const isSingleLine = isFirst && isLast; | |
| 320 | 324 | const radius = 10; |
| 325 | + | |
| 326 | + // Handle single line case (both first and last) | |
| 327 | + if (isSingleLine) { | |
| 328 | + return `<path d="M ${radius} ${y} | |
| 329 | + L ${options.dimensions.width - radius} ${y} | |
| 330 | + Q ${options.dimensions.width} ${y} ${options.dimensions.width} ${y + radius} | |
| 331 | + L ${options.dimensions.width} ${y + options.lineHeight - radius} | |
| 332 | + Q ${options.dimensions.width} ${y + options.lineHeight} ${options.dimensions.width - radius} ${y + options.lineHeight} | |
| 333 | + L ${radius} ${y + options.lineHeight} | |
| 334 | + Q ${0} ${y + options.lineHeight} ${0} ${y + options.lineHeight - radius} | |
| 335 | + L ${0} ${y + radius} | |
| 336 | + Q ${0} ${y} ${radius} ${y} | |
| 337 | + Z" | |
| 338 | + fill="${bgColor}" />`; | |
| 339 | + } | |
| 340 | + | |
| 321 | 341 | // SVG notes: |
| 322 | 342 | // By default SVGs have anti-aliasing on. |
| 323 | 343 | // This is undesirable in our case because pixel-perfect alignment of these rectangles will introduce thin gaps. |
| 324 | 344 | // Turning it off with 'shape-rendering="crispEdges"' solves the issue. |
| 325 | 345 | return isFirst |
| 326 | 346 | ? `<path d="M ${0} ${y + options.lineHeight} |
| 327 | - L ${0} ${y + radius} | |
| 328 | - Q ${0} ${y} ${radius} ${y} | |
| 329 | - L ${options.dimensions.width - radius} ${y} | |
| 330 | - Q ${options.dimensions.width} ${y} ${options.dimensions.width} ${y + radius} | |
| 331 | - L ${options.dimensions.width} ${y + options.lineHeight} | |
| 332 | - Z" | |
| 333 | - fill="${bgColor}" />` | |
| 347 | + L ${0} ${y + radius} | |
| 348 | + Q ${0} ${y} ${radius} ${y} | |
| 349 | + L ${options.dimensions.width - radius} ${y} | |
| 350 | + Q ${options.dimensions.width} ${y} ${options.dimensions.width} ${y + radius} | |
| 351 | + L ${options.dimensions.width} ${y + options.lineHeight} | |
| 352 | + Z" | |
| 353 | + fill="${bgColor}" />` | |
| 334 | 354 | : isLast |
| 335 | 355 | ? `<path d="M ${0} ${y} |
| 336 | - L ${0} ${y + options.lineHeight - radius} | |
| 337 | - Q ${0} ${y + options.lineHeight} ${radius} ${y + options.lineHeight} | |
| 338 | - L ${options.dimensions.width - radius} ${y + options.lineHeight} | |
| 339 | - Q ${options.dimensions.width} ${y + options.lineHeight} ${options.dimensions.width} ${y + options.lineHeight - 10} | |
| 340 | - L ${options.dimensions.width} ${y} | |
| 341 | - Z" | |
| 342 | - fill="${bgColor}" />` | |
| 356 | + L ${0} ${y + options.lineHeight - radius} | |
| 357 | + Q ${0} ${y + options.lineHeight} ${radius} ${y + options.lineHeight} | |
| 358 | + L ${options.dimensions.width - radius} ${y + options.lineHeight} | |
| 359 | + Q ${options.dimensions.width} ${y + options.lineHeight} ${options.dimensions.width} ${y + options.lineHeight - 10} | |
| 360 | + L ${options.dimensions.width} ${y} | |
| 361 | + Z" | |
| 362 | + fill="${bgColor}" />` | |
| 343 | 363 | : `<rect x="0" y="${y}" width="100%" height="${options.lineHeight}" fill="${bgColor}" shape-rendering="crispEdges" />`; |
| 344 | 364 | }) |
| 345 | 365 | .join("\n"); |
modified core/nextEdit/NextEditProvider.ts +28 −21
| @@ -33,7 +33,6 @@ | ||
| 33 | 33 | import { modelSupportsNextEdit } from "../llm/autodetect.js"; |
| 34 | 34 | import { countTokens } from "../llm/countTokens.js"; |
| 35 | 35 | import { localPathOrUriToPath } from "../util/pathToUri.js"; |
| 36 | -import { replaceEscapedCharacters } from "../util/text.js"; | |
| 37 | 36 | import { |
| 38 | 37 | INSTINCT_SYSTEM_PROMPT, |
| 39 | 38 | MERCURY_CODE_TO_EDIT_OPEN, |
| @@ -60,6 +59,7 @@ | ||
| 60 | 59 | PromptMetadata, |
| 61 | 60 | RecentlyEditedRange, |
| 62 | 61 | } from "./types.js"; |
| 62 | +import { isWhitespaceOnlyDeletion } from "./utils.js"; | |
| 63 | 63 | |
| 64 | 64 | const autocompleteCache = AutocompleteLruCache.get(); |
| 65 | 65 | |
| @@ -685,13 +685,17 @@ | ||
| 685 | 685 | return undefined; |
| 686 | 686 | } |
| 687 | 687 | |
| 688 | - const nextCompletion = msg.content.split( | |
| 689 | - `${MERCURY_CODE_TO_EDIT_OPEN}\n`, | |
| 690 | - )[1] | |
| 691 | - ? replaceEscapedCharacters( | |
| 692 | - msg.content.split(`${MERCURY_CODE_TO_EDIT_OPEN}\n`)[1], | |
| 693 | - ).replace(/\n$/, "") | |
| 694 | - : replaceEscapedCharacters(msg.content); | |
| 688 | + // const nextCompletion = msg.content.split( | |
| 689 | + // `${MERCURY_CODE_TO_EDIT_OPEN}\n`, | |
| 690 | + // )[1] | |
| 691 | + // ? replaceEscapedCharacters( | |
| 692 | + // msg.content.split(`${MERCURY_CODE_TO_EDIT_OPEN}\n`)[1], | |
| 693 | + // ).replace(/\n$/, "") | |
| 694 | + // : replaceEscapedCharacters(msg.content); | |
| 695 | + const nextCompletion = | |
| 696 | + msg.content | |
| 697 | + .split(`${MERCURY_CODE_TO_EDIT_OPEN}\n`)[1] | |
| 698 | + .replace(/\n$/, "") ?? msg.content; | |
| 695 | 699 | |
| 696 | 700 | if (opts?.usingFullFileDiff === false || !opts?.usingFullFileDiff) { |
| 697 | 701 | return await this._handlePartialFileDiff( |
| @@ -773,13 +777,16 @@ | ||
| 773 | 777 | .slice(editableRegionStartLine, editableRegionEndLine + 1) |
| 774 | 778 | .join("\n"); |
| 775 | 779 | const diffLines = myersDiff(fileSlice, nextCompletion); |
| 776 | - const diffGroups = groupDiffLines(diffLines, editableRegionStartLine, 5); | |
| 780 | + const diffGroups = groupDiffLines( | |
| 781 | + diffLines, | |
| 782 | + editableRegionStartLine, | |
| 783 | + 5, | |
| 784 | + ).filter((group) => !isWhitespaceOnlyDeletion(group.lines)); | |
| 777 | 785 | const currentLine = helper.pos.line; |
| 778 | - let cursorLocalDiffGroup: DiffGroup | undefined; | |
| 779 | 786 | const prefetchQueue = PrefetchQueue.getInstance(); |
| 780 | 787 | |
| 781 | 788 | // Process diff groups and find the one containing the cursor |
| 782 | - await this._processDiffGroups( | |
| 789 | + const cursorLocalDiffGroup = await this._processDiffGroups( | |
| 783 | 790 | diffGroups, |
| 784 | 791 | currentLine, |
| 785 | 792 | helper, |
| @@ -798,16 +805,16 @@ | ||
| 798 | 805 | helper.input.completionId, |
| 799 | 806 | true, |
| 800 | 807 | ); |
| 801 | - } else if (diffGroups.length > 0) { | |
| 802 | - // Fallback to first diff group if cursor's group not found | |
| 803 | - return await this._createOutcomeFromDiffGroup( | |
| 804 | - diffGroups[0], | |
| 805 | - helper, | |
| 806 | - startTime, | |
| 807 | - llm, | |
| 808 | - helper.input.completionId, | |
| 809 | - false, | |
| 810 | - ); | |
| 808 | + // } else if (diffGroups.length > 0) { | |
| 809 | + // // Fallback to first diff group if cursor's group not found | |
| 810 | + // return await this._createOutcomeFromDiffGroup( | |
| 811 | + // diffGroups[0], | |
| 812 | + // helper, | |
| 813 | + // startTime, | |
| 814 | + // llm, | |
| 815 | + // helper.input.completionId, | |
| 816 | + // false, | |
| 817 | + // ); | |
| 811 | 818 | } |
| 812 | 819 | |
| 813 | 820 | return undefined; |
modified core/nextEdit/utils.ts +10 −0
| @@ -1,3 +1,5 @@ | ||
| 1 | +import { DiffLine } from ".."; | |
| 2 | + | |
| 1 | 3 | export function isNextEditTest(): boolean { |
| 2 | 4 | const enabled = process.env.NEXT_EDIT_TEST_ENABLED; |
| 3 | 5 | |
| @@ -11,3 +13,11 @@ | ||
| 11 | 13 | |
| 12 | 14 | return false; |
| 13 | 15 | } |
| 16 | + | |
| 17 | +export function isWhitespaceOnlyDeletion(diffLines: DiffLine[]): boolean { | |
| 18 | + return diffLines.every( | |
| 19 | + (diff) => | |
| 20 | + diff.type === "old" && | |
| 21 | + (diff.line.trim() === "" || /^\s+$/.test(diff.line)), | |
| 22 | + ); | |
| 23 | +} |
added core/nextEdit/utils.vitest.ts +59 −0
| @@ -0,0 +1,59 @@ | ||
| 1 | +import { describe, expect, test, vi } from "vitest"; | |
| 2 | +import { DiffLine } from ".."; | |
| 3 | +import { isNextEditTest, isWhitespaceOnlyDeletion } from "./utils"; | |
| 4 | + | |
| 5 | +describe("isNextEditTest", () => { | |
| 6 | + test("returns true when NEXT_EDIT_TEST_ENABLED is 'true'", () => { | |
| 7 | + vi.stubEnv("NEXT_EDIT_TEST_ENABLED", "true"); | |
| 8 | + expect(isNextEditTest()).toBe(true); | |
| 9 | + }); | |
| 10 | + | |
| 11 | + test("returns false when NEXT_EDIT_TEST_ENABLED is 'false'", () => { | |
| 12 | + vi.stubEnv("NEXT_EDIT_TEST_ENABLED", "false"); | |
| 13 | + expect(isNextEditTest()).toBe(false); | |
| 14 | + }); | |
| 15 | + | |
| 16 | + test("returns false when NEXT_EDIT_TEST_ENABLED is undefined", () => { | |
| 17 | + vi.stubEnv("NEXT_EDIT_TEST_ENABLED", undefined); | |
| 18 | + expect(isNextEditTest()).toBe(false); | |
| 19 | + }); | |
| 20 | +}); | |
| 21 | + | |
| 22 | +describe("isWhitespaceOnlyDeletion", () => { | |
| 23 | + test("returns true for whitespace-only deletions", () => { | |
| 24 | + const diffLines: DiffLine[] = [ | |
| 25 | + { type: "old", line: " " }, | |
| 26 | + { type: "old", line: "\t" }, | |
| 27 | + ]; | |
| 28 | + expect(isWhitespaceOnlyDeletion(diffLines)).toBe(true); | |
| 29 | + }); | |
| 30 | + | |
| 31 | + test("returns false for non-whitespace deletions", () => { | |
| 32 | + const diffLines: DiffLine[] = [ | |
| 33 | + { type: "old", line: "code" }, | |
| 34 | + { type: "old", line: " " }, | |
| 35 | + ]; | |
| 36 | + expect(isWhitespaceOnlyDeletion(diffLines)).toBe(false); | |
| 37 | + }); | |
| 38 | + | |
| 39 | + test("returns false for mixed content", () => { | |
| 40 | + const diffLines: DiffLine[] = [ | |
| 41 | + { type: "old", line: " " }, | |
| 42 | + { type: "old", line: "code" }, | |
| 43 | + ]; | |
| 44 | + expect(isWhitespaceOnlyDeletion(diffLines)).toBe(false); | |
| 45 | + }); | |
| 46 | + | |
| 47 | + test("returns false for mixed type", () => { | |
| 48 | + const diffLines: DiffLine[] = [ | |
| 49 | + { type: "old", line: " " }, | |
| 50 | + { type: "new", line: "" }, | |
| 51 | + ]; | |
| 52 | + expect(isWhitespaceOnlyDeletion(diffLines)).toBe(false); | |
| 53 | + }); | |
| 54 | + | |
| 55 | + test("returns true for empty array", () => { | |
| 56 | + const diffLines: DiffLine[] = []; | |
| 57 | + expect(isWhitespaceOnlyDeletion(diffLines)).toBe(true); | |
| 58 | + }); | |
| 59 | +}); |
modified extensions/vscode/src/activation/JumpManager.ts +143 −21
| @@ -1,11 +1,65 @@ | ||
| 1 | 1 | import { NextEditProvider } from "core/nextEdit/NextEditProvider"; |
| 2 | 2 | import { NextEditOutcome } from "core/nextEdit/types"; |
| 3 | +// @ts-ignore | |
| 4 | +import svgBuilder from "svg-builder"; | |
| 3 | 5 | import * as vscode from "vscode"; |
| 6 | +import { getTheme } from "../util/getTheme"; | |
| 4 | 7 | import { |
| 5 | 8 | HandlerPriority, |
| 6 | 9 | SelectionChangeManager, |
| 7 | 10 | } from "./SelectionChangeManager"; |
| 8 | 11 | |
| 12 | +// Instead of getters that execute immediately, use methods or lazy properties | |
| 13 | +const SVG_CONFIG = { | |
| 14 | + stroke: "#999998", | |
| 15 | + strokeWidth: 1, | |
| 16 | + shortcutColor: "#999998", | |
| 17 | + filter: "drop-shadow(0 2px 2px rgba(0,0,0,0.2))", | |
| 18 | + radius: 3, | |
| 19 | + leftMargin: 40, | |
| 20 | + debounceDelay: 500, | |
| 21 | + label: "📍 Press Tab to jump, Esc to cancel", | |
| 22 | + | |
| 23 | + // Convert getters to methods that are called when needed | |
| 24 | + getFontSize(): number { | |
| 25 | + return Math.ceil( | |
| 26 | + (vscode.workspace.getConfiguration("editor").get<number>("fontSize") ?? | |
| 27 | + 14) * 0.8, | |
| 28 | + ); | |
| 29 | + }, | |
| 30 | + | |
| 31 | + getFontFamily(): string { | |
| 32 | + return ( | |
| 33 | + vscode.workspace.getConfiguration("editor").get<string>("fontFamily") || | |
| 34 | + "helvetica" | |
| 35 | + ); | |
| 36 | + }, | |
| 37 | + | |
| 38 | + getPaddingX(): number { | |
| 39 | + return Math.ceil(this.getEstimatedTextWidth(" ")); | |
| 40 | + }, | |
| 41 | + | |
| 42 | + getGap(): number { | |
| 43 | + return this.getFontSize() * 0.5; | |
| 44 | + }, | |
| 45 | + | |
| 46 | + getTipWidth(): number { | |
| 47 | + return this.getEstimatedTextWidth(this.label) + this.getPaddingX(); | |
| 48 | + }, | |
| 49 | + | |
| 50 | + getTipHeight(): number { | |
| 51 | + return this.getFontSize(); | |
| 52 | + }, | |
| 53 | + | |
| 54 | + getTextY(): number { | |
| 55 | + return (this.getTipHeight() + this.getFontSize()) / 2; | |
| 56 | + }, | |
| 57 | + | |
| 58 | + getEstimatedTextWidth(text: string): number { | |
| 59 | + return text.length * this.getFontSize() * 0.6; | |
| 60 | + }, | |
| 61 | +} as const; | |
| 62 | + | |
| 9 | 63 | export interface CompletionDataForAfterJump { |
| 10 | 64 | completionId: string; |
| 11 | 65 | outcome: NextEditOutcome; |
| @@ -16,16 +70,29 @@ | ||
| 16 | 70 | private static _instance: JumpManager | undefined; |
| 17 | 71 | |
| 18 | 72 | // Decoration state. |
| 73 | + private _jumpIcon: vscode.Uri | undefined; | |
| 19 | 74 | private _jumpDecoration: vscode.TextEditorDecorationType | undefined; |
| 20 | 75 | private _jumpDecorationVisible = false; |
| 21 | 76 | private _disposables: vscode.Disposable[] = []; |
| 77 | + private _theme = getTheme(); | |
| 22 | 78 | |
| 23 | 79 | private _jumpInProgress: boolean = false; |
| 24 | 80 | private _jumpAccepted: boolean = false; |
| 25 | 81 | private _completionAfterJump: CompletionDataForAfterJump | null = null; |
| 26 | 82 | private _oldCursorPosition: vscode.Position | undefined; |
| 27 | 83 | |
| 28 | - private constructor() {} | |
| 84 | + private constructor() { | |
| 85 | + // Build the first SVG icon | |
| 86 | + this._createSvgJumpIcon(); | |
| 87 | + | |
| 88 | + // Re‑build when the colour theme changes | |
| 89 | + vscode.workspace.onDidChangeConfiguration((e) => { | |
| 90 | + if (e.affectsConfiguration("workbench.colorTheme")) { | |
| 91 | + this._theme = getTheme(); | |
| 92 | + this._createSvgJumpIcon(); | |
| 93 | + } | |
| 94 | + }); | |
| 95 | + } | |
| 29 | 96 | |
| 30 | 97 | initialize() {} |
| 31 | 98 | |
| @@ -51,6 +118,62 @@ | ||
| 51 | 118 | this._disposables = []; |
| 52 | 119 | } |
| 53 | 120 | |
| 121 | + private _createSvgJumpIcon() { | |
| 122 | + // if (!this._theme) { | |
| 123 | + // return; | |
| 124 | + // } | |
| 125 | + | |
| 126 | + const baseTextConfig = { | |
| 127 | + y: SVG_CONFIG.getTextY(), | |
| 128 | + "font-family": SVG_CONFIG.getFontFamily(), | |
| 129 | + "font-size": SVG_CONFIG.getFontSize(), | |
| 130 | + }; | |
| 131 | + | |
| 132 | + try { | |
| 133 | + const svgContent = svgBuilder | |
| 134 | + .width(SVG_CONFIG.getTipWidth()) | |
| 135 | + .height(SVG_CONFIG.getTipHeight()) | |
| 136 | + .text( | |
| 137 | + { | |
| 138 | + ...baseTextConfig, | |
| 139 | + x: 4, | |
| 140 | + fill: this._theme?.colors["editor.foreground"] ?? SVG_CONFIG.stroke, | |
| 141 | + }, | |
| 142 | + SVG_CONFIG.label, | |
| 143 | + ) | |
| 144 | + .render(); | |
| 145 | + | |
| 146 | + const dataUri = `data:image/svg+xml;base64,${Buffer.from( | |
| 147 | + svgContent, | |
| 148 | + ).toString("base64")}`; | |
| 149 | + this._jumpIcon = vscode.Uri.parse(dataUri); | |
| 150 | + | |
| 151 | + // Dispose the old decoration (if any) and create a fresh one. | |
| 152 | + if (this._jumpDecoration) { | |
| 153 | + this._jumpDecoration.dispose(); | |
| 154 | + } | |
| 155 | + this._jumpDecoration = this._createSvgJumpDecoration(); | |
| 156 | + } catch (err) { | |
| 157 | + console.error("Error creating SVG jump tooltip:", err); | |
| 158 | + } | |
| 159 | + } | |
| 160 | + | |
| 161 | + private _createSvgJumpDecoration(): vscode.TextEditorDecorationType { | |
| 162 | + const backgroundColour = | |
| 163 | + this._theme?.colors["editor.background"] ?? "#333333"; | |
| 164 | + | |
| 165 | + return vscode.window.createTextEditorDecorationType({ | |
| 166 | + after: { | |
| 167 | + contentIconPath: this._jumpIcon, | |
| 168 | + border: `;box-shadow: inset 0 0 0 ${SVG_CONFIG.strokeWidth}px ${SVG_CONFIG.stroke}, inset 0 0 0 ${SVG_CONFIG.getTipHeight()}px ${backgroundColour}; | |
| 169 | + border-radius: ${SVG_CONFIG.radius}px; | |
| 170 | + filter: ${SVG_CONFIG.filter}`, | |
| 171 | + margin: `0 0 0 ${SVG_CONFIG.leftMargin}px`, | |
| 172 | + width: `${SVG_CONFIG.getTipWidth()}px`, | |
| 173 | + }, | |
| 174 | + }); | |
| 175 | + } | |
| 176 | + | |
| 54 | 177 | public async suggestJump( |
| 55 | 178 | currentPosition: vscode.Position, |
| 56 | 179 | nextJumpLocation: vscode.Position, |
| @@ -157,17 +280,6 @@ | ||
| 157 | 280 | ); |
| 158 | 281 | } |
| 159 | 282 | |
| 160 | - // Scroll to show the jump location. | |
| 161 | - editor.revealRange( | |
| 162 | - new vscode.Range(decorationLine, 0, decorationLine, 0), | |
| 163 | - vscode.TextEditorRevealType.InCenter, | |
| 164 | - ); | |
| 165 | - | |
| 166 | - // Clean up after timeout if no jump has been made. | |
| 167 | - // setTimeout(() => { | |
| 168 | - // this._jumpInProgress = false; | |
| 169 | - // }, 10000); | |
| 170 | - | |
| 171 | 283 | return true; |
| 172 | 284 | } |
| 173 | 285 | |
| @@ -180,18 +292,22 @@ | ||
| 180 | 292 | await this.clearJumpDecoration(); |
| 181 | 293 | |
| 182 | 294 | // Create a decoration for jump. |
| 183 | - this._jumpDecoration = vscode.window.createTextEditorDecorationType({ | |
| 184 | - before: { | |
| 185 | - contentText: "📍 Press Tab to jump, Esc to cancel", | |
| 186 | - color: new vscode.ThemeColor("editor.foreground"), | |
| 187 | - backgroundColor: new vscode.ThemeColor("editorInfo.background"), | |
| 188 | - margin: `0 0 0 4px`, | |
| 189 | - }, | |
| 190 | - }); | |
| 295 | + // this._jumpDecoration = vscode.window.createTextEditorDecorationType({ | |
| 296 | + // before: { | |
| 297 | + // contentText: "📍 Press Tab to jump, Esc to cancel", | |
| 298 | + // color: new vscode.ThemeColor("editor.foreground"), | |
| 299 | + // backgroundColor: new vscode.ThemeColor("editorHover.background"), | |
| 300 | + // margin: `0 0 0 4px`, | |
| 301 | + // }, | |
| 302 | + // }); | |
| 303 | + | |
| 304 | + if (!this._jumpDecoration) { | |
| 305 | + this._createSvgJumpIcon(); // makes both the icon & decoration | |
| 306 | + } | |
| 191 | 307 | |
| 192 | 308 | // Apply the decoration. |
| 193 | 309 | const lastIndexOfLine = editor.document.lineAt(lineToRenderOn).text.length; |
| 194 | - editor.setDecorations(this._jumpDecoration, [ | |
| 310 | + editor.setDecorations(this._jumpDecoration!, [ | |
| 195 | 311 | new vscode.Range( |
| 196 | 312 | lineToRenderOn, |
| 197 | 313 | lastIndexOfLine, |
| @@ -240,6 +356,12 @@ | ||
| 240 | 356 | if (this._jumpDecorationVisible) { |
| 241 | 357 | this._jumpAccepted = true; |
| 242 | 358 | |
| 359 | + // Scroll to show the jump location. | |
| 360 | + editor.revealRange( | |
| 361 | + new vscode.Range(jumpPosition.line, 0, jumpPosition.line, 0), | |
| 362 | + vscode.TextEditorRevealType.InCenter, | |
| 363 | + ); | |
| 364 | + | |
| 243 | 365 | // Move cursor to the jump position. |
| 244 | 366 | editor.selection = new vscode.Selection(jumpPosition, jumpPosition); |
| 245 | 367 | await this.clearJumpDecoration(); |
modified extensions/vscode/src/activation/JumpManager.vitest.ts +90 −13
| @@ -36,6 +36,21 @@ | ||
| 36 | 36 | dispose: vi.fn(), |
| 37 | 37 | }), |
| 38 | 38 | }, |
| 39 | + workspace: { | |
| 40 | + getConfiguration: vi.fn().mockImplementation((section?: string) => { | |
| 41 | + // Return a configuration object with a get method | |
| 42 | + return { | |
| 43 | + get: vi.fn().mockImplementation((key: string) => { | |
| 44 | + if (key === "fontSize") return 14; | |
| 45 | + if (key === "fontFamily") return "monaco"; | |
| 46 | + return undefined; | |
| 47 | + }), | |
| 48 | + }; | |
| 49 | + }), | |
| 50 | + onDidChangeConfiguration: vi.fn().mockReturnValue({ | |
| 51 | + dispose: vi.fn(), | |
| 52 | + }), | |
| 53 | + }, | |
| 39 | 54 | Position: class { |
| 40 | 55 | constructor( |
| 41 | 56 | public line: number, |
| @@ -69,6 +84,32 @@ | ||
| 69 | 84 | dispose: vi.fn(), |
| 70 | 85 | }), |
| 71 | 86 | }, |
| 87 | + Uri: { | |
| 88 | + parse: vi.fn().mockReturnValue({ toString: () => "mock-uri" }), | |
| 89 | + }, | |
| 90 | + }; | |
| 91 | +}); | |
| 92 | + | |
| 93 | +// Mock getTheme utility | |
| 94 | +vi.mock("../util/getTheme", () => ({ | |
| 95 | + getTheme: vi.fn().mockReturnValue({ | |
| 96 | + colors: { | |
| 97 | + "editor.foreground": "#ffffff", | |
| 98 | + "editor.background": "#1e1e1e", | |
| 99 | + }, | |
| 100 | + }), | |
| 101 | +})); | |
| 102 | + | |
| 103 | +// Mock svg-builder | |
| 104 | +vi.mock("svg-builder", () => { | |
| 105 | + const mockSvgBuilder = { | |
| 106 | + width: vi.fn().mockReturnThis(), | |
| 107 | + height: vi.fn().mockReturnThis(), | |
| 108 | + text: vi.fn().mockReturnThis(), | |
| 109 | + render: vi.fn().mockReturnValue("<svg>mock svg</svg>"), | |
| 110 | + }; | |
| 111 | + return { | |
| 112 | + default: mockSvgBuilder, | |
| 72 | 113 | }; |
| 73 | 114 | }); |
| 74 | 115 | |
| @@ -152,20 +193,32 @@ | ||
| 152 | 193 | let jumpManager: JumpManager; |
| 153 | 194 | |
| 154 | 195 | beforeEach(() => { |
| 155 | - // Reset mocks | |
| 156 | - vi.resetAllMocks(); | |
| 157 | - | |
| 158 | - // Re-setup the lineAt mock after reset | |
| 159 | - const mockLineAt = vi.fn().mockReturnValue({ | |
| 160 | - text: "Sample line text", | |
| 161 | - lineNumber: 0, | |
| 196 | + // Clear mock history but keep implementations | |
| 197 | + vi.clearAllMocks(); | |
| 198 | + | |
| 199 | + // Create a proper TextLine mock | |
| 200 | + const createMockTextLine = (text: string, lineNumber: number) => ({ | |
| 201 | + text, | |
| 202 | + lineNumber, | |
| 203 | + range: new vscode.Range(lineNumber, 0, lineNumber, text.length), | |
| 204 | + rangeIncludingLineBreak: new vscode.Range( | |
| 205 | + lineNumber, | |
| 206 | + 0, | |
| 207 | + lineNumber + 1, | |
| 208 | + 0, | |
| 209 | + ), | |
| 210 | + firstNonWhitespaceCharacterIndex: text.search(/\S/), | |
| 211 | + isEmptyOrWhitespace: text.trim().length === 0, | |
| 162 | 212 | }); |
| 163 | 213 | |
| 164 | - // Ensure our mock is properly set up after reset | |
| 165 | - if (vscode.window.activeTextEditor?.document) { | |
| 214 | + // Reset lineAt mock with proper TextLine objects | |
| 215 | + if (vscode.window.activeTextEditor?.document.lineAt) { | |
| 166 | 216 | vi.mocked( |
| 167 | 217 | vscode.window.activeTextEditor.document.lineAt, |
| 168 | - ).mockImplementation(mockLineAt); | |
| 218 | + // @ts-ignore | |
| 219 | + ).mockImplementation((line: number) => | |
| 220 | + createMockTextLine("Sample line text", line), | |
| 221 | + ); | |
| 169 | 222 | } |
| 170 | 223 | |
| 171 | 224 | // Clear any existing instance |
| @@ -240,7 +293,7 @@ | ||
| 240 | 293 | // Decorations should not be created |
| 241 | 294 | expect( |
| 242 | 295 | vscode.window.createTextEditorDecorationType, |
| 243 | - ).not.toHaveBeenCalled(); | |
| 296 | + ).toHaveBeenCalledOnce(); // only during setup | |
| 244 | 297 | }); |
| 245 | 298 | |
| 246 | 299 | it("should render decoration for jump location outside visible range (below)", async () => { |
| @@ -293,8 +346,32 @@ | ||
| 293 | 346 | |
| 294 | 347 | // Should create decoration |
| 295 | 348 | expect(vscode.window.createTextEditorDecorationType).toHaveBeenCalled(); |
| 296 | - // Should reveal range | |
| 297 | - expect(vscode.window.activeTextEditor!.revealRange).toHaveBeenCalled(); | |
| 349 | + // Should not reveal range | |
| 350 | + expect( | |
| 351 | + vscode.window.activeTextEditor!.revealRange, | |
| 352 | + ).not.toHaveBeenCalled(); | |
| 353 | + }); | |
| 354 | + | |
| 355 | + it("should call revealRange when jump is accepted", async () => { | |
| 356 | + const currentPosition = new vscode.Position(1, 0); | |
| 357 | + const nextJumpLocation = new vscode.Position(8, 0); // Outside visible range | |
| 358 | + | |
| 359 | + await jumpManager.suggestJump(currentPosition, nextJumpLocation); | |
| 360 | + | |
| 361 | + // Find the acceptJump command handler. | |
| 362 | + const commandArgs = vi | |
| 363 | + .mocked(vscode.commands.registerCommand) | |
| 364 | + .mock.calls.find((call: any) => call[0] === "continue.acceptJump"); | |
| 365 | + expect(commandArgs).toBeDefined(); | |
| 366 | + const acceptJumpHandler = commandArgs![1]; | |
| 367 | + | |
| 368 | + await acceptJumpHandler(); | |
| 369 | + | |
| 370 | + // Should reveal the jump location range after jumping. | |
| 371 | + expect(vscode.window.activeTextEditor!.revealRange).toHaveBeenCalledWith( | |
| 372 | + new vscode.Range(nextJumpLocation.line, 0, nextJumpLocation.line, 0), | |
| 373 | + vscode.TextEditorRevealType.InCenter, | |
| 374 | + ); | |
| 298 | 375 | }); |
| 299 | 376 | }); |
| 300 | 377 |
modified extensions/vscode/src/activation/NextEditWindowManager.ts +12 −16
| @@ -669,17 +669,9 @@ | ||
| 669 | 669 | const offsetFromTop = |
| 670 | 670 | (position.line - editableRegionStartLine) * SVG_CONFIG.lineHeight; |
| 671 | 671 | |
| 672 | - // Set the margin-left so that it's never covering code inside the editable region. | |
| 673 | - const marginLeft = | |
| 674 | - SVG_CONFIG.getTipWidth(originalCode) - | |
| 675 | - SVG_CONFIG.getTipWidth(originalCode.split("\n")[currLineOffsetFromTop]); | |
| 676 | - | |
| 677 | - // console.log(marginLeft); | |
| 678 | - // console.log(SVG_CONFIG.getTipWidth(originalCode)); | |
| 679 | - // console.log( | |
| 680 | - // SVG_CONFIG.getTipWidth(originalCode.split("\n")[currLineOffsetFromTop]), | |
| 681 | - // ); | |
| 682 | - // console.log(originalCode.split("\n")[currLineOffsetFromTop]); | |
| 672 | + // Position the decoration with minimal left margin since it's already at line end | |
| 673 | + const marginLeft = SVG_CONFIG.paddingX; // Use consistent padding instead of complex calculation | |
| 674 | + | |
| 683 | 675 | return vscode.window.createTextEditorDecorationType({ |
| 684 | 676 | before: { |
| 685 | 677 | contentIconPath: uri, |
| @@ -770,12 +762,16 @@ | ||
| 770 | 762 | ): vscode.Position { |
| 771 | 763 | // Create a position that's offset spaces to the right of the cursor. |
| 772 | 764 | |
| 765 | + // const line = editor.document.lineAt(position.line); | |
| 766 | + // const offsetChar = Math.min( | |
| 767 | + // position.character + SVG_CONFIG.cursorOffset, | |
| 768 | + // line.text.length, | |
| 769 | + // ); | |
| 770 | + // return new vscode.Position(position.line, offsetChar); | |
| 771 | + | |
| 772 | + // Place decoration at the end of the current line | |
| 773 | 773 | const line = editor.document.lineAt(position.line); |
| 774 | - const offsetChar = Math.min( | |
| 775 | - position.character + SVG_CONFIG.cursorOffset, | |
| 776 | - line.text.length, | |
| 777 | - ); | |
| 778 | - return new vscode.Position(position.line, offsetChar); | |
| 774 | + return new vscode.Position(position.line, line.text.length); | |
| 779 | 775 | } |
| 780 | 776 | |
| 781 | 777 | /** |