Addon manager takes wrong path when using Lua.addonManager.repositoryPath
How are you using the lua-language-server?
Visual Studio Code Extension (sumneko.lua)
Which OS are you using?
Windows
What is the issue affecting?
Libraries
Expected Behaviour
I expect it works with custom repository addons (workspaceStorage)
Actual Behaviour
It works with official repository addons (globalStorage)
important note: I copied the files from "workspaceStorage" to "globalStorage" to illustrate the problem. Without this, the custom library will not activate.
Reproduction steps
- Go to 'settings', search for 'Lua.addonManager.repositoryPath'
- Type 'https://github.com/antim0118/LLS-Addons-LPYT'
- Open 'Addon manager'
- Activate any custom addon
- Nothing happens (because it tries to find the addon in globalStorage folder)
Additional Notes
No response
Log File
From the logic of LuaLS addon manager: https://github.com/LuaLS/vscode-lua/blob/9e91c07ce7b3b9fa162763b0eb7d39cf90033798/client/src/addon_manager/registration.ts#L35-L39
- when
repositoryPathorrepositoryBranch(at least one) is set - it will use
context.storageUri(which isworkspaceStorageI believe?) instead ofcontext.globalStorageUri
if ((repositoryPath || repositoryBranch) && context.storageUri) {
REPOSITORY.PATH = !!repositoryPath ? repositoryPath : REPOSITORY.PATH
REPOSITORY.DEFAULT_BRANCH = !!repositoryBranch ? repositoryBranch : REPOSITORY.DEFAULT_BRANCH
setGlobalStorageUri(false)
}
however ...
the client extension always just send context.globalStorageUri as the storagePath to server
https://github.com/LuaLS/vscode-lua/blob/9e91c07ce7b3b9fa162763b0eb7d39cf90033798/client/src/languageserver.ts#L149-L159
initializationOptions: {
changeConfiguration: true,
statusBar: true,
viewDocument: true,
trustByClient: true,
useSemanticByRange: true,
codeLensViewReferences: true,
fixIndents: true,
languageConfiguration: true,
storagePath: this.context.globalStorageUri.fsPath,
},
and then ...
When server side is parsing ${addon}, it would find that client.getOption("storagePath") => is the global storage uri 😇
https://github.com/LuaLS/lua-language-server/blob/c2b282673c5a62a3225cd476087f1267bec08e49/script/files.lua#L930-L944
So this seems to be a bug in the client side extension 🤔 not server
The client should send the storagePath option using the getStorageUri() from addon_manager/config I believe?
https://github.com/LuaLS/vscode-lua/blob/9e91c07ce7b3b9fa162763b0eb7d39cf90033798/client/src/addon_manager/config.ts#L27-L30
let useGlobal = true
export function getStorageUri(context: vscode.ExtensionContext) {
return useGlobal ? context.globalStorageUri : (context.storageUri ?? context.globalStorageUri)
}
edit
The client should send the
storagePathoption using thegetStorageUri()fromaddon_manager/configI believe?
seems this approach doesn't work...
when the server is being initialized, the useGlobal var is still true
(it seems to be modified lately during the registration.ts of addon manager)
=> causing it to return the global storage uri to server at the beginning 😇 😇
I think I found a fix for it 🤔 (though I am not sure if it will cause any other side effects or not)
- Besides editing client/src/languageserver.ts to use
getStorageUri()from./addon_manager/config
import { getStorageUri } from "./addon_manager/config";
...
initializationOptions: {
...
storagePath: getStorageUri(this.context).fsPath,
},
- the addon manager needs to be activated first in client/src/extensions.ts before the languageserver, in order to initialize that
useGlobalvar beforehand.
export function activate(context: vscode.ExtensionContext) {
// Register and activate addon manager first to initialize storagePath
addonManager.activate(context);
languageserver.activate(context);
...
I tested by modifying the local transpiled js extension files and it seems to work 👀 You might want to open a PR in https://github.com/LuaLS/vscode-lua after testing it 😄