LSP: Set client working directory to project directory

If the server settings specify that a server is to be started "per
project".

This fixes e.g. running the haskell-language-server

Fixes: QTCREATORBUG-26115
Change-Id: If10af71d60786826a9218b4b98818df8d9710adf
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Eike Ziller
2021-08-25 12:48:39 +02:00
parent 1d5ddbf8f8
commit 940a203d93
3 changed files with 18 additions and 5 deletions

View File

@@ -166,9 +166,8 @@ Client *LanguageClientManager::startClient(BaseSettings *setting, ProjectExplore
QTC_ASSERT(managerInstance, return nullptr);
QTC_ASSERT(setting, return nullptr);
QTC_ASSERT(setting->isValid(), return nullptr);
Client *client = setting->createClient();
Client *client = setting->createClient(project);
QTC_ASSERT(client, return nullptr);
client->setCurrentProject(project);
client->start();
managerInstance->m_clientsForSetting[setting->m_id].append(client);
return client;

View File

@@ -557,16 +557,22 @@ bool BaseSettings::isValid() const
}
Client *BaseSettings::createClient()
{
return createClient(nullptr);
}
Client *BaseSettings::createClient(ProjectExplorer::Project *project)
{
if (!isValid() || !m_enabled)
return nullptr;
BaseClientInterface *interface = createInterface();
BaseClientInterface *interface = createInterfaceWithProject(project);
QTC_ASSERT(interface, return nullptr);
auto *client = createClient(interface);
client->setName(Utils::globalMacroExpander()->expand(m_name));
client->setSupportedLanguage(m_languageFilter);
client->setInitializationOptions(initializationOptions());
client->setActivateDocumentAutomatically(true);
client->setCurrentProject(project);
return client;
}
@@ -733,10 +739,12 @@ Utils::CommandLine StdIOSettings::command() const
Utils::CommandLine::Raw);
}
BaseClientInterface *StdIOSettings::createInterface() const
BaseClientInterface *StdIOSettings::createInterfaceWithProject(ProjectExplorer::Project *project) const
{
auto interface = new StdIOClientInterface;
interface->setCommandLine(command());
if (project)
interface->setWorkingDirectory(project->projectDirectory().toString());
return interface;
}

View File

@@ -96,12 +96,18 @@ public:
virtual BaseSettings *copy() const { return new BaseSettings(*this); }
virtual bool isValid() const;
Client *createClient();
Client *createClient(ProjectExplorer::Project *project);
virtual QVariantMap toMap() const;
virtual void fromMap(const QVariantMap &map);
protected:
// TODO: remove in Qt Creator 6 and rename createInterfaceWithProject back to it
virtual BaseClientInterface *createInterface() const { return nullptr; }
virtual Client *createClient(BaseClientInterface *interface) const;
virtual BaseClientInterface *createInterfaceWithProject(ProjectExplorer::Project *) const
{
return createInterface();
}
BaseSettings(const BaseSettings &other) = default;
BaseSettings(BaseSettings &&other) = default;
@@ -131,7 +137,7 @@ public:
Utils::CommandLine command() const;
protected:
BaseClientInterface *createInterface() const override;
BaseClientInterface *createInterfaceWithProject(ProjectExplorer::Project *project) const override;
StdIOSettings(const StdIOSettings &other) = default;
StdIOSettings(StdIOSettings &&other) = default;