1
1
import * as vscode from 'vscode' ;
2
2
import * as tt from './tt' ;
3
3
import * as fs from 'fs' ;
4
+ import * as os from 'os' ;
5
+ import * as _ from 'lodash' ;
4
6
5
7
const annotationsPaths = [ __dirname + "/Library" ] ;
6
8
const emmyrc = {
@@ -11,6 +13,31 @@ const emmyrc = {
11
13
"library" : annotationsPaths
12
14
}
13
15
} ;
16
+ const emmyrcFile = '.emmyrc.json' ;
17
+
18
+ async function initGlobalEmmyrc ( ) {
19
+ const globalEmmyrcPath = `${ os . homedir ( ) } /${ emmyrcFile } ` ;
20
+
21
+ if ( ! fs . existsSync ( globalEmmyrcPath ) ) {
22
+ fs . writeFileSync ( globalEmmyrcPath , JSON . stringify ( emmyrc , undefined , 2 ) ) ;
23
+ vscode . window . showInformationMessage ( `Initialized ${ globalEmmyrcPath } with Tarantool-specific settings` ) ;
24
+ return ;
25
+ }
26
+
27
+ const f = fs . readFileSync ( globalEmmyrcPath , 'utf8' ) ;
28
+ const existingEmmyrc = JSON . parse ( f ) ;
29
+ const upToDate = _ . isMatch ( existingEmmyrc , emmyrc ) ;
30
+ if ( upToDate ) {
31
+ vscode . window . showInformationMessage ( `${ globalEmmyrcPath } is up to date` ) ;
32
+ return ;
33
+ }
34
+
35
+ // TODO: Don't miss user-defined libraries.
36
+ const mergedEmmyrc = _ . merge ( existingEmmyrc , emmyrc ) ;
37
+
38
+ fs . writeFileSync ( globalEmmyrcPath , JSON . stringify ( mergedEmmyrc , undefined , 2 ) ) ;
39
+ vscode . window . showInformationMessage ( `Updated existing ${ globalEmmyrcPath } with actual Tarantool-specific configuration` ) ;
40
+ }
14
41
15
42
async function initVs ( ) {
16
43
const file = vscode . window . activeTextEditor ?. document . uri . fsPath ;
@@ -28,7 +55,6 @@ async function initVs() {
28
55
return ;
29
56
}
30
57
31
- const emmyrcFile = '.emmyrc.json' ;
32
58
const filePath = vscode . Uri . file ( `${ wsPath } /${ emmyrcFile } ` ) ;
33
59
if ( fs . existsSync ( filePath . fsPath ) ) {
34
60
const yes = "Yes" ;
@@ -38,7 +64,7 @@ async function initVs() {
38
64
}
39
65
wsedit . createFile ( filePath , {
40
66
overwrite : true ,
41
- contents : Buffer . from ( JSON . stringify ( emmyrc ) )
67
+ contents : Buffer . from ( JSON . stringify ( emmyrc , undefined , 2 ) )
42
68
} ) ;
43
69
vscode . workspace . applyEdit ( wsedit ) ;
44
70
vscode . window . showInformationMessage ( `Created a new file: ${ filePath . toString ( ) } ` ) ;
@@ -63,6 +89,8 @@ export function activate(context: vscode.ExtensionContext) {
63
89
return ;
64
90
}
65
91
92
+ initGlobalEmmyrc ( ) ;
93
+
66
94
const commands = [
67
95
{ name : 'init-vs' , cb : initVs } ,
68
96
{ name : 'create' , cb : tt . create } ,
0 commit comments