@@ -4,17 +4,19 @@ import { AtelierAPI } from "../api";
44import { config , explorerProvider , OBJECTSCRIPT_FILE_SCHEMA , schemas , workspaceState } from "../extension" ;
55import {
66 currentFile ,
7- currentFileFromContent ,
87 exportedUris ,
98 handleError ,
9+ isClassOrRtn ,
1010 notNull ,
1111 outputChannel ,
12+ RateLimiter ,
1213 stringifyError ,
13- throttleRequests ,
1414 uriOfWorkspaceFolder ,
15+ workspaceFolderOfUri ,
1516} from "../utils" ;
1617import { pickDocuments } from "../utils/documentPicker" ;
1718import { NodeBase } from "../explorer/nodes" ;
19+ import { updateIndexForDocument } from "../utils/documentIndex" ;
1820
1921export function getCategory ( fileName : string , addCategory : any | boolean ) : string {
2022 const fileExt = fileName . split ( "." ) . pop ( ) . toLowerCase ( ) ;
@@ -99,28 +101,19 @@ async function exportFile(wsFolderUri: vscode.Uri, namespace: string, name: stri
99101 throw new Error ( "Received malformed JSON object from server fetching document" ) ;
100102 }
101103 const content = data . result . content ;
102-
103- // Local function to update local record of mtime
104- const recordMtime = async ( ) => {
105- const contentString = Buffer . isBuffer ( content ) ? "" : content . join ( "\n" ) ;
106- const file = currentFileFromContent ( fileUri , contentString ) ;
107- const serverTime = Number ( new Date ( data . result . ts + "Z" ) ) ;
108- await workspaceState . update ( `${ file . uniqueId } :mtime` , serverTime ) ;
109- } ;
110- if ( Buffer . isBuffer ( content ) ) {
111- // This is a binary file
112- await vscode . workspace . fs . writeFile ( fileUri , content ) ;
113- exportedUris . push ( fileUri . toString ( ) ) ;
114- await recordMtime ( ) ;
115- log ( "Success" ) ;
116- } else {
117- // This is a text file
118- const joinedContent = content . join ( "\n" ) ;
119- await vscode . workspace . fs . writeFile ( fileUri , new TextEncoder ( ) . encode ( joinedContent ) ) ;
120- exportedUris . push ( fileUri . toString ( ) ) ;
121- await recordMtime ( ) ;
122- log ( "Success" ) ;
104+ await vscode . workspace . fs . writeFile (
105+ fileUri ,
106+ Buffer . isBuffer ( content ) ? content : new TextEncoder ( ) . encode ( content . join ( "\n" ) )
107+ ) ;
108+ if ( isClassOrRtn ( fileUri ) ) {
109+ // Update the document index
110+ updateIndexForDocument ( fileUri , undefined , undefined , content ) ;
123111 }
112+ exportedUris . push ( fileUri . toString ( ) ) ;
113+ const ws = workspaceFolderOfUri ( fileUri ) ;
114+ const mtime = Number ( new Date ( data . result . ts + "Z" ) ) ;
115+ if ( ws ) await workspaceState . update ( `${ ws } :${ name } :mtime` , mtime > 0 ? mtime : undefined ) ;
116+ log ( "Success" ) ;
124117 } catch ( error ) {
125118 const errorStr = stringifyError ( error ) ;
126119 log ( errorStr == "" ? "ERROR" : errorStr ) ;
@@ -146,6 +139,7 @@ export async function exportList(files: string[], workspaceFolder: string, names
146139 const { atelier, folder, addCategory, map } = config ( "export" , workspaceFolder ) ;
147140 const root = wsFolderUri . fsPath + ( folder . length ? path . sep + folder : "" ) ;
148141 outputChannel . show ( true ) ;
142+ const rateLimiter = new RateLimiter ( 50 ) ;
149143 return vscode . window . withProgress (
150144 {
151145 title : `Exporting ${ files . length == 1 ? files [ 0 ] : files . length + " documents" } ` ,
@@ -154,8 +148,8 @@ export async function exportList(files: string[], workspaceFolder: string, names
154148 } ,
155149 ( ) =>
156150 Promise . allSettled < void > (
157- files . map (
158- throttleRequests ( ( file : string ) =>
151+ files . map ( ( file ) =>
152+ rateLimiter . call ( ( ) =>
159153 exportFile ( wsFolderUri , namespace , file , getFileName ( root , file , atelier , addCategory , map ) )
160154 )
161155 )
0 commit comments