Commit 56daf9c2 authored by Amish Naidu's avatar Amish Naidu
Browse files

clang: Fix header-guard-assistant skipping whitespace

parent c133947b
......@@ -899,4 +899,14 @@ void TestAssistants::testHeaderGuardAssistant_data()
"int foo;\n"
"#endif // NO_ENDLINE_FILE_H_INCLUDED"
);
QTest::newRow("whitespace-at-start") << QStringLiteral("whitespace-at-start")
<< QStringLiteral("\nint foo;")
<< QStringLiteral("#pragma once\n\n\nint foo;")
<< QStringLiteral(
"#ifndef WHITESPACE_AT_START_H_INCLUDED\n"
"#define WHITESPACE_AT_START_H_INCLUDED\n\n"
"\nint foo;\n"
"#endif // WHITESPACE_AT_START_H_INCLUDED"
);
}
......@@ -471,6 +471,11 @@ unsigned int ClangUtils::skipTopCommentBlock(CXTranslationUnit unit, CXFile file
const auto nonCommentToken = std::find_if(tokens.begin(), tokens.end(),
[&](CXToken token) { return clang_getTokenKind(token) != CXToken_Comment; });
// explicitly handle this case, otherwise we skip the preceding whitespace
if (nonCommentToken == tokens.begin()) {
return 1;
}
const auto location = (nonCommentToken != tokens.end()) ? clang_getTokenExtent(unit, *nonCommentToken) : fileRange;
return KTextEditor::Cursor(ClangRange(location).end()).line() + 1;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment