@@ -11,6 +11,7 @@ import {
1111 notIsfs ,
1212 openLowCodeEditors ,
1313 outputChannel ,
14+ displayableUri ,
1415} from "." ;
1516import { isText } from "istextorbinary" ;
1617import { AtelierAPI } from "../api" ;
@@ -67,11 +68,11 @@ async function getCurrentFile(
6768 // or a TypeError from decode(). Don't log TypeError
6869 // since the file may be a non-text file that has
6970 // an extension that we interpret as text (like cls or mac).
70- // Also don 't log "FileNotFound" errors, which are probably
71- // caused by concurrency issues. We should ignore such files
72- // rather than alerting the user .
73- if ( error instanceof vscode . FileSystemError && error . code != "FileNotFound" ) {
74- outputChannel . appendLine ( `Failed to read contents of '${ uri . toString ( true ) } ': ${ error . toString ( ) } ` ) ;
71+ // Don 't log "FileNotFound" errors, which are probably
72+ // caused by concurrency issues, or "FileIsADirectory"
73+ // issues, since we don't care about directories .
74+ if ( error instanceof vscode . FileSystemError && ! [ "FileNotFound" , "FileIsADirectory" ] . includes ( error . code ) ) {
75+ outputChannel . appendLine ( `Failed to read contents of '${ displayableUri ( uri ) } ': ${ error . toString ( ) } ` ) ;
7576 }
7677 }
7778}
@@ -114,17 +115,9 @@ function generateDeleteFn(wsFolderUri: vscode.Uri): (doc: string) => void {
114115 docs . length = 0 ;
115116 api . deleteDocs ( docsCopy ) . then ( ( data ) => {
116117 let failed = 0 ;
118+ const ts = tsString ( ) ;
117119 for ( const doc of data . result ) {
118- if ( doc . status != "" && ! doc . status . includes ( "#16005:" ) ) {
119- // The document was not deleted, so log the error.
120- // Error 16005 means we tried to delete a document
121- // that didn't exist. Since the purpose of this
122- // call was to delete the document, and at the
123- // end the document isn't there, we should ignore
124- // this error so the user doesn't get confused.
125- failed ++ ;
126- outputChannel . appendLine ( `${ failed == 1 ? "\n" : "" } ${ doc . status } ` ) ;
127- }
120+ failed += outputDelete ( doc . name , doc . status , ts ) ;
128121 }
129122 if ( failed > 0 ) {
130123 outputChannel . show ( true ) ;
@@ -151,6 +144,37 @@ export function storeTouchedByVSCode(uri: vscode.Uri): void {
151144 }
152145}
153146
147+ /** Create a timestamp string for use in a log entry */
148+ function tsString ( ) : string {
149+ const date = new Date ( ) ;
150+ return `${ date . toISOString ( ) . split ( "T" ) . shift ( ) } ${ date . toLocaleTimeString ( undefined , { hour12 : false } ) } ` ;
151+ }
152+
153+ /** Output a log entry */
154+ function output ( docName : string , msg : string , ts ?: string ) : void {
155+ outputChannel . appendLine ( `${ ts ?? tsString ( ) } [${ docName } ] ${ msg } ` ) ;
156+ }
157+
158+ /** Output a log entry for a successful import */
159+ function outputImport ( docName : string , uri : vscode . Uri ) : void {
160+ output ( docName , `Imported from '${ displayableUri ( uri ) } '` ) ;
161+ }
162+
163+ /**
164+ * Output a log entry for a successful or failed delete.
165+ * Does not output a log entry if the file did not exist on the server.
166+ * Returns `1` if the deleton failed, else `0`.
167+ */
168+ function outputDelete ( docName : string , status : string , ts : string ) : number {
169+ if ( status == "" ) {
170+ output ( docName , "Deleted" , ts ) ;
171+ } else if ( ! status . includes ( "#16005:" ) ) {
172+ output ( docName , `Deletion failed: ${ status } ` , ts ) ;
173+ return 1 ;
174+ }
175+ return 0 ;
176+ }
177+
154178/** Create index of `wsFolder` and set up a `FileSystemWatcher` to keep the index up to date */
155179export async function indexWorkspaceFolder ( wsFolder : vscode . WorkspaceFolder ) : Promise < void > {
156180 if ( ! notIsfs ( wsFolder . uri ) ) return ;
@@ -186,6 +210,10 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
186210 // safely ignore the event.
187211 return ;
188212 }
213+ if ( ! uri . path . split ( "/" ) . pop ( ) . includes ( "." ) ) {
214+ // Ignore creation and change events for folders
215+ return ;
216+ }
189217 const uriString = uri . toString ( ) ;
190218 if ( ! created ) {
191219 const stat = await vscode . workspace . fs . stat ( uri ) . then ( undefined , ( ) => { } ) ;
@@ -237,6 +265,7 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
237265 // Create or update the document on the server
238266 importFile ( change . addedOrChanged )
239267 . then ( ( ) => {
268+ outputImport ( change . addedOrChanged . name , uri ) ;
240269 if ( conf . get ( "compileOnSave" ) ) {
241270 // Compile right away if this document is in the active text editor.
242271 // This is needed to avoid noticeable latency when a user is editing
0 commit comments