@@ -2,14 +2,7 @@ import * as messages from "./pure/messages-shared";
22import * as legacyMessages from "./pure/legacy-messages" ;
33import { DatabaseInfo , QueryMetadata } from "./common/interface-types" ;
44import { join , parse , dirname , basename } from "path" ;
5- import {
6- Range ,
7- TextDocument ,
8- TextEditor ,
9- Uri ,
10- window ,
11- workspace ,
12- } from "vscode" ;
5+ import { Range , TextEditor , Uri , window , workspace } from "vscode" ;
136import { isCanary , VSCODE_SAVE_BEFORE_START_SETTING } from "./config" ;
147import {
158 pathExists ,
@@ -503,61 +496,29 @@ export async function saveBeforeStart(): Promise<void> {
503496 ( VSCODE_SAVE_BEFORE_START_SETTING . getValue < string > ( ) as SaveBeforeStartMode ) ??
504497 "nonUntitledEditorsInActiveGroup" ;
505498
499+ // Despite the names of the modes, the VS Code implementation doesn't restrict itself to the
500+ // current tab group. It saves all dirty files in all groups. We'll do the same.
506501 switch ( mode ) {
507502 case "nonUntitledEditorsInActiveGroup" :
508- await saveAllInGroup ( false ) ;
503+ await workspace . saveAll ( false ) ;
509504 break ;
510505
511506 case "allEditorsInActiveGroup" :
512- await saveAllInGroup ( true ) ;
507+ // The VS Code implementation of this mode only saves an untitled file if it is the document
508+ // in the active editor. That's too much work for us, so we'll just live with the inconsistency.
509+ await workspace . saveAll ( true ) ;
513510 break ;
514511
515512 case "none" :
516513 break ;
517514
518515 default :
519516 // Unexpected value. Fall back to the default behavior.
520- await saveAllInGroup ( false ) ;
517+ await workspace . saveAll ( false ) ;
521518 break ;
522519 }
523520}
524521
525- // Used in tests
526- export async function saveAllInGroup ( includeUntitled : boolean ) : Promise < void > {
527- // There's no good way to get from a `Tab` to a `TextDocument`, so we'll collect all of the dirty
528- // documents indexed by their URI, and then compare those URIs against the URIs of the tabs.
529- const dirtyDocumentUris = new Map < string , TextDocument > ( ) ;
530- for ( const openDocument of workspace . textDocuments ) {
531- if ( openDocument . isDirty ) {
532- console . warn ( `${ openDocument . uri . toString ( ) } is dirty.` ) ;
533- if ( ! openDocument . isUntitled || includeUntitled ) {
534- dirtyDocumentUris . set ( openDocument . uri . toString ( ) , openDocument ) ;
535- }
536- }
537- }
538- if ( dirtyDocumentUris . size > 0 ) {
539- const tabGroup = window . tabGroups . activeTabGroup ;
540- for ( const tab of tabGroup . tabs ) {
541- const input = tab . input ;
542- // The `input` property can be of an arbitrary type, depending on the underlying tab type. For
543- // text editors (and potentially others), it's an object with a `uri` property. That's all we
544- // need to know to match it up with a dirty document.
545- if ( typeof input === "object" ) {
546- const uri = ( input as any ) . uri ;
547- if ( uri instanceof Uri ) {
548- const document = dirtyDocumentUris . get ( uri . toString ( ) ) ;
549- if ( document !== undefined ) {
550- await document . save ( ) ;
551- // Remove the URI from the dirty list so we don't wind up saving the same file twice
552- // if it's open in multiple editors.
553- dirtyDocumentUris . delete ( uri . toString ( ) ) ;
554- }
555- }
556- }
557- }
558- }
559- }
560-
561522/**
562523 * @param filePath This needs to be equivalent to Java's `Path.toRealPath(NO_FOLLOW_LINKS)`
563524 */
0 commit comments