@@ -50,7 +50,7 @@ let projectsFiles: Map<
50
50
let codeActionsFromDiagnostics : codeActions . filesCodeActions = { } ;
51
51
52
52
// will be properly defined later depending on the mode (stdio/node-rpc)
53
- let send : ( msg : p . Message ) => void = ( _ ) => { } ;
53
+ let send : ( msg : p . Message ) => void = ( _ ) => { } ;
54
54
55
55
interface CreateInterfaceRequestParams {
56
56
uri : string ;
@@ -588,6 +588,33 @@ function format(msg: p.RequestMessage): Array<p.Message> {
588
588
}
589
589
}
590
590
591
+ const updateDiagnosticSyntax = ( fileUri : string , fileContent : string ) => {
592
+ const filePath = fileURLToPath ( fileUri ) ;
593
+ const tmpname = utils . createFileInTempDir ( ) ;
594
+ fs . writeFileSync ( tmpname , fileContent , { encoding : "utf-8" } ) ;
595
+
596
+ const items : p . Diagnostic [ ] | [ ] = utils . runAnalysisAfterSanityCheck (
597
+ filePath ,
598
+ [
599
+ "diagnosticSyntax" ,
600
+ tmpname
601
+ ] ,
602
+ ) ;
603
+
604
+ const notification : p . NotificationMessage = {
605
+ jsonrpc : c . jsonrpcVersion ,
606
+ method : "textDocument/publishDiagnostics" ,
607
+ params : {
608
+ uri : fileUri ,
609
+ diagnostics : items ?? [ ]
610
+ }
611
+ }
612
+
613
+ fs . unlink ( tmpname , ( ) => null ) ;
614
+
615
+ send ( notification )
616
+ }
617
+
591
618
function createInterface ( msg : p . RequestMessage ) : p . Message {
592
619
let params = msg . params as CreateInterfaceRequestParams ;
593
620
let extension = path . extname ( params . uri ) ;
@@ -774,6 +801,7 @@ function onMessage(msg: p.Message) {
774
801
} else if ( msg . method === DidOpenTextDocumentNotification . method ) {
775
802
let params = msg . params as p . DidOpenTextDocumentParams ;
776
803
openedFile ( params . textDocument . uri , params . textDocument . text ) ;
804
+ updateDiagnosticSyntax ( params . textDocument . uri , params . textDocument . text ) ;
777
805
} else if ( msg . method === DidChangeTextDocumentNotification . method ) {
778
806
let params = msg . params as p . DidChangeTextDocumentParams ;
779
807
let extName = path . extname ( params . textDocument . uri ) ;
@@ -787,6 +815,7 @@ function onMessage(msg: p.Message) {
787
815
params . textDocument . uri ,
788
816
changes [ changes . length - 1 ] . text
789
817
) ;
818
+ updateDiagnosticSyntax ( params . textDocument . uri , changes [ changes . length - 1 ] . text ) ;
790
819
}
791
820
}
792
821
} else if ( msg . method === DidCloseTextDocumentNotification . method ) {
0 commit comments