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