Skip to content

Commit e356b99

Browse files
Set up language server configuration automatically
Now, Tarantool VS Code extension automatically setups annotations on system level by providing the default configuration within `$HOME/.emmyrc.json`. This requires [VSCode Emmylua 0.9.18] (https://github.com/EmmyLua/VSCode-EmmyLua/tree/0.9.18). Closes #12
1 parent 6713254 commit e356b99

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88

99
## [Unreleased]
1010

11+
### Changed
12+
13+
- Now the extension automatically setups Tarantool annotations without need to
14+
explicitly execute any commands like `initialize VS Code extension`.
15+
1116
## [0.1.3] - 14.04.2025
1217

1318
### Added

package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
"linter",
2525
"snippets"
2626
],
27-
"activationEvents": [],
27+
"activationEvents": [
28+
"onLanguage:lua"
29+
],
2830
"main": "./dist/extension.js",
2931
"contributes": {
3032
"commands": [
@@ -89,6 +91,7 @@
8991
"devDependencies": {
9092
"@octokit/core": "^5",
9193
"@types/command-exists": "^1.2.3",
94+
"@types/lodash": "^4.17.16",
9295
"@types/mocha": "^10.0.10",
9396
"@types/node": "20.x",
9497
"@types/vscode": "^1.88.0",
@@ -99,6 +102,7 @@
99102
"command-exists": "^1.2.9",
100103
"copy-webpack-plugin": "^13.0.0",
101104
"eslint": "^9.23.0",
105+
"lodash": "^4.17.21",
102106
"ts-loader": "^9.5.2",
103107
"typescript": "^5.8.2",
104108
"webpack": "^5.98.0",

src/extension.ts

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import * as vscode from 'vscode';
22
import * as tt from './tt';
33
import * as fs from 'fs';
4+
import * as os from 'os';
5+
import * as _ from 'lodash';
46

57
const 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

1845
async 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

Comments
 (0)