forked from qt-creator/qt-creator
ClangFormat: Add showing error message in general messages
Change-Id: Ia3e8d7217f0551a768a456ea27b09977507687f2 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
#include "llvmfilesystem.h"
|
#include "llvmfilesystem.h"
|
||||||
|
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
#include <coreplugin/messagemanager.h>
|
||||||
|
|
||||||
#include <projectexplorer/editorconfiguration.h>
|
#include <projectexplorer/editorconfiguration.h>
|
||||||
#include <projectexplorer/project.h>
|
#include <projectexplorer/project.h>
|
||||||
@@ -944,6 +945,37 @@ const clang::format::FormatStyle &ClangFormatBaseIndenter::styleForFile() const
|
|||||||
return d->styleForFile();
|
return d->styleForFile();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const llvm::Expected<clang::format::FormatStyle> getStyleFromProjectFolder(
|
||||||
|
const Utils::FilePath *fileName)
|
||||||
|
{
|
||||||
|
#if LLVM_VERSION_MAJOR >= 19
|
||||||
|
static QString s_cachedError;
|
||||||
|
llvm::SourceMgr::DiagHandlerTy diagHandler = [](const llvm::SMDiagnostic &diag, void *) {
|
||||||
|
QString errorMessage = QString::fromStdString(diag.getMessage().str()) + " "
|
||||||
|
+ QString::number(diag.getLineNo()) + ":"
|
||||||
|
+ QString::number(diag.getColumnNo());
|
||||||
|
|
||||||
|
if (s_cachedError == errorMessage)
|
||||||
|
return;
|
||||||
|
|
||||||
|
s_cachedError = errorMessage;
|
||||||
|
Core::MessageManager::writeSilently("ClangFormat file error: " + errorMessage);
|
||||||
|
};
|
||||||
|
|
||||||
|
return clang::format::getStyle(
|
||||||
|
"file",
|
||||||
|
fileName->toFSPathString().toStdString(),
|
||||||
|
"none",
|
||||||
|
"",
|
||||||
|
&llvmFileSystemAdapter,
|
||||||
|
true,
|
||||||
|
diagHandler);
|
||||||
|
#else
|
||||||
|
return clang::format::getStyle(
|
||||||
|
"file", fileName->toFSPathString().toStdString(), "none", "", &llvmFileSystemAdapter, true);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
const clang::format::FormatStyle &ClangFormatBaseIndenterPrivate::styleForFile() const
|
const clang::format::FormatStyle &ClangFormatBaseIndenterPrivate::styleForFile() const
|
||||||
{
|
{
|
||||||
static const milliseconds cacheTimeout = getCacheTimeout();
|
static const milliseconds cacheTimeout = getCacheTimeout();
|
||||||
@@ -962,8 +994,8 @@ const clang::format::FormatStyle &ClangFormatBaseIndenterPrivate::styleForFile()
|
|||||||
return m_cachedStyle.style;
|
return m_cachedStyle.style;
|
||||||
}
|
}
|
||||||
|
|
||||||
llvm::Expected<clang::format::FormatStyle> styleFromProjectFolder = clang::format::getStyle(
|
llvm::Expected<clang::format::FormatStyle> styleFromProjectFolder = getStyleFromProjectFolder(
|
||||||
"file", m_fileName->toFSPathString().toStdString(), "none", "", &llvmFileSystemAdapter, true);
|
m_fileName);
|
||||||
|
|
||||||
if (styleFromProjectFolder && !(*styleFromProjectFolder == clang::format::getNoStyle())) {
|
if (styleFromProjectFolder && !(*styleFromProjectFolder == clang::format::getNoStyle())) {
|
||||||
addQtcStatementMacros(*styleFromProjectFolder);
|
addQtcStatementMacros(*styleFromProjectFolder);
|
||||||
|
Reference in New Issue
Block a user