1414
1515import * as archiver from "archiver" ;
1616import * as fs from "fs" ;
17- import * as fsPromises from "fs/promises" ;
1817import * as path from "path" ;
1918import * as vscode from "vscode" ;
2019import { tmpdir } from "os" ;
@@ -31,7 +30,7 @@ import { DebugAdapter } from "../debugger/debugAdapter";
3130export async function captureDiagnostics (
3231 ctx : WorkspaceContext ,
3332 allowMinimalCapture : boolean = true
34- ) : Promise < string | undefined > {
33+ ) : Promise < vscode . Uri | undefined > {
3534 try {
3635 const captureMode = await captureDiagnosticsMode ( ctx , allowMinimalCapture ) ;
3736
@@ -40,16 +39,18 @@ export async function captureDiagnostics(
4039 return ;
4140 }
4241
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 ( ) ) } ` )
4644 ) ;
4745
48- await fsPromises . mkdir ( diagnosticsDir ) ;
46+ await vscode . workspace . fs . createDirectory ( diagnosticsDir ) ;
4947
5048 const singleFolderWorkspace = ctx . folders . length === 1 ;
5149 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+ ) ;
5354 const { archive, done : archivingDone } = configureZipArchiver ( zipFilePath ) ;
5455
5556 const archivedLldbDapLogFolders = new Set < string > ( ) ;
@@ -58,10 +59,13 @@ export async function captureDiagnostics(
5859 ) ;
5960 if ( captureMode === "Full" && includeLldbDapLogs ) {
6061 for ( const defaultLldbDapLogs of [ defaultLldbDapLogFolder ( ctx ) , lldbDapLogFolder ( ) ] ) {
61- if ( ! defaultLldbDapLogs || archivedLldbDapLogFolders . has ( defaultLldbDapLogs ) ) {
62+ if (
63+ ! defaultLldbDapLogs ||
64+ archivedLldbDapLogFolders . has ( defaultLldbDapLogs . fsPath )
65+ ) {
6266 continue ;
6367 }
64- archivedLldbDapLogFolders . add ( defaultLldbDapLogs ) ;
68+ archivedLldbDapLogFolders . add ( defaultLldbDapLogs . fsPath ) ;
6569 await copyLogFolder ( ctx , diagnosticsDir , defaultLldbDapLogs ) ;
6670 }
6771 }
@@ -71,8 +75,8 @@ export async function captureDiagnostics(
7175 const guid = Math . random ( ) . toString ( 36 ) . substring ( 2 , 10 ) ;
7276 const outputDir = singleFolderWorkspace
7377 ? 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 ) ;
7680 await writeLogFile ( outputDir , `${ baseName } -${ guid } -settings.txt` , settingsLogs ( folder ) ) ;
7781
7882 if ( captureMode === "Full" ) {
@@ -102,36 +106,36 @@ export async function captureDiagnostics(
102106 }
103107 // Copy lldb-dap logs
104108 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 ) ;
107111 await copyLogFolder ( ctx , outputDir , lldbDapLogs ) ;
108112 }
109113 }
110114 }
111115 // Leave at end in case log above
112116 await copyLogFile ( diagnosticsDir , extensionLogFile ( ctx ) ) ;
113117
114- archive . directory ( diagnosticsDir , false ) ;
118+ archive . directory ( diagnosticsDir . fsPath , false ) ;
115119 void archive . finalize ( ) ;
116120 await archivingDone ;
117121
118122 // 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 } ) ;
120124
121125 ctx . logger . info ( `Saved diagnostics to ${ zipFilePath } ` ) ;
122- await showCapturedDiagnosticsResults ( zipFilePath ) ;
126+ await showCapturedDiagnosticsResults ( zipFilePath . fsPath ) ;
123127
124128 return zipFilePath ;
125129 } catch ( error ) {
126130 void vscode . window . showErrorMessage ( `Unable to capture diagnostic logs: ${ error } ` ) ;
127131 }
128132}
129133
130- function configureZipArchiver ( zipFilePath : string ) : {
134+ function configureZipArchiver ( zipFilePath : vscode . Uri ) : {
131135 archive : archiver . Archiver ;
132136 done : Promise < void > ;
133137} {
134- const output = fs . createWriteStream ( zipFilePath ) ;
138+ const output = fs . createWriteStream ( zipFilePath . fsPath ) ;
135139 // Create an archive with max compression
136140 const archive = archiver . create ( "zip" , {
137141 zlib : { level : 9 } ,
@@ -232,49 +236,59 @@ async function showCapturedDiagnosticsResults(diagnosticsPath: string) {
232236 }
233237}
234238
235- async function writeLogFile ( dir : string , name : string , logs : string ) {
239+ async function writeLogFile ( dir : vscode . Uri , name : string , logs : string ) {
236240 if ( logs . length === 0 ) {
237241 return ;
238242 }
239- await fsPromises . writeFile ( path . join ( dir , name ) , logs ) ;
243+ await vscode . workspace . fs . writeFile ( vscode . Uri . joinPath ( dir , name ) , Buffer . from ( logs ) ) ;
240244}
241245
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+ ) ;
244251}
245252
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+ ) {
247258 try {
248- const lldbLogFiles = await fsPromises . readdir ( folderPath ) ;
259+ await vscode . workspace . fs . stat ( folderToCopy ) ;
260+ const lldbLogFiles = await vscode . workspace . fs . readDirectory ( folderToCopy ) ;
249261 for ( const log of lldbLogFiles ) {
250- await copyLogFile ( dir , path . join ( folderPath , log ) ) ;
262+ await copyLogFile ( outputDir , vscode . Uri . joinPath ( folderToCopy , log [ 0 ] ) ) ;
251263 }
252264 } 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 } ` ) ;
255267 }
256268 }
257269}
258270
259271/**
260272 * Creates a directory for diagnostics zip files, located in the system's temporary directory.
261273 */
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 ) ;
265279 return diagnosticsDir ;
266280}
267281
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 ) ;
270284}
271285
272- function defaultLldbDapLogFolder ( ctx : WorkspaceContext ) : string {
286+ function defaultLldbDapLogFolder ( ctx : WorkspaceContext ) : vscode . Uri {
273287 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 ) ) ;
275289}
276290
277- function lldbDapLogFolder ( workspaceFolder ?: vscode . WorkspaceFolder ) : string | undefined {
291+ function lldbDapLogFolder ( workspaceFolder ?: vscode . WorkspaceFolder ) : vscode . Uri | undefined {
278292 const config = vscode . workspace . workspaceFile
279293 ? vscode . workspace . getConfiguration ( "lldb-dap" )
280294 : vscode . workspace . getConfiguration ( "lldb-dap" , workspaceFolder ) ;
@@ -291,7 +305,7 @@ function lldbDapLogFolder(workspaceFolder?: vscode.WorkspaceFolder): string | un
291305 logFolder = path . join ( vscode . workspace . workspaceFolders [ 0 ] . uri . fsPath , logFolder ) ;
292306 }
293307 }
294- return logFolder ;
308+ return vscode . Uri . file ( logFolder ) ;
295309}
296310
297311function settingsLogs ( ctx : FolderContext ) : string {
@@ -312,14 +326,15 @@ function diagnosticLogs(): string {
312326 . join ( "\n" ) ;
313327}
314328
315- function sourceKitLogFile ( folder : FolderContext ) {
329+ function sourceKitLogFile ( folder : FolderContext ) : vscode . Uri | undefined {
316330 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 ;
318333}
319334
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 ) ;
323338
324339 const toolchainSourceKitLSP = ctx . toolchain . getToolchainExecutable ( "sourcekit-lsp" ) ;
325340 const lspConfig = configuration . lsp ;
@@ -341,7 +356,7 @@ async function sourcekitDiagnose(ctx: FolderContext, dir: string) {
341356 [
342357 "diagnose" ,
343358 "--bundle-output-path" ,
344- sourcekitDiagnosticDir ,
359+ sourcekitDiagnosticDir . fsPath ,
345360 "--toolchain" ,
346361 ctx . toolchain . toolchainPath ,
347362 ] ,
0 commit comments