@@ -22,22 +22,8 @@ let initialized = false;
2222// https://microsoft.github.io/language-server-protocol/specification#exit
2323let shutdownRequestAlreadyReceived = false ;
2424let stupidFileContentCache : Map < string , string > = new Map ( )
25- /*
26- Map {
27- '/foo/lib/bs/.compiler.log': Map {
28- '/foo/src/A.res': {
29- trackedContent: 'let a = 1',
30- hasDiagnostics: false
31- }
32- '/foo/src/B.res': {
33- trackedContent: null,
34- hasDiagnostics: true
35- }
36- },
37- }
38- */
3925let projectsFiles : Map <
40- string ,
26+ string , // project root path
4127 {
4228 openFiles : Set < string > ,
4329 filesWithDiagnostics : Set < string > ,
@@ -46,14 +32,12 @@ let projectsFiles: Map<
4632// ^ caching AND states AND distributed system. Why does LSP has to be stupid like this
4733
4834let sendUpdatedDiagnostics = ( ) => {
49- projectsFiles . forEach ( ( { filesWithDiagnostics } , compilerLogPath ) => {
50- let content = fs . readFileSync ( compilerLogPath , { encoding : 'utf-8' } ) ;
51- console . log ( "new log content: " , compilerLogPath , content )
35+ projectsFiles . forEach ( ( { filesWithDiagnostics } , projectRootPath ) => {
36+ let content = fs . readFileSync ( path . join ( projectRootPath , c . compilerLogPartialPath ) , { encoding : 'utf-8' } ) ;
5237 let { done, result : filesAndErrors } = utils . parseCompilerLogOutput ( content )
5338
5439 // diff
5540 Object . keys ( filesAndErrors ) . forEach ( file => {
56- // send diagnostic
5741 let params : p . PublishDiagnosticsParams = {
5842 uri : file ,
5943 diagnostics : filesAndErrors [ file ] ,
@@ -88,10 +72,10 @@ let sendUpdatedDiagnostics = () => {
8872 }
8973 } ) ;
9074}
91- let deleteProjectDiagnostics = ( compilerLogPath : string ) => {
92- let compilerLog = projectsFiles . get ( compilerLogPath )
93- if ( compilerLog != null ) {
94- compilerLog . filesWithDiagnostics . forEach ( file => {
75+ let deleteProjectDiagnostics = ( projectRootPath : string ) => {
76+ let root = projectsFiles . get ( projectRootPath )
77+ if ( root != null ) {
78+ root . filesWithDiagnostics . forEach ( file => {
9579 let params : p . PublishDiagnosticsParams = {
9680 uri : file ,
9781 diagnostics : [ ] ,
@@ -104,7 +88,7 @@ let deleteProjectDiagnostics = (compilerLogPath: string) => {
10488 process . send ! ( notification ) ;
10589 } )
10690
107- projectsFiles . delete ( compilerLogPath )
91+ projectsFiles . delete ( projectRootPath )
10892 }
10993}
11094
@@ -123,15 +107,14 @@ let openedFile = (fileUri: string, fileContent: string) => {
123107
124108 stupidFileContentCache . set ( filePath , fileContent )
125109
126- let compilerLogDir = utils . findDirOfFileNearFile ( c . compilerLogPartialPath , filePath )
127- if ( compilerLogDir != null ) {
128- let compilerLogPath = path . join ( compilerLogDir , c . compilerLogPartialPath ) ;
129- if ( ! projectsFiles . has ( compilerLogPath ) ) {
130- projectsFiles . set ( compilerLogPath , { openFiles : new Set ( ) , filesWithDiagnostics : new Set ( ) } )
131- compilerLogsWatcher . add ( compilerLogPath )
110+ let projectRootPath = utils . findDirOfFileNearFile ( c . bsconfigPartialPath , filePath )
111+ if ( projectRootPath != null ) {
112+ if ( ! projectsFiles . has ( projectRootPath ) ) {
113+ projectsFiles . set ( projectRootPath , { openFiles : new Set ( ) , filesWithDiagnostics : new Set ( ) } )
114+ compilerLogsWatcher . add ( path . join ( projectRootPath , c . compilerLogPartialPath ) )
132115 }
133- let compilerLog = projectsFiles . get ( compilerLogPath ) !
134- compilerLog . openFiles . add ( filePath )
116+ let root = projectsFiles . get ( projectRootPath ) !
117+ root . openFiles . add ( filePath )
135118 // no need to call sendUpdatedDiagnostics() here; the watcher add will
136119 // call the listener which calls it
137120 }
@@ -141,16 +124,15 @@ let closedFile = (fileUri: string) => {
141124
142125 stupidFileContentCache . delete ( filePath )
143126
144- let compilerLogDir = utils . findDirOfFileNearFile ( c . compilerLogPartialPath , filePath )
145- if ( compilerLogDir != null ) {
146- let compilerLogPath = path . join ( compilerLogDir , c . compilerLogPartialPath ) ;
147- let compilerLog = projectsFiles . get ( compilerLogPath )
148- if ( compilerLog != null ) {
149- compilerLog . openFiles . delete ( filePath )
127+ let projectRootPath = utils . findDirOfFileNearFile ( c . bsconfigPartialPath , filePath )
128+ if ( projectRootPath != null ) {
129+ let root = projectsFiles . get ( projectRootPath )
130+ if ( root != null ) {
131+ root . openFiles . delete ( filePath )
150132 // clear diagnostics too if no open files open in said project
151- if ( compilerLog . openFiles . size === 0 ) {
152- compilerLogsWatcher . unwatch ( compilerLogPath )
153- deleteProjectDiagnostics ( compilerLogPath )
133+ if ( root . openFiles . size === 0 ) {
134+ compilerLogsWatcher . unwatch ( path . join ( projectRootPath , c . compilerLogPartialPath ) )
135+ deleteProjectDiagnostics ( projectRootPath )
154136 }
155137 }
156138 }
0 commit comments