@@ -11,6 +11,7 @@ import {
11
11
notIsfs ,
12
12
openLowCodeEditors ,
13
13
outputChannel ,
14
+ displayableUri ,
14
15
} from "." ;
15
16
import { isText } from "istextorbinary" ;
16
17
import { AtelierAPI } from "../api" ;
@@ -67,11 +68,11 @@ async function getCurrentFile(
67
68
// or a TypeError from decode(). Don't log TypeError
68
69
// since the file may be a non-text file that has
69
70
// 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 ( ) } ` ) ;
75
76
}
76
77
}
77
78
}
@@ -114,17 +115,9 @@ function generateDeleteFn(wsFolderUri: vscode.Uri): (doc: string) => void {
114
115
docs . length = 0 ;
115
116
api . deleteDocs ( docsCopy ) . then ( ( data ) => {
116
117
let failed = 0 ;
118
+ const ts = tsString ( ) ;
117
119
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 ) ;
128
121
}
129
122
if ( failed > 0 ) {
130
123
outputChannel . show ( true ) ;
@@ -151,6 +144,37 @@ export function storeTouchedByVSCode(uri: vscode.Uri): void {
151
144
}
152
145
}
153
146
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
+
154
178
/** Create index of `wsFolder` and set up a `FileSystemWatcher` to keep the index up to date */
155
179
export async function indexWorkspaceFolder ( wsFolder : vscode . WorkspaceFolder ) : Promise < void > {
156
180
if ( ! notIsfs ( wsFolder . uri ) ) return ;
@@ -186,6 +210,10 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
186
210
// safely ignore the event.
187
211
return ;
188
212
}
213
+ if ( ! uri . path . split ( "/" ) . pop ( ) . includes ( "." ) ) {
214
+ // Ignore creation and change events for folders
215
+ return ;
216
+ }
189
217
const uriString = uri . toString ( ) ;
190
218
if ( ! created ) {
191
219
const stat = await vscode . workspace . fs . stat ( uri ) . then ( undefined , ( ) => { } ) ;
@@ -237,6 +265,7 @@ export async function indexWorkspaceFolder(wsFolder: vscode.WorkspaceFolder): Pr
237
265
// Create or update the document on the server
238
266
importFile ( change . addedOrChanged )
239
267
. then ( ( ) => {
268
+ outputImport ( change . addedOrChanged . name , uri ) ;
240
269
if ( conf . get ( "compileOnSave" ) ) {
241
270
// Compile right away if this document is in the active text editor.
242
271
// This is needed to avoid noticeable latency when a user is editing
0 commit comments