diff --git a/interfaces/iproblem.h b/interfaces/iproblem.h --- a/interfaces/iproblem.h +++ b/interfaces/iproblem.h @@ -59,6 +59,25 @@ }; Q_DECLARE_FLAGS(Severities, Severity) + /// Final location mode of the problem. Used during highlighting. + enum FinalLocationMode + { + /// Location range used "As Is" + Range = 0, + + /// Location range used to highlight whole line. + /// + /// Mode applied only if location range is wholly contained within one line + WholeLine, + + /// Location range used to highlight only trimmed part of the line. + /// For example for the line: " int x = 0; \t" + /// only "int x = 0;" will be highlighted. + /// + /// Mode applied only if location range is wholly contained within one line + TrimmedLine + }; + IProblem(){} virtual ~IProblem(){} @@ -77,6 +96,18 @@ /// Sets the location of the problem (path, line, column) virtual void setFinalLocation(const KDevelop::DocumentRange& location) = 0; + /// Returns the final location mode of the problem + inline FinalLocationMode finalLocationMode() + { + return m_finalLocationMode; + } + + /// Sets the final location mode of the problem + inline void setFinalLocationMode(FinalLocationMode mode) + { + m_finalLocationMode = mode; + } + /// Returns the short description of the problem. virtual QString description() const = 0; @@ -112,6 +143,9 @@ /// Returns a solution assistant for the problem, if applicable that is. virtual QExplicitlySharedDataPointer solutionAssistant() const = 0; + +protected: + FinalLocationMode m_finalLocationMode = Range; }; Q_DECLARE_OPERATORS_FOR_FLAGS(IProblem::Severities) diff --git a/plugins/problemreporter/problemhighlighter.cpp b/plugins/problemreporter/problemhighlighter.cpp --- a/plugins/problemreporter/problemhighlighter.cpp +++ b/plugins/problemreporter/problemhighlighter.cpp @@ -149,6 +149,29 @@ else range = problem->finalLocation(); + // Fix problem's location range if necessary + if (problem->finalLocationMode() != IProblem::Range && range.onSingleLine()) { + int line = range.start().line(); + const QString lineString = m_document->line(line); + + int startColumn = 0; + int endColumn = lineString.length(); + + if (problem->finalLocationMode() == IProblem::TrimmedLine) { + while (lineString.at(startColumn++).isSpace()) {} + --startColumn; + + while (lineString.at(endColumn--).isSpace()) {} + ++endColumn; + } + + range.setStart(Cursor(line, startColumn)); + range.setEnd(Cursor(line, endColumn)); + + problem->setFinalLocation(DocumentRange(problem->finalLocation().document, range)); + problem->setFinalLocationMode(IProblem::Range); + } + if (range.end().line() >= m_document->lines()) range.end() = KTextEditor::Cursor(m_document->endOfLine(m_document->lines() - 1));