Changeset View
Changeset View
Standalone View
Standalone View
languages/clang/codecompletion/context.cpp
Show All 16 Lines | |||||
17 | * GNU General Public License for more details. | 17 | * GNU General Public License for more details. | ||
18 | * | 18 | * | ||
19 | * You should have received a copy of the GNU General Public License | 19 | * You should have received a copy of the GNU General Public License | ||
20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | 20 | * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
21 | */ | 21 | */ | ||
22 | 22 | | |||
23 | #include "context.h" | 23 | #include "context.h" | ||
24 | 24 | | |||
25 | #include <KConfigGroup> | ||||
26 | #include <KConfig> | ||||
27 | | ||||
25 | #include <QRegularExpression> | 28 | #include <QRegularExpression> | ||
26 | 29 | | |||
27 | #include <interfaces/icore.h> | 30 | #include <interfaces/icore.h> | ||
31 | #include <interfaces/iproject.h> | ||||
28 | #include <interfaces/idocumentcontroller.h> | 32 | #include <interfaces/idocumentcontroller.h> | ||
33 | #include <interfaces/iprojectcontroller.h> | ||||
29 | 34 | | |||
30 | #include <language/duchain/duchainlock.h> | 35 | #include <language/duchain/duchainlock.h> | ||
31 | #include <language/duchain/ducontext.h> | 36 | #include <language/duchain/ducontext.h> | ||
32 | #include <language/duchain/topducontext.h> | 37 | #include <language/duchain/topducontext.h> | ||
33 | #include <language/duchain/declaration.h> | 38 | #include <language/duchain/declaration.h> | ||
34 | #include <language/duchain/classmemberdeclaration.h> | 39 | #include <language/duchain/classmemberdeclaration.h> | ||
35 | #include <language/duchain/classdeclaration.h> | 40 | #include <language/duchain/classdeclaration.h> | ||
36 | #include <language/duchain/duchainutils.h> | 41 | #include <language/duchain/duchainutils.h> | ||
▲ Show 20 Lines • Show All 118 Lines • ▼ Show 20 Line(s) | 158 | if (index.column() == KTextEditor::CodeCompletionModel::Icon) { | |||
155 | return icon; | 160 | return icon; | ||
156 | } | 161 | } | ||
157 | } | 162 | } | ||
158 | return CompletionItem<CompletionTreeItem>::data(index, role, model); | 163 | return CompletionItem<CompletionTreeItem>::data(index, role, model); | ||
159 | } | 164 | } | ||
160 | 165 | | |||
161 | void execute(KTextEditor::View* view, const KTextEditor::Range& word) override | 166 | void execute(KTextEditor::View* view, const KTextEditor::Range& word) override | ||
162 | { | 167 | { | ||
163 | view->document()->replaceText(word, m_returnType + QLatin1Char(' ') + m_display.replace(QRegularExpression(QStringLiteral("\\s*=\\s*0")), QString()) + QLatin1String(" override;")); | 168 | auto documentPath = Path(view->document()->url()); | ||
169 | auto project = ICore::self()->projectController()->findProjectForUrl(view->document()->url()); | ||||
170 | auto grp = project->projectConfiguration()->group(QLatin1String("CustomDefinesAndIncludes")); | ||||
171 | QString argumentsCpp = QLatin1String("c++11"); | ||||
172 | Path lastPath; | ||||
173 | | ||||
174 | for( const QString &grpName : grp.groupList() ) { | ||||
175 | KConfigGroup pathgrp = grp.group( grpName ); | ||||
176 | auto path = Path(project->path(), pathgrp.readEntry(QLatin1String("Path"), "")); | ||||
177 | | ||||
178 | if (path.isDirectParentOf(documentPath) || (path.isParentOf(documentPath) | ||||
179 | && ((!lastPath.isEmpty() && lastPath.isParentOf(path)) | ||||
180 | || lastPath.isEmpty()))) { | ||||
181 | argumentsCpp = pathgrp.readEntry("parserArguments", "c++11"); | ||||
182 | | ||||
183 | if (argumentsCpp.isEmpty()) | ||||
184 | argumentsCpp = QLatin1String("c++11"); | ||||
185 | lastPath = path; | ||||
186 | if (path.isDirectParentOf(documentPath)) | ||||
187 | break; | ||||
188 | } | ||||
189 | } | ||||
190 | auto currentStandard = QRegularExpression(QStringLiteral("c\\+\\+\\d{2}")).match(argumentsCpp).captured(); | ||||
191 | view->document()->replaceText(word, m_returnType + QLatin1Char(' ') + m_display.replace(QRegularExpression(QStringLiteral("\\s*=\\s*0")), QString()) | ||||
192 | + (currentStandard == QStringLiteral("c++03") ? QLatin1String(";") : QLatin1String(" override;"))); | ||||
164 | } | 193 | } | ||
165 | 194 | | |||
166 | private: | 195 | private: | ||
167 | QString m_returnType; | 196 | QString m_returnType; | ||
168 | }; | 197 | }; | ||
169 | 198 | | |||
170 | /** | 199 | /** | ||
171 | * Specialized completion item class for items which are represented by a Declaration | 200 | * Specialized completion item class for items which are represented by a Declaration | ||
▲ Show 20 Lines • Show All 1048 Lines • Show Last 20 Lines |