refactor: Reuse getContext{Before,After}() instead of duplicating logic (#95)

getContextAfter(int lineNumber, int cursorPosition) and
getContextBefore(int lineNumber, int cursorPosition) are currently not
tested. Thus as little logic as possible should live there.
This commit is contained in:
Povilas Kanapickas 2025-03-05 20:43:51 +02:00 committed by GitHub
parent 3dc0d910bf
commit e218699e64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -264,14 +264,8 @@ QString DocumentContextReader::getContextBefore(int lineNumber, int cursorPositi
if (Settings::codeCompletionSettings().readFullFile()) {
return readWholeFileBefore(lineNumber, cursorPosition);
} else {
int effectiveStartLine;
int beforeCursor = Settings::codeCompletionSettings().readStringsBeforeCursor();
if (m_copyrightInfo.found) {
effectiveStartLine = qMax(m_copyrightInfo.endLine + 1, lineNumber - beforeCursor);
} else {
effectiveStartLine = qMax(0, lineNumber - beforeCursor);
}
return getContextBetween(effectiveStartLine, -1, lineNumber, cursorPosition);
int linesCount = Settings::codeCompletionSettings().readStringsBeforeCursor();
return getContextBefore(lineNumber, cursorPosition, linesCount);
}
}
@ -280,10 +274,8 @@ QString DocumentContextReader::getContextAfter(int lineNumber, int cursorPositio
if (Settings::codeCompletionSettings().readFullFile()) {
return readWholeFileAfter(lineNumber, cursorPosition);
} else {
int endLine = qMin(
m_document->blockCount() - 1,
lineNumber + Settings::codeCompletionSettings().readStringsAfterCursor());
return getContextBetween(lineNumber, cursorPosition, endLine, -1);
int linesCount = Settings::codeCompletionSettings().readStringsAfterCursor();
return getContextAfter(lineNumber, cursorPosition, linesCount);
}
}