changes to address patrick's comments
This commit is contained in:
parent
7dadfb6e15
commit
b11e831a20
5 changed files with 59 additions and 38 deletions
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
4
extensions/vscode/package-lock.json
generated
4
extensions/vscode/package-lock.json
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue