@@ -31,8 +31,9 @@ let diagnosticTimer: null | NodeJS.Timeout = null;
31
31
32
32
// congrats. A simple UI problem is now a distributed system problem
33
33
let stupidFileContentCache : { [ key : string ] : string } = { }
34
- let previousDiagnosticFiles : Set < string > = new Set ( )
34
+ let previouslyDiagnosedFiles : Set < string > = new Set ( )
35
35
36
+ // TODO: races here
36
37
let findDirOfFileNearFile = ( fileToFind : p . DocumentUri , source : p . DocumentUri ) : null | p . DocumentUri => {
37
38
let dir = path . dirname ( source )
38
39
if ( fs . existsSync ( path . join ( dir , fileToFind ) ) ) {
@@ -113,31 +114,20 @@ let parseDiagnosticLocation = (location: string): Range => {
113
114
}
114
115
115
116
let parseCompilerLogOutput = ( content : string , separator : string ) => {
116
- // TODO: update this content example
117
- /* example .compiler.log file content:
118
-
119
- Cleaning... 6 files.
120
- Cleaning... 87 files.
121
- [1/5] [34mBuilding[39m [2msrc/TestFramework.reiast[22m
122
- [2/5] [34mBuilding[39m [2msrc/TestFramework.reast[22m
123
- [3/5] Building src/test.resast
124
- FAILED: src/test.resast
125
- /Users/chenglou/github/bucklescript/darwin/bsc.exe -bs-jsx 3 -bs-no-version-header -o src/test.resast -bs-syntax-only -bs-binary-ast /Users/chenglou/github/reason-react/src/test.res
117
+ /* example .compiler.log file content that we're gonna parse:
126
118
127
119
Syntax error!
128
- /Users/chenglou/github/reason-react/src/test.res 1:8-2:3
120
+ /Users/chenglou/github/reason-react/src/test.res: 1:8-2:3
129
121
130
122
1 │ let a =
131
123
2 │ let b =
132
124
3 │
133
125
134
126
This let-binding misses an expression
135
127
136
- [8/29] Building src/legacy/ReactDOMServerRe.reast
137
- FAILED: src/test.cmj src/test.cmi
138
128
139
129
Warning number 8
140
- /Users/chenglou/github/reason-react/src/test.res 3:5-8
130
+ /Users/chenglou/github/reason-react/src/test.res: 3:5-8
141
131
142
132
1 │ let a = j`😀`
143
133
2 │ let b = `😀`
@@ -148,8 +138,9 @@ FAILED: src/test.cmj src/test.cmi
148
138
You forgot to handle a possible case here, for example:
149
139
Some _
150
140
141
+
151
142
We've found a bug for you!
152
- /Users/chenglou/github/reason-react/src/test.res 3:9
143
+ /Users/chenglou/github/reason-react/src/test.res: 3:9
153
144
154
145
1 │ let a = 1
155
146
2 │ let b = "hi"
@@ -160,13 +151,8 @@ FAILED: src/test.cmj src/test.cmi
160
151
161
152
But somewhere wanted:
162
153
int
163
-
164
-
165
- [15/62] [34mBuilding[39m [2msrc/ReactDOMServer.reast[22m
166
154
*/
167
155
168
- // we're gonna chop that
169
-
170
156
type parsedDiagnostic = {
171
157
code : number | undefined ,
172
158
severity : t . DiagnosticSeverity ,
@@ -183,9 +169,9 @@ FAILED: src/test.cmj src/test.cmi
183
169
content : [ ]
184
170
} )
185
171
} else if ( line . startsWith ( ' Warning number ' ) ) {
186
- let match = line . match ( / W a r n i n g n u m b e r ( \d + ) / )
172
+ let match = parseInt ( line . slice ( ' Warning number ' . length ) )
187
173
parsedDiagnostics . push ( {
188
- code : match ? parseInt ( match [ 1 ] ) : undefined ,
174
+ code : Number . isNaN ( match ) ? undefined : match ,
189
175
severity : t . DiagnosticSeverity . Warning ,
190
176
content : [ ]
191
177
} )
@@ -234,7 +220,6 @@ FAILED: src/test.cmj src/test.cmi
234
220
235
221
let startWatchingCompilerLog = ( process : NodeJS . Process ) => {
236
222
// chokidar.watch()
237
- // TOOD: setTimeout instead
238
223
let id = setInterval ( ( ) => {
239
224
let openFiles = Object . keys ( stupidFileContentCache ) ;
240
225
let compilerLogDirs : Set < p . DocumentUri > = new Set ( ) ;
@@ -246,27 +231,26 @@ let startWatchingCompilerLog = (process: NodeJS.Process) => {
246
231
}
247
232
} ) ;
248
233
249
- let files : { [ key : string ] : t . Diagnostic [ ] } = { }
250
-
234
+ let diagnosedFiles : { [ key : string ] : t . Diagnostic [ ] } = { }
251
235
compilerLogDirs . forEach ( compilerLogDir => {
252
236
let compilerLogPath = path . join ( compilerLogDir , compilerLogPartialPath ) ;
253
237
let content = fs . readFileSync ( compilerLogPath , { encoding : 'utf-8' } ) ;
254
238
let filesAndErrors = parseCompilerLogOutput ( content , ":" )
255
239
Object . keys ( filesAndErrors ) . forEach ( file => {
256
240
// assumption: there's no existing files[file] entry
257
241
// this is true; see the lines above. A file can only belong to one .compiler.log root
258
- files [ file ] = filesAndErrors [ file ]
242
+ diagnosedFiles [ file ] = filesAndErrors [ file ]
259
243
} )
260
244
} ) ;
261
245
262
246
// Send new diagnostic, wipe old ones
263
- let filePaths = Object . keys ( files )
264
- filePaths . forEach ( file => {
247
+ let diagnosedFilePaths = Object . keys ( diagnosedFiles )
248
+ diagnosedFilePaths . forEach ( file => {
265
249
let params : p . PublishDiagnosticsParams = {
266
250
uri : file ,
267
251
// there's a new optional version param from https://github.com/microsoft/language-server-protocol/issues/201
268
252
// not using it for now, sigh
269
- diagnostics : files [ file ] ,
253
+ diagnostics : diagnosedFiles [ file ] ,
270
254
}
271
255
let notification : m . NotificationMessage = {
272
256
jsonrpc : jsonrpcVersion ,
@@ -276,10 +260,10 @@ let startWatchingCompilerLog = (process: NodeJS.Process) => {
276
260
process . send ! ( notification ) ;
277
261
278
262
// this file's taken care of already now. Remove from old diagnostic files
279
- previousDiagnosticFiles . delete ( file )
263
+ previouslyDiagnosedFiles . delete ( file )
280
264
} )
281
265
// wipe the errors from the files that are no longer erroring
282
- previousDiagnosticFiles . forEach ( remainingPreviousFile => {
266
+ previouslyDiagnosedFiles . forEach ( remainingPreviousFile => {
283
267
let params : p . PublishDiagnosticsParams = {
284
268
uri : remainingPreviousFile ,
285
269
diagnostics : [ ] ,
@@ -291,7 +275,7 @@ let startWatchingCompilerLog = (process: NodeJS.Process) => {
291
275
} ;
292
276
process . send ! ( notification ) ;
293
277
} )
294
- previousDiagnosticFiles = new Set ( filePaths )
278
+ previouslyDiagnosedFiles = new Set ( diagnosedFilePaths )
295
279
} , 1000 ) ;
296
280
297
281
return id ;
@@ -351,19 +335,11 @@ process.on('message', (a: (m.RequestMessage | m.NotificationMessage)) => {
351
335
} ;
352
336
process . send ! ( response ) ;
353
337
} else if ( aa . method === 'initialize' ) {
354
- let param : p . InitializeParams = aa . params
355
- // TODO: sigh what's deprecated now?
356
- let root = param . rootUri
357
- if ( root == null ) {
358
- // TODO: handle single file
359
- console . log ( "not handling single file" )
360
- } else {
361
- diagnosticTimer = startWatchingCompilerLog ( process )
362
- }
338
+ diagnosticTimer = startWatchingCompilerLog ( process )
363
339
// send the list of things we support
364
340
let result : p . InitializeResult = {
365
341
capabilities : {
366
- // TODO: incremental sync
342
+ // TODO: incremental sync?
367
343
textDocumentSync : v . TextDocumentSyncKind . Full ,
368
344
documentFormattingProvider : true ,
369
345
}
@@ -434,12 +410,8 @@ process.on('message', (a: (m.RequestMessage | m.NotificationMessage)) => {
434
410
} ;
435
411
process . send ! ( response ) ;
436
412
} else {
437
- // file to format potentially doesn't exist anymore because of races. But that's ok, the error from bsc should handle it
413
+ // code will always be defined here, even though technically it can be undefined
438
414
let code = stupidFileContentCache [ params . textDocument . uri ] ;
439
- // TODO: error here?
440
- if ( code === undefined ) {
441
- console . log ( "can't find file" )
442
- }
443
415
let formattedResult = formatUsingValidBscPath (
444
416
code ,
445
417
path . join ( nodeModulesParentPath , bscPartialPath ) ,
0 commit comments