Skip to content

Commit 811fed8

Browse files
committed
Auto-format helpers.ts
1 parent 4c07939 commit 811fed8

File tree

1 file changed

+32
-15
lines changed

1 file changed

+32
-15
lines changed

integration/vscode/ada/src/helpers.ts

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
-- of the license. --
1616
----------------------------------------------------------------------------*/
1717
import * as vscode from 'vscode';
18-
import * as path from 'path'
18+
import * as path from 'path';
1919

2020
/**
2121
* Substitue any variable reference present in the given string. VS Code
@@ -26,12 +26,11 @@ import * as path from 'path'
2626
* @returns
2727
*/
2828
export function substituteVariables(str: string, recursive = false) {
29-
30-
let workspaces = vscode.workspace.workspaceFolders ?? [];
31-
let workspace = workspaces.length ? workspaces[0] : null;
32-
let activeEditor = vscode.window.activeTextEditor
33-
let activeFile = activeEditor?.document;
34-
let absoluteFilePath = activeFile?.uri.fsPath ?? ""
29+
const workspaces = vscode.workspace.workspaceFolders ?? [];
30+
const workspace = workspaces.length ? workspaces[0] : null;
31+
const activeEditor = vscode.window.activeTextEditor;
32+
const activeFile = activeEditor?.document;
33+
const absoluteFilePath = activeFile?.uri.fsPath ?? '';
3534

3635
if (workspace != null) {
3736
str = str.replace(/\${workspaceFolder}/g, workspace?.uri.fsPath);
@@ -41,31 +40,44 @@ export function substituteVariables(str: string, recursive = false) {
4140
str = str.replace(/\${file}/g, absoluteFilePath);
4241
let activeWorkspace = workspace;
4342
let relativeFilePath = absoluteFilePath;
44-
for (let workspace of workspaces) {
43+
for (const workspace of workspaces) {
4544
if (absoluteFilePath.replace(workspace.uri.fsPath, '') !== absoluteFilePath) {
4645
activeWorkspace = workspace;
47-
relativeFilePath = absoluteFilePath.replace(workspace.uri.fsPath, '').substr(path.sep.length);
46+
relativeFilePath = absoluteFilePath
47+
.replace(workspace.uri.fsPath, '')
48+
.substr(path.sep.length);
4849
break;
4950
}
5051
}
51-
let parsedPath = path.parse(absoluteFilePath);
52+
const parsedPath = path.parse(absoluteFilePath);
5253

5354
if (activeWorkspace != null) {
5455
str = str.replace(/\${fileWorkspaceFolder}/g, activeWorkspace?.uri.fsPath);
5556
}
5657

5758
str = str.replace(/\${relativeFile}/g, relativeFilePath);
58-
str = str.replace(/\${relativeFileDirname}/g, relativeFilePath.substr(0, relativeFilePath.lastIndexOf(path.sep)));
59+
str = str.replace(
60+
/\${relativeFileDirname}/g,
61+
relativeFilePath.substr(0, relativeFilePath.lastIndexOf(path.sep))
62+
);
5963
str = str.replace(/\${fileBasename}/g, parsedPath.base);
6064
str = str.replace(/\${fileBasenameNoExtension}/g, parsedPath.name);
6165
str = str.replace(/\${fileExtname}/g, parsedPath.ext);
62-
str = str.replace(/\${fileDirname}/g, parsedPath.dir.substr(parsedPath.dir.lastIndexOf(path.sep) + 1));
66+
str = str.replace(
67+
/\${fileDirname}/g,
68+
parsedPath.dir.substr(parsedPath.dir.lastIndexOf(path.sep) + 1)
69+
);
6370
str = str.replace(/\${cwd}/g, parsedPath.dir);
6471
str = str.replace(/\${pathSeparator}/g, path.sep);
6572

6673
if (activeEditor != null) {
6774
str = str.replace(/\${lineNumber}/g, (activeEditor.selection.start.line + 1).toString());
68-
str = str.replace(/\${selectedText}/g, activeEditor.document.getText(new vscode.Range(activeEditor.selection.start, activeEditor.selection.end)));
75+
str = str.replace(
76+
/\${selectedText}/g,
77+
activeEditor.document.getText(
78+
new vscode.Range(activeEditor.selection.start, activeEditor.selection.end)
79+
)
80+
);
6981
}
7082

7183
str = str.replace(/\${env:(.*?)}/g, function (variable) {
@@ -76,8 +88,13 @@ export function substituteVariables(str: string, recursive = false) {
7688
return vscode.workspace.getConfiguration().get(variable.match(/\${config:(.*?)}/)![1], '');
7789
});
7890

79-
if (recursive && str.match(/\${(workspaceFolder|workspaceFolderBasename|fileWorkspaceFolder|relativeFile|fileBasename|fileBasenameNoExtension|fileExtname|fileDirname|cwd|pathSeparator|lineNumber|selectedText|env:(.*?)|config:(.*?))}/)) {
91+
if (
92+
recursive &&
93+
str.match(
94+
/\${(workspaceFolder|workspaceFolderBasename|fileWorkspaceFolder|relativeFile|fileBasename|fileBasenameNoExtension|fileExtname|fileDirname|cwd|pathSeparator|lineNumber|selectedText|env:(.*?)|config:(.*?))}/
95+
)
96+
) {
8097
str = substituteVariables(str, recursive);
8198
}
8299
return str;
83-
}
100+
}

0 commit comments

Comments
 (0)