Skip to content

Use VSCode-EmmyLua config to provide global config #22

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 27, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as vscode from 'vscode';
import * as tt from './tt';
import * as fs from 'fs';
import * as os from 'os';
import * as _ from 'lodash';

Check warning on line 4 in src/extension.ts

View workflow job for this annotation

GitHub Actions / Lint

Import name `_` must match one of the following formats: camelCase, PascalCase
import * as utils from './utils';

const annotationsPaths = [
Expand All @@ -18,28 +17,41 @@
}
};
const emmyrcFile = '.emmyrc.json';
const globalEmmyrcKey = 'emmylua.misc.globalConfigPath';
const globalEmmyrcPath = __dirname + `/${emmyrcFile}`;

async function initGlobalEmmyrc() {
const globalEmmyrcPath = `${os.homedir()}/${emmyrcFile}`;

if (!fs.existsSync(globalEmmyrcPath)) {
fs.writeFileSync(globalEmmyrcPath, JSON.stringify(emmyrc, undefined, 2));
vscode.window.showInformationMessage(`Initialized ${globalEmmyrcPath} with Tarantool-specific settings`);
return;
const config = vscode.workspace.getConfiguration(undefined, null);
const configuredGlobalEmmyrcPath = config.get(globalEmmyrcKey);

let existingEmmyrc = {};
try {
const f = fs.readFileSync(globalEmmyrcPath, 'utf8');
existingEmmyrc = JSON.parse(f);
} catch {
existingEmmyrc = {};
}

const f = fs.readFileSync(globalEmmyrcPath, 'utf8');
const existingEmmyrc = JSON.parse(f);
const upToDate = _.isMatch(existingEmmyrc, emmyrc);
if (upToDate) {
return;
if (!upToDate) {
fs.writeFileSync(globalEmmyrcPath, JSON.stringify(emmyrc, undefined, 2));
}

// TODO: Don't miss user-defined libraries.
const mergedEmmyrc = _.merge(existingEmmyrc, emmyrc);

fs.writeFileSync(globalEmmyrcPath, JSON.stringify(mergedEmmyrc, undefined, 2));
vscode.window.showInformationMessage(`Updated existing ${globalEmmyrcPath} with actual Tarantool-specific configuration`);
const desiredGlobalEmmyrcPath = globalEmmyrcPath;
if (configuredGlobalEmmyrcPath !== desiredGlobalEmmyrcPath) {
try {
await config.update(globalEmmyrcKey, desiredGlobalEmmyrcPath, vscode.ConfigurationTarget.Global);
} catch {
vscode.window.showWarningMessage(`Tarantool extension has been unable to update the global configuration of the EmmyLua extension with its specific annotations. Run 'Tarantool: Initialize VS Code extension...' to initialize the annotations per-project`);
return;
}
try {
await vscode.commands.executeCommand('emmy.restartServer');
} catch {
vscode.window.showWarningMessage(`Tarantool extension has updated the configuration but wasn't able to restart the EmmyLua extension. Please, restart it manually`);
return;
}
vscode.window.showInformationMessage(`The EmmyLua extension has been updated with Tarantool-specific settings`);
}
}

async function initVs() {
Expand Down