Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
liangfung committed Dec 27, 2024
1 parent 70852db commit 9385c42
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions clients/vscode/src/chat/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ export function chatPanelFilepathToLocalUri(filepath: Filepath, gitProvider: Git
if (filepath.kind === "uri") {
try {
if (isNotebook) {
return generateLocalNotebookCellUri(Uri.parse(filepath.uri), 0);
const handle = chatPanelFilePathToNotebookCellHandle(filepath.uri);
if (typeof handle === 'number') {
return generateLocalNotebookCellUri(Uri.parse(filepath.uri), handle);
}
}

return Uri.parse(filepath.uri, true);
} catch (e) {
// FIXME(@icycodes): this is a hack for uri is relative filepaths in workspaces
Expand Down Expand Up @@ -103,26 +107,33 @@ function chatPanelFilepathToVscodeNotebookCellUri(root: Uri, filepath: FilepathI
return null;
}

const fileUri = Uri.parse(filepath.filepath);
const fragment = fileUri.fragment;
const filePathUri = Uri.parse(filepath.filepath);
const notebookUri = Uri.joinPath(root, filePathUri.path);

const uri = Uri.joinPath(root, fileUri.path);
const handle = chatPanelFilePathToNotebookCellHandle(filepath.filepath)
if (typeof handle === "undefined") {
logger.warn(`Invalid filepath params.`, filepath);
return null;
}
return generateLocalNotebookCellUri(notebookUri, handle);
}

function chatPanelFilePathToNotebookCellHandle(filepath: string): number | undefined {
let handle: number | undefined;

const fileUri = Uri.parse(filepath);
const fragment = fileUri.fragment;
const searchParams = new URLSearchParams(fragment);

if (searchParams.has("cell")) {
const cellString = searchParams.get("cell")?.toString() || "";
handle = parseInt(cellString, 10);
}

if (typeof handle === "undefined" || isNaN(handle)) {
logger.warn(`Invalid handle in filepath.`, filepath.filepath);
return null;
return undefined
}

return generateLocalNotebookCellUri(uri, handle);
return handle
}

export function vscodePositionToChatPanelPosition(position: VSCodePosition): ChatPanelPosition {
Expand Down

0 comments on commit 9385c42

Please sign in to comment.