forked from qt-creator/qt-creator
ClangCodeModel: Add experimental clangd support
If the user has enabled clangd (default is off), we start up one instance per project when it is opened/changed (including build config switches), and trigger background indexing. So far, the index is used to provide results for locators and "Find Usages". Per-document functionality such as semantic highlighting and completion is still provided by libclang. Change-Id: I12532fca1b9c6278baab560e7238cba6189cde9f Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -35,6 +35,7 @@
|
||||
#include <QSettings>
|
||||
|
||||
using namespace CppTools;
|
||||
using namespace Utils;
|
||||
|
||||
static Utils::Id initialClangDiagnosticConfigId()
|
||||
{ return Constants::CPP_CLANG_DIAG_CONFIG_BUILDSYSTEM; }
|
||||
@@ -60,6 +61,17 @@ static QString skipIndexingBigFilesKey()
|
||||
static QString indexerFileSizeLimitKey()
|
||||
{ return QLatin1String(Constants::CPPTOOLS_INDEXER_FILE_SIZE_LIMIT); }
|
||||
|
||||
static QString useClangdKey() { return QLatin1String("UseClangd"); }
|
||||
static QString clangdPathKey() { return QLatin1String("ClangdPath"); }
|
||||
|
||||
static FilePath g_defaultClangdFilePath;
|
||||
static FilePath fallbackClangdFilePath()
|
||||
{
|
||||
if (g_defaultClangdFilePath.exists())
|
||||
return g_defaultClangdFilePath;
|
||||
return FilePath::fromString("clangd");
|
||||
}
|
||||
|
||||
static Utils::Id clangDiagnosticConfigIdFromSettings(QSettings *s)
|
||||
{
|
||||
QTC_ASSERT(s->group() == QLatin1String(Constants::CPPTOOLS_SETTINGSGROUP), return Utils::Id());
|
||||
@@ -160,6 +172,9 @@ void CppCodeModelSettings::fromSettings(QSettings *s)
|
||||
const QVariant indexerFileSizeLimit = s->value(indexerFileSizeLimitKey(), 5);
|
||||
setIndexerFileSizeLimitInMb(indexerFileSizeLimit.toInt());
|
||||
|
||||
setUseClangd(s->value(useClangdKey(), false).toBool());
|
||||
setClangdFilePath(FilePath::fromString(s->value(clangdPathKey()).toString()));
|
||||
|
||||
s->endGroup();
|
||||
|
||||
if (write)
|
||||
@@ -183,6 +198,8 @@ void CppCodeModelSettings::toSettings(QSettings *s)
|
||||
s->setValue(interpretAmbiguousHeadersAsCHeadersKey(), interpretAmbigiousHeadersAsCHeaders());
|
||||
s->setValue(skipIndexingBigFilesKey(), skipIndexingBigFiles());
|
||||
s->setValue(indexerFileSizeLimitKey(), indexerFileSizeLimitInMb());
|
||||
s->setValue(useClangdKey(), useClangd());
|
||||
s->setValue(clangdPathKey(), m_clangdFilePath.toString());
|
||||
|
||||
s->endGroup();
|
||||
|
||||
@@ -282,3 +299,15 @@ void CppCodeModelSettings::setEnableLowerClazyLevels(bool yesno)
|
||||
{
|
||||
m_enableLowerClazyLevels = yesno;
|
||||
}
|
||||
|
||||
void CppCodeModelSettings::setDefaultClangdPath(const Utils::FilePath &filePath)
|
||||
{
|
||||
g_defaultClangdFilePath = filePath;
|
||||
}
|
||||
|
||||
FilePath CppCodeModelSettings::clangdFilePath() const
|
||||
{
|
||||
if (!m_clangdFilePath.isEmpty())
|
||||
return m_clangdFilePath;
|
||||
return fallbackClangdFilePath();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user