Skip to content

Commit

Permalink
Fix indentation for last line
Browse files Browse the repository at this point in the history
  • Loading branch information
ibre5041 committed Jul 27, 2020
1 parent ef759f6 commit e01a9d1
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions src/parsing/toindent.cpp
Expand Up @@ -298,12 +298,22 @@ QString toIndent::indent(QString const&input)
// append the last remaining part(last line)
while (!lineBuf.isEmpty())
{
LineBuffer oldLine = lineBuf.split(); // split the lineBuf (in case there are ANY single line comments in lineBuf
// The length of lineBuf exceeded the requested length
if (lineBuf.lineLenght() > IndentLineWidthInt)
{
LineBuffer oldLine = lineBuf.split(); // split the lineBuf (in case there are ANY single line comments in lineBuf

int depth = oldLine.front()->metadata().value("INDENT_DEPTH").toInt();
retval.append(QString(depth * IndentWidthInt + adjustment, ' '));
retval.append(oldLine.toString());
retval.append('\n');
int depth = oldLine.front()->metadata().value("INDENT_DEPTH").toInt();
retval.append(QString(depth * IndentWidthInt + adjustment, ' '));
retval.append(oldLine.toString());
retval.append('\n');
} else {
int depth = lineBuf.front()->metadata().value("INDENT_DEPTH").toInt();
retval.append(QString(depth * IndentWidthInt + adjustment, ' '));
retval.append(lineBuf.toString());
retval.append('\n');
break; // the last line was drained
}
}

// validation part
Expand Down Expand Up @@ -533,6 +543,14 @@ static void indentPriv(SQLParser::Token const* root, QList<SQLParser::Token cons
QRegExp white("^[ \\n\\r\\t]*$");

Token const *t = root; // this sub-tree's root
#if 0
auto s = t->toString();
//auto t = t->toStringRecursive();
auto l = t->toLispStringRecursive();
auto a = t->getTokenATypeName();
auto b = t->getTokenTypeString();
#endif

unsigned indentDepth = 0; // indentDepth counter
while(t->parent()) // iterate to real root, compute indent depth, ignore nodes having no text
{
Expand Down

0 comments on commit e01a9d1

Please sign in to comment.