| 301 | using IncludeTester = CodeCompletionItemTester<IncludePathCompletionContext>; |
| 302 | |
| 303 | QExplicitlySharedDataPointer<IncludePathCompletionContext> executeIncludePathCompletion(TestFile* file, const KTextEditor::Cursor& position) |
| 304 | { |
| 305 | if (!file->parseAndWait(TopDUContext::AllDeclarationsContextsUsesAndAST)) { |
| 306 | QTest::qFail("Failed to parse source file.", __FILE__, __LINE__); |
| 307 | return {}; |
| 308 | } |
| 309 | |
| 310 | DUChainReadLocker lock; |
| 311 | auto top = file->topContext(); |
| 312 | if (!top) { |
| 313 | QTest::qFail("Failed to parse source file.", __FILE__, __LINE__); |
| 314 | return {}; |
| 315 | } |
| 316 | const ParseSessionData::Ptr sessionData(dynamic_cast<ParseSessionData*>(top->ast().data())); |
| 317 | if (!sessionData) { |
| 318 | QTest::qFail("Failed to acquire parse session data.", __FILE__, __LINE__); |
| 319 | return {}; |
| 320 | } |
| 321 | |
| 322 | DUContextPointer topPtr(top); |
| 323 | |
| 324 | lock.unlock(); |
| 325 | |
| 326 | auto text = file->fileContents(); |
| 327 | int textLength = -1; |
| 328 | if (position.isValid()) { |
| 329 | textLength = 0; |
| 330 | for (int i = 0; i < position.line(); ++i) { |
| 331 | textLength = text.indexOf('\n', textLength) + 1; |
| 332 | } |
| 333 | textLength += position.column(); |
| 334 | } |
| 335 | auto context = new IncludePathCompletionContext(topPtr, sessionData, file->url().toUrl(), position, text.mid(0, textLength)); |
| 336 | return QExplicitlySharedDataPointer<IncludePathCompletionContext>{context}; |
| 337 | } |
| 338 | |
| 339 | constexpr const char* definesAndIncludesConfigName = "CustomDefinesAndIncludes"; |
| 340 |
no test coverage detected