@@ -60,14 +60,20 @@ let codeActionsFromDiagnostics: codeActions.filesCodeActions = {};
60
60
// will be properly defined later depending on the mode (stdio/node-rpc)
61
61
let send : ( msg : p . Message ) => void = ( _ ) => { } ;
62
62
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" ) ;
67
73
}
68
74
69
- return utils . findRescriptBinary ( projectRootPath )
70
- }
75
+ return utils . findRescriptBinary ( projectRootPath ) ;
76
+ } ;
71
77
72
78
let createInterfaceRequest = new v . RequestType <
73
79
p . TextDocumentIdentifier ,
@@ -99,7 +105,12 @@ let sendUpdatedDiagnostics = async () => {
99
105
for ( const [ projectRootPath , projectFile ] of projectsFiles ) {
100
106
let { filesWithDiagnostics } = projectFile ;
101
107
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
+ }
103
114
let {
104
115
done,
105
116
result : filesAndErrors ,
@@ -197,7 +208,10 @@ let debug = false;
197
208
let syncProjectConfigCache = async ( rootPath : string ) => {
198
209
try {
199
210
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
+ ] ) ;
201
215
if ( debug ) console . log ( "OK - synced project config cache for " + rootPath ) ;
202
216
} catch ( e ) {
203
217
if ( debug ) console . error ( e ) ;
@@ -207,7 +221,10 @@ let syncProjectConfigCache = async (rootPath: string) => {
207
221
let deleteProjectConfigCache = async ( rootPath : string ) => {
208
222
try {
209
223
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
+ ] ) ;
211
228
if ( debug ) console . log ( "OK - deleted project config cache for " + rootPath ) ;
212
229
} catch ( e ) {
213
230
if ( debug ) console . error ( e ) ;
@@ -217,31 +234,35 @@ let deleteProjectConfigCache = async (rootPath: string) => {
217
234
async function onWorkspaceDidChangeWatchedFiles (
218
235
params : p . DidChangeWatchedFilesParams
219
236
) {
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
+ }
234
247
}
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" ) ;
237
260
}
238
- } catch {
239
- console . log ( "Error while sending updated diagnostics" ) ;
261
+ } else {
262
+ ic . incrementalCompilationFileChanged ( fileURLToPath ( change . uri ) ) ;
240
263
}
241
- } else {
242
- ic . incrementalCompilationFileChanged ( fileURLToPath ( change . uri ) ) ;
243
- }
244
- } ) ) ;
264
+ } )
265
+ ) ;
245
266
}
246
267
247
268
type clientSentBuildAction = {
@@ -269,10 +290,14 @@ let openedFile = async (fileUri: string, fileContent: string) => {
269
290
filesDiagnostics : { } ,
270
291
namespaceName :
271
292
namespaceName . kind === "success" ? namespaceName . result : null ,
272
- rescriptVersion : await utils . findReScriptVersionForProjectRoot ( projectRootPath ) ,
293
+ rescriptVersion : await utils . findReScriptVersionForProjectRoot (
294
+ projectRootPath
295
+ ) ,
273
296
bsbWatcherByEditor : null ,
274
297
bscBinaryLocation : await utils . findBscExeBinary ( projectRootPath ) ,
275
- editorAnalysisLocation : await utils . findEditorAnalysisBinary ( projectRootPath ) ,
298
+ editorAnalysisLocation : await utils . findEditorAnalysisBinary (
299
+ projectRootPath
300
+ ) ,
276
301
hasPromptedToStartBuild : / ( \/ | \\ ) n o d e _ m o d u l e s ( \/ | \\ ) / . test (
277
302
projectRootPath
278
303
)
@@ -297,7 +322,7 @@ let openedFile = async (fileUri: string, fileContent: string) => {
297
322
// TODO: sometime stale .bsb.lock dangling. bsb -w knows .bsb.lock is
298
323
// stale. Use that logic
299
324
// TODO: close watcher when lang-server shuts down
300
- if ( await findRescriptBinary ( projectRootPath ) != null ) {
325
+ if ( ( await findRescriptBinary ( projectRootPath ) ) != null ) {
301
326
let payload : clientSentBuildAction = {
302
327
title : c . startBuildAction ,
303
328
projectRootPath : projectRootPath ,
@@ -536,10 +561,8 @@ async function references(msg: p.RequestMessage) {
536
561
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
537
562
let params = msg . params as p . ReferenceParams ;
538
563
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 ) ;
543
566
let response : p . ResponseMessage = {
544
567
jsonrpc : c . jsonrpcVersion ,
545
568
id : msg . id ,
@@ -549,7 +572,9 @@ async function references(msg: p.RequestMessage) {
549
572
return response ;
550
573
}
551
574
552
- async function prepareRename ( msg : p . RequestMessage ) : Promise < p . ResponseMessage > {
575
+ async function prepareRename (
576
+ msg : p . RequestMessage
577
+ ) : Promise < p . ResponseMessage > {
553
578
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_prepareRename
554
579
let params = msg . params as p . PrepareRenameParams ;
555
580
let filePath = fileURLToPath ( params . textDocument . uri ) ;
@@ -840,7 +865,10 @@ let updateDiagnosticSyntax = async (fileUri: string, fileContent: string) => {
840
865
let compilerDiagnosticsForFile =
841
866
getCurrentCompilerDiagnosticsForFile ( fileUri ) ;
842
867
let syntaxDiagnosticsForFile : p . Diagnostic [ ] =
843
- await utils . runAnalysisAfterSanityCheck ( filePath , [ "diagnosticSyntax" , tmpname ] ) ;
868
+ await utils . runAnalysisAfterSanityCheck ( filePath , [
869
+ "diagnosticSyntax" ,
870
+ tmpname ,
871
+ ] ) ;
844
872
845
873
let notification : p . NotificationMessage = {
846
874
jsonrpc : c . jsonrpcVersion ,
@@ -1051,17 +1079,29 @@ async function onMessage(msg: p.Message) {
1051
1079
const watchers = Array . from ( workspaceFolders ) . flatMap (
1052
1080
( projectRootPath ) => [
1053
1081
{
1054
- globPattern : path . join ( projectRootPath , '**' , c . compilerLogPartialPath ) ,
1082
+ globPattern : path . join (
1083
+ projectRootPath ,
1084
+ "**" ,
1085
+ c . compilerLogPartialPath
1086
+ ) ,
1055
1087
kind : p . WatchKind . Change | p . WatchKind . Create | p . WatchKind . Delete ,
1056
1088
} ,
1057
1089
{
1058
- globPattern : path . join ( projectRootPath , '**' , c . buildNinjaPartialPath ) ,
1090
+ globPattern : path . join (
1091
+ projectRootPath ,
1092
+ "**" ,
1093
+ c . buildNinjaPartialPath
1094
+ ) ,
1059
1095
kind : p . WatchKind . Change | p . WatchKind . Create | p . WatchKind . Delete ,
1060
1096
} ,
1061
1097
{
1062
- globPattern : `${ path . join ( projectRootPath , '**' , c . compilerDirPartialPath ) } /**/*.{cmt,cmi}` ,
1098
+ globPattern : `${ path . join (
1099
+ projectRootPath ,
1100
+ "**" ,
1101
+ c . compilerDirPartialPath
1102
+ ) } /**/*.{cmt,cmi}`,
1063
1103
kind : p . WatchKind . Change | p . WatchKind . Delete ,
1064
- }
1104
+ } ,
1065
1105
]
1066
1106
) ;
1067
1107
const registrationParams : p . RegistrationParams = {
@@ -1089,7 +1129,10 @@ async function onMessage(msg: p.Message) {
1089
1129
let params = msg . params as p . DidOpenTextDocumentParams ;
1090
1130
await openedFile ( params . textDocument . uri , params . textDocument . text ) ;
1091
1131
await sendUpdatedDiagnostics ( ) ;
1092
- await updateDiagnosticSyntax ( params . textDocument . uri , params . textDocument . text ) ;
1132
+ await updateDiagnosticSyntax (
1133
+ params . textDocument . uri ,
1134
+ params . textDocument . text
1135
+ ) ;
1093
1136
} else if ( msg . method === DidChangeTextDocumentNotification . method ) {
1094
1137
let params = msg . params as p . DidChangeTextDocumentParams ;
1095
1138
let extName = path . extname ( params . textDocument . uri ) ;
0 commit comments