@@ -10,37 +10,50 @@ const CmdExport = require( './commands/export' )
10
10
const { CurrentDoc } = require ( './commands/currentdoc' )
11
11
const IsApiError = require ( './is-api-error' )
12
12
13
-
14
-
15
13
const activate = context => {
16
14
17
15
const log = LOG ( window )
18
- const options = workspace . getConfiguration ( 'cos' )
19
- const conn = options . get ( 'conn' )
20
- conn . toString = function ( ) {
21
- return JSON . stringify (
22
- Object . assign ( { } , conn , {
23
- password : "***" //hide passw
24
- } ) ,
25
- null , //replacer
26
- 4 //space
27
- )
16
+
17
+ const Config = workspace => {
18
+
19
+ let options = null ;
20
+ const init = ( ) => { options = workspace . getConfiguration ( 'cos' ) }
21
+ init ( )
22
+
23
+ return {
24
+
25
+ init,
26
+ conn : ( ) => {
27
+ const _conn = options . get ( 'conn' )
28
+ _conn . toString = ( ) => JSON . stringify ( Object . assign ( { } , _conn , { password : '***' } ) , null , 4 )
29
+ return _conn
30
+ } ,
31
+ export : ( ) => {
32
+ const root = workspace . rootPath
33
+ return Object . assign ( { } , options . get ( 'export' ) , { root } )
34
+ }
35
+ }
28
36
}
29
37
30
- const api = API ( conn )
38
+ const config = Config ( workspace )
39
+ let api = API ( config . conn ( ) )
40
+ let { exportAll, ExportDoc } = CmdExport ( { api, log, options : config . export } )
31
41
32
- api . headServer ( err => {
42
+ workspace . onDidChangeConfiguration ( ( ) => {
33
43
34
- if ( err ) return log ( 'Connection FAILED: ' + conn )
44
+ config . init ( )
45
+ api = API ( config . conn ( ) )
46
+ ( { exportAll, ExportDoc } = CmdExport ( { api, log, options : config . export } ) )
47
+
48
+ } , null , context . subscriptions ) //reload config on event
49
+
50
+ api . headServer ( err => {
51
+ const conn = config . conn ( )
52
+ if ( err ) return log ( 'Connection FAILED: ' + conn , err )
35
53
log ( 'Connected ' + conn )
36
54
panel . set ( conn )
37
-
38
55
} )
39
56
40
- const exportTo = options . get ( 'export' )
41
- exportTo . root = workspace . rootPath
42
-
43
- const { exportAll, ExportDoc } = CmdExport ( { api, log, options : exportTo } )
44
57
const currentDoc = CurrentDoc ( { window, languages, log } )
45
58
46
59
const Save = ( { name, log } ) => ( err , data ) => {
@@ -99,8 +112,8 @@ const activate = context => {
99
112
}
100
113
101
114
context . subscriptions . push (
102
- vscode . commands . registerCommand ( 'cos.compile' , importCompileExport ) ,
103
- vscode . commands . registerCommand ( 'cos.export' , exportAll )
115
+ vscode . commands . registerCommand ( 'cos.compile' , importCompileExport ) ,
116
+ vscode . commands . registerCommand ( 'cos.export' , ( ) => exportAll ( ) )
104
117
)
105
118
106
119
}
0 commit comments