@@ -60,20 +60,14 @@ 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 (
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" ) ;
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" )
73
67
}
74
68
75
- return utils . findRescriptBinary ( projectRootPath ) ;
76
- } ;
69
+ return utils . findRescriptBinary ( projectRootPath )
70
+ }
77
71
78
72
let createInterfaceRequest = new v . RequestType <
79
73
p . TextDocumentIdentifier ,
@@ -208,10 +202,7 @@ let debug = false;
208
202
let syncProjectConfigCache = async ( rootPath : string ) => {
209
203
try {
210
204
if ( debug ) console . log ( "syncing project config cache for " + rootPath ) ;
211
- await utils . runAnalysisAfterSanityCheck ( rootPath , [
212
- "cache-project" ,
213
- rootPath ,
214
- ] ) ;
205
+ await utils . runAnalysisAfterSanityCheck ( rootPath , [ "cache-project" , rootPath ] ) ;
215
206
if ( debug ) console . log ( "OK - synced project config cache for " + rootPath ) ;
216
207
} catch ( e ) {
217
208
if ( debug ) console . error ( e ) ;
@@ -221,10 +212,7 @@ let syncProjectConfigCache = async (rootPath: string) => {
221
212
let deleteProjectConfigCache = async ( rootPath : string ) => {
222
213
try {
223
214
if ( debug ) console . log ( "deleting project config cache for " + rootPath ) ;
224
- await utils . runAnalysisAfterSanityCheck ( rootPath , [
225
- "cache-delete" ,
226
- rootPath ,
227
- ] ) ;
215
+ await utils . runAnalysisAfterSanityCheck ( rootPath , [ "cache-delete" , rootPath ] ) ;
228
216
if ( debug ) console . log ( "OK - deleted project config cache for " + rootPath ) ;
229
217
} catch ( e ) {
230
218
if ( debug ) console . error ( e ) ;
@@ -234,35 +222,31 @@ let deleteProjectConfigCache = async (rootPath: string) => {
234
222
async function onWorkspaceDidChangeWatchedFiles (
235
223
params : p . DidChangeWatchedFilesParams
236
224
) {
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
- }
225
+ await Promise . all ( params . changes . map ( async ( change ) => {
226
+ if ( change . uri . includes ( "build.ninja" ) ) {
227
+ if ( config . extensionConfiguration . cache ?. projectConfig ?. enable === true ) {
228
+ let projectRoot = utils . findProjectRootOfFile ( change . uri ) ;
229
+ if ( projectRoot != null ) {
230
+ await syncProjectConfigCache ( projectRoot ) ;
247
231
}
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" ) ;
232
+ }
233
+ } else if ( change . uri . includes ( "compiler.log" ) ) {
234
+ try {
235
+ await sendUpdatedDiagnostics ( ) ;
236
+ sendCompilationFinishedMessage ( ) ;
237
+ if ( config . extensionConfiguration . inlayHints ?. enable === true ) {
238
+ sendInlayHintsRefresh ( ) ;
260
239
}
261
- } else {
262
- ic . incrementalCompilationFileChanged ( fileURLToPath ( change . uri ) ) ;
240
+ if ( config . extensionConfiguration . codeLens === true ) {
241
+ sendCodeLensRefresh ( ) ;
242
+ }
243
+ } catch {
244
+ console . log ( "Error while sending updated diagnostics" ) ;
263
245
}
264
- } )
265
- ) ;
246
+ } else {
247
+ ic . incrementalCompilationFileChanged ( fileURLToPath ( change . uri ) ) ;
248
+ }
249
+ } ) ) ;
266
250
}
267
251
268
252
type clientSentBuildAction = {
@@ -290,14 +274,10 @@ let openedFile = async (fileUri: string, fileContent: string) => {
290
274
filesDiagnostics : { } ,
291
275
namespaceName :
292
276
namespaceName . kind === "success" ? namespaceName . result : null ,
293
- rescriptVersion : await utils . findReScriptVersionForProjectRoot (
294
- projectRootPath
295
- ) ,
277
+ rescriptVersion : await utils . findReScriptVersionForProjectRoot ( projectRootPath ) ,
296
278
bsbWatcherByEditor : null ,
297
279
bscBinaryLocation : await utils . findBscExeBinary ( projectRootPath ) ,
298
- editorAnalysisLocation : await utils . findEditorAnalysisBinary (
299
- projectRootPath
300
- ) ,
280
+ editorAnalysisLocation : await utils . findEditorAnalysisBinary ( projectRootPath ) ,
301
281
hasPromptedToStartBuild : / ( \/ | \\ ) n o d e _ m o d u l e s ( \/ | \\ ) / . test (
302
282
projectRootPath
303
283
)
@@ -322,7 +302,7 @@ let openedFile = async (fileUri: string, fileContent: string) => {
322
302
// TODO: sometime stale .bsb.lock dangling. bsb -w knows .bsb.lock is
323
303
// stale. Use that logic
324
304
// TODO: close watcher when lang-server shuts down
325
- if ( ( await findRescriptBinary ( projectRootPath ) ) != null ) {
305
+ if ( await findRescriptBinary ( projectRootPath ) != null ) {
326
306
let payload : clientSentBuildAction = {
327
307
title : c . startBuildAction ,
328
308
projectRootPath : projectRootPath ,
@@ -561,8 +541,10 @@ async function references(msg: p.RequestMessage) {
561
541
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
562
542
let params = msg . params as p . ReferenceParams ;
563
543
let filePath = fileURLToPath ( params . textDocument . uri ) ;
564
- let result : typeof p . ReferencesRequest . type =
565
- await utils . getReferencesForPosition ( filePath , params . position ) ;
544
+ let result : typeof p . ReferencesRequest . type = await utils . getReferencesForPosition (
545
+ filePath ,
546
+ params . position
547
+ ) ;
566
548
let response : p . ResponseMessage = {
567
549
jsonrpc : c . jsonrpcVersion ,
568
550
id : msg . id ,
@@ -572,9 +554,7 @@ async function references(msg: p.RequestMessage) {
572
554
return response ;
573
555
}
574
556
575
- async function prepareRename (
576
- msg : p . RequestMessage
577
- ) : Promise < p . ResponseMessage > {
557
+ async function prepareRename ( msg : p . RequestMessage ) : Promise < p . ResponseMessage > {
578
558
// https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_prepareRename
579
559
let params = msg . params as p . PrepareRenameParams ;
580
560
let filePath = fileURLToPath ( params . textDocument . uri ) ;
@@ -865,10 +845,7 @@ let updateDiagnosticSyntax = async (fileUri: string, fileContent: string) => {
865
845
let compilerDiagnosticsForFile =
866
846
getCurrentCompilerDiagnosticsForFile ( fileUri ) ;
867
847
let syntaxDiagnosticsForFile : p . Diagnostic [ ] =
868
- await utils . runAnalysisAfterSanityCheck ( filePath , [
869
- "diagnosticSyntax" ,
870
- tmpname ,
871
- ] ) ;
848
+ await utils . runAnalysisAfterSanityCheck ( filePath , [ "diagnosticSyntax" , tmpname ] ) ;
872
849
873
850
let notification : p . NotificationMessage = {
874
851
jsonrpc : c . jsonrpcVersion ,
@@ -1079,29 +1056,17 @@ async function onMessage(msg: p.Message) {
1079
1056
const watchers = Array . from ( workspaceFolders ) . flatMap (
1080
1057
( projectRootPath ) => [
1081
1058
{
1082
- globPattern : path . join (
1083
- projectRootPath ,
1084
- "**" ,
1085
- c . compilerLogPartialPath
1086
- ) ,
1059
+ globPattern : path . join ( projectRootPath , '**' , c . compilerLogPartialPath ) ,
1087
1060
kind : p . WatchKind . Change | p . WatchKind . Create | p . WatchKind . Delete ,
1088
1061
} ,
1089
1062
{
1090
- globPattern : path . join (
1091
- projectRootPath ,
1092
- "**" ,
1093
- c . buildNinjaPartialPath
1094
- ) ,
1063
+ globPattern : path . join ( projectRootPath , '**' , c . buildNinjaPartialPath ) ,
1095
1064
kind : p . WatchKind . Change | p . WatchKind . Create | p . WatchKind . Delete ,
1096
1065
} ,
1097
1066
{
1098
- globPattern : `${ path . join (
1099
- projectRootPath ,
1100
- "**" ,
1101
- c . compilerDirPartialPath
1102
- ) } /**/*.{cmt,cmi}`,
1067
+ globPattern : `${ path . join ( projectRootPath , '**' , c . compilerDirPartialPath ) } /**/*.{cmt,cmi}` ,
1103
1068
kind : p . WatchKind . Change | p . WatchKind . Delete ,
1104
- } ,
1069
+ }
1105
1070
]
1106
1071
) ;
1107
1072
const registrationParams : p . RegistrationParams = {
@@ -1129,10 +1094,7 @@ async function onMessage(msg: p.Message) {
1129
1094
let params = msg . params as p . DidOpenTextDocumentParams ;
1130
1095
await openedFile ( params . textDocument . uri , params . textDocument . text ) ;
1131
1096
await sendUpdatedDiagnostics ( ) ;
1132
- await updateDiagnosticSyntax (
1133
- params . textDocument . uri ,
1134
- params . textDocument . text
1135
- ) ;
1097
+ await updateDiagnosticSyntax ( params . textDocument . uri , params . textDocument . text ) ;
1136
1098
} else if ( msg . method === DidChangeTextDocumentNotification . method ) {
1137
1099
let params = msg . params as p . DidChangeTextDocumentParams ;
1138
1100
let extName = path . extname ( params . textDocument . uri ) ;
0 commit comments