Vscode: Provide additional workspace API (read / write)

Created on 30 Sep 2017  路  17Comments  路  Source: microsoft/vscode

Today I can call vscode.openFolder to open a folder programmatically:

vscode.commands.executeCommand("vscode.openFolder", vscode.Uri.file(path), false);

However, I would like to be able to do the same thing with the new multi-root workspace and just _add_ a folder to the workspace. Something like this, but where I can pass in a Uri

For more context on our scenario, see @chrisdias's comments on this issue: https://github.com/Microsoft/vscode/issues/13807

NOTE: We realize such a command might restart the extension host, but we don't care if that happens.

api feature-request on-testplan remote workbench-multiroot

Most helpful comment

azure function extension is a good example, it lets you create a new Azure Function "project", which is really just a folder.

So, imagine I have a folder open, my web app called "stickerApp". It could be the only folder open, or it could be a part of a workspace.

image

With the Azure Functions extension I choose to "Create a new Azure Function Project" from the command palette or the explorer commands.

image

This command first prompts me for the folder location in which to scaffold the project:

image

I choose Browse... and get the folder picker:

image

And I pick some new folder called stickerFunctions

The func cli then scaffolds out the new sticker function in the stickerFunctions folder.

At this point I probably want to start working on this function. Ideally it would be added to the explorer as a second top level root node:

image

All 17 comments

fyi @jrieken @sandy081 I guess eventually it would make sense to expose some kind of workspace editing API to extensions.

I like, tho the weird thing we need to communicate is that calling such API might restart the extension itself

The 'openFolder' api has the same behavior and just includes this in the description:

Open a folder in the current window or new window depending on the newWindow argument. Note that opening in the same window will shutdown the current extension host process and start a new one on the given folder unless the newWindow parameter is set to true.

This landed as workspace.addWorkspaceFolder and workspace.removeWorkspaceFolder.

I reverted this change due to https://github.com/Microsoft/vscode/issues/37301

@EricJizbaMSFT as a workaround you could just create a workspace file with the correct set of folders for the user and open that (via vscode.openFolder passing in the path to the workspace file). You could ask the user for a location of that workspace file via the showSaveDialog API and then just create a *.code-workspace file with a content like this:

{
    "folders": [
        {
            "path": "<either relative path to the workspace file>"
        },
        {
            "path": "<or an absolute path>"
        }
    ],
    "settings": {}
}

I hope that workspace.addWorkspaceFolder will come back. I'm working on an extension that would allow to open .zip files as workspace folders, along with using proposed api FileSystemProvider.

Creating a workspace file and opening it is not really an option here.

@bpasero, what about vscode.workspace.path/vscode.workspace.uri too? I mean, we have the uri for each folder in a workspace, but not for the workspace itself.

I would love to have this, so I could update my Project Manager extension and add workspaces as favorite projects, just like regular folders.

Thanks

@alefragnani I extracted that particular request to https://github.com/Microsoft/vscode/issues/37421

@stef-levesque we are still in discussion how to best do the API, it might need another iteration.

The splice'ish solution works for me, it easily cover most cases (add, delete, insert)

Except moving order? Not a show-stopper though.

@stef-levesque reordering would be possible via add & remove as well

Is closing a workspace going to close all related TextDocument ?

@stef-levesque no, closing a workspace is currently not closing any documents.

@bpasero any update on this? I see the api was removed because of https://github.com/Microsoft/vscode/issues/37301, but we don't need all of the functionality listed in that. We just want a single command to add a folder to a workspace. If 'remove' and 'insert' are blocking 'add', can we save those for later?

@EricJizbaMSFT no update so far other than this is "on deck" so it will happen eventually. Please talk to @egamma or @kieferrm to put some pressure on this if this must happen at a specific time and thus have it planned for an iteration.

@EricJizbaMSFT can you share more details on your scenario of adding a workspace folder from an extension?

azure function extension is a good example, it lets you create a new Azure Function "project", which is really just a folder.

So, imagine I have a folder open, my web app called "stickerApp". It could be the only folder open, or it could be a part of a workspace.

image

With the Azure Functions extension I choose to "Create a new Azure Function Project" from the command palette or the explorer commands.

image

This command first prompts me for the folder location in which to scaffold the project:

image

I choose Browse... and get the folder picker:

image

And I pick some new folder called stickerFunctions

The func cli then scaffolds out the new sticker function in the stickerFunctions folder.

At this point I probably want to start working on this function. Ideally it would be added to the explorer as a second top level root node:

image

Was this page helpful?
0 / 5 - 0 ratings

Related issues

v-pavanp picture v-pavanp  路  3Comments

omidgolparvar picture omidgolparvar  路  3Comments

trstringer picture trstringer  路  3Comments

DovydasNavickas picture DovydasNavickas  路  3Comments

lukehoban picture lukehoban  路  3Comments