Skip to content

Commit 28384ef

Browse files
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
1 parent e356b99 commit 28384ef

File tree

5 files changed

+48
-14
lines changed

5 files changed

+48
-14
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
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+
### Added
12+
13+
- A `tarantool.ttPath` configuration option can now be used to specify a path to
14+
TT utility if it's not available in the `$PATH`.
15+
1116
### Changed
1217

1318
- Now the extension automatically setups Tarantool annotations without need to

package.json

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,17 @@
7575
],
7676
"url": "https://download.tarantool.org/tarantool/schema/config.schema.json"
7777
}
78-
]
78+
],
79+
"configuration": {
80+
"title": "Tarantool",
81+
"properties": {
82+
"tarantool.ttPath": {
83+
"type": "string",
84+
"default": "tt",
85+
"markdownDescription": "Specifies a path to the TT executable, defaults to the one available in the `$PATH`."
86+
}
87+
}
88+
}
7989
},
8090
"scripts": {
8191
"vscode:prepublish": "npm run package",

src/extension.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import * as tt from './tt';
33
import * as fs from 'fs';
44
import * as os from 'os';
55
import * as _ from 'lodash';
6+
import * as utils from './utils';
67

78
const annotationsPaths = [
89
__dirname + "/Library",
@@ -43,21 +44,12 @@ async function initGlobalEmmyrc() {
4344
}
4445

4546
async function initVs() {
46-
const file = vscode.window.activeTextEditor?.document.uri.fsPath;
47-
48-
const wsedit = new vscode.WorkspaceEdit();
49-
const wsFolders = vscode.workspace.workspaceFolders?.map((folder) => folder.uri.fsPath);
50-
if (!wsFolders) {
51-
vscode.window.showWarningMessage('Please, open a project before running this command');
52-
return;
53-
}
54-
55-
const wsPath = file ? wsFolders.find((folder) => file.startsWith(folder)) : wsFolders.at(0);
47+
const wsPath = utils.fetchWsFolder({ showWarning: true })?.uri.fsPath;
5648
if (!wsPath) {
57-
vscode.window.showWarningMessage('Please, open at least one folder within the workspace');
5849
return;
5950
}
6051

52+
const wsedit = new vscode.WorkspaceEdit();
6153
const filePath = vscode.Uri.file(`${wsPath}/${emmyrcFile}`);
6254
if (fs.existsSync(filePath.fsPath)) {
6355
const yes = "Yes";

src/tt.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as vscode from 'vscode';
22
import commandExists = require('command-exists');
33
import { Octokit } from '@octokit/core';
4+
import * as utils from './utils';
45

56
const octokit = new Octokit();
67

@@ -15,12 +16,15 @@ function getTerminal(): vscode.Terminal {
1516

1617
function cmd(body: string) {
1718
return async () => {
18-
const tt = 'tt';
19+
const wsFolder = utils.fetchWsFolder();
20+
const config = vscode.workspace.getConfiguration(undefined, wsFolder);
21+
const tt = config.get<string>('tarantool.ttPath') || 'tt';
22+
1923
commandExists(`${tt}`).then(() => {
2024
const t = getTerminal();
2125
t.sendText(`${tt} ${body}`);
2226
}).catch(function () {
23-
vscode.window.showErrorMessage('TT is not installed');
27+
vscode.window.showErrorMessage('TT is not available. Install it or provide a path to it explicitly in the Tarantool plugin configuration.');
2428
});
2529
};
2630
}

src/utils.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import * as vscode from 'vscode';
2+
3+
export function fetchWsFolder(opts?: { showWarning?: boolean }): vscode.WorkspaceFolder | null {
4+
const file = vscode.window.activeTextEditor?.document.uri.fsPath;
5+
6+
const wsFolders = vscode.workspace.workspaceFolders;
7+
if (!wsFolders) {
8+
if (opts?.showWarning) {
9+
vscode.window.showWarningMessage('Please, open a project before running this command');
10+
}
11+
return null;
12+
}
13+
14+
const wsFolder = file ? wsFolders.find((folder) => file.startsWith(folder.uri.fsPath)) : wsFolders.at(0);
15+
if (!wsFolder) {
16+
if (opts?.showWarning) {
17+
vscode.window.showWarningMessage('Please, open at least one folder within the workspace');
18+
}
19+
return null;
20+
}
21+
22+
return wsFolder;
23+
}

0 commit comments

Comments
 (0)