ClangCodeModel: Provide outline via clangd

Note that we used to encode the information about symbol visibility and
static-ness in the icons, which we can't do anymore, because clangd does
not provide this information.
On the upside, this change likely fixes a ton of bugs, as our own outline
was rather "quirky".

Change-Id: I099f11ec4e3c6f52cd461fb43080bbdde3bed5e5
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2021-06-08 14:28:25 +02:00
parent f4a3310059
commit c0a44be27b
12 changed files with 97 additions and 18 deletions

View File

@@ -732,6 +732,31 @@ ClangdClient::ClangdClient(Project *project, const Utils::FilePath &jsonDbDir)
const auto hideDiagsHandler = []{ ClangDiagnosticManager::clearTaskHubIssues(); };
setDiagnosticsHandlers(textMarkCreator, hideDiagsHandler);
static const auto symbolStringifier = [](SymbolKind kind, const QString &name,
const QString &detail) -> QString
{
switch (kind) {
case LanguageServerProtocol::SymbolKind::Constructor:
return name + detail;
case LanguageServerProtocol::SymbolKind::Method:
case LanguageServerProtocol::SymbolKind::Function: {
const int parenOffset = detail.indexOf(" (");
if (parenOffset == -1)
return name;
return name + detail.mid(parenOffset + 1) + " -> " + detail.mid(0, parenOffset);
}
case LanguageServerProtocol::SymbolKind::Variable:
case LanguageServerProtocol::SymbolKind::Field:
case LanguageServerProtocol::SymbolKind::Constant:
if (detail.isEmpty())
return name;
return name + " -> " + detail;
default:
return name;
}
};
setSymbolStringifier(symbolStringifier);
hoverHandler()->setHelpItemProvider([this](const HoverRequest::Response &response,
const DocumentUri &uri) {
gatherHelpItemForTooltip(response, uri);

View File

@@ -171,6 +171,11 @@ std::unique_ptr<CppTools::AbstractOverviewModel> ClangModelManagerSupport::creat
return std::make_unique<OverviewModel>();
}
bool ClangModelManagerSupport::supportsOutline(const TextEditor::TextDocument *document) const
{
return !clientForFile(document->filePath());
}
CppTools::BaseEditorDocumentProcessor *ClangModelManagerSupport::createEditorDocumentProcessor(
TextEditor::TextDocument *baseTextDocument)
{
@@ -344,7 +349,7 @@ void ClangModelManagerSupport::updateLanguageClient(ProjectExplorer::Project *pr
}
ClangdClient *ClangModelManagerSupport::clientForProject(
const ProjectExplorer::Project *project)
const ProjectExplorer::Project *project) const
{
const QList<Client *> clients = Utils::filtered(
LanguageClientManager::clientsForProject(project),
@@ -357,7 +362,7 @@ ClangdClient *ClangModelManagerSupport::clientForProject(
return clients.empty() ? nullptr : qobject_cast<ClangdClient *>(clients.first());
}
ClangdClient *ClangModelManagerSupport::clientForFile(const Utils::FilePath &file)
ClangdClient *ClangModelManagerSupport::clientForFile(const Utils::FilePath &file) const
{
return clientForProject(ProjectExplorer::SessionManager::projectForFile(file));
}

View File

@@ -72,6 +72,7 @@ public:
CppTools::FollowSymbolInterface &followSymbolInterface() override;
CppTools::RefactoringEngineInterface &refactoringEngineInterface() override;
std::unique_ptr<CppTools::AbstractOverviewModel> createOverviewModel() override;
bool supportsOutline(const TextEditor::TextDocument *document) const override;
BackendCommunicator &communicator();
QString dummyUiHeaderOnDiskDirPath() const;
@@ -79,8 +80,8 @@ public:
ClangProjectSettings &projectSettings(ProjectExplorer::Project *project) const;
ClangdClient *clientForProject(const ProjectExplorer::Project *project);
ClangdClient *clientForFile(const Utils::FilePath &file);
ClangdClient *clientForProject(const ProjectExplorer::Project *project) const;
ClangdClient *clientForFile(const Utils::FilePath &file) const;
static ClangModelManagerSupport *instance();