Skip to content

Commit 09b6663

Browse files
committed
Refactor CodeContextStructure.trim method to improve line trimming logic and indentation handling
1 parent cb50768 commit 09b6663

1 file changed

Lines changed: 13 additions & 2 deletions

File tree

codetide/core/models.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,19 @@ class CodeContextStructure(BaseModel):
280280
_unique_class_elements_ids :List[str] = list()
281281

282282
@staticmethod
283-
def trim(raw :str, top_lines :int=50)->str:
284-
return "\n".join(raw.splitlines()[:top_lines]+["\n..."])
283+
def trim(raw: str, top_lines: int = 15) -> str:
284+
lines = raw.splitlines()
285+
if len(lines) <= top_lines:
286+
return "\n".join(lines)
287+
288+
trimmed = lines[:top_lines]
289+
290+
# Determine indentation from the last line
291+
last_line = trimmed[-1]
292+
indent = len(last_line) - len(last_line.lstrip())
293+
ellipsis_line = " " * indent + "..."
294+
295+
return "\n".join(trimmed + [ellipsis_line])
285296

286297
def add_requested_element(self, element :Union[ImportStatement, VariableDeclaration, FunctionDefinition, ClassDefinition, ClassAttribute, MethodDefinition]):
287298
if isinstance(element, (ClassDefinition, ClassAttribute, MethodDefinition)):

0 commit comments

Comments
 (0)