@@ -60,20 +60,14 @@ 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 (
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" )
7367 }
7468
75- return utils . findRescriptBinary ( projectRootPath ) ;
76- } ;
69+ return utils . findRescriptBinary ( projectRootPath )
70+ }
7771
7872let createInterfaceRequest = new v . RequestType <
7973 p . TextDocumentIdentifier ,
@@ -208,10 +202,7 @@ let debug = false;
208202let syncProjectConfigCache = async ( rootPath : string ) => {
209203 try {
210204 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 ] ) ;
215206 if ( debug ) console . log ( "OK - synced project config cache for " + rootPath ) ;
216207 } catch ( e ) {
217208 if ( debug ) console . error ( e ) ;
@@ -221,10 +212,7 @@ let syncProjectConfigCache = async (rootPath: string) => {
221212let deleteProjectConfigCache = async ( rootPath : string ) => {
222213 try {
223214 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 ] ) ;
228216 if ( debug ) console . log ( "OK - deleted project config cache for " + rootPath ) ;
229217 } catch ( e ) {
230218 if ( debug ) console . error ( e ) ;
@@ -234,35 +222,31 @@ let deleteProjectConfigCache = async (rootPath: string) => {
234222async function onWorkspaceDidChangeWatchedFiles (
235223 params : p . DidChangeWatchedFilesParams
236224) {
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 ) ;
247231 }
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 ( ) ;
260239 }
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" ) ;
263245 }
264- } )
265- ) ;
246+ } else {
247+ ic . incrementalCompilationFileChanged ( fileURLToPath ( change . uri ) ) ;
248+ }
249+ } ) ) ;
266250}
267251
268252type clientSentBuildAction = {
@@ -290,14 +274,10 @@ let openedFile = async (fileUri: string, fileContent: string) => {
290274 filesDiagnostics : { } ,
291275 namespaceName :
292276 namespaceName . kind === "success" ? namespaceName . result : null ,
293- rescriptVersion : await utils . findReScriptVersionForProjectRoot (
294- projectRootPath
295- ) ,
277+ rescriptVersion : await utils . findReScriptVersionForProjectRoot ( projectRootPath ) ,
296278 bsbWatcherByEditor : null ,
297279 bscBinaryLocation : await utils . findBscExeBinary ( projectRootPath ) ,
298- editorAnalysisLocation : await utils . findEditorAnalysisBinary (
299- projectRootPath
300- ) ,
280+ editorAnalysisLocation : await utils . findEditorAnalysisBinary ( projectRootPath ) ,
301281 hasPromptedToStartBuild : / ( \/ | \\ ) n o d e _ m o d u l e s ( \/ | \\ ) / . test (
302282 projectRootPath
303283 )
@@ -322,7 +302,7 @@ let openedFile = async (fileUri: string, fileContent: string) => {
322302 // TODO: sometime stale .bsb.lock dangling. bsb -w knows .bsb.lock is
323303 // stale. Use that logic
324304 // TODO: close watcher when lang-server shuts down
325- if ( ( await findRescriptBinary ( projectRootPath ) ) != null ) {
305+ if ( await findRescriptBinary ( projectRootPath ) != null ) {
326306 let payload : clientSentBuildAction = {
327307 title : c . startBuildAction ,
328308 projectRootPath : projectRootPath ,
@@ -561,8 +541,10 @@ async function references(msg: p.RequestMessage) {
561541 // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
562542 let params = msg . params as p . ReferenceParams ;
563543 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+ ) ;
566548 let response : p . ResponseMessage = {
567549 jsonrpc : c . jsonrpcVersion ,
568550 id : msg . id ,
@@ -572,9 +554,7 @@ async function references(msg: p.RequestMessage) {
572554 return response ;
573555}
574556
575- async function prepareRename (
576- msg : p . RequestMessage
577- ) : Promise < p . ResponseMessage > {
557+ async function prepareRename ( msg : p . RequestMessage ) : Promise < p . ResponseMessage > {
578558 // https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_prepareRename
579559 let params = msg . params as p . PrepareRenameParams ;
580560 let filePath = fileURLToPath ( params . textDocument . uri ) ;
@@ -865,10 +845,7 @@ let updateDiagnosticSyntax = async (fileUri: string, fileContent: string) => {
865845 let compilerDiagnosticsForFile =
866846 getCurrentCompilerDiagnosticsForFile ( fileUri ) ;
867847 let syntaxDiagnosticsForFile : p . Diagnostic [ ] =
868- await utils . runAnalysisAfterSanityCheck ( filePath , [
869- "diagnosticSyntax" ,
870- tmpname ,
871- ] ) ;
848+ await utils . runAnalysisAfterSanityCheck ( filePath , [ "diagnosticSyntax" , tmpname ] ) ;
872849
873850 let notification : p . NotificationMessage = {
874851 jsonrpc : c . jsonrpcVersion ,
@@ -1079,29 +1056,17 @@ async function onMessage(msg: p.Message) {
10791056 const watchers = Array . from ( workspaceFolders ) . flatMap (
10801057 ( projectRootPath ) => [
10811058 {
1082- globPattern : path . join (
1083- projectRootPath ,
1084- "**" ,
1085- c . compilerLogPartialPath
1086- ) ,
1059+ globPattern : path . join ( projectRootPath , '**' , c . compilerLogPartialPath ) ,
10871060 kind : p . WatchKind . Change | p . WatchKind . Create | p . WatchKind . Delete ,
10881061 } ,
10891062 {
1090- globPattern : path . join (
1091- projectRootPath ,
1092- "**" ,
1093- c . buildNinjaPartialPath
1094- ) ,
1063+ globPattern : path . join ( projectRootPath , '**' , c . buildNinjaPartialPath ) ,
10951064 kind : p . WatchKind . Change | p . WatchKind . Create | p . WatchKind . Delete ,
10961065 } ,
10971066 {
1098- globPattern : `${ path . join (
1099- projectRootPath ,
1100- "**" ,
1101- c . compilerDirPartialPath
1102- ) } /**/*.{cmt,cmi}`,
1067+ globPattern : `${ path . join ( projectRootPath , '**' , c . compilerDirPartialPath ) } /**/*.{cmt,cmi}` ,
11031068 kind : p . WatchKind . Change | p . WatchKind . Delete ,
1104- } ,
1069+ }
11051070 ]
11061071 ) ;
11071072 const registrationParams : p . RegistrationParams = {
@@ -1129,10 +1094,7 @@ async function onMessage(msg: p.Message) {
11291094 let params = msg . params as p . DidOpenTextDocumentParams ;
11301095 await openedFile ( params . textDocument . uri , params . textDocument . text ) ;
11311096 await sendUpdatedDiagnostics ( ) ;
1132- await updateDiagnosticSyntax (
1133- params . textDocument . uri ,
1134- params . textDocument . text
1135- ) ;
1097+ await updateDiagnosticSyntax ( params . textDocument . uri , params . textDocument . text ) ;
11361098 } else if ( msg . method === DidChangeTextDocumentNotification . method ) {
11371099 let params = msg . params as p . DidChangeTextDocumentParams ;
11381100 let extName = path . extname ( params . textDocument . uri ) ;
0 commit comments