-
Notifications
You must be signed in to change notification settings - Fork 30.1k
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
Conversation
src/vs/vscode.d.ts
Outdated
* | ||
* @param folders a list of workspace folders to add. | ||
*/ | ||
export function addWorkspaceFolders(folders: { uri: Uri, name?: string }[]): Thenable<void>; |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed via 158d152
src/vs/vscode.d.ts
Outdated
* | ||
* @param folders a list of [workspace folders](#WorkspaceFolder) to remove. | ||
*/ | ||
export function removeWorkspaceFolders(folders: WorkspaceFolder[]): Thenable<void>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same, N vs 1
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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: 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. |
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? |
src/vs/vscode.d.ts
Outdated
@@ -5211,6 +5211,34 @@ declare module 'vscode' { | |||
export const onDidChangeWorkspaceFolders: Event<WorkspaceFoldersChangeEvent>; | |||
|
|||
/** | |||
* Adds a workspac folder to the currently opened workspace. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
e
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
via 95eccd6
@jrieken the The "Canceled" error seems to originate from |
Give as we doing and I'll. |
Don't we handle those standard-cancellation-errors everywhere? And by "handle" I meaning "ignore"? |
Added the confirm dialog via 42e6cd5 with a new setting |
…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
@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: