-
Notifications
You must be signed in to change notification settings - Fork 30k
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
Provide API to get access to the workspace configuration file #37421
Comments
@alefragnani I think what I would like to avoid is that people just open that file and write into it arbitrary data. So if possible I would like to not expose the raw path. If this is only about being able to open a workspace again that was opened before we should maybe introduce some other identifier that we understand how to open. |
I understand that it is dangerous, but people already have access to that file, because they can use However, I would need to two new APIs, based on this identifier:
Thanks in advance |
@alefragnani access via the settings API is fine imho because there we open the file for a specific purpose: adding settings. What I would want to avoid is that extensions introduce a new root-level node in that file for their own metadata (this happened in the past when extensions suddenly added files into the .vscode folder that is local to a workspace). Your requirements make good sense to me 👍 |
Hi @bpasero , Any plans about this request? I see some improvements in Workspaces API in the latest VS Code releases and was wondering when I could see something like Thanks in advance |
I would also like an API for this, for basically the same use case as @alefragnani.
VSC could just remove extra root nodes automatically. The lack of an API for getting the path to this file doesn't really prevent people from manually adding those root nodes, for whatever reason they might want to do so.
I think this is fine, I do it for some of my extensions too. It makes their configurations easier to edit (#41040 (comment)) and amazingly using separate files for configuration kept them working even in multi-root workspaces (#47995). |
My current idea in 96a2358 API: export namespace workspace {
/**
* The location of the workspace. `undefined` when no folder
* has been opened.
*/
export const uri: Uri | undefined;
} This will be:
The idea is that you can pass Thoughts? |
@bpasero Shouldn't it always return the path to the relevant configuration file so that it returns |
@bpasero just to be clear, when you say the location of the workspace file it means the location of the That sounds perfect to me 👍 |
@fabiospampinato that is an interesting thought but would turn around this feature to something else I would argue. What is the use case for knowing the location of the settings file for the workspace given you can use the configuration APIs to add content to it? @alefragnani here is an example depending on what is opened:
|
@bpasero That's great! I understand an unsaved multi-root window to be |
@bpasero I've added my comment partially because this issue is named "Provide API to get access to the workspace configuration file", and I'd say the path to the
Those project management extensions need to know the path to the I suppose the proposed |
@alefragnani that is a good point, I forgot to handle that case. Given that, I wonder if this new API should be strictly for workspace files only that are not untitled. Then the name should probably change too, to make that clear. I will bring this up in our API discussion call next week. @fabiospampinato the title of this issue is misleading, I never meant to return the I think we should make very clear what the intent of the API is: to be able to build a list of recently opened workspaces and open them again. NOT to provide access to the underlying JSON file of workspace settings in general. |
Pushed an update and this is now how it behaves: export namespace workspace {
/**
* The location of the workspace. Depending on the workspace that
* is opened, the value will be:
* * `undefined` when no workspace or folder is opened
* * `undefined` when an untitled workspace is opened
* * the path of the folder as `Uri` if a single folder is opened
* * the path of the workspace file as `Uri` if a workspace is opened
*
* The location can e.g. be used with the `vscode.openFolder` command to
* open the workspace again after it has been closed.
*
* **Example:**
* ```typescript
* vscode.commands.executeCommand('vscode.openFolder', uriOfWorkspace);
* ```
*
* **Note:** it is not advised to use `workspace.uri` to write configuration
* data into the file. You can use `workspace.getConfiguration().update()`
* for that purpose which will work both when a single folder is opened as
* well as an untitled or saved workspace.
*/
export const uri: Uri | undefined;
} Up for debate:
|
It could be Edit: Maybe not and it might be confusing to overload this single folder cases. So, I think a better idea would be have this value defined only when opening a workspace (e.g. no folder) and to have a better name reflecting that, maybe |
Summary from the API sync:
|
@jrieken to clarify, the suggested name is I can look into supporting untitled, though this can be weird because we always reopen untitled workspaces and they quickly get deleted when you close the window. For an extension that wants to build a list of recently opened this could be frustrating, especially since we do not really provide a method to test if the workspace is untitled or not (though you could check by the file name). |
PR: #72490 |
Landed as proposed: export namespace workspace {
/**
* The location of the workspace file, for example:
*
* file:///Users/name/Development/myProject.code-workspace`
*
* or
*
* `untitled:1555503116870`
*
* for a workspace that is untitled and not yet saved.
*
* Depending on the workspace that is opened, the value will be:
* * `undefined` when no workspace or a single folder is opened
* * the path of the workspace file as `Uri` otherwise. if the workspace
* is untitled, the returned URI will use the `untitled:` scheme
*
* The location can e.g. be used with the `vscode.openFolder` command to
* open the workspace again after it has been closed.
*
* **Example:**
*
* vscode.commands.executeCommand('vscode.openFolder', uriOfWorkspace);
*
*
* **Note:** it is not advised to use `workspace.workspaceFile` to write
* configuration data into the file. You can use `workspace.getConfiguration().update()`
* for that purpose which will work both when a single folder is opened as
* well as an untitled or saved workspace.
*/
export const workspaceFile: Uri | undefined;
} |
The plan is to move the API out of proposed state for this milestone. See #76469 |
Extracted from #35407
The text was updated successfully, but these errors were encountered: