| 74 | } |
| 75 | |
| 76 | void ProblemHighlighter::setProblems(const QVector<IProblem::Ptr>& problems) |
| 77 | { |
| 78 | if (!m_document) |
| 79 | return; |
| 80 | |
| 81 | if (m_problems == problems) |
| 82 | return; |
| 83 | |
| 84 | const bool hadProblems = !m_problems.isEmpty(); |
| 85 | m_problems = problems; |
| 86 | |
| 87 | qDeleteAll(m_topHLRanges); |
| 88 | m_topHLRanges.clear(); |
| 89 | |
| 90 | IndexedString url(m_document->url()); |
| 91 | |
| 92 | /// TODO: create a better MarkInterface that makes it possible to add the marks to the scrollbar |
| 93 | /// but having no background. |
| 94 | /// also make it nicer together with other plugins, this would currently fail with |
| 95 | /// this method... |
| 96 | const uint errorMarkType = KTextEditor::Document::MarkTypes::Error; |
| 97 | const uint warningMarkType = KTextEditor::Document::MarkTypes::Warning; |
| 98 | if (hadProblems) { |
| 99 | // clear previously added marks |
| 100 | const auto oldMarks = m_document->marks(); |
| 101 | for (KTextEditor::Mark* mark : oldMarks) { |
| 102 | if (mark->type & (errorMarkType | warningMarkType)) { |
| 103 | m_document->removeMark(mark->line, errorMarkType | warningMarkType); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | if (problems.isEmpty()) { |
| 109 | return; |
| 110 | } |
| 111 | |
| 112 | DUChainReadLocker lock; |
| 113 | |
| 114 | TopDUContext* top = DUChainUtils::standardContextForUrl(m_document->url()); |
| 115 | |
| 116 | for (const IProblem::Ptr& problem : problems) { |
| 117 | if (problem->finalLocation().document != url || !problem->finalLocation().isValid()) |
| 118 | continue; |
| 119 | |
| 120 | KTextEditor::Range range; |
| 121 | if (top) |
| 122 | range = top->transformFromLocalRevision(RangeInRevision::castFromSimpleRange(problem->finalLocation())); |
| 123 | else |
| 124 | range = problem->finalLocation(); |
| 125 | |
| 126 | // Fix problem's location range if necessary |
| 127 | if (problem->finalLocationMode() != IProblem::Range && range.onSingleLine()) { |
| 128 | int line = range.start().line(); |
| 129 | const QString lineString = m_document->line(line); |
| 130 | |
| 131 | int startColumn = 0; |
| 132 | int endColumn = lineString.length(); |
| 133 | |