diff --git a/CHANGELOG.md b/CHANGELOG.md index 9230315..01437cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/package-lock.json b/package-lock.json index 521ece6..b6abf04 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,6 +10,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", @@ -20,6 +21,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", @@ -641,6 +643,13 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/lodash": { + "version": "4.17.16", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.16.tgz", + "integrity": "sha512-HX7Em5NYQAXKW+1T+FiuG27NGwzJfCX3s1GjOa7ujxZa52kjJLOr4FUxT+giF6Tgxv1e+/czV/iTtBw27WTU9g==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/mocha": { "version": "10.0.10", "resolved": "https://registry.npmjs.org/@types/mocha/-/mocha-10.0.10.tgz", @@ -3001,6 +3010,13 @@ "url": "https://github.com/sponsors/sindresorhus" } }, + "node_modules/lodash": { + "version": "4.17.21", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.21.tgz", + "integrity": "sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==", + "dev": true, + "license": "MIT" + }, "node_modules/lodash.merge": { "version": "4.6.2", "resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz", diff --git a/package.json b/package.json index ba0823a..79b099a 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,9 @@ "linter", "snippets" ], - "activationEvents": [], + "activationEvents": [ + "onLanguage:lua" + ], "main": "./dist/extension.js", "contributes": { "commands": [ @@ -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", @@ -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", diff --git a/src/extension.ts b/src/extension.ts index e06678f..6cdd433 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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'; const annotationsPaths = [ __dirname + "/Library", @@ -14,6 +16,31 @@ const emmyrc = { "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; @@ -31,7 +58,6 @@ async function initVs() { return; } - const emmyrcFile = '.emmyrc.json'; const filePath = vscode.Uri.file(`${wsPath}/${emmyrcFile}`); if (fs.existsSync(filePath.fsPath)) { const yes = "Yes"; @@ -41,7 +67,7 @@ async function initVs() { } 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()}`); @@ -66,6 +92,8 @@ export function activate(context: vscode.ExtensionContext) { return; } + initGlobalEmmyrc(); + const commands = [ { name: 'init-vs', cb: initVs }, { name: 'create', cb: tt.create },