Skip to content

Commit 89f10a0

Browse files
Set up language server configuration automatically [WIP]
Closes #12
1 parent 5c3808c commit 89f10a0

File tree

4 files changed

+56
-3
lines changed

4 files changed

+56
-3
lines changed

Diff for: CHANGELOG.md

+5
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 set ups Tarantool annotations without need to
14+
explicitly execute any commands like `initialize VS Code extension`.
15+
1116
### Fixed
1217

1318
- Fixed a few typos in various Tarantool builtin modules caught up by automatic

Diff for: package-lock.json

+16
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+5-1
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",

Diff for: src/extension.ts

+30-2
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 = [ __dirname + "/Library" ];
68
const emmyrc = {
@@ -11,6 +13,31 @@ const emmyrc = {
1113
"library": annotationsPaths
1214
}
1315
};
16+
const emmyrcFile = '.emmyrc.json';
17+
18+
async function initGlobalEmmyrc() {
19+
const globalEmmyrcPath = `${os.homedir()}/${emmyrcFile}`;
20+
21+
if (!fs.existsSync(globalEmmyrcPath)) {
22+
fs.writeFileSync(globalEmmyrcPath, JSON.stringify(emmyrc, undefined, 2));
23+
vscode.window.showInformationMessage(`Initialized ${globalEmmyrcPath} with Tarantool-specific settings`);
24+
return;
25+
}
26+
27+
const f = fs.readFileSync(globalEmmyrcPath, 'utf8');
28+
const existingEmmyrc = JSON.parse(f);
29+
const upToDate = _.isMatch(existingEmmyrc, emmyrc);
30+
if (upToDate) {
31+
vscode.window.showInformationMessage(`${globalEmmyrcPath} is up to date`);
32+
return;
33+
}
34+
35+
// TODO: Don't miss user-defined libraries.
36+
const mergedEmmyrc = _.merge(existingEmmyrc, emmyrc);
37+
38+
fs.writeFileSync(globalEmmyrcPath, JSON.stringify(mergedEmmyrc, undefined, 2));
39+
vscode.window.showInformationMessage(`Updated existing ${globalEmmyrcPath} with actual Tarantool-specific configuration`);
40+
}
1441

1542
async function initVs() {
1643
const file = vscode.window.activeTextEditor?.document.uri.fsPath;
@@ -28,7 +55,6 @@ async function initVs() {
2855
return;
2956
}
3057

31-
const emmyrcFile = '.emmyrc.json';
3258
const filePath = vscode.Uri.file(`${wsPath}/${emmyrcFile}`);
3359
if (fs.existsSync(filePath.fsPath)) {
3460
const yes = "Yes";
@@ -38,7 +64,7 @@ async function initVs() {
3864
}
3965
wsedit.createFile(filePath, {
4066
overwrite: true,
41-
contents: Buffer.from(JSON.stringify(emmyrc))
67+
contents: Buffer.from(JSON.stringify(emmyrc, undefined, 2))
4268
});
4369
vscode.workspace.applyEdit(wsedit);
4470
vscode.window.showInformationMessage(`Created a new file: ${filePath.toString()}`);
@@ -63,6 +89,8 @@ export function activate(context: vscode.ExtensionContext) {
6389
return;
6490
}
6591

92+
initGlobalEmmyrc();
93+
6694
const commands = [
6795
{ name: 'init-vs', cb: initVs },
6896
{ name: 'create', cb: tt.create },

0 commit comments

Comments
 (0)