Changeset View
Changeset View
Standalone View
Standalone View
plugins/clang/codecompletion/context.cpp
Show All 21 Lines | |||||
22 | 22 | | |||
23 | #include "context.h" | 23 | #include "context.h" | ||
24 | 24 | | |||
25 | #include <QRegularExpression> | 25 | #include <QRegularExpression> | ||
26 | #include <QStandardPaths> | 26 | #include <QStandardPaths> | ||
27 | 27 | | |||
28 | #include <interfaces/icore.h> | 28 | #include <interfaces/icore.h> | ||
29 | #include <interfaces/idocumentcontroller.h> | 29 | #include <interfaces/idocumentcontroller.h> | ||
30 | #include <interfaces/iprojectcontroller.h> | ||||
31 | #include <interfaces/iproject.h> | ||||
30 | 32 | | |||
31 | #include <language/duchain/duchainlock.h> | 33 | #include <language/duchain/duchainlock.h> | ||
32 | #include <language/duchain/ducontext.h> | 34 | #include <language/duchain/ducontext.h> | ||
33 | #include <language/duchain/topducontext.h> | 35 | #include <language/duchain/topducontext.h> | ||
34 | #include <language/duchain/declaration.h> | 36 | #include <language/duchain/declaration.h> | ||
35 | #include <language/duchain/classmemberdeclaration.h> | 37 | #include <language/duchain/classmemberdeclaration.h> | ||
36 | #include <language/duchain/classdeclaration.h> | 38 | #include <language/duchain/classdeclaration.h> | ||
37 | #include <language/duchain/duchainutils.h> | 39 | #include <language/duchain/duchainutils.h> | ||
38 | #include <language/duchain/persistentsymboltable.h> | 40 | #include <language/duchain/persistentsymboltable.h> | ||
39 | #include <language/duchain/types/integraltype.h> | 41 | #include <language/duchain/types/integraltype.h> | ||
40 | #include <language/duchain/types/functiontype.h> | 42 | #include <language/duchain/types/functiontype.h> | ||
41 | #include <language/duchain/types/pointertype.h> | 43 | #include <language/duchain/types/pointertype.h> | ||
42 | #include <language/duchain/types/typealiastype.h> | 44 | #include <language/duchain/types/typealiastype.h> | ||
43 | #include <language/duchain/types/typeutils.h> | 45 | #include <language/duchain/types/typeutils.h> | ||
44 | #include <language/duchain/stringhelpers.h> | 46 | #include <language/duchain/stringhelpers.h> | ||
45 | #include <language/codecompletion/codecompletionmodel.h> | 47 | #include <language/codecompletion/codecompletionmodel.h> | ||
46 | #include <language/codecompletion/normaldeclarationcompletionitem.h> | 48 | #include <language/codecompletion/normaldeclarationcompletionitem.h> | ||
47 | #include <util/foregroundlock.h> | 49 | #include <util/foregroundlock.h> | ||
50 | #include <custom-definesandincludes/idefinesandincludesmanager.h> | ||||
51 | #include <project/projectmodel.h> | ||||
48 | 52 | | |||
49 | #include "../util/clangdebug.h" | 53 | #include "../util/clangdebug.h" | ||
50 | #include "../util/clangtypes.h" | 54 | #include "../util/clangtypes.h" | ||
51 | #include "../util/clangutils.h" | 55 | #include "../util/clangutils.h" | ||
52 | #include "../duchain/clangdiagnosticevaluator.h" | 56 | #include "../duchain/clangdiagnosticevaluator.h" | ||
53 | #include "../duchain/parsesession.h" | 57 | #include "../duchain/parsesession.h" | ||
54 | #include "../duchain/duchainutils.h" | 58 | #include "../duchain/duchainutils.h" | ||
55 | #include "../duchain/navigationwidget.h" | 59 | #include "../duchain/navigationwidget.h" | ||
▲ Show 20 Lines • Show All 110 Lines • ▼ Show 20 Line(s) | 168 | if (index.column() == KTextEditor::CodeCompletionModel::Icon) { | |||
166 | return icon; | 170 | return icon; | ||
167 | } | 171 | } | ||
168 | } | 172 | } | ||
169 | return CompletionItem<CompletionTreeItem>::data(index, role, model); | 173 | return CompletionItem<CompletionTreeItem>::data(index, role, model); | ||
170 | } | 174 | } | ||
171 | 175 | | |||
172 | void execute(KTextEditor::View* view, const KTextEditor::Range& word) override | 176 | void execute(KTextEditor::View* view, const KTextEditor::Range& word) override | ||
173 | { | 177 | { | ||
174 | view->document()->replaceText(word, m_returnType + QLatin1Char(' ') + m_display.replace(QRegularExpression(QStringLiteral("\\s*=\\s*0")), QString()) + QLatin1String(" override;")); | 178 | QString replacement = m_returnType + QLatin1Char(' ') + m_display.replace(QRegularExpression(QStringLiteral("\\s*=\\s*0")), QString()); | ||
179 | | ||||
180 | bool appendSpecifer = true; | ||||
181 | if (const auto* project = | ||||
182 | KDevelop::ICore::self()->projectController()->findProjectForUrl(view->document()->url())) { | ||||
183 | const auto arguments = KDevelop::IDefinesAndIncludesManager::manager()->parserArguments( | ||||
184 | project->filesForPath(IndexedString(view->document()->url().path())).first()); | ||||
185 | const auto match = QRegularExpression(QStringLiteral(R"(-std=c\+\+(\w+))")).match(arguments); | ||||
kfunk: The correct way to capture this would probably be `-std=c\+\+(\w+)`, to also capture potential… | |||||
186 | | ||||
187 | appendSpecifer = match.hasMatch(); // assume non-modern if no standard is specified | ||||
188 | if (appendSpecifer) { | ||||
189 | const auto standard = match.captured(1); | ||||
190 | appendSpecifer = (standard != QLatin1String("98") && standard != QLatin1String("03")); | ||||
And consecutively here: (standard != "98" && standard != "03") Was a little confused by the 3 here at first. I think the string version makes it clearer. kfunk: And consecutively here: `(standard != "98" && standard != "03")`
Was a little confused by the… | |||||
191 | } | ||||
192 | } | ||||
193 | | ||||
194 | if (appendSpecifer) { | ||||
195 | replacement.append(QLatin1String(" override;")); | ||||
196 | } else { | ||||
197 | replacement.append(QLatin1Char(';')); | ||||
198 | } | ||||
199 | | ||||
200 | view->document()->replaceText(word, replacement); | ||||
175 | } | 201 | } | ||
176 | 202 | | |||
177 | private: | 203 | private: | ||
178 | QString m_returnType; | 204 | QString m_returnType; | ||
179 | }; | 205 | }; | ||
180 | 206 | | |||
181 | /** | 207 | /** | ||
182 | * Specialized completion item class for items which are represented by a Declaration | 208 | * Specialized completion item class for items which are represented by a Declaration | ||
▲ Show 20 Lines • Show All 1142 Lines • Show Last 20 Lines |
The correct way to capture this would probably be -std=c\+\+(\w+), to also capture potential things like "-std=c++1x" (though you don't check that here). Still feels cleaner.