forked from qt-creator/qt-creator
LuaLS: Improve error reporting
Changes LSP.Client:documentVersion() and LSP.Client:hostPathToServerUri() to return ok and error message in case of errors. Also fixes the binding to take a self parameter so it fits to the function documentation. Change-Id: I605b7bacba2822c3efd5291d1f7bacf1ecb863d5 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -277,15 +277,15 @@ local function buildRequest()
|
|||||||
|
|
||||||
local document = editor:document()
|
local document = editor:document()
|
||||||
local filePath = document:file()
|
local filePath = document:file()
|
||||||
local doc_version = Client.documentVersion(filePath)
|
local ok, doc_version = Client:documentVersion(filePath)
|
||||||
if doc_version == -1 then
|
if not ok then
|
||||||
print("No document version found")
|
print("No document version found:", doc_version)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local doc_uri = Client.hostPathToServerUri(filePath)
|
local ok, doc_uri = Client:hostPathToServerUri(filePath)
|
||||||
if doc_uri == nil or doc_uri == "" then
|
if not ok then
|
||||||
print("No document uri found")
|
print("No document uri found", doc_uri)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@@ -695,25 +695,24 @@ static void registerLuaApi()
|
|||||||
return luaClientWrapper;
|
return luaClientWrapper;
|
||||||
},
|
},
|
||||||
"documentVersion",
|
"documentVersion",
|
||||||
[](const Utils::FilePath &path) -> int {
|
[](LuaClientWrapper *wrapper,
|
||||||
auto client = LanguageClientManager::clientForFilePath(path);
|
const Utils::FilePath &path) -> std::tuple<bool, std::variant<int, QString>> {
|
||||||
if (!client) {
|
auto clients = wrapper->clientsForDocument(
|
||||||
qWarning() << "documentVersion(). No client for file path:" << path;
|
TextEditor::TextDocument::textDocumentForFilePath(path));
|
||||||
return -1;
|
if (clients.empty())
|
||||||
}
|
return {false, "No client found."};
|
||||||
|
|
||||||
return client->documentVersion(path);
|
return {true, clients.first()->documentVersion(path)};
|
||||||
},
|
},
|
||||||
|
|
||||||
"hostPathToServerUri",
|
"hostPathToServerUri",
|
||||||
[](const Utils::FilePath &path) -> QString {
|
[](LuaClientWrapper *wrapper, const Utils::FilePath &path) -> std::tuple<bool, QString> {
|
||||||
auto client = LanguageClientManager::clientForFilePath(path);
|
auto clients = wrapper->clientsForDocument(
|
||||||
if (!client) {
|
TextEditor::TextDocument::textDocumentForFilePath(path));
|
||||||
qWarning() << "hostPathToServerUri(). No client for file path:" << path;
|
if (clients.empty())
|
||||||
return {};
|
return {false, "No client found."};
|
||||||
}
|
|
||||||
|
|
||||||
return client->hostPathToServerUri(path).toString();
|
return {true, clients.first()->hostPathToServerUri(path).toString()};
|
||||||
});
|
});
|
||||||
|
|
||||||
wrapperClass["sendMessageWithIdForDocument"]
|
wrapperClass["sendMessageWithIdForDocument"]
|
||||||
|
@@ -46,11 +46,13 @@ function lsp.Client:sendMessageForDocument(document, msg) end
|
|||||||
function lsp.Client:sendMessageWithIdForDocument(document, msg) end
|
function lsp.Client:sendMessageWithIdForDocument(document, msg) end
|
||||||
|
|
||||||
---@param filePath FilePath to get the version of.
|
---@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
|
function lsp.Client:documentVersion(filePath) end
|
||||||
---
|
---
|
||||||
---@param filePath table file path to get the uri of.
|
---@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
|
function lsp.Client:hostPathToServerUri(filePath) end
|
||||||
|
|
||||||
---Creates a new Language Client.
|
---Creates a new Language Client.
|
||||||
|
Reference in New Issue
Block a user