Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/common/lsp/client/client.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ void Client::diagnostic(const WorkspaceDiagnosticParams &params)

void Client::selectLspServer(const newlsp::ProjectKey &key)
{
if (d->proKey == key)
if (d->proKey == key && d->isClientValid)
return;

d->proKey = key;
Expand Down Expand Up @@ -1342,6 +1342,7 @@ bool ClientPrivate::calledResult(const QJsonObject &jsonObj)
|| !jsonObj.contains(K_RESULT))
return false;

isClientValid = true;
bool any = false;
any |= initResult(jsonObj);
any |= openResult(jsonObj);
Expand Down Expand Up @@ -1401,6 +1402,11 @@ lsp::SemanticTokensProvider Client::initSecTokensProvider()
return d->secTokensProvider;
}

bool Client::isValid() const
{
return d->isClientValid;
}

ClientPrivate::ClientPrivate(Client *const q)
: newlsp::StdoutJsonRpcParser(), q(q), requestIndex(0), requestSave({}), semanticTokenResultId(0), fileVersion({}), secTokensProvider({}), proKey({})
{
Expand Down
1 change: 1 addition & 0 deletions src/common/lsp/client/client.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
virtual ~Client();

lsp::SemanticTokensProvider initSecTokensProvider();
bool isValid() const;

public slots:

Check warning on line 28 in src/common/lsp/client/client.h

View workflow job for this annotation

GitHub Actions / static-check / static-check

There is an unknown macro here somewhere. Configuration is required. If slots is a macro then please configure it.

Check warning on line 28 in src/common/lsp/client/client.h

View workflow job for this annotation

GitHub Actions / cppcheck

There is an unknown macro here somewhere. Configuration is required. If slots is a macro then please configure it.
// textDocument/semanticTokens/full/delta
void delta(const newlsp::SemanticTokensDeltaParams &params);
// textDocument/semanticTokens/full
Expand Down
35 changes: 18 additions & 17 deletions src/common/lsp/client/private/client_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,34 +32,35 @@ class ClientPrivate : public newlsp::StdoutJsonRpcParser
QHash<QString, int> fileVersion;
lsp::SemanticTokensProvider secTokensProvider;
newlsp::ProjectKey proKey;
bool isClientValid { false };

ClientPrivate(Client *const q);

QStringList cvtStringList(const QJsonArray &array);

/* server response parse */
bool calledError(const QJsonObject &jsonObj);
bool calledResult(const QJsonObject &jsonObj); //found result key from json && not found method
bool initResult(const QJsonObject &jsonObj); // client call server rpc return
bool openResult(const QJsonObject &jsonObj); // client call server rpc return
bool changeResult(const QJsonObject &jsonObj); // client call server rpc return
bool symbolResult(const QJsonObject &jsonObj); // client call server rpc return
bool renameResult(const QJsonObject &jsonObj); // client call server rpc return
bool definitionResult(const QJsonObject &jsonObj); // client call server rpc return above uri
bool completionResult(const QJsonObject &jsonObj); // client call server rpc return
bool rangeFormattingResult(const QJsonObject &jsonObj); // client call server rpc return
bool signatureHelpResult(const QJsonObject &jsonObj); // client call server rpc return
bool hoverResult(const QJsonObject &jsonObj); // client call server rpc return
bool referencesResult(const QJsonObject &jsonObj); // client call server rpc return
bool docHighlightResult(const QJsonObject &jsonObj); // client call server rpc return
bool docSemanticTokensFullResult(const QJsonObject &jsonObj); // client call server rpc return
bool closeResult(const QJsonObject &jsonObj); // client call server rpc return
bool calledResult(const QJsonObject &jsonObj); // found result key from json && not found method
bool initResult(const QJsonObject &jsonObj); // client call server rpc return
bool openResult(const QJsonObject &jsonObj); // client call server rpc return
bool changeResult(const QJsonObject &jsonObj); // client call server rpc return
bool symbolResult(const QJsonObject &jsonObj); // client call server rpc return
bool renameResult(const QJsonObject &jsonObj); // client call server rpc return
bool definitionResult(const QJsonObject &jsonObj); // client call server rpc return above uri
bool completionResult(const QJsonObject &jsonObj); // client call server rpc return
bool rangeFormattingResult(const QJsonObject &jsonObj); // client call server rpc return
bool signatureHelpResult(const QJsonObject &jsonObj); // client call server rpc return
bool hoverResult(const QJsonObject &jsonObj); // client call server rpc return
bool referencesResult(const QJsonObject &jsonObj); // client call server rpc return
bool docHighlightResult(const QJsonObject &jsonObj); // client call server rpc return
bool docSemanticTokensFullResult(const QJsonObject &jsonObj); // client call server rpc return
bool closeResult(const QJsonObject &jsonObj); // client call server rpc return
bool shutdownResult(const QJsonObject &jsonObj);
bool exitResult(const QJsonObject &jsonObj);
bool switchHeaderSourceResult(const QJsonObject &jsonObj);

/* server called method */
bool serverCalled(const QJsonObject &jsonObj); // not found result key from json && found key method
bool serverCalled(const QJsonObject &jsonObj); // not found result key from json && found key method
bool diagnosticsCalled(const QJsonObject &jsonObj);

QList<DocumentSymbol> parseDocumentSymbol(const QJsonArray &array);
Expand All @@ -80,4 +81,4 @@ public Q_SLOTS:

}

#endif // CLIENT_P_H
#endif // CLIENT_P_H
6 changes: 6 additions & 0 deletions src/plugins/codeeditor/lsp/languageclienthandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,26 +523,32 @@ void LanguageClientHandlerPrivate::handleShowContextMenu(QMenu *menu)
if (!editor)
return;

bool isClientValid = getClient() ? getClient()->isValid() : false;
auto actionList = menu->actions();
for (auto act : actionList) {
if (act->text() == tr("Refactor")) {
QMenu *subMenu = new QMenu(menu);
subMenu->addAction(tr("Rename Symbol Under Cursor"), q, &LanguageClientHandler::renameActionTriggered);
act->setMenu(subMenu);
act->setEnabled(isClientValid);
break;
}
}

auto act = menu->addAction(tr("Switch Header/Source"), q, std::bind(&LanguageClientHandler::switchHeaderSource, q, editor->getFile()));
act->setEnabled(isClientValid);
menu->insertAction(actionList.first(), act);

act = menu->addAction(tr("Follow Symbol Under Cursor"), q, &LanguageClientHandler::followSymbolUnderCursor);
act->setEnabled(isClientValid);
menu->insertAction(actionList.first(), act);

act = menu->addAction(tr("Find Usages"), q, &LanguageClientHandler::findUsagesActionTriggered);
act->setEnabled(isClientValid);
menu->insertAction(actionList.first(), act);

act = menu->addAction(tr("Format Selection"), q, &LanguageClientHandler::formatSelections);
act->setEnabled(isClientValid);
menu->insertAction(actionList.first(), act);
menu->insertSeparator(actionList.first());
}
Expand Down
11 changes: 8 additions & 3 deletions src/plugins/codeeditor/lsp/lspclientmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,17 @@ newlsp::Client *LSPClientManager::get(const newlsp::ProjectKey &key)
if (!key.isValid())
return nullptr;

auto selectLSP = [key](newlsp::Client *client) {
qApp->metaObject()->invokeMethod(client, "selectLspServer", Q_ARG(const newlsp::ProjectKey &, key));
if (!client->isValid())
qApp->metaObject()->invokeMethod(client, "initRequest");
};

if (clientHash.contains(key)) {
qApp->metaObject()->invokeMethod(clientHash[key], "selectLspServer", Q_ARG(const newlsp::ProjectKey &, key));
selectLSP(clientHash[key]);
} else {
auto client = new newlsp::Client();
qApp->metaObject()->invokeMethod(client, "selectLspServer", Q_ARG(const newlsp::ProjectKey &, key));
qApp->metaObject()->invokeMethod(client, "initRequest");
selectLSP(client);
clientHash.insert(key, client);
}

Expand Down
Loading