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

Provide additional workspace API to add/remove workspace folders (for #35407) #36820

Merged
merged 9 commits into from
Oct 30, 2017

Conversation

bpasero
Copy link
Member

@bpasero bpasero commented Oct 24, 2017

@jrieken here is the suggested API for adding/removing workspace folders, feedback welcome.

Note that I am still planning to tackle 2 outstanding issues independent of this PR to keep the discussion on the API shape only:

  • when removing a workspace folder from a single-folder workspace, we should probably turn the workspace into an empty one (same as File > Close Folder)
  • when adding a workspace folder while you are in empty/single-folder workspace we should transition into a workspace (same as we do today via File > Add Folder To Workspace...).

@bpasero bpasero added this to the October 2017 milestone Oct 24, 2017
@bpasero bpasero requested a review from jrieken October 24, 2017 12:45
*
* @param folders a list of workspace folders to add.
*/
export function addWorkspaceFolders(folders: { uri: Uri, name?: string }[]): Thenable<void>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is adding many folders at once really a use-case? I'd expect this to be called for single folders in 99% of the cases. My proposal would be function addWorkspaceFolder(uri: Uri, name?: string)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed via 158d152

*
* @param folders a list of [workspace folders](#WorkspaceFolder) to remove.
*/
export function removeWorkspaceFolders(folders: WorkspaceFolder[]): Thenable<void>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same, N vs 1

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed via 158d152

@@ -78,6 +78,17 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape {
}
}

addWorkspaceFolders(folders: { uri: URI, name?: string }[]): Thenable<void> {
return this._proxy.$addFolders(folders);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not yet decided if those changes should be reflected sync... We do that in some place, e.g the editor or Memento#update, where we assume optimistically that the change is good, then send to the main side which might cause another change... Needs some thinking.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrieken well in some of the cases this action will result in the extension host restarting, so in that case it does not really matter. For the other case of an already opened workspace, I think even with the current promise chaining there is a chance that the onDidChangeWorkspaceFolders has not yet fired when the method returns.

What is your suggestion?


removeWorkspaceFolder(folder: vscode.WorkspaceFolder): Thenable<void> {
if (this.getWorkspaceFolders().indexOf(folder) === -1) {
return Promise.resolve(undefined);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe make this return a boolean to indicate success/failure. Might also be useful when having a user-confirmation in between. Then false could also mean blocked by the user

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jrieken yeah added via 1dc821b

@bpasero
Copy link
Member Author

bpasero commented Oct 26, 2017

@jrieken the corner cases are now covered such as the API call will work in any workspace state (empty workspace, single-folder or multi-root workspace).

There is one remaining issue (related to your comment about running this sync or not): When the extension host needs to be restarted as a matter of the call (this can happen when adding a root folder while either no workspace is opened or when a single-folder is opened), the extension host goes down while executing the request and the result is an ugly error message:

image

The only way how to prevent this message is to run the workspace edit operation in a timeout and return to the extension directly without executing and waiting for the operation to be finished.

Undecided what to do here, I feel that executing the command sync and waiting for it is correct and we should maybe add code to not show this error message in that case.

@jrieken
Copy link
Member

jrieken commented Oct 26, 2017

workspace edit operation in a timeout and return to the extension directly without executing and waiting for the operation to be finished.

Not nice... In the does-not-need-to-restart case we should ensure that the workspace change event happened in-between making the call and resolving the promise. Timeout-trick will likely break that. What of the call is causing the cancel-error? Is this us calling back to the extension host?

@@ -5211,6 +5211,34 @@ declare module 'vscode' {
export const onDidChangeWorkspaceFolders: Event<WorkspaceFoldersChangeEvent>;

/**
* Adds a workspac folder to the currently opened workspace.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

e

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

via 95eccd6

@bpasero
Copy link
Member Author

bpasero commented Oct 26, 2017

@jrieken the onDidChangeWorkspaceFolders is firing before the method returns with the current code. Agree that a timeout is just ugly.

The "Canceled" error seems to originate from rpcProtocol#dispose().

image

@HutzlerGregg
Copy link

Give as we doing and I'll.

@jrieken
Copy link
Member

jrieken commented Oct 27, 2017

The "Canceled" error seems to originate from rpcProtocol#dispose().

Don't we handle those standard-cancellation-errors everywhere? And by "handle" I meaning "ignore"?

@bpasero
Copy link
Member Author

bpasero commented Oct 30, 2017

@jrieken yeah looks like the commands list was not checking for that, I added it via 48c4511

Can we merge this in so that we have it for October or do you want more changes? I was still planning to look into the confirmation dialog thing but can do that outside of this PR.

@bpasero
Copy link
Member Author

bpasero commented Oct 30, 2017

Added the confirm dialog via 42e6cd5 with a new setting workbench.confirmChangesToWorkspaceFromExtensions.

image

@bpasero bpasero merged commit 80ece09 into master Oct 30, 2017
@bpasero bpasero deleted the ben/35407 branch October 30, 2017 13:49
egamma pushed a commit that referenced this pull request Oct 31, 2017
…35407) (#36820)

* Provide additional workspace API to add/remove workspace folders (for #35407)

* add/removeFolders => add/removeFolder

* make add/remove folder return a boolean

* use proper service for workspace editing

* workspac => workspace

* do not log promise canceled messages

* show confirm dialog
@github-actions github-actions bot locked and limited conversation to collaborators Mar 29, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants