lua-language-server icon indicating copy to clipboard operation
lua-language-server copied to clipboard

Addon manager takes wrong path when using Lua.addonManager.repositoryPath

Open antim0118 opened this issue 6 months ago • 2 comments

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)

Image

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.

Image

Reproduction steps

  1. Go to 'settings', search for 'Lua.addonManager.repositoryPath'
  2. Type 'https://github.com/antim0118/LLS-Addons-LPYT'
  3. Open 'Addon manager'
  4. Activate any custom addon
  5. Nothing happens (because it tries to find the addon in globalStorage folder)

Additional Notes

No response

Log File

Log file

antim0118 avatar Jul 16 '25 03:07 antim0118

From the logic of LuaLS addon manager: https://github.com/LuaLS/vscode-lua/blob/9e91c07ce7b3b9fa162763b0eb7d39cf90033798/client/src/addon_manager/registration.ts#L35-L39

  • when repositoryPath or repositoryBranch (at least one) is set
  • it will use context.storageUri (which is workspaceStorage I believe?) instead of context.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 storagePath option using the getStorageUri() from addon_manager/config I 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 😇 😇

tomlau10 avatar Jul 16 '25 15:07 tomlau10

I think I found a fix for it 🤔 (though I am not sure if it will cause any other side effects or not)

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 useGlobal var 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 😄

Image Image

tomlau10 avatar Jul 19 '25 02:07 tomlau10