continue-custom/core/commands/util.ts
2024-09-26 20:40:57 -07:00

42 lines
890 B
TypeScript

import { ContextItemWithId } from "../";
export interface RangeInFileWithContents {
filepath: string;
range: {
start: { line: number; character: number };
end: { line: number; character: number };
};
contents: string;
}
export function ctxItemToRifWithContents(
item: ContextItemWithId,
): RangeInFileWithContents {
let startLine = 0;
let endLine = 0;
const nameSplit = item.name.split("(");
if (nameSplit.length > 1) {
const lines = nameSplit[1].split(")")[0].split("-");
startLine = Number.parseInt(lines[0], 10);
endLine = Number.parseInt(lines[1], 10);
}
const rif: RangeInFileWithContents = {
filepath: item.uri?.value || "",
range: {
start: {
line: startLine,
character: 0,
},
end: {
line: endLine,
character: 0,
},
},
contents: item.content,
};
return rif;
}