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 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
|
||||
|
||||
|
@@ -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<bool, std::variant<int, QString>> {
|
||||
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<bool, QString> {
|
||||
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"]
|
||||
|
@@ -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.
|
||||
|
Reference in New Issue
Block a user