diff --git a/clients/tabby-agent/src/codeCompletion/contexts.ts b/clients/tabby-agent/src/codeCompletion/contexts.ts index 751d9b04f554..c9ff37a3ea6a 100644 --- a/clients/tabby-agent/src/codeCompletion/contexts.ts +++ b/clients/tabby-agent/src/codeCompletion/contexts.ts @@ -141,6 +141,10 @@ export class CompletionContext { const prefix = this.prefixLines.slice(Math.max(this.prefixLines.length - config.maxPrefixLines, 0)).join(""); const suffix = this.suffixLines.slice(0, config.maxSuffixLines).join(""); + // determine system separator + const isWindows = process.platform === "win32"; + const separator = isWindows ? "\\" : "/"; + // filepath && git_url let relativeFilepathRoot: string | undefined = undefined; let filepath: string | undefined = undefined; @@ -161,14 +165,16 @@ export class CompletionContext { relativeFilepathRoot = this.workspace; } if (relativeFilepathRoot) { - filepath = path.relative(relativeFilepathRoot, this.filepath); + filepath = path.normalize(path.relative(relativeFilepathRoot, this.filepath)).replace(/[/\\]/g, separator); } // declarations const declarations = this.declarations?.map((declaration) => { let declarationFilepath = declaration.filepath; if (relativeFilepathRoot && declarationFilepath.startsWith(relativeFilepathRoot)) { - declarationFilepath = path.relative(relativeFilepathRoot, declarationFilepath); + declarationFilepath = path + .normalize(path.relative(relativeFilepathRoot, declarationFilepath)) + .replace(/[/\\]/g, separator); } return { filepath: declarationFilepath, @@ -195,7 +201,9 @@ export class CompletionContext { .map((snippet) => { let snippetFilepath = snippet.filepath; if (relativeFilepathRoot && snippetFilepath.startsWith(relativeFilepathRoot)) { - snippetFilepath = path.relative(relativeFilepathRoot, snippetFilepath); + snippetFilepath = path + .normalize(path.relative(relativeFilepathRoot, snippetFilepath)) + .replace(/[/\\]/g, separator); } return { filepath: snippetFilepath, @@ -209,7 +217,7 @@ export class CompletionContext { const snippetsOpenedFiles = this.snippetsFromOpenedFiles ?.map((snippet) => { return { - filepath: snippet.filepath, + filepath: path.normalize(snippet.filepath).replace(/[/\\]/g, separator), body: snippet.text, score: snippet.score, };