forked from qt-creator/qt-creator
Merge remote-tracking branch 'origin/3.6'
Conflicts: src/plugins/baremetal/gdbserverproviderprocess.cpp Change-Id: I1ba618db9db6669edada6477c05a1b56b7b5b430
This commit is contained in:
@@ -38,6 +38,8 @@
|
||||
#include <utils/fileutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
#include <QTextBlock>
|
||||
|
||||
namespace {
|
||||
|
||||
QTextEdit::ExtraSelection createExtraSelections(const QTextCharFormat &mainformat,
|
||||
@@ -53,6 +55,14 @@ QTextEdit::ExtraSelection createExtraSelections(const QTextCharFormat &mainforma
|
||||
return extraSelection;
|
||||
}
|
||||
|
||||
int positionInText(QTextDocument *textDocument,
|
||||
const ClangBackEnd::SourceLocationContainer &sourceLocationContainer)
|
||||
{
|
||||
auto textBlock = textDocument->findBlockByNumber(int(sourceLocationContainer.line()) - 1);
|
||||
|
||||
return textBlock.position() + int(sourceLocationContainer.column()) - 1;
|
||||
}
|
||||
|
||||
void addRangeSelections(const ClangBackEnd::DiagnosticContainer &diagnostic,
|
||||
QTextDocument *textDocument,
|
||||
const QTextCharFormat &contextFormat,
|
||||
@@ -61,8 +71,8 @@ void addRangeSelections(const ClangBackEnd::DiagnosticContainer &diagnostic,
|
||||
{
|
||||
for (auto &&range : diagnostic.ranges()) {
|
||||
QTextCursor cursor(textDocument);
|
||||
cursor.setPosition(int(range.start().offset()));
|
||||
cursor.setPosition(int(range.end().offset()), QTextCursor::KeepAnchor);
|
||||
cursor.setPosition(positionInText(textDocument, range.start()));
|
||||
cursor.setPosition(positionInText(textDocument, range.end()), QTextCursor::KeepAnchor);
|
||||
|
||||
auto extraSelection = createExtraSelections(contextFormat, cursor, diagnosticText);
|
||||
|
||||
@@ -70,14 +80,15 @@ void addRangeSelections(const ClangBackEnd::DiagnosticContainer &diagnostic,
|
||||
}
|
||||
}
|
||||
|
||||
QTextCursor createSelectionCursor(QTextDocument *textDocument, uint position)
|
||||
QTextCursor createSelectionCursor(QTextDocument *textDocument,
|
||||
const ClangBackEnd::SourceLocationContainer &sourceLocationContainer)
|
||||
{
|
||||
QTextCursor cursor(textDocument);
|
||||
cursor.setPosition(int(position));
|
||||
cursor.setPosition(positionInText(textDocument, sourceLocationContainer));
|
||||
cursor.movePosition(QTextCursor::EndOfWord, QTextCursor::KeepAnchor);
|
||||
|
||||
if (!cursor.hasSelection()) {
|
||||
cursor.setPosition(int(position) - 1);
|
||||
cursor.setPosition(positionInText(textDocument, sourceLocationContainer) - 1);
|
||||
cursor.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 2);
|
||||
}
|
||||
|
||||
@@ -122,7 +133,7 @@ void addSelections(const QVector<ClangBackEnd::DiagnosticContainer> &diagnostics
|
||||
QList<QTextEdit::ExtraSelection> &extraSelections)
|
||||
{
|
||||
for (auto &&diagnostic : diagnostics) {
|
||||
auto cursor = createSelectionCursor(textDocument, diagnostic.location().offset());
|
||||
auto cursor = createSelectionCursor(textDocument, diagnostic.location());
|
||||
|
||||
auto text = diagnosticText(diagnostic);
|
||||
auto extraSelection = createExtraSelections(mainFormat, cursor, text);
|
||||
|
||||
@@ -170,18 +170,37 @@ void ClangEditorDocumentProcessor::updateCodeWarnings(const QVector<ClangBackEnd
|
||||
emit codeWarningsUpdated(revision(), codeWarnings);
|
||||
}
|
||||
}
|
||||
namespace {
|
||||
|
||||
static QList<TextEditor::BlockRange>
|
||||
toTextEditorBlocks(const QVector<ClangBackEnd::SourceRangeContainer> &ifdefedOutRanges)
|
||||
int positionInText(QTextDocument *textDocument,
|
||||
const ClangBackEnd::SourceLocationContainer &sourceLocationContainer)
|
||||
{
|
||||
auto textBlock = textDocument->findBlockByNumber(int(sourceLocationContainer.line()) - 1);
|
||||
|
||||
return textBlock.position() + int(sourceLocationContainer.column()) - 1;
|
||||
}
|
||||
|
||||
TextEditor::BlockRange
|
||||
toTextEditorBlock(QTextDocument *textDocument,
|
||||
const ClangBackEnd::SourceRangeContainer &sourceRangeContainer)
|
||||
{
|
||||
return TextEditor::BlockRange(positionInText(textDocument, sourceRangeContainer.start()),
|
||||
positionInText(textDocument, sourceRangeContainer.end()));
|
||||
}
|
||||
|
||||
QList<TextEditor::BlockRange>
|
||||
toTextEditorBlocks(QTextDocument *textDocument,
|
||||
const QVector<ClangBackEnd::SourceRangeContainer> &ifdefedOutRanges)
|
||||
{
|
||||
QList<TextEditor::BlockRange> blockRanges;
|
||||
blockRanges.reserve(ifdefedOutRanges.size());
|
||||
|
||||
for (const auto &range : ifdefedOutRanges)
|
||||
blockRanges.append(TextEditor::BlockRange(range.start().offset(),range.end().offset()));
|
||||
blockRanges.append(toTextEditorBlock(textDocument, range));
|
||||
|
||||
return blockRanges;
|
||||
}
|
||||
}
|
||||
|
||||
void ClangEditorDocumentProcessor::updateHighlighting(
|
||||
const QVector<ClangBackEnd::HighlightingMarkContainer> &highlightingMarks,
|
||||
@@ -189,7 +208,7 @@ void ClangEditorDocumentProcessor::updateHighlighting(
|
||||
uint documentRevision)
|
||||
{
|
||||
if (documentRevision == revision()) {
|
||||
const auto skippedPreprocessorBlocks = toTextEditorBlocks(skippedPreprocessorRanges);
|
||||
const auto skippedPreprocessorBlocks = toTextEditorBlocks(textDocument(), skippedPreprocessorRanges);
|
||||
emit ifdefedOutBlocksUpdated(documentRevision, skippedPreprocessorBlocks);
|
||||
|
||||
m_semanticHighlighter.setHighlightingRunner(
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
|
||||
#include <texteditor/refactoringchanges.h>
|
||||
|
||||
#include <QTextDocument>
|
||||
|
||||
namespace ClangCodeModel {
|
||||
|
||||
ClangFixItOperation::ClangFixItOperation(const Utf8String &filePath,
|
||||
@@ -56,19 +58,26 @@ QString ClangCodeModel::ClangFixItOperation::description() const
|
||||
void ClangFixItOperation::perform()
|
||||
{
|
||||
const TextEditor::RefactoringChanges refactoringChanges;
|
||||
TextEditor::RefactoringFilePtr refactoringFile = refactoringChanges.file(filePath.toString());
|
||||
refactoringFile = refactoringChanges.file(filePath.toString());
|
||||
refactoringFile->setChangeSet(changeSet());
|
||||
refactoringFile->apply();
|
||||
}
|
||||
|
||||
QString ClangFixItOperation::refactoringFileContent_forTestOnly() const
|
||||
{
|
||||
return refactoringFile->document()->toPlainText();
|
||||
}
|
||||
|
||||
Utils::ChangeSet ClangFixItOperation::changeSet() const
|
||||
{
|
||||
Utils::ChangeSet changeSet;
|
||||
|
||||
for (const auto &fixItContainer : fixItContainers) {
|
||||
const auto range = fixItContainer.range();
|
||||
changeSet.replace(range.start().offset(),
|
||||
range.end().offset(),
|
||||
const auto start = range.start();
|
||||
const auto end = range.end();
|
||||
changeSet.replace(refactoringFile->position(start.line(), start.column()),
|
||||
refactoringFile->position(end.line(), end.column()),
|
||||
fixItContainer.text());
|
||||
}
|
||||
|
||||
|
||||
@@ -34,9 +34,16 @@
|
||||
#include <texteditor/quickfix.h>
|
||||
|
||||
#include <clangbackendipc/fixitcontainer.h>
|
||||
|
||||
#include <utils/changeset.h>
|
||||
|
||||
#include <QVector>
|
||||
#include <QSharedPointer>
|
||||
|
||||
namespace TextEditor
|
||||
{
|
||||
class RefactoringFile;
|
||||
}
|
||||
|
||||
namespace ClangCodeModel {
|
||||
|
||||
@@ -51,11 +58,15 @@ public:
|
||||
QString description() const override;
|
||||
void perform() override;
|
||||
|
||||
QString refactoringFileContent_forTestOnly() const;
|
||||
|
||||
private:
|
||||
Utils::ChangeSet changeSet() const;
|
||||
|
||||
private:
|
||||
Utf8String filePath;
|
||||
Utf8String fixItText;
|
||||
QSharedPointer<TextEditor::RefactoringFile> refactoringFile;
|
||||
QVector<ClangBackEnd::FixItContainer> fixItContainers;
|
||||
};
|
||||
|
||||
|
||||
@@ -62,6 +62,8 @@ CppTools::SemanticHighlighter::Kind toCppToolsSemanticHighlighterKind(
|
||||
case HighlightingType::Label:
|
||||
return SemanticHighlighter::LabelUse;
|
||||
case HighlightingType::Preprocessor:
|
||||
case HighlightingType::PreprocessorDefinition:
|
||||
case HighlightingType::PreprocessorExpansion:
|
||||
return SemanticHighlighter::MacroUse;
|
||||
default:
|
||||
return SemanticHighlighter::Unknown;
|
||||
|
||||
Reference in New Issue
Block a user