@@ -22,22 +22,8 @@ let initialized = false;
22
22
// https://microsoft.github.io/language-server-protocol/specification#exit
23
23
let shutdownRequestAlreadyReceived = false ;
24
24
let 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
- */
39
25
let projectsFiles : Map <
40
- string ,
26
+ string , // project root path
41
27
{
42
28
openFiles : Set < string > ,
43
29
filesWithDiagnostics : Set < string > ,
@@ -46,14 +32,12 @@ let projectsFiles: Map<
46
32
// ^ caching AND states AND distributed system. Why does LSP has to be stupid like this
47
33
48
34
let 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' } ) ;
52
37
let { done, result : filesAndErrors } = utils . parseCompilerLogOutput ( content )
53
38
54
39
// diff
55
40
Object . keys ( filesAndErrors ) . forEach ( file => {
56
- // send diagnostic
57
41
let params : p . PublishDiagnosticsParams = {
58
42
uri : file ,
59
43
diagnostics : filesAndErrors [ file ] ,
@@ -88,10 +72,10 @@ let sendUpdatedDiagnostics = () => {
88
72
}
89
73
} ) ;
90
74
}
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 => {
95
79
let params : p . PublishDiagnosticsParams = {
96
80
uri : file ,
97
81
diagnostics : [ ] ,
@@ -104,7 +88,7 @@ let deleteProjectDiagnostics = (compilerLogPath: string) => {
104
88
process . send ! ( notification ) ;
105
89
} )
106
90
107
- projectsFiles . delete ( compilerLogPath )
91
+ projectsFiles . delete ( projectRootPath )
108
92
}
109
93
}
110
94
@@ -123,15 +107,14 @@ let openedFile = (fileUri: string, fileContent: string) => {
123
107
124
108
stupidFileContentCache . set ( filePath , fileContent )
125
109
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 ) )
132
115
}
133
- let compilerLog = projectsFiles . get ( compilerLogPath ) !
134
- compilerLog . openFiles . add ( filePath )
116
+ let root = projectsFiles . get ( projectRootPath ) !
117
+ root . openFiles . add ( filePath )
135
118
// no need to call sendUpdatedDiagnostics() here; the watcher add will
136
119
// call the listener which calls it
137
120
}
@@ -141,16 +124,15 @@ let closedFile = (fileUri: string) => {
141
124
142
125
stupidFileContentCache . delete ( filePath )
143
126
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 )
150
132
// 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 )
154
136
}
155
137
}
156
138
}
0 commit comments