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

[Feature] Multi-Root support #55

Closed
cyraid opened this issue Feb 18, 2024 · 8 comments
Closed

[Feature] Multi-Root support #55

cyraid opened this issue Feb 18, 2024 · 8 comments

Comments

@cyraid
Copy link

cyraid commented Feb 18, 2024

Hi there, I do appreciate the warning of multiple workspaces, but, it would be nice if we could configure the path and rootDir ourselves and use "${workspaceFolder:name}", and binPath would be "${workspaceFolder:name}/vendor/bin/phpstan" etc. But instead when I set rootDir, it shows "/home/user/some/folder/${workspaceFolder:name}" does not exist, and I'm also guessing binPath doesn't scan for the workspace folder either?

@SanderRonde
Copy link
Owner

Hmm I'm not really sure how this would look. The workspaceFolder:name field is not a native-to-vscode variable so it won't do anything unless I implement support for it. (I did at support for just ${workspaceFolder} but that only works in single-workspace configs since it just uses VSCode's workspace variable) In multi-root workspaces this presents two problems:

  • There is no "current" workspace in multi-root configurations
  • If the workspace were to change, the extension would essentially have to reboot because it's not built with the idea that a workspace is not an absolute thing

Could you maybe enter a path to the workspace you want phpstan-linted and save that in the (multi-root) workspace settings? That way it'll only lint a single workspace but will (I think) work.

@cyraid
Copy link
Author

cyraid commented Feb 19, 2024

Sure! I'd be fine for a setting to set the folder path to the one that'll be "stanned", that would be great.

@SanderRonde
Copy link
Owner

You should be able to do that by setting rootDir right? Or does that not work

@cyraid
Copy link
Author

cyraid commented Feb 19, 2024

Nope. It sets whatever I put in there relative to the first workspace. It should be relative to the directory of the workspace root if anything? Ultimately if you supported ${workspace folder:name} would be great too. :)

@SanderRonde
Copy link
Owner

It should be relative to the directory of the workspace root
What is the workspace root in the case of multiple workspaces? Do you mean a sort of shared root between the two of them? If I have the workspaces /home/sander/js-projects/X and /home/sander/php-projects/Y open, what is the workspace root?

I'm not against supporting ${workspace folder:name}, I'm just not really sure what its value would be and how it would work. In the case of a multi-root workspace it can essentially have two values right?

It's indeed correct that it sets whatever is in there relative to the first workspace if it's a relative path, because otherwise it's kind of hard to say "to what" it is relative. It should work with an absolute path though.

@cyraid
Copy link
Author

cyraid commented Feb 19, 2024

I definitely wanna stay away from absolute paths. If the rootDir could be fixed to be relative to the multi-root workspace folder I'm sure that would work too, then I could just put a relative path to the right folder.

In a .code-workspace file, you can add multiple folders (or through the editor). It ends up looking like this:

{
	"folders": [
		{
			"path": "path1"
		},
		{
			"path": "path2"
		},
		{
			"path": "path3"
		}
	],
}

And using ${workspaceFolder:path1} uses the folder for path1 in the folders. :)

As for more information on the topic, going here: https://code.visualstudio.com/docs/editor/variables-reference#_variables-scoped-per-workspace-folder

You can see that:

By appending the root folder's name to a variable (separated by a colon), it is possible to reach into sibling root folders of a workspace. Without the root folder name, the variable is scoped to the same folder where it is used.

For example, in a multi root workspace with folders Server and Client, a ${workspaceFolder:Client} refers to the path of the Client root.

There's also a little more located at: https://code.visualstudio.com/docs/editor/multi-root-workspaces

If you wanna know about the "folders" setting. Thanks for all the help.

@SanderRonde
Copy link
Owner

If the rootDir could be fixed to be relative to the multi-root workspace folder I'm sure that would work too, then I could just put a relative path to the right folder.
What would be the multi-root workspace folder in the case of the example I gave? I still don't really understand this concept.

And using ${workspaceFolder:path1} uses the folder for path1 in the folders. :)
Ahhh I only just understood that you meant for ${workspace folder:name} to actually have the name of a workspace after the colon instead of just the raw string name. Okay that makes more sense. Yeah that should be doable. I've attached a version of the extension that adds support for ${workspaceFolder:name}, can you test that? (I've attached it as a zip file because github doesn't allow attaching of .vsix files, just rename it to that and drop it into your extensiosn panel)

phpstan-vscode-2.2.26.zip

@cyraid
Copy link
Author

cyraid commented Feb 19, 2024

Beautiful! Thanks man. <3

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

2 participants