forked from qt-creator/qt-creator
ClangCodeModel: Create a clangd config file, if none exists yet
There are some clangd settings that can only be provided via a config file (i.e. neither via the command line nor via LSP extensions). In addition, clangd is very picky about that file's location; in particular, we cannot put it at the "pseudo project root" where our generated compilation database resides. Therefore, we have to go with a user config file (as we don't want to write into any project source directories). If there already is such a file, we don't do anything, based on the assumption that the user is familiar with clangd and has already configured it to their liking. Otherwise, we create the file, including a special marker that tells us it was generated by us and can safely be overwritten. The set of options we set is currently quite small, but we expect it to grow in the future. Change-Id: I1605bf7b0edecc844f3e7cdd1d7dddda7af33956 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -70,6 +70,7 @@
|
|||||||
#include <texteditor/texteditorsettings.h>
|
#include <texteditor/texteditorsettings.h>
|
||||||
#include <texteditor/texteditor.h>
|
#include <texteditor/texteditor.h>
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
|
#include <utils/fileutils.h>
|
||||||
#include <utils/itemviews.h>
|
#include <utils/itemviews.h>
|
||||||
#include <utils/runextensions.h>
|
#include <utils/runextensions.h>
|
||||||
#include <utils/treemodel.h>
|
#include <utils/treemodel.h>
|
||||||
@@ -86,6 +87,7 @@
|
|||||||
#include <QPair>
|
#include <QPair>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QRegularExpression>
|
#include <QRegularExpression>
|
||||||
|
#include <QStandardPaths>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include <QtConcurrent>
|
#include <QtConcurrent>
|
||||||
@@ -598,6 +600,24 @@ public:
|
|||||||
: Request("textDocument/symbolInfo", params) {}
|
: Request("textDocument/symbolInfo", params) {}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void setupClangdConfigFile()
|
||||||
|
{
|
||||||
|
const Utils::FilePath baseDir = Utils::FilePath::fromString(
|
||||||
|
QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation)) / "clangd";
|
||||||
|
baseDir.ensureWritableDir();
|
||||||
|
const Utils::FilePath targetConfigFile = baseDir / "config.yaml";
|
||||||
|
Utils::FileReader configReader;
|
||||||
|
const QByteArray firstLine = "# This file was generated by Qt Creator and will be overwritten "
|
||||||
|
"unless you remove this line.";
|
||||||
|
if (!configReader.fetch(targetConfigFile) || configReader.data().startsWith(firstLine)) {
|
||||||
|
Utils::FileSaver saver(targetConfigFile);
|
||||||
|
saver.write(firstLine + '\n');
|
||||||
|
saver.write("Hover:\n");
|
||||||
|
saver.write(" ShowAKA: Yes\n");
|
||||||
|
QTC_CHECK(saver.finalize());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static BaseClientInterface *clientInterface(Project *project, const Utils::FilePath &jsonDbDir)
|
static BaseClientInterface *clientInterface(Project *project, const Utils::FilePath &jsonDbDir)
|
||||||
{
|
{
|
||||||
QString indexingOption = "--background-index";
|
QString indexingOption = "--background-index";
|
||||||
|
@@ -42,6 +42,8 @@ namespace TextEditor { class BaseTextEditor; }
|
|||||||
namespace ClangCodeModel {
|
namespace ClangCodeModel {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
|
void setupClangdConfigFile();
|
||||||
|
|
||||||
class ClangdClient : public LanguageClient::Client
|
class ClangdClient : public LanguageClient::Client
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@@ -113,6 +113,7 @@ ClangModelManagerSupport::ClangModelManagerSupport()
|
|||||||
|
|
||||||
watchForExternalChanges();
|
watchForExternalChanges();
|
||||||
watchForInternalChanges();
|
watchForInternalChanges();
|
||||||
|
setupClangdConfigFile();
|
||||||
cppModelManager()->setCurrentDocumentFilter(std::make_unique<ClangdCurrentDocumentFilter>());
|
cppModelManager()->setCurrentDocumentFilter(std::make_unique<ClangdCurrentDocumentFilter>());
|
||||||
cppModelManager()->setLocatorFilter(std::make_unique<ClangGlobalSymbolFilter>());
|
cppModelManager()->setLocatorFilter(std::make_unique<ClangGlobalSymbolFilter>());
|
||||||
cppModelManager()->setClassesFilter(std::make_unique<ClangClassesFilter>());
|
cppModelManager()->setClassesFilter(std::make_unique<ClangClassesFilter>());
|
||||||
|
Reference in New Issue
Block a user