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

cleanup save API #180476

Merged
merged 1 commit into from Apr 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 8 additions & 13 deletions src/vs/workbench/api/browser/mainThreadWorkspace.ts
Expand Up @@ -203,25 +203,20 @@ export class MainThreadWorkspace implements MainThreadWorkspaceShape {

// --- save & edit resources ---

async $save(uriComponents: UriComponents): Promise<UriComponents | undefined> {
async $save(uriComponents: UriComponents, options: { saveAs: boolean }): Promise<UriComponents | undefined> {
const uri = URI.revive(uriComponents);

const editors = [...this._editorService.findEditors(uri, { supportSideBySide: SideBySideEditor.PRIMARY })];
const result = await this._editorService.save(editors, { reason: SaveReason.EXPLICIT, force: true /* force save even when non-dirty */ });

return firstOrDefault(this.saveResultToUris(result));
}

async $saveAs(uriComponents: UriComponents): Promise<UriComponents | undefined> {
const uri = URI.revive(uriComponents);

const editors = [...this._editorService.findEditors(uri, { supportSideBySide: SideBySideEditor.PRIMARY })];
const result = await this._editorService.save(editors, { reason: SaveReason.EXPLICIT, saveAs: true });
const result = await this._editorService.save(editors, {
reason: SaveReason.EXPLICIT,
saveAs: options.saveAs,
force: !options.saveAs
});

return firstOrDefault(this.saveResultToUris(result));
return firstOrDefault(this._saveResultToUris(result));
}

private saveResultToUris(result: ISaveEditorsResult): URI[] {
private _saveResultToUris(result: ISaveEditorsResult): URI[] {
if (!result.success) {
return [];
}
Expand Down
3 changes: 1 addition & 2 deletions src/vs/workbench/api/common/extHost.protocol.ts
Expand Up @@ -1169,8 +1169,7 @@ export interface MainThreadWorkspaceShape extends IDisposable {
$startFileSearch(includePattern: string | null, includeFolder: UriComponents | null, excludePatternOrDisregardExcludes: string | false | null, maxResults: number | null, token: CancellationToken): Promise<UriComponents[] | null>;
$startTextSearch(query: search.IPatternInfo, folder: UriComponents | null, options: ITextQueryBuilderOptions, requestId: number, token: CancellationToken): Promise<ITextSearchComplete | null>;
$checkExists(folders: readonly UriComponents[], includes: string[], token: CancellationToken): Promise<boolean>;
$save(uri: UriComponents): Promise<UriComponents | undefined>;
$saveAs(uri: UriComponents): Promise<UriComponents | undefined>;
$save(uri: UriComponents, options: { saveAs: boolean }): Promise<UriComponents | undefined>;
$saveAll(includeUntitled?: boolean): Promise<boolean>;
$updateWorkspaceFolders(extensionName: string, index: number, deleteCount: number, workspaceFoldersToAdd: { uri: UriComponents; name?: string }[]): Promise<void>;
$resolveProxy(url: string): Promise<string | undefined>;
Expand Down
4 changes: 2 additions & 2 deletions src/vs/workbench/api/common/extHostWorkspace.ts
Expand Up @@ -558,13 +558,13 @@ export class ExtHostWorkspace implements ExtHostWorkspaceShape, IExtHostWorkspac
}

async save(uri: URI): Promise<URI | undefined> {
const result = await this._proxy.$save(uri);
const result = await this._proxy.$save(uri, { saveAs: false });

return URI.revive(result);
}

async saveAs(uri: URI): Promise<URI | undefined> {
const result = await this._proxy.$saveAs(uri);
const result = await this._proxy.$save(uri, { saveAs: true });

return URI.revive(result);
}
Expand Down
8 changes: 6 additions & 2 deletions src/vscode-dts/vscode.proposed.saveEditor.d.ts
Expand Up @@ -13,7 +13,9 @@ declare module 'vscode' {
* Saves the editor identified by the given resource and returns the resulting resource or `undefined`
* if save was not successful.
*
* @param uri the associated uri for the editor to save.
* **Note** that an editor with the provided resource must be opened in order to be saved.
*
* @param uri the associated uri for the opened editor to save.
* @return A thenable that resolves when the save operation has finished.
*/
export function save(uri: Uri): Thenable<Uri | undefined>;
Expand All @@ -22,7 +24,9 @@ declare module 'vscode' {
* Saves the editor identified by the given resource to a new file name as provided by the user and
* returns the resulting resource or `undefined` if save was not successful or cancelled.
*
* @param uri the associated uri for the editor to save as.
* **Note** that an editor with the provided resource must be opened in order to be saved as.
*
* @param uri the associated uri for the opened editor to save as.
* @return A thenable that resolves when the save-as operation has finished.
*/
export function saveAs(uri: Uri): Thenable<Uri | undefined>;
Expand Down