cleanup save API (#180476)

This commit is contained in:
Benjamin Pasero
2023-04-21 09:04:32 +02:00
committed by GitHub
parent 3fedc560a1
commit cd79fe9f27
4 changed files with 17 additions and 19 deletions
@@ -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 */ });
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));
}
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 });
return firstOrDefault(this.saveResultToUris(result));
}
private saveResultToUris(result: ISaveEditorsResult): URI[] {
private _saveResultToUris(result: ISaveEditorsResult): URI[] {
if (!result.success) {
return [];
}
@@ -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>;
@@ -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);
}
+6 -2
View File
@@ -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>;
@@ -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>;