Bug 394200 - #include and #<whitespace>include are not handled identically by the parser
Summary: #include and #<whitespace>include are not handled identically by the parser
Status: RESOLVED FIXED
Alias: None
Product: kdevelop
Classification: Applications
Component: Language Support: CPP (Clang-based) (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR normal
Target Milestone: ---
Assignee: kdevelop-bugs-null
URL:
Keywords: junior-jobs
Depends on:
Blocks:
 
Reported: 2018-05-13 11:43 UTC by RJVB
Modified: 2018-05-16 07:33 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In: 5.2.2


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description RJVB 2018-05-13 11:43:19 UTC
Hovering over `#include "foo.h"` will open a tooltip with a link to open foo.h ; not so when there's whitespace after the hash (`# include "foo.h"`). Both are valid  syntax; is this difference in behaviour a bug or a feature?
Comment 1 Milian Wolff 2018-05-15 11:44:02 UTC
a bug, patches welcome
Comment 2 RJVB 2018-05-15 12:17:57 UTC
Any suggestions where to start looking for the source of this bug? I'd search for "#include" but somehow I think that won't be of much help :) (including the quotes actually gives only a single hit, in the astyle plugin).
Comment 3 Kevin Funk 2018-05-15 15:05:06 UTC
I think those are the spots you should look at:
```
% ag -s ClangUtils::rangeForIncludePathSpec
plugins/clang/clangsupport.cpp
102:    KTextEditor::Range wordRange = ClangUtils::rangeForIncludePathSpec(line, pair.second);

plugins/clang/util/clangutils.cpp
79:KTextEditor::Range ClangUtils::rangeForIncludePathSpec(const QString& line, const KTextEditor::Range& originalRange)

plugins/clang/tests/test_clangutils.cpp
273:    QCOMPARE(ClangUtils::rangeForIncludePathSpec("#include <vector>"), KTextEditor::Range(0, 10, 0, 16));
274:    QCOMPARE(ClangUtils::rangeForIncludePathSpec("#include <foo\\\".h>"), KTextEditor::Range(0, 10, 0, 17));
275:    QCOMPARE(ClangUtils::rangeForIncludePathSpec("#include \"foo\\\".h\""), KTextEditor::Range(0, 10, 0, 17));
276:    QCOMPARE(ClangUtils::rangeForIncludePathSpec("#include \"foo<>.h\""), KTextEditor::Range(0, 10, 0, 17));
```
Comment 4 RJVB 2018-05-15 18:06:45 UTC
Can it really be so simple to fix?

https://phabricator.kde.org/D12903
Comment 5 RJVB 2018-05-15 18:07:07 UTC
Can it really be so simple to fix?

https://phabricator.kde.org/D12903
Comment 6 Kevin Funk 2018-05-16 07:33:58 UTC
Git commit 06cbebf36cfa39388430d7043197189b2e54a5d2 by Kevin Funk, on behalf of René J.V. Bertin.
Committed on 16/05/2018 at 07:28.
Pushed by kfunk into branch '5.2'.

KDevelop : support whitespace between the '#' and 'include' (or 'import')

Summary:
The C/C++ parser fails to recognise include statements where the hash symbol has whitespace between it and the include/import command.

This patch fixes that.
FIXED-IN: 5.2.2

Test Plan: Works as expected.

Reviewers: #kdevelop, antonanikin, kfunk

Reviewed By: #kdevelop, antonanikin, kfunk

Subscribers: kfunk, kdevelop-devel

Tags: #kdevelop

Differential Revision: https://phabricator.kde.org/D12903

M  +2    -0    plugins/clang/tests/test_clangutils.cpp
M  +1    -1    plugins/clang/util/clangutils.cpp

https://commits.kde.org/kdevelop/06cbebf36cfa39388430d7043197189b2e54a5d2