mirror of
https://github.com/Palm1r/QodeAssist.git
synced 2025-07-18 04:54:30 -04:00
fix: Properly omit copyright information (#103)
This commit ensures that copyright information is always excluded and that context is always split into prefix and suffix at correct position.
This commit is contained in:
committed by
GitHub
parent
8a167bf248
commit
61ca5c9a1b
@ -84,18 +84,22 @@ QString DocumentContextReader::getLineText(int lineNumber, int cursorPosition) c
|
||||
QString DocumentContextReader::getContextBefore(
|
||||
int lineNumber, int cursorPosition, int linesCount) const
|
||||
{
|
||||
int effectiveStartLine = qMax(0, lineNumber - linesCount + 1);
|
||||
int startLine = lineNumber - linesCount + 1;
|
||||
if (m_copyrightInfo.found) {
|
||||
effectiveStartLine = qMax(m_copyrightInfo.endLine + 1, effectiveStartLine);
|
||||
startLine = qMax(m_copyrightInfo.endLine + 1, startLine);
|
||||
}
|
||||
|
||||
return getContextBetween(effectiveStartLine, -1, lineNumber, cursorPosition);
|
||||
return getContextBetween(startLine, -1, lineNumber, cursorPosition);
|
||||
}
|
||||
|
||||
QString DocumentContextReader::getContextAfter(
|
||||
int lineNumber, int cursorPosition, int linesCount) const
|
||||
{
|
||||
int endLine = qMin(m_document->blockCount() - 1, lineNumber + linesCount - 1);
|
||||
int endLine = lineNumber + linesCount - 1;
|
||||
if (m_copyrightInfo.found && m_copyrightInfo.endLine >= lineNumber) {
|
||||
lineNumber = m_copyrightInfo.endLine + 1;
|
||||
cursorPosition = -1;
|
||||
}
|
||||
return getContextBetween(lineNumber, cursorPosition, endLine, -1);
|
||||
}
|
||||
|
||||
@ -106,14 +110,17 @@ QString DocumentContextReader::readWholeFileBefore(int lineNumber, int cursorPos
|
||||
startLine = m_copyrightInfo.endLine + 1;
|
||||
}
|
||||
|
||||
startLine = qMin(startLine, lineNumber);
|
||||
|
||||
return getContextBetween(startLine, -1, lineNumber, cursorPosition);
|
||||
}
|
||||
|
||||
QString DocumentContextReader::readWholeFileAfter(int lineNumber, int cursorPosition) const
|
||||
{
|
||||
return getContextBetween(lineNumber, cursorPosition, m_document->blockCount() - 1, -1);
|
||||
int endLine = m_document->blockCount() - 1;
|
||||
if (m_copyrightInfo.found && m_copyrightInfo.endLine >= lineNumber) {
|
||||
lineNumber = m_copyrightInfo.endLine + 1;
|
||||
cursorPosition = -1;
|
||||
}
|
||||
return getContextBetween(lineNumber, cursorPosition, endLine, -1);
|
||||
}
|
||||
|
||||
QString DocumentContextReader::getLanguageAndFileInfo() const
|
||||
@ -173,6 +180,9 @@ QString DocumentContextReader::getContextBetween(
|
||||
{
|
||||
QString context;
|
||||
|
||||
startLine = qMax(startLine, 0);
|
||||
endLine = qMin(endLine, m_document->blockCount() - 1);
|
||||
|
||||
if (startLine > endLine) {
|
||||
return context;
|
||||
}
|
||||
|
Reference in New Issue
Block a user