LanguageClient: do not auto-assign documents to all clients

Only assign documents to a client if the client was started by a
setting. Programatically started clients should handle assigned
documents manually.

Change-Id: I192c4c011a48e0406f267d3cab3c860f740ddad7
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
David Schulz
2021-04-20 11:40:24 +02:00
parent 3d1ad9db60
commit d66b410adb
3 changed files with 13 additions and 2 deletions

View File

@@ -345,11 +345,14 @@ void Client::openDocument(TextEditor::TextDocument *document)
sendContent(DidOpenTextDocumentNotification(DidOpenTextDocumentParams(item)));
const Client *currentClient = LanguageClientManager::clientForDocument(document);
if (currentClient == this) // this is the active client for the document so directly activate it
if (currentClient == this) {
// this is the active client for the document so directly activate it
activateDocument(document);
else if (currentClient == nullptr) // there is no client for this document so assign it to this server
} else if (m_activateDocAutomatically && currentClient == nullptr) {
// there is no client for this document so assign it to this server
LanguageClientManager::openDocumentWithClient(document, this);
}
}
void Client::sendContent(const IContent &content)
{
@@ -878,6 +881,11 @@ void Client::setSupportedLanguage(const LanguageFilter &filter)
m_languagFilter = filter;
}
void Client::setActivateDocumentAutomatically(bool enabled)
{
m_activateDocAutomatically = enabled;
}
void Client::setInitializationOptions(const QJsonObject &initializationOptions)
{
m_initializationOptions = initializationOptions;

View File

@@ -118,6 +118,7 @@ public:
// document synchronization
void setSupportedLanguage(const LanguageFilter &filter);
void setActivateDocumentAutomatically(bool enabled);
bool isSupportedDocument(const TextEditor::TextDocument *document) const;
bool isSupportedFile(const Utils::FilePath &filePath, const QString &mimeType) const;
bool isSupportedUri(const LanguageServerProtocol::DocumentUri &uri) const;
@@ -242,6 +243,7 @@ private:
QSet<TextEditor::IAssistProcessor *> m_runningAssistProcessors;
SymbolSupport m_symbolSupport;
ProgressManager m_progressManager;
bool m_activateDocAutomatically = false;
};
} // namespace LanguageClient

View File

@@ -566,6 +566,7 @@ Client *BaseSettings::createClient()
client->setName(Utils::globalMacroExpander()->expand(m_name));
client->setSupportedLanguage(m_languageFilter);
client->setInitializationOptions(initializationOptions());
client->setActivateDocumentAutomatically(true);
return client;
}