@@ -14,12 +14,7 @@ import { getRewatchBscArgs, RewatchCompilerArgs } from "./bsc-args/rewatch";
1414import { BsbCompilerArgs , getBsbBscArgs } from "./bsc-args/bsb" ;
1515import { getCurrentCompilerDiagnosticsForFile } from "./server" ;
1616import { NormalizedPath } from "./utils" ;
17-
18- export function debug ( ) {
19- return (
20- config . extensionConfiguration . incrementalTypechecking ?. debugLogging ?? false
21- ) ;
22- }
17+ import { getLogger } from "./logger" ;
2318
2419const INCREMENTAL_FOLDER_NAME = "___incremental" ;
2520const INCREMENTAL_FILE_FOLDER_LOCATION = path . join (
@@ -96,13 +91,11 @@ export function incrementalCompilationFileChanged(changedPath: NormalizedPath) {
9691 if ( filePath != null ) {
9792 const entry = incrementallyCompiledFileInfo . get ( filePath ) ;
9893 if ( entry != null ) {
99- if ( debug ( ) ) {
100- console . log ( "[watcher] Cleaning up incremental files for " + filePath ) ;
101- }
94+ getLogger ( ) . log (
95+ "[watcher] Cleaning up incremental files for " + filePath ,
96+ ) ;
10297 if ( entry . compilation != null ) {
103- if ( debug ( ) ) {
104- console . log ( "[watcher] Was compiling, killing" ) ;
105- }
98+ getLogger ( ) . log ( "[watcher] Was compiling, killing" ) ;
10699 clearTimeout ( entry . compilation . timeout ) ;
107100 entry . killCompilationListeners . forEach ( ( cb ) => cb ( ) ) ;
108101 entry . compilation = null ;
@@ -129,9 +122,7 @@ export function removeIncrementalFileFolder(
129122}
130123
131124export function recreateIncrementalFileFolder ( projectRootPath : NormalizedPath ) {
132- if ( debug ( ) ) {
133- console . log ( "Recreating incremental file folder" ) ;
134- }
125+ getLogger ( ) . log ( "Recreating incremental file folder" ) ;
135126 removeIncrementalFileFolder ( projectRootPath , ( ) => {
136127 fs . mkdir (
137128 path . resolve ( projectRootPath , INCREMENTAL_FILE_FOLDER_LOCATION ) ,
@@ -153,9 +144,7 @@ export function cleanUpIncrementalFiles(
153144 ? `${ fileNameNoExt } -${ namespace . result } `
154145 : fileNameNoExt ;
155146
156- if ( debug ( ) ) {
157- console . log ( "Cleaning up incremental file assets for: " + fileNameNoExt ) ;
158- }
147+ getLogger ( ) . log ( "Cleaning up incremental file assets for: " + fileNameNoExt ) ;
159148
160149 fs . unlink (
161150 path . resolve (
@@ -252,15 +241,14 @@ function triggerIncrementalCompilationOfFile(
252241 // New file
253242 const projectRootPath = utils . findProjectRootOfFile ( filePath ) ;
254243 if ( projectRootPath == null ) {
255- if ( debug ( ) )
256- console . log ( "Did not find project root path for " + filePath ) ;
244+ getLogger ( ) . log ( "Did not find project root path for " + filePath ) ;
257245 return ;
258246 }
259247 // projectRootPath is already normalized (NormalizedPath) from findProjectRootOfFile
260248 // Use getProjectFile to verify the project exists
261249 const project = utils . getProjectFile ( projectRootPath ) ;
262250 if ( project == null ) {
263- if ( debug ( ) ) console . log ( "Did not find open project for " + filePath ) ;
251+ getLogger ( ) . log ( "Did not find open project for " + filePath ) ;
264252 return ;
265253 }
266254
@@ -279,20 +267,19 @@ function triggerIncrementalCompilationOfFile(
279267 projectRootPath != null &&
280268 utils . findProjectRootOfDir ( projectRootPath ) != null ;
281269
282- if ( foundRewatchLockfileInProjectRoot && debug ( ) ) {
283- console . log (
270+ if ( foundRewatchLockfileInProjectRoot ) {
271+ getLogger ( ) . log (
284272 `Found rewatch/rescript lockfile in project root, treating as local package in workspace` ,
285273 ) ;
286- } else if ( ! foundRewatchLockfileInProjectRoot && debug ( ) ) {
287- console . log (
274+ } else {
275+ getLogger ( ) . log (
288276 `Did not find rewatch/rescript lockfile in project root, assuming bsb` ,
289277 ) ;
290278 }
291279
292280 const bscBinaryLocation = project . bscBinaryLocation ;
293281 if ( bscBinaryLocation == null ) {
294- if ( debug ( ) )
295- console . log ( "Could not find bsc binary location for " + filePath ) ;
282+ getLogger ( ) . log ( "Could not find bsc binary location for " + filePath ) ;
296283 return ;
297284 }
298285 const ext = filePath . endsWith ( ".resi" ) ? ".resi" : ".res" ;
@@ -401,12 +388,9 @@ async function figureOutBscArgs(
401388) {
402389 const project = projectsFiles . get ( entry . project . rootPath ) ;
403390 if ( project ?. rescriptVersion == null ) {
404- if ( debug ( ) ) {
405- console . log (
406- "Found no project (or ReScript version) for " +
407- entry . file . sourceFilePath ,
408- ) ;
409- }
391+ getLogger ( ) . log (
392+ "Found no project (or ReScript version) for " + entry . file . sourceFilePath ,
393+ ) ;
410394 return null ;
411395 }
412396 const res = await getBscArgs ( send , entry ) ;
@@ -515,11 +499,9 @@ async function compileContents(
515499 callArgs = callArgsRetried ;
516500 entry . project . callArgs = Promise . resolve ( callArgsRetried ) ;
517501 } else {
518- if ( debug ( ) ) {
519- console . log (
520- "Could not figure out call args. Maybe build.ninja does not exist yet?" ,
521- ) ;
522- }
502+ getLogger ( ) . log (
503+ "Could not figure out call args. Maybe build.ninja does not exist yet?" ,
504+ ) ;
523505 return ;
524506 }
525507 }
@@ -537,41 +519,35 @@ async function compileContents(
537519 entry . buildSystem === "bsb"
538520 ? entry . project . rootPath
539521 : path . resolve ( entry . project . rootPath , c . compilerDirPartialPath ) ;
540- if ( debug ( ) ) {
541- console . log (
542- `About to invoke bsc from \"${ cwd } \", used ${ entry . buildSystem } ` ,
543- ) ;
544- console . log (
545- `${ entry . project . bscBinaryLocation } ${ callArgs . map ( ( c ) => `"${ c } "` ) . join ( " " ) } ` ,
546- ) ;
547- }
522+ getLogger ( ) . log (
523+ `About to invoke bsc from \"${ cwd } \", used ${ entry . buildSystem } ` ,
524+ ) ;
525+ getLogger ( ) . log (
526+ `${ entry . project . bscBinaryLocation } ${ callArgs . map ( ( c ) => `"${ c } "` ) . join ( " " ) } ` ,
527+ ) ;
548528 const process = cp . execFile (
549529 entry . project . bscBinaryLocation ,
550530 callArgs ,
551531 { cwd } ,
552532 async ( error , _stdout , stderr ) => {
553533 if ( ! error ?. killed ) {
554- if ( debug ( ) )
555- console . log (
556- `Recompiled ${ entry . file . sourceFileName } in ${
557- ( performance . now ( ) - startTime ) / 1000
558- } s`,
559- ) ;
534+ getLogger ( ) . log (
535+ `Recompiled ${ entry . file . sourceFileName } in ${
536+ ( performance . now ( ) - startTime ) / 1000
537+ } s`,
538+ ) ;
560539 } else {
561- if ( debug ( ) )
562- console . log (
563- `Compilation of ${ entry . file . sourceFileName } was killed.` ,
564- ) ;
540+ getLogger ( ) . log (
541+ `Compilation of ${ entry . file . sourceFileName } was killed.` ,
542+ ) ;
565543 }
566544 let hasIgnoredErrorMessages = false ;
567545 if (
568546 ! error ?. killed &&
569547 triggerToken != null &&
570548 verifyTriggerToken ( entry . file . sourceFilePath , triggerToken )
571549 ) {
572- if ( debug ( ) ) {
573- console . log ( "Resetting compilation status." ) ;
574- }
550+ getLogger ( ) . log ( "Resetting compilation status." ) ;
575551 // Reset compilation status as this compilation finished
576552 entry . compilation = null ;
577553 const { result, codeActions } = await utils . parseCompilerLogOutput (
@@ -706,9 +682,7 @@ export function handleUpdateOpenedFile(
706682 send : send ,
707683 onCompilationFinished ?: ( ) => void ,
708684) {
709- if ( debug ( ) ) {
710- console . log ( "Updated: " + filePath ) ;
711- }
685+ getLogger ( ) . log ( "Updated: " + filePath ) ;
712686 triggerIncrementalCompilationOfFile (
713687 filePath ,
714688 fileContent ,
@@ -718,9 +692,7 @@ export function handleUpdateOpenedFile(
718692}
719693
720694export function handleClosedFile ( filePath : NormalizedPath ) {
721- if ( debug ( ) ) {
722- console . log ( "Closed: " + filePath ) ;
723- }
695+ getLogger ( ) . log ( "Closed: " + filePath ) ;
724696 const entry = incrementallyCompiledFileInfo . get ( filePath ) ;
725697 if ( entry == null ) return ;
726698 cleanUpIncrementalFiles ( filePath , entry . project . rootPath ) ;
0 commit comments