Skip to content

Set up language server configuration automatically #14

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
Apr 26, 2025
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Changed

- Now the extension automatically setups Tarantool annotations without need to
explicitly execute any commands like `initialize VS Code extension`.

## [0.1.3] - 14.04.2025

### Added
Expand Down
16 changes: 16 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"linter",
"snippets"
],
"activationEvents": [],
"activationEvents": [
"onLanguage:lua"
],
"main": "./dist/extension.js",
"contributes": {
"commands": [
Expand Down Expand Up @@ -89,6 +91,7 @@
"devDependencies": {
"@octokit/core": "^5",
"@types/command-exists": "^1.2.3",
"@types/lodash": "^4.17.16",
"@types/mocha": "^10.0.10",
"@types/node": "20.x",
"@types/vscode": "^1.88.0",
Expand All @@ -99,6 +102,7 @@
"command-exists": "^1.2.9",
"copy-webpack-plugin": "^13.0.0",
"eslint": "^9.23.0",
"lodash": "^4.17.21",
"ts-loader": "^9.5.2",
"typescript": "^5.8.2",
"webpack": "^5.98.0",
Expand Down
32 changes: 30 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
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 5 in src/extension.ts

View workflow job for this annotation

GitHub Actions / Lint

Import name `_` must match one of the following formats: camelCase, PascalCase

const annotationsPaths = [
__dirname + "/Library",
Expand All @@ -14,6 +16,31 @@
"library": annotationsPaths
}
};
const emmyrcFile = '.emmyrc.json';

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 f = fs.readFileSync(globalEmmyrcPath, 'utf8');
const existingEmmyrc = JSON.parse(f);
const upToDate = _.isMatch(existingEmmyrc, emmyrc);
if (upToDate) {
vscode.window.showInformationMessage(`${globalEmmyrcPath} is up to date`);
return;
}

// 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`);
}

async function initVs() {
const file = vscode.window.activeTextEditor?.document.uri.fsPath;
Expand All @@ -31,7 +58,6 @@
return;
}

const emmyrcFile = '.emmyrc.json';
const filePath = vscode.Uri.file(`${wsPath}/${emmyrcFile}`);
if (fs.existsSync(filePath.fsPath)) {
const yes = "Yes";
Expand All @@ -41,7 +67,7 @@
}
wsedit.createFile(filePath, {
overwrite: true,
contents: Buffer.from(JSON.stringify(emmyrc))
contents: Buffer.from(JSON.stringify(emmyrc, undefined, 2))
});
vscode.workspace.applyEdit(wsedit);
vscode.window.showInformationMessage(`Created a new file: ${filePath.toString()}`);
Expand All @@ -66,6 +92,8 @@
return;
}

initGlobalEmmyrc();

const commands = [
{ name: 'init-vs', cb: initVs },
{ name: 'create', cb: tt.create },
Expand Down