From 5dceb5cd19a839fb78ce3942a2e2430b4bdb370f Mon Sep 17 00:00:00 2001 From: Povilas Kanapickas Date: Wed, 5 Mar 2025 21:27:16 +0200 Subject: [PATCH] fix: Bring back old behavior of readStrings{After,Before}Cursor setting (#97) --- context/DocumentContextReader.cpp | 6 ++++-- test/DocumentContextReaderTest.cpp | 8 ++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/context/DocumentContextReader.cpp b/context/DocumentContextReader.cpp index f76d9a1..c7cc2bf 100644 --- a/context/DocumentContextReader.cpp +++ b/context/DocumentContextReader.cpp @@ -253,10 +253,12 @@ LLMCore::ContextData DocumentContextReader::prepareContext( contextBefore = readWholeFileBefore(lineNumber, cursorPosition); contextAfter = readWholeFileAfter(lineNumber, cursorPosition); } else { + // Note that readStrings{After,Before}Cursor include current line, but linesCount argument of + // getContext{After,Before} do not contextBefore - = getContextBefore(lineNumber, cursorPosition, settings.readStringsBeforeCursor()); + = getContextBefore(lineNumber, cursorPosition, settings.readStringsBeforeCursor() + 1); contextAfter - = getContextAfter(lineNumber, cursorPosition, settings.readStringsAfterCursor()); + = getContextAfter(lineNumber, cursorPosition, settings.readStringsAfterCursor() + 1); } QString fileContext; diff --git a/test/DocumentContextReaderTest.cpp b/test/DocumentContextReaderTest.cpp index fe0379e..68df5f6 100644 --- a/test/DocumentContextReaderTest.cpp +++ b/test/DocumentContextReaderTest.cpp @@ -283,15 +283,15 @@ TEST_F(DocumentContextReaderTest, testPrepareContext) EXPECT_EQ( reader.prepareContext(2, 3, *createSettingsForLines(1, 1)), (ContextData{ - .prefix = "Lin", - .suffix = "e 3", + .prefix = "Line 2\nLin", + .suffix = "e 3\nLine 4", .fileContext = "\n Language: (MIME: text/python) filepath: /path/to/file()\n\n\n "})); EXPECT_EQ( reader.prepareContext(2, 3, *createSettingsForLines(2, 2)), (ContextData{ - .prefix = "Line 2\nLin", - .suffix = "e 3\nLine 4", + .prefix = "Line 1\nLine 2\nLin", + .suffix = "e 3\nLine 4\nLine 5", .fileContext = "\n Language: (MIME: text/python) filepath: /path/to/file()\n\n\n "})); }