| 615 | } |
| 616 | |
| 617 | KTextEditor::Range CMakeManager::termRangeAtPosition(const KTextEditor::Document* textDocument, |
| 618 | const KTextEditor::Cursor& position) const |
| 619 | { |
| 620 | const KTextEditor::Cursor step(0, 1); |
| 621 | |
| 622 | enum ParseState { |
| 623 | NoChar, |
| 624 | NonLeadingChar, |
| 625 | AnyChar, |
| 626 | }; |
| 627 | |
| 628 | ParseState parseState = NoChar; |
| 629 | KTextEditor::Cursor start = position; |
| 630 | while (true) { |
| 631 | const QChar c = textDocument->characterAt(start); |
| 632 | if (c.isDigit()) { |
| 633 | parseState = NonLeadingChar; |
| 634 | } else if (c.isLetter() || c == QLatin1Char('_')) { |
| 635 | parseState = AnyChar; |
| 636 | } else { |
| 637 | // also catches going out of document range, where c is invalid |
| 638 | break; |
| 639 | } |
| 640 | start -= step; |
| 641 | } |
| 642 | |
| 643 | if (parseState != AnyChar) { |
| 644 | return KTextEditor::Range::invalid(); |
| 645 | } |
| 646 | // undo step before last valid char |
| 647 | start += step; |
| 648 | |
| 649 | KTextEditor::Cursor end = position + step; |
| 650 | while (true) { |
| 651 | const QChar c = textDocument->characterAt(end); |
| 652 | if (!(c.isDigit() || c.isLetter() || c == QLatin1Char('_'))) { |
| 653 | // also catches going out of document range, where c is invalid |
| 654 | break; |
| 655 | } |
| 656 | end += step; |
| 657 | } |
| 658 | |
| 659 | return KTextEditor::Range(start, end); |
| 660 | } |
| 661 | |
| 662 | void CMakeManager::showConfigureOutdatedMessage(const KDevelop::IProject& project) |
| 663 | { |