From 825c8c83be4e9de5a753c973e2db0c7badd8d6d8 Mon Sep 17 00:00:00 2001 From: Georgiy Belyanin Date: Mon, 28 Apr 2025 17:35:04 +0300 Subject: [PATCH 1/2] Add option for providing a path to TT This patch introduces a new `tarantool.ttPath` option allowing one to provide a path to TT. It defaults to `tt` available in the `$PATH`. Closes #20 --- CHANGELOG.md | 5 +++++ package.json | 12 +++++++++++- src/extension.ts | 14 +++----------- src/tt.ts | 8 ++++++-- src/utils.ts | 23 +++++++++++++++++++++++ 5 files changed, 48 insertions(+), 14 deletions(-) create mode 100644 src/utils.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 01437cc..33aa193 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] +### Added + +- A `tarantool.ttPath` configuration option can now be used to specify a path to + TT utility if it's not available in the `$PATH`. + ### Changed - Now the extension automatically setups Tarantool annotations without need to diff --git a/package.json b/package.json index 79b099a..888e822 100644 --- a/package.json +++ b/package.json @@ -75,7 +75,17 @@ ], "url": "https://download.tarantool.org/tarantool/schema/config.schema.json" } - ] + ], + "configuration": { + "title": "Tarantool", + "properties": { + "tarantool.ttPath": { + "type": "string", + "default": "tt", + "markdownDescription": "Specifies a path to the TT executable, defaults to the one available in the `$PATH`." + } + } + } }, "scripts": { "vscode:prepublish": "npm run package", diff --git a/src/extension.ts b/src/extension.ts index 6cdd433..c9cb8eb 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,6 +3,7 @@ import * as tt from './tt'; import * as fs from 'fs'; import * as os from 'os'; import * as _ from 'lodash'; +import * as utils from './utils'; const annotationsPaths = [ __dirname + "/Library", @@ -43,21 +44,12 @@ async function initGlobalEmmyrc() { } async function initVs() { - const file = vscode.window.activeTextEditor?.document.uri.fsPath; - - const wsedit = new vscode.WorkspaceEdit(); - const wsFolders = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath); - if (!wsFolders) { - vscode.window.showWarningMessage('Please, open a project before running this command'); - return; - } - - const wsPath = file ? wsFolders.find((folder) => file.startsWith(folder)) : wsFolders.at(0); + const wsPath = utils.fetchWsFolder({ showWarning: true })?.uri.fsPath; if (!wsPath) { - vscode.window.showWarningMessage('Please, open at least one folder within the workspace'); return; } + const wsedit = new vscode.WorkspaceEdit(); const filePath = vscode.Uri.file(`${wsPath}/${emmyrcFile}`); if (fs.existsSync(filePath.fsPath)) { const yes = "Yes"; diff --git a/src/tt.ts b/src/tt.ts index 970fa51..00da1be 100644 --- a/src/tt.ts +++ b/src/tt.ts @@ -1,6 +1,7 @@ import * as vscode from 'vscode'; import commandExists = require('command-exists'); import { Octokit } from '@octokit/core'; +import * as utils from './utils'; const octokit = new Octokit(); @@ -15,12 +16,15 @@ function getTerminal(): vscode.Terminal { function cmd(body: string) { return async () => { - const tt = 'tt'; + const wsFolder = utils.fetchWsFolder(); + const config = vscode.workspace.getConfiguration(undefined, wsFolder); + const tt = config.get('tarantool.ttPath') || 'tt'; + commandExists(`${tt}`).then(() => { const t = getTerminal(); t.sendText(`${tt} ${body}`); }).catch(function () { - vscode.window.showErrorMessage('TT is not installed'); + vscode.window.showErrorMessage('TT is not available. Install it or provide a path to it explicitly in the Tarantool plugin configuration.'); }); }; } diff --git a/src/utils.ts b/src/utils.ts new file mode 100644 index 0000000..c28dbaf --- /dev/null +++ b/src/utils.ts @@ -0,0 +1,23 @@ +import * as vscode from 'vscode'; + +export function fetchWsFolder(opts?: { showWarning?: boolean }): vscode.WorkspaceFolder | null { + const file = vscode.window.activeTextEditor?.document.uri.fsPath; + + const wsFolders = vscode.workspace.workspaceFolders; + if (!wsFolders) { + if (opts?.showWarning) { + vscode.window.showWarningMessage('Please, open a project before running this command'); + } + return null; + } + + const wsFolder = file ? wsFolders.find((folder) => file.startsWith(folder.uri.fsPath)) : wsFolders.at(0); + if (!wsFolder) { + if (opts?.showWarning) { + vscode.window.showWarningMessage('Please, open at least one folder within the workspace'); + } + return null; + } + + return wsFolder; +} From 77d333a522195cb592d8e3fc7b911630993adca6 Mon Sep 17 00:00:00 2001 From: Georgiy Belyanin Date: Mon, 28 Apr 2025 17:46:38 +0300 Subject: [PATCH 2/2] Don't issue message on actual config In e356b998 ('Set up language server configuration automatically') a global LSP configuration has been introduced. It issued a message when the configuration has been actual and there was nothing to do. It turned to be quite nasty since it appears quite often. Let's remove it. --- src/extension.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/extension.ts b/src/extension.ts index c9cb8eb..8560698 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -32,7 +32,6 @@ async function initGlobalEmmyrc() { const existingEmmyrc = JSON.parse(f); const upToDate = _.isMatch(existingEmmyrc, emmyrc); if (upToDate) { - vscode.window.showInformationMessage(`${globalEmmyrcPath} is up to date`); return; }