Lua: Fix LSP Plugins

Change-Id: I8d79d6c56ef4f0e54866a84f0e4535c7f507e963
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-05-30 09:58:28 +02:00
parent 7ad1e20a48
commit a273990819
2 changed files with 77 additions and 36 deletions

View File

@@ -7,6 +7,7 @@ local S = require('Settings')
local Gui = require('Gui') local Gui = require('Gui')
local a = require('async') local a = require('async')
local fetch = require('Fetch').fetch local fetch = require('Fetch').fetch
local Install = require('Install')
Settings = {} Settings = {}
@@ -44,7 +45,6 @@ local function installOrUpdateServer()
if type(data) == "table" and #data > 0 then if type(data) == "table" and #data > 0 then
local r = data[1] local r = data[1]
Install = require('Install')
local lspPkgInfo = Install.packageInfo("lua-language-server") local lspPkgInfo = Install.packageInfo("lua-language-server")
if not lspPkgInfo or lspPkgInfo.version ~= r.tag_name then if not lspPkgInfo or lspPkgInfo.version ~= r.tag_name then
local osTr = { mac = "darwin", windows = "win32", linux = "linux" } local osTr = { mac = "darwin", windows = "win32", linux = "linux" }
@@ -83,7 +83,7 @@ local function installOrUpdateServer()
binary = "bin/lua-language-server.exe" binary = "bin/lua-language-server.exe"
end end
Settings.binary.defaultPath = lspPkgInfo.path:resolvePath(binary) Settings.binary:setValue(lspPkgInfo.path:resolvePath(binary))
Settings:apply() Settings:apply()
return return
end end
@@ -138,31 +138,53 @@ local function layoutSettings()
--- "using namespace Gui" --- "using namespace Gui"
local _ENV = using(Gui) local _ENV = using(Gui)
local installButton = {}
if Settings.binary.expandedValue:isExecutableFile() == false then
installButton = {
"Language server not found:",
Row {
PushButton {
text = "Try to install lua language server",
onClicked = function() a.sync(installServer)() end,
},
st
}
}
end
local layout = Form { local layout = Form {
Settings.binary, br, Settings.binary, br,
Settings.developMode, br, Settings.developMode, br,
Settings.showSource, br, Settings.showSource, br,
Settings.showNode, br, Settings.showNode, br,
table.unpack(installButton) Row {
PushButton {
text = "Update Lua Language Server",
onClicked = function() a.sync(installOrUpdateServer)() end,
},
st
}
} }
return layout return layout
end end
local function binaryFromPkg()
local lspPkgInfo = Install.packageInfo("lua-language-server")
if lspPkgInfo then
local binary = "bin/lua-language-server"
if Utils.HostOsInfo.isWindowsHost() then
binary = "bin/lua-language-server.exe"
end
local binaryPath = lspPkgInfo.path:resolvePath(binary)
if binaryPath:isExecutableFile() == true then
return binaryPath
end
end
return nil
end
local function findBinary()
local binary = binaryFromPkg()
if binary then
return binary
end
-- Search for the binary in the PATH
local serverPath = Utils.FilePath.fromUserInput("lua-language-server")
local absolute = a.wait(serverPath:searchInPath()):resolveSymlinks()
if absolute:isExecutableFile() == true then
return absolute
end
return serverPath
end
local function setupAspect() local function setupAspect()
---@class Settings: AspectContainer ---@class Settings: AspectContainer
Settings = S.AspectContainer.create({ Settings = S.AspectContainer.create({
@@ -176,14 +198,9 @@ local function setupAspect()
labelText = "Binary:", labelText = "Binary:",
toolTip = "The path to the lua-language-server binary.", toolTip = "The path to the lua-language-server binary.",
expectedKind = S.Kind.ExistingCommand, expectedKind = S.Kind.ExistingCommand,
defaultPath = Utils.FilePath.fromUserInput("lua-language-server"), defaultPath = findBinary(),
}) })
-- Search for the binary in the PATH
local serverPath = Settings.binary.defaultPath
local absolute = a.wait(serverPath:searchInPath()):resolveSymlinks()
if absolute:isExecutableFile() == true then
Settings.binary.defaultPath = absolute
end
Settings.developMode = S.BoolAspect.create({ Settings.developMode = S.BoolAspect.create({
settingsKey = "LuaCopilot.DevelopMode", settingsKey = "LuaCopilot.DevelopMode",
displayName = "Enable Develop Mode", displayName = "Enable Develop Mode",

View File

@@ -8,6 +8,7 @@ local S = require('Settings')
local Gui = require('Gui') local Gui = require('Gui')
local a = require('async') local a = require('async')
local fetch = require('Fetch').fetch local fetch = require('Fetch').fetch
local Install = require('Install')
Settings = {} Settings = {}
@@ -39,7 +40,6 @@ local function installOrUpdateServer()
if r.prerelease then if r.prerelease then
r = data[2] r = data[2]
end end
Install = require('Install')
local lspPkgInfo = Install.packageInfo("rust-analyzer") local lspPkgInfo = Install.packageInfo("rust-analyzer")
if not lspPkgInfo or lspPkgInfo.version ~= r.tag_name then if not lspPkgInfo or lspPkgInfo.version ~= r.tag_name then
local osTr = { mac = "apple-darwin", windows = "pc-windows-msvc", linux = "unknown-linux-gnu" } local osTr = { mac = "apple-darwin", windows = "pc-windows-msvc", linux = "unknown-linux-gnu" }
@@ -80,7 +80,7 @@ local function installOrUpdateServer()
binary = "rust-analyzer.exe" binary = "rust-analyzer.exe"
end end
Settings.binary.defaultPath = lspPkgInfo.path:resolvePath(binary) Settings.binary:setValue(lspPkgInfo.path:resolvePath(binary))
Settings:apply() Settings:apply()
return return
end end
@@ -130,8 +130,8 @@ local function layoutSettings()
Settings.binary, br, Settings.binary, br,
Row { Row {
PushButton { PushButton {
text("Try to install Rust language server"), text = "Try to install Rust language server",
onClicked(function() a.sync(installOrUpdateServer)() end), onClicked = function() a.sync(installOrUpdateServer)() end,
br, br,
}, },
st st
@@ -141,6 +141,36 @@ local function layoutSettings()
return layout return layout
end end
local function binaryFromPkg()
local lspPkgInfo = Install.packageInfo("rust-analyzer")
if lspPkgInfo then
local binary = "rust-analyzer"
if Utils.HostOsInfo.isWindowsHost() then
binary = "rust-analyzer.exe"
end
local binaryPath = lspPkgInfo.path:resolvePath(binary)
if binaryPath:isExecutableFile() == true then
return binaryPath
end
end
return nil
end
local function findBinary()
local binary = binaryFromPkg()
if binary then
return binary
end
-- Search for the binary in the PATH
local serverPath = Utils.FilePath.fromUserInput("rust-analyzer")
local absolute = a.wait(serverPath:searchInPath()):resolveSymlinks()
if absolute:isExecutableFile() == true then
return absolute
end
return serverPath
end
local function setupAspect() local function setupAspect()
---@class Settings: AspectContainer ---@class Settings: AspectContainer
Settings = S.AspectContainer.create({ Settings = S.AspectContainer.create({
@@ -154,14 +184,8 @@ local function setupAspect()
labelText = "Binary:", labelText = "Binary:",
toolTip = "The path to the rust analyzer binary.", toolTip = "The path to the rust analyzer binary.",
expectedKind = S.Kind.ExistingCommand, expectedKind = S.Kind.ExistingCommand,
defaultPath = Utils.FilePath.fromUserInput("rust-analyzer"), defaultPath = findBinary(),
}) })
-- Search for the binary in the PATH
local serverPath = Settings.binary.defaultPath
local absolute = a.wait(serverPath:searchInPath()):resolveSymlinks()
if absolute:isExecutableFile() == true then
Settings.binary.defaultPath = absolute
end
return Settings return Settings
end end