Skip to content

Add option for providing a path to TT #21

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 2 commits into from
Apr 28, 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]

### 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
Expand Down
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
15 changes: 3 additions & 12 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@
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
import * as utils from './utils';

const annotationsPaths = [
__dirname + "/Library",
Expand Down Expand Up @@ -31,7 +32,6 @@
const existingEmmyrc = JSON.parse(f);
const upToDate = _.isMatch(existingEmmyrc, emmyrc);
if (upToDate) {
vscode.window.showInformationMessage(`${globalEmmyrcPath} is up to date`);
return;
}

Expand All @@ -43,21 +43,12 @@
}

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";
Expand Down
8 changes: 6 additions & 2 deletions src/tt.ts
Original file line number Diff line number Diff line change
@@ -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();

Expand All @@ -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<string>('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.');
});
};
}
Expand Down
23 changes: 23 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -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;
}