14
14
15
15
import * as archiver from "archiver" ;
16
16
import * as fs from "fs" ;
17
- import * as fsPromises from "fs/promises" ;
18
17
import * as path from "path" ;
19
18
import * as vscode from "vscode" ;
20
19
import { tmpdir } from "os" ;
@@ -31,7 +30,7 @@ import { DebugAdapter } from "../debugger/debugAdapter";
31
30
export async function captureDiagnostics (
32
31
ctx : WorkspaceContext ,
33
32
allowMinimalCapture : boolean = true
34
- ) : Promise < string | undefined > {
33
+ ) : Promise < vscode . Uri | undefined > {
35
34
try {
36
35
const captureMode = await captureDiagnosticsMode ( ctx , allowMinimalCapture ) ;
37
36
@@ -40,16 +39,18 @@ export async function captureDiagnostics(
40
39
return ;
41
40
}
42
41
43
- const diagnosticsDir = path . join (
44
- tmpdir ( ) ,
45
- `vscode-diagnostics-${ formatDateString ( new Date ( ) ) } `
42
+ const diagnosticsDir = vscode . Uri . file (
43
+ path . join ( tmpdir ( ) , `vscode-diagnostics-${ formatDateString ( new Date ( ) ) } ` )
46
44
) ;
47
45
48
- await fsPromises . mkdir ( diagnosticsDir ) ;
46
+ await vscode . workspace . fs . createDirectory ( diagnosticsDir ) ;
49
47
50
48
const singleFolderWorkspace = ctx . folders . length === 1 ;
51
49
const zipDir = await createDiagnosticsZipDir ( ) ;
52
- const zipFilePath = path . join ( zipDir , `${ path . basename ( diagnosticsDir ) } .zip` ) ;
50
+ const zipFilePath = vscode . Uri . joinPath (
51
+ zipDir ,
52
+ `${ path . basename ( diagnosticsDir . fsPath ) } .zip`
53
+ ) ;
53
54
const { archive, done : archivingDone } = configureZipArchiver ( zipFilePath ) ;
54
55
55
56
const archivedLldbDapLogFolders = new Set < string > ( ) ;
@@ -58,10 +59,13 @@ export async function captureDiagnostics(
58
59
) ;
59
60
if ( captureMode === "Full" && includeLldbDapLogs ) {
60
61
for ( const defaultLldbDapLogs of [ defaultLldbDapLogFolder ( ctx ) , lldbDapLogFolder ( ) ] ) {
61
- if ( ! defaultLldbDapLogs || archivedLldbDapLogFolders . has ( defaultLldbDapLogs ) ) {
62
+ if (
63
+ ! defaultLldbDapLogs ||
64
+ archivedLldbDapLogFolders . has ( defaultLldbDapLogs . fsPath )
65
+ ) {
62
66
continue ;
63
67
}
64
- archivedLldbDapLogFolders . add ( defaultLldbDapLogs ) ;
68
+ archivedLldbDapLogFolders . add ( defaultLldbDapLogs . fsPath ) ;
65
69
await copyLogFolder ( ctx , diagnosticsDir , defaultLldbDapLogs ) ;
66
70
}
67
71
}
@@ -71,8 +75,8 @@ export async function captureDiagnostics(
71
75
const guid = Math . random ( ) . toString ( 36 ) . substring ( 2 , 10 ) ;
72
76
const outputDir = singleFolderWorkspace
73
77
? diagnosticsDir
74
- : path . join ( diagnosticsDir , baseName ) ;
75
- await fsPromises . mkdir ( outputDir , { recursive : true } ) ;
78
+ : vscode . Uri . joinPath ( diagnosticsDir , baseName ) ;
79
+ await vscode . workspace . fs . createDirectory ( outputDir ) ;
76
80
await writeLogFile ( outputDir , `${ baseName } -${ guid } -settings.txt` , settingsLogs ( folder ) ) ;
77
81
78
82
if ( captureMode === "Full" ) {
@@ -102,36 +106,36 @@ export async function captureDiagnostics(
102
106
}
103
107
// Copy lldb-dap logs
104
108
const lldbDapLogs = lldbDapLogFolder ( folder . workspaceFolder ) ;
105
- if ( lldbDapLogs && ! archivedLldbDapLogFolders . has ( lldbDapLogs ) ) {
106
- archivedLldbDapLogFolders . add ( lldbDapLogs ) ;
109
+ if ( lldbDapLogs && ! archivedLldbDapLogFolders . has ( lldbDapLogs . fsPath ) ) {
110
+ archivedLldbDapLogFolders . add ( lldbDapLogs . fsPath ) ;
107
111
await copyLogFolder ( ctx , outputDir , lldbDapLogs ) ;
108
112
}
109
113
}
110
114
}
111
115
// Leave at end in case log above
112
116
await copyLogFile ( diagnosticsDir , extensionLogFile ( ctx ) ) ;
113
117
114
- archive . directory ( diagnosticsDir , false ) ;
118
+ archive . directory ( diagnosticsDir . fsPath , false ) ;
115
119
void archive . finalize ( ) ;
116
120
await archivingDone ;
117
121
118
122
// Clean up the diagnostics directory, leaving `zipFilePath` with the zip file.
119
- await fsPromises . rm ( diagnosticsDir , { recursive : true , force : true } ) ;
123
+ await vscode . workspace . fs . delete ( diagnosticsDir , { recursive : true , useTrash : false } ) ;
120
124
121
125
ctx . logger . info ( `Saved diagnostics to ${ zipFilePath } ` ) ;
122
- await showCapturedDiagnosticsResults ( zipFilePath ) ;
126
+ await showCapturedDiagnosticsResults ( zipFilePath . fsPath ) ;
123
127
124
128
return zipFilePath ;
125
129
} catch ( error ) {
126
130
void vscode . window . showErrorMessage ( `Unable to capture diagnostic logs: ${ error } ` ) ;
127
131
}
128
132
}
129
133
130
- function configureZipArchiver ( zipFilePath : string ) : {
134
+ function configureZipArchiver ( zipFilePath : vscode . Uri ) : {
131
135
archive : archiver . Archiver ;
132
136
done : Promise < void > ;
133
137
} {
134
- const output = fs . createWriteStream ( zipFilePath ) ;
138
+ const output = fs . createWriteStream ( zipFilePath . fsPath ) ;
135
139
// Create an archive with max compression
136
140
const archive = archiver . create ( "zip" , {
137
141
zlib : { level : 9 } ,
@@ -232,49 +236,59 @@ async function showCapturedDiagnosticsResults(diagnosticsPath: string) {
232
236
}
233
237
}
234
238
235
- async function writeLogFile ( dir : string , name : string , logs : string ) {
239
+ async function writeLogFile ( dir : vscode . Uri , name : string , logs : string ) {
236
240
if ( logs . length === 0 ) {
237
241
return ;
238
242
}
239
- await fsPromises . writeFile ( path . join ( dir , name ) , logs ) ;
243
+ await vscode . workspace . fs . writeFile ( vscode . Uri . joinPath ( dir , name ) , Buffer . from ( logs ) ) ;
240
244
}
241
245
242
- async function copyLogFile ( dir : string , filePath : string ) {
243
- await fsPromises . copyFile ( filePath , path . join ( dir , path . basename ( filePath ) ) ) ;
246
+ async function copyLogFile ( outputDir : vscode . Uri , file : vscode . Uri ) {
247
+ await vscode . workspace . fs . copy (
248
+ file ,
249
+ vscode . Uri . joinPath ( outputDir , path . basename ( file . fsPath ) )
250
+ ) ;
244
251
}
245
252
246
- async function copyLogFolder ( ctx : WorkspaceContext , dir : string , folderPath : string ) {
253
+ async function copyLogFolder (
254
+ ctx : WorkspaceContext ,
255
+ outputDir : vscode . Uri ,
256
+ folderToCopy : vscode . Uri
257
+ ) {
247
258
try {
248
- const lldbLogFiles = await fsPromises . readdir ( folderPath ) ;
259
+ await vscode . workspace . fs . stat ( folderToCopy ) ;
260
+ const lldbLogFiles = await vscode . workspace . fs . readDirectory ( folderToCopy ) ;
249
261
for ( const log of lldbLogFiles ) {
250
- await copyLogFile ( dir , path . join ( folderPath , log ) ) ;
262
+ await copyLogFile ( outputDir , vscode . Uri . joinPath ( folderToCopy , log [ 0 ] ) ) ;
251
263
}
252
264
} catch ( error ) {
253
- if ( ( error as NodeJS . ErrnoException ) . code !== "ENOENT " ) {
254
- ctx . logger . error ( `Failed to read log files from ${ folderPath } : ${ error } ` ) ;
265
+ if ( ( error as vscode . FileSystemError ) . code !== "FileNotFound " ) {
266
+ ctx . logger . error ( `Failed to read log files from ${ folderToCopy } : ${ error } ` ) ;
255
267
}
256
268
}
257
269
}
258
270
259
271
/**
260
272
* Creates a directory for diagnostics zip files, located in the system's temporary directory.
261
273
*/
262
- async function createDiagnosticsZipDir ( ) : Promise < string > {
263
- const diagnosticsDir = path . join ( tmpdir ( ) , "vscode-diagnostics" , formatDateString ( new Date ( ) ) ) ;
264
- await fsPromises . mkdir ( diagnosticsDir , { recursive : true } ) ;
274
+ async function createDiagnosticsZipDir ( ) : Promise < vscode . Uri > {
275
+ const diagnosticsDir = vscode . Uri . file (
276
+ path . join ( tmpdir ( ) , "vscode-diagnostics" , formatDateString ( new Date ( ) ) )
277
+ ) ;
278
+ await vscode . workspace . fs . createDirectory ( diagnosticsDir ) ;
265
279
return diagnosticsDir ;
266
280
}
267
281
268
- function extensionLogFile ( ctx : WorkspaceContext ) : string {
269
- return ctx . logger . logFilePath ;
282
+ function extensionLogFile ( ctx : WorkspaceContext ) : vscode . Uri {
283
+ return vscode . Uri . file ( ctx . logger . logFilePath ) ;
270
284
}
271
285
272
- function defaultLldbDapLogFolder ( ctx : WorkspaceContext ) : string {
286
+ function defaultLldbDapLogFolder ( ctx : WorkspaceContext ) : vscode . Uri {
273
287
const rootLogFolder = path . dirname ( ctx . loggerFactory . logFolderUri . fsPath ) ;
274
- return path . join ( rootLogFolder , Extension . LLDBDAP ) ;
288
+ return vscode . Uri . file ( path . join ( rootLogFolder , Extension . LLDBDAP ) ) ;
275
289
}
276
290
277
- function lldbDapLogFolder ( workspaceFolder ?: vscode . WorkspaceFolder ) : string | undefined {
291
+ function lldbDapLogFolder ( workspaceFolder ?: vscode . WorkspaceFolder ) : vscode . Uri | undefined {
278
292
const config = vscode . workspace . workspaceFile
279
293
? vscode . workspace . getConfiguration ( "lldb-dap" )
280
294
: vscode . workspace . getConfiguration ( "lldb-dap" , workspaceFolder ) ;
@@ -291,7 +305,7 @@ function lldbDapLogFolder(workspaceFolder?: vscode.WorkspaceFolder): string | un
291
305
logFolder = path . join ( vscode . workspace . workspaceFolders [ 0 ] . uri . fsPath , logFolder ) ;
292
306
}
293
307
}
294
- return logFolder ;
308
+ return vscode . Uri . file ( logFolder ) ;
295
309
}
296
310
297
311
function settingsLogs ( ctx : FolderContext ) : string {
@@ -312,14 +326,15 @@ function diagnosticLogs(): string {
312
326
. join ( "\n" ) ;
313
327
}
314
328
315
- function sourceKitLogFile ( folder : FolderContext ) {
329
+ function sourceKitLogFile ( folder : FolderContext ) : vscode . Uri | undefined {
316
330
const languageClient = folder . workspaceContext . languageClientManager . get ( folder ) ;
317
- return languageClient . languageClientOutputChannel ?. logFilePath ;
331
+ const logPath = languageClient . languageClientOutputChannel ?. logFilePath ;
332
+ return logPath ? vscode . Uri . file ( logPath ) : undefined ;
318
333
}
319
334
320
- async function sourcekitDiagnose ( ctx : FolderContext , dir : string ) {
321
- const sourcekitDiagnosticDir = path . join ( dir , "sourcekit-lsp" ) ;
322
- await fsPromises . mkdir ( sourcekitDiagnosticDir ) ;
335
+ async function sourcekitDiagnose ( ctx : FolderContext , dir : vscode . Uri ) {
336
+ const sourcekitDiagnosticDir = vscode . Uri . joinPath ( dir , "sourcekit-lsp" ) ;
337
+ await vscode . workspace . fs . createDirectory ( sourcekitDiagnosticDir ) ;
323
338
324
339
const toolchainSourceKitLSP = ctx . toolchain . getToolchainExecutable ( "sourcekit-lsp" ) ;
325
340
const lspConfig = configuration . lsp ;
@@ -341,7 +356,7 @@ async function sourcekitDiagnose(ctx: FolderContext, dir: string) {
341
356
[
342
357
"diagnose" ,
343
358
"--bundle-output-path" ,
344
- sourcekitDiagnosticDir ,
359
+ sourcekitDiagnosticDir . fsPath ,
345
360
"--toolchain" ,
346
361
ctx . toolchain . toolchainPath ,
347
362
] ,
0 commit comments