11import * as vscode from 'vscode' ;
22import * as tt from './tt' ;
33import * as fs from 'fs' ;
4+ import * as os from 'os' ;
5+ import * as _ from 'lodash' ;
46
57const annotationsPaths = [
68 __dirname + "/Library" ,
@@ -14,6 +16,31 @@ const emmyrc = {
1416 "library" : annotationsPaths
1517 }
1618} ;
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+ }
1744
1845async function initVs ( ) {
1946 const file = vscode . window . activeTextEditor ?. document . uri . fsPath ;
@@ -31,7 +58,6 @@ async function initVs() {
3158 return ;
3259 }
3360
34- const emmyrcFile = '.emmyrc.json' ;
3561 const filePath = vscode . Uri . file ( `${ wsPath } /${ emmyrcFile } ` ) ;
3662 if ( fs . existsSync ( filePath . fsPath ) ) {
3763 const yes = "Yes" ;
@@ -41,7 +67,7 @@ async function initVs() {
4167 }
4268 wsedit . createFile ( filePath , {
4369 overwrite : true ,
44- contents : Buffer . from ( JSON . stringify ( emmyrc ) )
70+ contents : Buffer . from ( JSON . stringify ( emmyrc , undefined , 2 ) )
4571 } ) ;
4672 vscode . workspace . applyEdit ( wsedit ) ;
4773 vscode . window . showInformationMessage ( `Created a new file: ${ filePath . toString ( ) } ` ) ;
@@ -66,6 +92,8 @@ export function activate(context: vscode.ExtensionContext) {
6692 return ;
6793 }
6894
95+ initGlobalEmmyrc ( ) ;
96+
6997 const commands = [
7098 { name : 'init-vs' , cb : initVs } ,
7199 { name : 'create' , cb : tt . create } ,
0 commit comments