Skip to content

Commit f79afc5

Browse files
Use VSCode-EmmyLua config to provide global config
In e356b99 ('Set up language server configuration automatically') logic for setting up EmmyLuaLs automatically has been added. It used a configuration file at the home directory. It's not really very cool to spam with extension-specific files at the user's home dir. A patch [^1] has been introduced allowing one to specify a path to a global language server configuration file within the VS Code options. Let's set up this instead. [^1] EmmyLua/VSCode-EmmyLua#227
1 parent b490488 commit f79afc5

File tree

1 file changed

+14
-15
lines changed

1 file changed

+14
-15
lines changed

src/extension.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import * as vscode from 'vscode';
22
import * as tt from './tt';
33
import * as fs from 'fs';
4-
import * as os from 'os';
54
import * as _ from 'lodash';
65
import * as utils from './utils';
76

@@ -18,28 +17,28 @@ const emmyrc = {
1817
}
1918
};
2019
const emmyrcFile = '.emmyrc.json';
20+
const globalEmmyrcKey = 'emmylua.misc.globalConfigPath';
21+
const globalEmmyrcPath = __dirname + '/emmyrc.json';
2122

2223
async function initGlobalEmmyrc() {
23-
const globalEmmyrcPath = `${os.homedir()}/${emmyrcFile}`;
24+
const config = vscode.workspace.getConfiguration(undefined, null);
25+
const configuredGlobalEmmyrcPath = config.get(globalEmmyrcKey);
2426

25-
if (!fs.existsSync(globalEmmyrcPath)) {
26-
fs.writeFileSync(globalEmmyrcPath, JSON.stringify(emmyrc, undefined, 2));
27-
vscode.window.showInformationMessage(`Initialized ${globalEmmyrcPath} with Tarantool-specific settings`);
28-
return;
29-
}
30-
31-
const f = fs.readFileSync(globalEmmyrcPath, 'utf8');
27+
const f = fs.existsSync(globalEmmyrcPath) ? fs.readFileSync(globalEmmyrcPath, 'utf8') : '{}';
3228
const existingEmmyrc = JSON.parse(f);
3329
const upToDate = _.isMatch(existingEmmyrc, emmyrc);
34-
if (upToDate) {
35-
return;
30+
if (!upToDate) {
31+
fs.writeFileSync(globalEmmyrcPath, JSON.stringify(emmyrc, undefined, 2), { });
3632
}
3733

38-
// TODO: Don't miss user-defined libraries.
39-
const mergedEmmyrc = _.merge(existingEmmyrc, emmyrc);
34+
const desiredGlobalEmmyrcPath = globalEmmyrcPath;
4035

41-
fs.writeFileSync(globalEmmyrcPath, JSON.stringify(mergedEmmyrc, undefined, 2));
42-
vscode.window.showInformationMessage(`Updated existing ${globalEmmyrcPath} with actual Tarantool-specific configuration`);
36+
if (configuredGlobalEmmyrcPath !== desiredGlobalEmmyrcPath) {
37+
await config.update(globalEmmyrcKey, desiredGlobalEmmyrcPath, vscode.ConfigurationTarget.Global);
38+
vscode.commands.executeCommand('emmy.restartServer');
39+
vscode.window.showInformationMessage(`Updated EmmyLua extension with Tarantool-specific settings`);
40+
return;
41+
}
4342
}
4443

4544
async function initVs() {

0 commit comments

Comments
 (0)