LSP: Use localSource

This change allows the LSP to find a local version of a source
file even if the server is running on a remote device.

Change-Id: I274cb327ad958ac3c4486859da666702758b7d42
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Marcus Tillmanns
2022-12-02 08:26:16 +01:00
parent a9c1beed7a
commit bf9e2110e6

View File

@@ -2080,10 +2080,16 @@ bool Client::fileBelongsToProject(const Utils::FilePath &filePath) const
return project() && project()->isKnownFile(filePath);
}
FilePath toHostPath(const FilePath serverDeviceTemplate, const FilePath localClientPath)
{
const FilePath onDevice = serverDeviceTemplate.withNewPath(localClientPath.path());
return onDevice.localSource().value_or(onDevice);
}
DocumentUri::PathMapper Client::hostPathMapper() const
{
return [serverDeviceTemplate = d->m_serverDeviceTemplate](const Utils::FilePath &serverPath) {
return serverDeviceTemplate.withNewPath(serverPath.path());
return toHostPath(serverDeviceTemplate, serverPath);
};
}
@@ -2094,7 +2100,7 @@ FilePath Client::serverUriToHostPath(const LanguageServerProtocol::DocumentUri &
DocumentUri Client::hostPathToServerUri(const Utils::FilePath &path) const
{
return DocumentUri::fromFilePath(path, [&](const Utils::FilePath &clientPath){
return DocumentUri::fromFilePath(path, [&](const Utils::FilePath &clientPath) {
return clientPath.onDevice(d->m_serverDeviceTemplate);
});
}