Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[VS Code] Cannot use scoped workspace folder variables in multiroot workspaces to define paths #2987

Open
dljsjr opened this issue Dec 11, 2024 · 3 comments

Comments

@dljsjr
Copy link

dljsjr commented Dec 11, 2024

How are you using the lua-language-server?

Visual Studio Code Extension (sumneko.lua)

Which OS are you using?

Linux

What is the issue affecting?

Other

Expected Behaviour

It should be possible to configure the Lua.runtime.path and Lua.workspace.library, and other file path related options in a multi-root workspace using scoped workspace folder variables.


Additional Information

Take the following multi-root workspace JSON, for example:

{
  "folders": [
    {
      "name": "projectFoo",
      "path": "/home/dstephen/AppProject/foo"
    },
    {
      "name": "projectBar",
      "path": "/home/dstephen/LibProject/bar"
    }
  ]
}

We have two projects in two totally different directory trees that are part of the same workspace, one of which is a "library".

Furthermore, let's assume that the workspace .json file is in a completely separate, third directory tree.

VS Code provides workspace folder scoping via the syntax ${workspaceFolder:} and the value in the name field after the colon (or the basename of the path as a fallback).

Given all of this, I would expect to be able to do the following:

{
  "folders": [
    {
      "name": "projectFoo",
      "path": "/home/dstephen/AppProject/foo"
    },
    {
      "name": "projectBar",
      "path": "/home/dstephen/LibProject/bar"
    }
  ],
  "settings": {
    "Lua.runtime.path": [
      "?.lua",
      "?/init.lua",
      "${workspaceFolder:projectBar}/?.lua",
      "${workspaceFolder:projectBar}/?/init.lua"
    ],
    // and/or:
    "Lua.workspace.library": [
      "${workspaceFolder:projectBar}"
    ]
  }
}

However, this doesn't seem to work; the only way to work around this is to use absolute paths for the language server configurations.

Actual Behaviour

Files that should be resolved at require time in the referenced directories are not resolved when workspace folder scoped variables are used

Reproduction steps

See the context/explanation in Expected Behavior

Additional Notes

No response

Log File

No response

@tomlau10
Copy link
Contributor

I just come across some usage of multi-root workspace in vscode.
And I found out that variable substitution is only supported in launch.json and task.json, but not in a .code-workspace file.

https://code.visualstudio.com/docs/editor/variables-reference

Visual Studio Code supports variable substitution in Debugging and Task configuration files as well as some select settings. Variable substitution is supported inside some key and value strings in launch.json and tasks.json files using ${variableName} syntax.

A vscode ticket is tracking this feature request: microsoft/vscode#44755


In short, variable substitution is the responsibility of vscode instead of luals, and seems it is unsupported right now ☹️

@vhenriet-sfy
Copy link

I think the feature request is more related to this ticket: microsoft/vscode#2809.

I doubt this feature will ever be implemented, as there have already been attempts at pull requests, and one of the reasons for rejection is that it breaks existing functionality. Many plugins already handle variable resolution on their own.

Would it be acceptable to implement variable resolution in luals?

@tomlau10
Copy link
Contributor

Would it be acceptable to implement variable resolution in luals?

(First thing first, I am not maintainer, so my understanding may not be fully correct.)

There is already a limited variable resolution in luals, in particular the ${env:ENV_VAR} syntax: #2139 (comment)
Seems that more resolution logic / handling maybe added there 🤔


I tried to create a dummy workspace json with content similar to to above example:

{
	"folders": [
		{
			"name": "root",
			"path": "."
		},
		{
			"name": "client",
			"path": "client"
		},
		{
			"name": "server",
			"path": "server"
		}
	],
	"settings": {
		"Lua.workspace.library": [
			"${workspaceFolder:client}",
		]
	}
}

and from the luals log file, the client has sent the followings to server:

  workspaceFolders = { {
      name = "root",
      uri = "file:///c%3A/Users/TomLau/test"
    }, {
      name = "client",
      uri = "file:///c%3A/Users/TomLau/test/client"
    }, {
      name = "server",
      uri = "file:///c%3A/Users/TomLau/test/server"
    } }

=> so I believe it is possible for luals to know the mapping between workspace names and paths

And finally we have to add some extra resolution logic here:

elseif key:sub(1, 4) == "env:" then
local env = os.getenv(key:sub(5))
return env
end

(some more elseif I believe)

  • currently without extra handling, the key can already be correctly identified as "workspaceFolder:client"
    => we just need some extra logic to resolve it maybe?
    • like supporting solely workspaceFolder
    • and if there is a :, then we need to map the scope name to the actual path, using the mapping mentioned above
    • otherwise just leave it be if the server cannot resolve it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants