forked from qt-creator/qt-creator
AI Assistant: aiassistantserver installation based on platform (linux)
Change-Id: Ifbebac39d453c0e162c62d1b0aa9754d6e57f106 Reviewed-by: <mua@spyro-soft.com> Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -7,10 +7,13 @@ local Gui = require('Gui')
|
|||||||
local a = require('async')
|
local a = require('async')
|
||||||
local TextEditor = require('TextEditor')
|
local TextEditor = require('TextEditor')
|
||||||
local mm = require('MessageManager')
|
local mm = require('MessageManager')
|
||||||
|
local fetch = require('Fetch').fetch
|
||||||
local Install = require('Install')
|
local Install = require('Install')
|
||||||
|
|
||||||
Hooks = {}
|
Hooks = {}
|
||||||
AutoSuggestionDelay = 2000
|
AutoSuggestionDelay = 2000
|
||||||
|
ServerName = "qtaiassistantserver"
|
||||||
|
ServerReleasesURL = "https://qtaiassistant.gitlab-pages.qt.io/qtails/releases/" .. ServerName .. ".json"
|
||||||
|
|
||||||
local function collectSuggestions(responseTable)
|
local function collectSuggestions(responseTable)
|
||||||
local suggestions = {}
|
local suggestions = {}
|
||||||
@@ -59,35 +62,89 @@ local function createInitOptions()
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function filter(tbl, callback)
|
||||||
|
for i = #tbl, 1, -1 do
|
||||||
|
if not callback(tbl[i]) then
|
||||||
|
table.remove(tbl, i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
local function installOrUpdateServer()
|
local function installOrUpdateServer()
|
||||||
local lspPkgInfo = Install.packageInfo("qtaiassistantserver")
|
-- TODO: Support Windows and Mac OS
|
||||||
|
|
||||||
-- TODO: Support multiple platforms
|
local data = a.wait(fetch({
|
||||||
|
url = ServerReleasesURL,
|
||||||
|
convertToTable = true
|
||||||
|
}))
|
||||||
|
|
||||||
local url = "https://qtaiassistant.gitlab-pages.qt.io/qtails/downloads/qtaiassistantserver-x86_64-unknown-linux-gnu.gz"
|
if data == nil or data["assets"] == nil then
|
||||||
local res, err = a.wait(Install.install(
|
print("Failed to fetch release data.")
|
||||||
"Do you want to install the qtaiassistantserver?", {
|
|
||||||
name = "qtaiassistantserver",
|
|
||||||
url = url,
|
|
||||||
version = "0.0.1"
|
|
||||||
}))
|
|
||||||
|
|
||||||
if not res then
|
|
||||||
mm.writeFlashing("Failed to install qtaiassistantserver: " .. err)
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
lspPkgInfo = Install.packageInfo("qtaiassistantserver")
|
local links = data["assets"]["links"]
|
||||||
print("Installed:", lspPkgInfo.name, "version:", lspPkgInfo.version, "at", lspPkgInfo.path)
|
if type(links) == "table" and #links > 0 then
|
||||||
|
local tag_name = data["tag_name"]
|
||||||
|
print("Found tag name:", tag_name)
|
||||||
|
|
||||||
local binary = "qtaiassistantserver"
|
local lspPkgInfo = Install.packageInfo(ServerName)
|
||||||
if Utils.HostOsInfo.isWindowsHost() then
|
if not lspPkgInfo or lspPkgInfo.version ~= tag_name then
|
||||||
binary = "qtaiassistantserver.exe"
|
local osTr = { mac = "darwin", windows = "win32", linux = "linux" }
|
||||||
|
local archTr = { unknown = "", x86 = "ia32", x86_64 = "x64", itanium = "", arm = "", arm64 = "arm64" }
|
||||||
|
local extTr = { mac = "gz", windows = "zip", linux = "tar.gz" }
|
||||||
|
local os = osTr[Utils.HostOsInfo.os]
|
||||||
|
|
||||||
|
if os ~= "linux" then
|
||||||
|
print("Currently unsupported OS:", Utils.HostOsInfo.os)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
local arch = archTr[Utils.HostOsInfo.architecture]
|
||||||
|
local ext = extTr[Utils.HostOsInfo.os]
|
||||||
|
local expectedFileName = ServerName .. "-" .. tag_name .. "-" .. os .. "-" .. arch .. "." .. ext
|
||||||
|
|
||||||
|
filter(links, function(asset)
|
||||||
|
return string.find(asset.name, expectedFileName, 1, true) == 1
|
||||||
|
end)
|
||||||
|
|
||||||
|
if #links == 0 then
|
||||||
|
print("No assets found for this platform. Expected file base name:", expectedFileName)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
print("Using link:", links[1].url)
|
||||||
|
|
||||||
|
local res, err = a.wait(Install.install(
|
||||||
|
"Do you want to install the qtaiassistantserver?", {
|
||||||
|
name = "qtaiassistantserver",
|
||||||
|
url = links[1].url,
|
||||||
|
version = tag_name
|
||||||
|
}))
|
||||||
|
|
||||||
|
if not res then
|
||||||
|
mm.writeFlashing("Failed to install qtaiassistantserver: " .. err)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
lspPkgInfo = Install.packageInfo("qtaiassistantserver")
|
||||||
|
print("Installed:", lspPkgInfo.name, " version:", lspPkgInfo.version, " at:", lspPkgInfo.path)
|
||||||
|
end
|
||||||
|
|
||||||
|
local base_name = "qtaiassistantserver-" .. tag_name
|
||||||
|
local binary = base_name .. "-linux-x64"
|
||||||
|
if Utils.HostOsInfo.isWindowsHost() then
|
||||||
|
binary = base_name .. "-windows-x64.exe"
|
||||||
|
end
|
||||||
|
|
||||||
|
Settings.binary:setValue(lspPkgInfo.path:resolvePath(binary))
|
||||||
|
Settings:apply()
|
||||||
|
|
||||||
|
else
|
||||||
|
print("No links found in the release data.")
|
||||||
end
|
end
|
||||||
|
|
||||||
Settings.binary:setValue(lspPkgInfo.path:resolvePath(binary))
|
|
||||||
Settings:apply()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
IsTryingToInstall = false
|
IsTryingToInstall = false
|
||||||
|
Reference in New Issue
Block a user