1
1
/* @flow */
2
2
3
- import net from 'net'
4
- import { CompositeDisposable } from 'atom'
5
- import { spawnServer , terminateServer } from './server'
6
- import type { Server } from './types'
3
+ import net from 'net' ;
4
+ import { CompositeDisposable } from 'atom' ;
5
+ import { spawnServer , terminateServer } from './server' ;
6
+ import type { Server } from './types' ;
7
7
8
- let spawnedServer : ?Server = null
9
- let subscriptions : ?Object = null
8
+ let spawnedServer : ?Server = null ;
9
+ let subscriptions : ?Object = null ;
10
10
11
- let ignoreInfo
12
- let ignoreWarning
13
- let showErrorCodes
14
- let ignoreIssueCodes
11
+ let ignoreInfo ;
12
+ let ignoreWarning ;
13
+ let showErrorCodes ;
14
+ let ignoreIssueCodes ;
15
15
16
16
export function activate ( ) {
17
17
// eslint-disable-next-line global-require
18
- require ( 'atom-package-deps' ) . install ( 'linter-julia' )
19
- subscriptions = new CompositeDisposable ( )
18
+ require ( 'atom-package-deps' ) . install ( 'linter-julia' ) ;
19
+ subscriptions = new CompositeDisposable ( ) ;
20
20
subscriptions . add ( atom . config . observe ( 'linter-julia.executablePath' , async ( executablePath ) => {
21
21
if ( spawnedServer ) {
22
22
try {
23
- await terminateServer ( spawnedServer )
24
- spawnedServer = null
25
- spawnedServer = await spawnServer ( executablePath )
23
+ await terminateServer ( spawnedServer ) ;
24
+ spawnedServer = null ;
25
+ spawnedServer = await spawnServer ( executablePath ) ;
26
26
} catch ( e ) {
27
- console . error ( '[Linter-Julia] Unable to spawn server after config change' , e )
27
+ const message = '[Linter-Julia] '
28
+ + 'Unable to spawn server after config change' ;
29
+ atom . notifications . addError ( `${ message } . See console for details.` ) ;
30
+ // eslint-disable-next-line no-console
31
+ console . error ( `${ message } : ` , e ) ;
28
32
}
29
33
}
30
- } ) )
34
+ } ) ) ;
31
35
subscriptions . add ( atom . config . observe ( 'linter-julia.ignoreInfo' , ( _ignoreInfo ) => {
32
- ignoreInfo = _ignoreInfo
33
- } ) )
36
+ ignoreInfo = _ignoreInfo ;
37
+ } ) ) ;
34
38
subscriptions . add ( atom . config . observe ( 'linter-julia.ignoreWarning' , ( _ignoreWarning ) => {
35
- ignoreWarning = _ignoreWarning
36
- } ) )
39
+ ignoreWarning = _ignoreWarning ;
40
+ } ) ) ;
37
41
subscriptions . add ( atom . config . observe ( 'linter-julia.showErrorCodes' , ( _showErrorCodes ) => {
38
- showErrorCodes = _showErrorCodes
39
- } ) )
42
+ showErrorCodes = _showErrorCodes ;
43
+ } ) ) ;
40
44
subscriptions . add ( atom . config . observe ( 'linter-julia.ignoreIssueCodes' , ( _ignoreIssueCodes ) => {
41
- ignoreIssueCodes = _ignoreIssueCodes
42
- } ) )
45
+ ignoreIssueCodes = _ignoreIssueCodes ;
46
+ } ) ) ;
43
47
}
44
48
45
49
export function deactivate ( ) {
46
50
if ( spawnedServer ) {
47
- terminateServer ( spawnedServer )
48
- spawnedServer = null
51
+ terminateServer ( spawnedServer ) ;
52
+ spawnedServer = null ;
49
53
}
50
54
if ( subscriptions ) {
51
- subscriptions . dispose ( )
55
+ subscriptions . dispose ( ) ;
52
56
}
53
57
}
54
58
@@ -60,45 +64,48 @@ export function provideLinter() {
60
64
grammarScopes : [ 'source.julia' ] ,
61
65
async lint ( textEditor : Object ) {
62
66
if ( ! spawnedServer ) {
63
- spawnedServer = await spawnServer ( atom . config . get ( 'linter-julia.executablePath' ) )
67
+ spawnedServer = await spawnServer ( atom . config . get ( 'linter-julia.executablePath' ) ) ;
64
68
}
65
- const connection = net . createConnection ( spawnedServer . path )
66
- connection . on ( 'connect' , function ( ) {
69
+ const connection = net . createConnection ( spawnedServer . path ) ;
70
+ connection . on ( 'connect' , ( ) => {
67
71
this . write ( JSON . stringify ( {
68
72
file : textEditor . getPath ( ) ,
69
73
code_str : textEditor . getText ( ) ,
70
74
show_code : showErrorCodes ,
71
75
ignore_info : ignoreInfo ,
72
76
ignore_codes : ignoreIssueCodes ,
73
77
ignore_warnings : ignoreWarning ,
74
- } ) )
75
- } )
78
+ } ) ) ;
79
+ } ) ;
76
80
77
- return new Promise ( function ( resolve , reject ) {
78
- setTimeout ( function ( ) {
81
+ return new Promise ( ( ( resolve , reject ) => {
82
+ setTimeout ( ( ) => {
79
83
// This is the timeout because net.Socket doesn't have one for connections
80
- reject ( new Error ( 'Request timed out' ) )
81
- connection . end ( )
82
- } , 60 * 1000 )
83
- connection . on ( 'error' , reject )
84
+ reject ( new Error ( 'Request timed out' ) ) ;
85
+ connection . end ( ) ;
86
+ } , 60 * 1000 ) ;
87
+ connection . on ( 'error' , reject ) ;
84
88
85
- const data = [ ]
86
- connection . on ( 'data' , function ( chunk ) {
87
- data . push ( chunk )
88
- } )
89
- connection . on ( 'close' , function ( ) {
90
- let parsed
91
- const merged = data . join ( '' )
89
+ const data = [ ] ;
90
+ connection . on ( 'data' , ( chunk ) => {
91
+ data . push ( chunk ) ;
92
+ } ) ;
93
+ connection . on ( 'close' , ( ) => {
94
+ let parsed ;
95
+ const merged = data . join ( '' ) ;
92
96
try {
93
- parsed = JSON . parse ( merged )
97
+ parsed = JSON . parse ( merged ) ;
94
98
} catch ( _ ) {
95
- console . error ( '[Linter-Julia] Server returned non-JSON response: ' , merged )
96
- reject ( new Error ( 'Error parsing server response. See console for more info' ) )
97
- return
99
+ const msg = '[Linter-Julia] Server returned non-JSON response' ;
100
+ atom . notifications . addError ( `${ msg } . See console for more info` ) ;
101
+ // eslint-disable-next-line no-console
102
+ console . error ( `${ msg } : ` , merged ) ;
103
+ resolve ( null ) ;
104
+ return ;
98
105
}
99
- resolve ( parsed )
100
- } )
101
- } )
106
+ resolve ( parsed ) ;
107
+ } ) ;
108
+ } ) ) ;
102
109
} ,
103
- }
110
+ } ;
104
111
}
0 commit comments