@@ -118,86 +118,91 @@ export async function importFile(
118118 mtime < 0 ||
119119 ( notIsfs ( file . uri ) &&
120120 vscode . workspace . getConfiguration ( "objectscript" , file . uri ) . get < boolean > ( "overwriteServerChanges" ) ) ;
121- try {
122- const data = await api . putDoc (
121+ return api
122+ . putDoc (
123123 file . name ,
124124 {
125125 content,
126126 enc,
127127 mtime,
128128 } ,
129129 ignoreConflict
130- ) ;
131- workspaceState . update ( `${ file . uniqueId } :mtime` , Number ( new Date ( data . result . ts + "Z" ) ) ) ;
132- if ( ! willCompile && isClass ( file . name ) && data . result . content . length ) {
133- // In this case, the file must be a CLS and data.result.content must be the new Storage definitions
134- // (with the rest of the class if flags === 0)
135- const oldContent = new TextDecoder ( ) . decode ( await vscode . workspace . fs . readFile ( file . uri ) ) ;
136- const oldContentArray = oldContent . split ( / \r ? \n / ) ;
137- const storage = Buffer . isBuffer ( data . result . content )
138- ? new TextDecoder ( ) . decode ( data . result . content ) . split ( / \r ? \n / )
139- : data . result . content ;
140- const newContentArray = updateStorage ( oldContentArray , storage ) ;
141- if ( oldContentArray . some ( ( oldLine , index ) => oldLine !== newContentArray [ index ] ) ) {
142- const EOL = ( ( < CurrentTextFile > file ) ?. eol ?? vscode . EndOfLine . LF ) == vscode . EndOfLine . CRLF ? "\r\n" : "\n" ;
143- const newContent = newContentArray . join ( EOL ) ;
144- await vscode . workspace . fs . writeFile ( file . uri , new TextEncoder ( ) . encode ( newContent ) ) ;
145- }
146- }
147- // In case another extension has used an 'objectscript://' uri to load a document read-only from the server,
148- // make it reload with what we just imported to the server.
149- const serverUri = DocumentContentProvider . getUri (
150- file . name ,
151- file . workspaceFolder ,
152- undefined ,
153- false ,
154- undefined ,
155- true
156- ) ;
157- documentContentProvider . update ( serverUri . with ( { scheme : OBJECTSCRIPT_FILE_SCHEMA } ) ) ;
158- return ;
159- } catch ( error ) {
160- if ( error ?. statusCode == 409 ) {
161- const choices : string [ ] = [ ] ;
162- if ( ! enc ) {
163- choices . push ( "Compare" ) ;
130+ )
131+ . then ( ( data ) => {
132+ // Update cache entry
133+ workspaceState . update ( `${ file . uniqueId } :mtime` , Number ( new Date ( data . result . ts + "Z" ) ) ) ;
134+
135+ if ( ! willCompile && isClass ( file . name ) && data . result . content . length ) {
136+ // In this case, the file must be a CLS and data.result.content must be the new Storage definitions
137+ // (with the rest of the class if flags === 0)
138+ const oldContent = new TextDecoder ( ) . decode ( await vscode . workspace . fs . readFile ( file . uri ) ) ;
139+ const oldContentArray = oldContent . split ( / \r ? \n / ) ;
140+ const storage = Buffer . isBuffer ( data . result . content )
141+ ? new TextDecoder ( ) . decode ( data . result . content ) . split ( / \r ? \n / )
142+ : data . result . content ;
143+ const newContentArray = updateStorage ( oldContentArray , storage ) ;
144+ if ( oldContentArray . some ( ( oldLine , index ) => oldLine !== newContentArray [ index ] ) ) {
145+ const EOL = ( ( < CurrentTextFile > file ) ?. eol ?? vscode . EndOfLine . LF ) == vscode . EndOfLine . CRLF ? "\r\n" : "\n" ;
146+ const newContent = newContentArray . join ( EOL ) ;
147+ await vscode . workspace . fs . writeFile ( file . uri , new TextEncoder ( ) . encode ( newContent ) ) ;
148+ }
164149 }
165- choices . push ( "Overwrite on Server" , "Pull Server Changes" , "Cancel" ) ;
166- const action = await vscode . window . showErrorMessage (
167- `Failed to import '${ file . name } ': The version of the file on the server is newer.
168- What do you want to do?` ,
169- ...choices
150+ // In case another extension has used an 'objectscript://' uri to load a document read-only from the server,
151+ // make it reload with what we just imported to the server.
152+ const serverUri = DocumentContentProvider . getUri (
153+ file . name ,
154+ file . workspaceFolder ,
155+ undefined ,
156+ false ,
157+ undefined ,
158+ true
170159 ) ;
171- switch ( action ) {
172- case "Compare" :
173- await vscode . commands . executeCommand (
174- "vscode.diff" ,
175- vscode . Uri . file ( file . name ) . with ( {
176- scheme : OBJECTSCRIPT_FILE_SCHEMA ,
177- authority : file . workspaceFolder ,
178- query : file . name . includes ( "/" ) ? "csp" : "" ,
179- } ) ,
180- file . uri ,
181- `Server • ${ file . name } ↔ Local • ${ file . fileName } `
182- ) ;
183- return Promise . reject ( ) ;
184- case "Overwrite on Server" :
185- // Clear cache entry
186- workspaceState . update ( `${ file . uniqueId } :mtime` , undefined ) ;
187- // Overwrite
188- return importFile ( file , willCompile , true , true ) ;
189- case "Pull Server Changes" :
190- loadChanges ( [ file ] ) ;
191- return Promise . reject ( ) ;
192- case "Cancel" :
193- return Promise . reject ( ) ;
160+ documentContentProvider . update ( serverUri . with ( { scheme : OBJECTSCRIPT_FILE_SCHEMA } ) ) ;
161+ return ;
162+ } )
163+ . catch ( ( error ) => {
164+ if ( error ?. statusCode == 409 ) {
165+ const choices : string [ ] = [ ] ;
166+ if ( ! enc ) {
167+ choices . push ( "Compare" ) ;
168+ }
169+ choices . push ( "Overwrite on Server" , "Pull Server Changes" , "Cancel" ) ;
170+ const action = await vscode . window . showErrorMessage (
171+ `Failed to import '${ file . name } ': The version of the file on the server is newer.
172+ What do you want to do?` ,
173+ ...choices
174+ ) ;
175+ switch ( action ) {
176+ case "Compare" :
177+ return vscode . commands
178+ . executeCommand (
179+ "vscode.diff" ,
180+ vscode . Uri . file ( file . name ) . with ( {
181+ scheme : OBJECTSCRIPT_FILE_SCHEMA ,
182+ authority : file . workspaceFolder ,
183+ query : file . name . includes ( "/" ) ? "csp" : "" ,
184+ } ) ,
185+ file . uri ,
186+ `Server • ${ file . name } ↔ Local • ${ file . fileName } `
187+ )
188+ . then ( ( ) => Promise . reject ( ) ) ;
189+ case "Overwrite on Server" :
190+ // Clear cache entry
191+ workspaceState . update ( `${ file . uniqueId } :mtime` , undefined ) ;
192+ // Overwrite
193+ return importFile ( file , willCompile , true , true ) ;
194+ case "Pull Server Changes" :
195+ loadChanges ( [ file ] ) ;
196+ return Promise . reject ( ) ;
197+ case "Cancel" :
198+ return Promise . reject ( ) ;
199+ }
200+ return Promise . reject ( ) ;
201+ } else {
202+ handleError ( error , `Failed to save file '${ file . name } ' on the server.` ) ;
203+ return Promise . reject ( ) ;
194204 }
195- return Promise . reject ( ) ;
196- } else {
197- handleError ( error , `Failed to save file '${ file . name } ' on the server.` ) ;
198- return Promise . reject ( ) ;
199- }
200- }
205+ } ) ;
201206}
202207
203208function updateOthers ( others : string [ ] , baseUri : vscode . Uri ) {
0 commit comments