From bf9e2110e6d05ba949bedd8bb0e3b6d9f267e3e6 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Fri, 2 Dec 2022 08:26:16 +0100 Subject: [PATCH] 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 --- src/plugins/languageclient/client.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/plugins/languageclient/client.cpp b/src/plugins/languageclient/client.cpp index e5b04e5af38..466fbd1d43b 100644 --- a/src/plugins/languageclient/client.cpp +++ b/src/plugins/languageclient/client.cpp @@ -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); }); }