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:
@@ -26,6 +26,12 @@
|
||||
#include "clangrefactoringengine.h"
|
||||
#include "clangeditordocumentprocessor.h"
|
||||
|
||||
#include "clangmodelmanagersupport.h"
|
||||
|
||||
#include <cpptools/cppmodelmanager.h>
|
||||
#include <languageclient/client.h>
|
||||
#include <languageclient/languageclientsymbolsupport.h>
|
||||
#include <projectexplorer/session.h>
|
||||
#include <utils/textutils.h>
|
||||
#include <utils/qtcassert.h>
|
||||
|
||||
@@ -80,5 +86,27 @@ void RefactoringEngine::startLocalRenaming(const CppTools::CursorInEditor &data,
|
||||
m_watcher->setFuture(cursorFuture);
|
||||
}
|
||||
|
||||
void RefactoringEngine::findUsages(const CppTools::CursorInEditor &cursor,
|
||||
CppTools::UsagesCallback &&callback) const
|
||||
{
|
||||
ProjectExplorer::Project * const project
|
||||
= ProjectExplorer::SessionManager::projectForFile(cursor.filePath());
|
||||
LanguageClient::Client * const client
|
||||
= ClangModelManagerSupport::instance()->clientForProject(project);
|
||||
if (!client || client->state() != LanguageClient::Client::Initialized) {
|
||||
// TODO: Also forward to built-in if index is not ready.
|
||||
// This requires us to keep track of workDone status in the client.
|
||||
// Related: Also allow to override the server string for progress info
|
||||
CppTools::CppModelManager::builtinRefactoringEngine()
|
||||
->findUsages(cursor, std::move(callback));
|
||||
return;
|
||||
}
|
||||
// TODO: We want to keep our "access type info" feature.
|
||||
// Check whether we can support it using clang 12's textDocument/ast request
|
||||
if (!client->documentOpen(cursor.textDocument()))
|
||||
client->openDocument(cursor.textDocument()); // TODO: Just a workaround
|
||||
client->symbolSupport().findUsages(cursor.textDocument(), cursor.cursor());
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
} // namespace ClangCodeModel
|
||||
|
||||
Reference in New Issue
Block a user