forked from qt-creator/qt-creator
LanguageClient: select current client when opening inspector
Change-Id: I4bfd74e7e9a8c0f4b60ed034faac86c2fb9bb018 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -398,7 +398,10 @@ void LanguageClientManager::logBaseMessage(const LspLogMessage::MessageSender se
|
||||
|
||||
void LanguageClientManager::showInspector()
|
||||
{
|
||||
QWidget *inspectorWidget = instance()->m_inspector.createWidget();
|
||||
QString clientName;
|
||||
if (Client *client = clientForDocument(TextEditor::TextDocument::currentTextDocument()))
|
||||
clientName = client->name();
|
||||
QWidget *inspectorWidget = instance()->m_inspector.createWidget(clientName);
|
||||
inspectorWidget->setAttribute(Qt::WA_DeleteOnClose);
|
||||
inspectorWidget->show();
|
||||
}
|
||||
|
@@ -356,10 +356,11 @@ class LspInspectorWidget : public QDialog
|
||||
public:
|
||||
explicit LspInspectorWidget(LspInspector *inspector);
|
||||
|
||||
void selectClient(const QString &clientName);
|
||||
private:
|
||||
void addMessage(const QString &clientName, const LspLogMessage &message);
|
||||
void updateCapabilities(const QString &clientName);
|
||||
void setCurrentClient(const QString &clientName);
|
||||
void currentClientChanged(const QString &clientName);
|
||||
|
||||
LspInspector *m_inspector = nullptr;
|
||||
LspLogWidget *m_log = nullptr;
|
||||
@@ -367,9 +368,11 @@ private:
|
||||
QListWidget *m_clients = nullptr;
|
||||
};
|
||||
|
||||
QWidget *LspInspector::createWidget()
|
||||
QWidget *LspInspector::createWidget(const QString &defaultClient)
|
||||
{
|
||||
return new LspInspectorWidget(this);
|
||||
auto *inspector = new LspInspectorWidget(this);
|
||||
inspector->selectClient(defaultClient);
|
||||
return inspector;
|
||||
}
|
||||
|
||||
void LspInspector::log(const LspLogMessage::MessageSender sender,
|
||||
@@ -399,7 +402,7 @@ void LspInspector::updateCapabilities(const QString &clientName,
|
||||
|
||||
std::list<LspLogMessage> LspInspector::messages(const QString &clientName) const
|
||||
{
|
||||
return m_logs[clientName];
|
||||
return m_logs.value(clientName);
|
||||
}
|
||||
|
||||
Capabilities LspInspector::capabilities(const QString &clientName) const
|
||||
@@ -449,7 +452,7 @@ LspInspectorWidget::LspInspectorWidget(LspInspector *inspector)
|
||||
connect(m_clients,
|
||||
&QListWidget::currentTextChanged,
|
||||
this,
|
||||
&LspInspectorWidget::setCurrentClient);
|
||||
&LspInspectorWidget::currentClientChanged);
|
||||
|
||||
// save
|
||||
connect(buttonBox, &QDialogButtonBox::accepted, m_log, &LspLogWidget::saveLog);
|
||||
@@ -459,6 +462,14 @@ LspInspectorWidget::LspInspectorWidget(LspInspector *inspector)
|
||||
resize(1024, 768);
|
||||
}
|
||||
|
||||
void LspInspectorWidget::selectClient(const QString &clientName)
|
||||
{
|
||||
auto items = m_clients->findItems(clientName, Qt::MatchExactly);
|
||||
if (items.isEmpty())
|
||||
return;
|
||||
m_clients->setCurrentItem(items.first());
|
||||
}
|
||||
|
||||
void LspInspectorWidget::addMessage(const QString &clientName, const LspLogMessage &message)
|
||||
{
|
||||
if (m_clients->findItems(clientName, Qt::MatchExactly).isEmpty())
|
||||
@@ -475,7 +486,7 @@ void LspInspectorWidget::updateCapabilities(const QString &clientName)
|
||||
m_capabilities->setCapabilities(m_inspector->capabilities(clientName));
|
||||
}
|
||||
|
||||
void LspInspectorWidget::setCurrentClient(const QString &clientName)
|
||||
void LspInspectorWidget::currentClientChanged(const QString &clientName)
|
||||
{
|
||||
m_log->setMessages(m_inspector->messages(clientName));
|
||||
m_capabilities->setCapabilities(m_inspector->capabilities(clientName));
|
||||
|
@@ -56,7 +56,7 @@ class LspInspector : public QObject
|
||||
public:
|
||||
LspInspector() {}
|
||||
|
||||
QWidget *createWidget();
|
||||
QWidget *createWidget(const QString &defaultClient = {});
|
||||
|
||||
|
||||
void log(const LspLogMessage::MessageSender sender,
|
||||
|
Reference in New Issue
Block a user