diff --git a/share/qtcreator/lua-plugins/ai_asistant/init.lua b/share/qtcreator/lua-plugins/ai_asistant/init.lua index e6ab2f4a611..afd6c743da3 100644 --- a/share/qtcreator/lua-plugins/ai_asistant/init.lua +++ b/share/qtcreator/lua-plugins/ai_asistant/init.lua @@ -277,15 +277,15 @@ local function buildRequest() local document = editor:document() local filePath = document:file() - local doc_version = Client.documentVersion(filePath) - if doc_version == -1 then - print("No document version found") + local ok, doc_version = Client:documentVersion(filePath) + if not ok then + print("No document version found:", doc_version) return end - local doc_uri = Client.hostPathToServerUri(filePath) - if doc_uri == nil or doc_uri == "" then - print("No document uri found") + local ok, doc_uri = Client:hostPathToServerUri(filePath) + if not ok then + print("No document uri found", doc_uri) return end diff --git a/src/plugins/languageclient/lualanguageclient/lualanguageclient.cpp b/src/plugins/languageclient/lualanguageclient/lualanguageclient.cpp index c78be12ac4b..82f4a091dc2 100644 --- a/src/plugins/languageclient/lualanguageclient/lualanguageclient.cpp +++ b/src/plugins/languageclient/lualanguageclient/lualanguageclient.cpp @@ -695,25 +695,24 @@ static void registerLuaApi() return luaClientWrapper; }, "documentVersion", - [](const Utils::FilePath &path) -> int { - auto client = LanguageClientManager::clientForFilePath(path); - if (!client) { - qWarning() << "documentVersion(). No client for file path:" << path; - return -1; - } + [](LuaClientWrapper *wrapper, + const Utils::FilePath &path) -> std::tuple> { + auto clients = wrapper->clientsForDocument( + TextEditor::TextDocument::textDocumentForFilePath(path)); + if (clients.empty()) + return {false, "No client found."}; - return client->documentVersion(path); + return {true, clients.first()->documentVersion(path)}; }, "hostPathToServerUri", - [](const Utils::FilePath &path) -> QString { - auto client = LanguageClientManager::clientForFilePath(path); - if (!client) { - qWarning() << "hostPathToServerUri(). No client for file path:" << path; - return {}; - } + [](LuaClientWrapper *wrapper, const Utils::FilePath &path) -> std::tuple { + auto clients = wrapper->clientsForDocument( + TextEditor::TextDocument::textDocumentForFilePath(path)); + if (clients.empty()) + return {false, "No client found."}; - return client->hostPathToServerUri(path).toString(); + return {true, clients.first()->hostPathToServerUri(path).toString()}; }); wrapperClass["sendMessageWithIdForDocument"] diff --git a/src/plugins/lua/meta/lsp.lua b/src/plugins/lua/meta/lsp.lua index 5186afe2349..37a3c2671e5 100644 --- a/src/plugins/lua/meta/lsp.lua +++ b/src/plugins/lua/meta/lsp.lua @@ -46,11 +46,13 @@ function lsp.Client:sendMessageForDocument(document, msg) end function lsp.Client:sendMessageWithIdForDocument(document, msg) end ---@param filePath FilePath to get the version of. ----@return integer Returns -1 on error, otherwise current document version. +---@return boolean ok Returns false on error, otherwise true. +---@return integer|string error_or_version Current document version, or an error message. function lsp.Client:documentVersion(filePath) end --- ---@param filePath table file path to get the uri of. ----@return string Returns empty string on error, otherwise the server URI string. +---@return boolean ok Returns false on error, otherwise true. +---@return string error_or_uri The server URI string, or an error message. function lsp.Client:hostPathToServerUri(filePath) end ---Creates a new Language Client.