From b11e831a20638f7065e3ee47e8e954436d4e5a82 Mon Sep 17 00:00:00 2001 From: adarshramiyer Date: Wed, 9 Jul 2025 20:20:58 -0700 Subject: [PATCH] changes to address patrick's comments --- core/nextEdit/context/diffFormatting.ts | 22 ++++++++---- core/nextEdit/context/processNextEditData.ts | 14 ++++---- core/util/paths.ts | 34 +++++++++++++++++++ extensions/vscode/package-lock.json | 4 +-- .../vscode/src/util/editLoggingUtils.ts | 23 +------------ 5 files changed, 59 insertions(+), 38 deletions(-) diff --git a/core/nextEdit/context/diffFormatting.ts b/core/nextEdit/context/diffFormatting.ts index 3c7deb933..e373c56bc 100644 --- a/core/nextEdit/context/diffFormatting.ts +++ b/core/nextEdit/context/diffFormatting.ts @@ -12,13 +12,21 @@ export type BeforeAfterDiff = { afterContent: string; }; -export const createDiff = ( - beforeContent: string, - afterContent: string, - filePath: string, - diffType: DiffFormatType, - contextLines: number = 3, -) => { +export interface createDiffArgs { + beforeContent: string; + afterContent: string; + filePath: string; + diffType: DiffFormatType; + contextLines: number; +} + +export const createDiff = ({ + beforeContent, + afterContent, + filePath, + diffType, + contextLines, +}: createDiffArgs) => { switch (diffType) { case DiffFormatType.Unified: return createUnifiedDiff( diff --git a/core/nextEdit/context/processNextEditData.ts b/core/nextEdit/context/processNextEditData.ts index 45c9e231b..aaa89d33a 100644 --- a/core/nextEdit/context/processNextEditData.ts +++ b/core/nextEdit/context/processNextEditData.ts @@ -127,13 +127,13 @@ export const processNextEditData = async ({ // add current edit to history const thisEdit: prevEdit = { - unidiff: createDiff( - beforeContent, - afterContent, - filePath, - DiffFormatType.Unified, - 25, // 25 context lines; store a large number for trimming later on - ), + unidiff: createDiff({ + beforeContent: beforeContent, + afterContent: afterContent, + filePath: filePath, + diffType: DiffFormatType.Unified, + contextLines: 25, // storing many context lines for downstream trimming + }), fileUri: filePath, workspaceUri: workspaceDir, timestamp: timestamp, diff --git a/core/util/paths.ts b/core/util/paths.ts index 1123b7eda..92ea5be94 100644 --- a/core/util/paths.ts +++ b/core/util/paths.ts @@ -1,6 +1,7 @@ import * as fs from "fs"; import * as os from "os"; import * as path from "path"; +import * as URI from "uri-js"; import * as YAML from "yaml"; import { ConfigYaml, DevEventName } from "@continuedev/config-yaml"; @@ -466,3 +467,36 @@ export function getDiffsDirectoryPath(): string { } return diffsPath; } + +export const isFileWithinFolder = ( + fileUri: string, + folderPath: string, +): boolean => { + try { + if (!fileUri || !folderPath) { + return false; + } + + const fileUriParsed = URI.parse(fileUri); + const fileScheme = fileUriParsed.scheme || "file"; + let filePath = fileUriParsed.path || ""; + filePath = decodeURIComponent(filePath); + + let folderWithScheme = folderPath; + if (!folderPath.includes("://")) { + folderWithScheme = `${fileScheme}://${folderPath.startsWith("/") ? "" : "/"}${folderPath}`; + } + const folderUriParsed = URI.parse(folderWithScheme); + + let folderPathClean = folderUriParsed.path || ""; + folderPathClean = decodeURIComponent(folderPathClean); + + filePath = filePath.replace(/\/$/, ""); + folderPathClean = folderPathClean.replace(/\/$/, ""); + + return filePath === folderPath || filePath.startsWith(`${folderPath}/`); + } catch (error) { + console.error("Error in isFileWithinFolder:", error); + return false; + } +}; diff --git a/extensions/vscode/package-lock.json b/extensions/vscode/package-lock.json index f58d4cba8..6936cc88b 100644 --- a/extensions/vscode/package-lock.json +++ b/extensions/vscode/package-lock.json @@ -1,12 +1,12 @@ { "name": "continue", - "version": "1.1.58", + "version": "1.1.59", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "continue", - "version": "1.1.58", + "version": "1.1.59", "license": "Apache-2.0", "dependencies": { "@continuedev/config-types": "^1.0.14", diff --git a/extensions/vscode/src/util/editLoggingUtils.ts b/extensions/vscode/src/util/editLoggingUtils.ts index 1c6bd3dfb..4ef1fabc6 100644 --- a/extensions/vscode/src/util/editLoggingUtils.ts +++ b/extensions/vscode/src/util/editLoggingUtils.ts @@ -3,8 +3,7 @@ import { AutocompleteCodeSnippet } from "core/autocomplete/snippets/types"; import { GetLspDefinitionsFunction } from "core/autocomplete/types"; import { ConfigHandler } from "core/config/ConfigHandler"; import { RecentlyEditedRange } from "core/nextEdit/types"; -import { getContinueGlobalPath } from "core/util/paths"; -import { findUriInDirs } from "core/util/uri"; +import { getContinueGlobalPath, isFileWithinFolder } from "core/util/paths"; import fs from "fs"; import { resolve } from "path"; import * as vscode from "vscode"; @@ -22,26 +21,6 @@ export const getBeforeCursorPos = (range: Range, activePos: Position) => { } }; -const isFileWithinFolder = (fileUri: string, folderPath: string): boolean => { - try { - const uriMatch = fileUri.match(/^([a-zA-Z]+:\/\/)/); - const scheme = uriMatch ? uriMatch[1] : "file://"; - - const folderUri = folderPath.match(/^[a-zA-Z]+:\/\//) - ? folderPath - : `${scheme}${folderPath}`; - - const normalizedFolderUri = folderUri.endsWith("/") - ? folderUri - : `${folderUri}/`; - - const { foundInDir } = findUriInDirs(fileUri, [normalizedFolderUri]); - return foundInDir !== null; - } catch (error) { - return false; - } -}; - const isEditLoggingAllowed = async (editedFileURI: string) => { const globalContinuePath = getContinueGlobalPath(); const editLogDirsPath = resolve(globalContinuePath, ".editlogdirs");