Skip to content

Commit

Permalink
fix(assignments-service): Find end of python function with no newline…
Browse files Browse the repository at this point in the history
… at EOF
  • Loading branch information
Clashsoft committed Sep 18, 2023
1 parent df22541 commit 7a9d638
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@ def baz():

expect(findIndentEnd(code, 0, 10)).toEqual(34);
expect(findIndentEnd(code, 35, 45)).toEqual(52);
// TODO test with no newline at end of file
expect(findIndentEnd(code.trim(), 35, 45)).toEqual(51);
});
});
5 changes: 4 additions & 1 deletion services/apps/assignments/src/embedding/embedding.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,10 @@ export function findIndentEnd(code: string, headStart: number, headEnd: number):
const bodyIndent = code.substring(firstLineStart, bodyIndentEnd);
let currentIndex = firstLineStart;
while (true) {
const nextLineIndex = (code.indexOf('\n', currentIndex)) || code.length;
const nextLineIndex = code.indexOf('\n', currentIndex);
if (nextLineIndex === -1) {
return code.length - 1;
}
if (currentIndex === nextLineIndex) { // line is empty
currentIndex++;
continue;
Expand Down

0 comments on commit 7a9d638

Please sign in to comment.