@@ -60,14 +60,20 @@ let codeActionsFromDiagnostics: codeActions.filesCodeActions = {};
6060// will be properly defined later depending on the mode (stdio/node-rpc)
6161let send : ( msg : p . Message ) => void = ( _ ) => { } ;
6262
63- let findRescriptBinary = async ( projectRootPath : p . DocumentUri | null ) : Promise < string | null > => {
64- if ( config . extensionConfiguration . binaryPath != null &&
65- fs . existsSync ( path . join ( config . extensionConfiguration . binaryPath , "rescript" ) ) ) {
66- return path . join ( config . extensionConfiguration . binaryPath , "rescript" )
63+ let findRescriptBinary = async (
64+ projectRootPath : p . DocumentUri | null
65+ ) : Promise < string | null > => {
66+ if (
67+ config . extensionConfiguration . binaryPath != null &&
68+ fs . existsSync (
69+ path . join ( config . extensionConfiguration . binaryPath , "rescript" )
70+ )
71+ ) {
72+ return path . join ( config . extensionConfiguration . binaryPath , "rescript" ) ;
6773 }
6874
69- return utils . findRescriptBinary ( projectRootPath )
70- }
75+ return utils . findRescriptBinary ( projectRootPath ) ;
76+ } ;
7177
7278let createInterfaceRequest = new v . RequestType <
7379 p . TextDocumentIdentifier ,
@@ -99,7 +105,12 @@ let sendUpdatedDiagnostics = async () => {
99105 for ( const [ projectRootPath , projectFile ] of projectsFiles ) {
100106 let { filesWithDiagnostics } = projectFile ;
101107 let compilerLogPath = path . join ( projectRootPath , c . compilerLogPartialPath ) ;
102- let content = fs . readFileSync ( compilerLogPath , { encoding : "utf-8" } ) ;
108+ let content = "" ;
109+ try {
110+ content = fs . readFileSync ( compilerLogPath , { encoding : "utf-8" } ) ;
111+ } catch ( e ) {
112+ console . error ( `Error reading compiler log file ${ compilerLogPath } : ${ e } ` ) ;
113+ }
103114 let {
104115 done,
105116 result : filesAndErrors ,
@@ -197,7 +208,10 @@ let debug = false;
197208let syncProjectConfigCache = async ( rootPath : string ) => {
198209 try {
199210 if ( debug ) console . log ( "syncing project config cache for " + rootPath ) ;
200- await utils . runAnalysisAfterSanityCheck ( rootPath , [ "cache-project" , rootPath ] ) ;
211+ await utils . runAnalysisAfterSanityCheck ( rootPath , [
212+ "cache-project" ,
213+ rootPath ,
214+ ] ) ;
201215 if ( debug ) console . log ( "OK - synced project config cache for " + rootPath ) ;
202216 } catch ( e ) {
203217 if ( debug ) console . error ( e ) ;
@@ -207,7 +221,10 @@ let syncProjectConfigCache = async (rootPath: string) => {
207221let deleteProjectConfigCache = async ( rootPath : string ) => {
208222 try {
209223 if ( debug ) console . log ( "deleting project config cache for " + rootPath ) ;
210- await utils . runAnalysisAfterSanityCheck ( rootPath , [ "cache-delete" , rootPath ] ) ;
224+ await utils . runAnalysisAfterSanityCheck ( rootPath , [
225+ "cache-delete" ,
226+ rootPath ,
227+ ] ) ;
211228 if ( debug ) console . log ( "OK - deleted project config cache for " + rootPath ) ;
212229 } catch ( e ) {
213230 if ( debug ) console . error ( e ) ;
@@ -217,31 +234,35 @@ let deleteProjectConfigCache = async (rootPath: string) => {
217234async function onWorkspaceDidChangeWatchedFiles (
218235 params : p . DidChangeWatchedFilesParams
219236) {
220- await Promise . all ( params . changes . map ( async ( change ) => {
221- if ( change . uri . includes ( "build.ninja" ) ) {
222- if ( config . extensionConfiguration . cache ?. projectConfig ?. enable === true ) {
223- let projectRoot = utils . findProjectRootOfFile ( change . uri ) ;
224- if ( projectRoot != null ) {
225- await syncProjectConfigCache ( projectRoot ) ;
226- }
227- }
228- } else if ( change . uri . includes ( "compiler.log" ) ) {
229- try {
230- await sendUpdatedDiagnostics ( ) ;
231- sendCompilationFinishedMessage ( ) ;
232- if ( config . extensionConfiguration . inlayHints ?. enable === true ) {
233- sendInlayHintsRefresh ( ) ;
237+ await Promise . all (
238+ params . changes . map ( async ( change ) => {
239+ if ( change . uri . includes ( "build.ninja" ) ) {
240+ if (
241+ config . extensionConfiguration . cache ?. projectConfig ?. enable === true
242+ ) {
243+ let projectRoot = utils . findProjectRootOfFile ( change . uri ) ;
244+ if ( projectRoot != null ) {
245+ await syncProjectConfigCache ( projectRoot ) ;
246+ }
234247 }
235- if ( config . extensionConfiguration . codeLens === true ) {
236- sendCodeLensRefresh ( ) ;
248+ } else if ( change . uri . includes ( "compiler.log" ) ) {
249+ try {
250+ await sendUpdatedDiagnostics ( ) ;
251+ sendCompilationFinishedMessage ( ) ;
252+ if ( config . extensionConfiguration . inlayHints ?. enable === true ) {
253+ sendInlayHintsRefresh ( ) ;
254+ }
255+ if ( config . extensionConfiguration . codeLens === true ) {
256+ sendCodeLensRefresh ( ) ;
257+ }
258+ } catch {
259+ console . log ( "Error while sending updated diagnostics" ) ;
237260 }
238- } catch {
239- console . log ( "Error while sending updated diagnostics" ) ;
261+ } else {
262+ ic . incrementalCompilationFileChanged ( fileURLToPath ( change . uri ) ) ;
240263 }
241- } else {
242- ic . incrementalCompilationFileChanged ( fileURLToPath ( change . uri ) ) ;
243- }
244- } ) ) ;
264+ } )
265+ ) ;
245266}
246267
247268type clientSentBuildAction = {
@@ -269,10 +290,14 @@ let openedFile = async (fileUri: string, fileContent: string) => {
269290 filesDiagnostics : { } ,
270291 namespaceName :
271292 namespaceName . kind === "success" ? namespaceName . result : null ,
272- rescriptVersion : await utils . findReScriptVersionForProjectRoot ( projectRootPath ) ,
293+ rescriptVersion : await utils . findReScriptVersionForProjectRoot (
294+ projectRootPath
295+ ) ,
273296 bsbWatcherByEditor : null ,
274297 bscBinaryLocation : await utils . findBscExeBinary ( projectRootPath ) ,
275- editorAnalysisLocation : await utils . findEditorAnalysisBinary ( projectRootPath ) ,
298+ editorAnalysisLocation : await utils . findEditorAnalysisBinary (
299+ projectRootPath
300+ ) ,
276301 hasPromptedToStartBuild : / ( \/ | \\ ) n o d e _ m o d u l e s ( \/ | \\ ) / . test (
277302 projectRootPath
278303 )
@@ -297,7 +322,7 @@ let openedFile = async (fileUri: string, fileContent: string) => {
297322 // TODO: sometime stale .bsb.lock dangling. bsb -w knows .bsb.lock is
298323 // stale. Use that logic
299324 // TODO: close watcher when lang-server shuts down
300- if ( await findRescriptBinary ( projectRootPath ) != null ) {
325+ if ( ( await findRescriptBinary ( projectRootPath ) ) != null ) {
301326 let payload : clientSentBuildAction = {
302327 title : c . startBuildAction ,
303328 projectRootPath : projectRootPath ,
@@ -536,10 +561,8 @@ async function references(msg: p.RequestMessage) {
536561 // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
537562 let params = msg . params as p . ReferenceParams ;
538563 let filePath = fileURLToPath ( params . textDocument . uri ) ;
539- let result : typeof p . ReferencesRequest . type = await utils . getReferencesForPosition (
540- filePath ,
541- params . position
542- ) ;
564+ let result : typeof p . ReferencesRequest . type =
565+ await utils . getReferencesForPosition ( filePath , params . position ) ;
543566 let response : p . ResponseMessage = {
544567 jsonrpc : c . jsonrpcVersion ,
545568 id : msg . id ,
@@ -549,7 +572,9 @@ async function references(msg: p.RequestMessage) {
549572 return response ;
550573}
551574
552- async function prepareRename ( msg : p . RequestMessage ) : Promise < p . ResponseMessage > {
575+ async function prepareRename (
576+ msg : p . RequestMessage
577+ ) : Promise < p . ResponseMessage > {
553578 // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_prepareRename
554579 let params = msg . params as p . PrepareRenameParams ;
555580 let filePath = fileURLToPath ( params . textDocument . uri ) ;
@@ -840,7 +865,10 @@ let updateDiagnosticSyntax = async (fileUri: string, fileContent: string) => {
840865 let compilerDiagnosticsForFile =
841866 getCurrentCompilerDiagnosticsForFile ( fileUri ) ;
842867 let syntaxDiagnosticsForFile : p . Diagnostic [ ] =
843- await utils . runAnalysisAfterSanityCheck ( filePath , [ "diagnosticSyntax" , tmpname ] ) ;
868+ await utils . runAnalysisAfterSanityCheck ( filePath , [
869+ "diagnosticSyntax" ,
870+ tmpname ,
871+ ] ) ;
844872
845873 let notification : p . NotificationMessage = {
846874 jsonrpc : c . jsonrpcVersion ,
@@ -1051,17 +1079,29 @@ async function onMessage(msg: p.Message) {
10511079 const watchers = Array . from ( workspaceFolders ) . flatMap (
10521080 ( projectRootPath ) => [
10531081 {
1054- globPattern : path . join ( projectRootPath , '**' , c . compilerLogPartialPath ) ,
1082+ globPattern : path . join (
1083+ projectRootPath ,
1084+ "**" ,
1085+ c . compilerLogPartialPath
1086+ ) ,
10551087 kind : p . WatchKind . Change | p . WatchKind . Create | p . WatchKind . Delete ,
10561088 } ,
10571089 {
1058- globPattern : path . join ( projectRootPath , '**' , c . buildNinjaPartialPath ) ,
1090+ globPattern : path . join (
1091+ projectRootPath ,
1092+ "**" ,
1093+ c . buildNinjaPartialPath
1094+ ) ,
10591095 kind : p . WatchKind . Change | p . WatchKind . Create | p . WatchKind . Delete ,
10601096 } ,
10611097 {
1062- globPattern : `${ path . join ( projectRootPath , '**' , c . compilerDirPartialPath ) } /**/*.{cmt,cmi}` ,
1098+ globPattern : `${ path . join (
1099+ projectRootPath ,
1100+ "**" ,
1101+ c . compilerDirPartialPath
1102+ ) } /**/*.{cmt,cmi}`,
10631103 kind : p . WatchKind . Change | p . WatchKind . Delete ,
1064- }
1104+ } ,
10651105 ]
10661106 ) ;
10671107 const registrationParams : p . RegistrationParams = {
@@ -1089,7 +1129,10 @@ async function onMessage(msg: p.Message) {
10891129 let params = msg . params as p . DidOpenTextDocumentParams ;
10901130 await openedFile ( params . textDocument . uri , params . textDocument . text ) ;
10911131 await sendUpdatedDiagnostics ( ) ;
1092- await updateDiagnosticSyntax ( params . textDocument . uri , params . textDocument . text ) ;
1132+ await updateDiagnosticSyntax (
1133+ params . textDocument . uri ,
1134+ params . textDocument . text
1135+ ) ;
10931136 } else if ( msg . method === DidChangeTextDocumentNotification . method ) {
10941137 let params = msg . params as p . DidChangeTextDocumentParams ;
10951138 let extName = path . extname ( params . textDocument . uri ) ;
0 commit comments