Skip to content

Commit d7e5cf6

Browse files
authored
Merge pull request #26 from PraneshASP/staging
✨ Release v1.2.0
2 parents 2a29a87 + 6e563a2 commit d7e5cf6

File tree

6 files changed

+215
-4
lines changed

6 files changed

+215
-4
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ TL;DR, this is my first VSCode extension, so feel free to provide feedback as I
2222
- Flatten current file (or) selected file(s).
2323
- Inline highlighting in code editor for unused imports.
2424
- Generate and view Foundry deployment report in a clean and concise table format.
25+
- Syntax highlighting of for `.tree` files.
26+
- Generate foundry test stub using [bulloak](https://github.com/alexfertel/bulloak)'s `scaffold` command.
2527

2628
---
2729

@@ -34,6 +36,9 @@ The following will need to be installed in order to use this template. Please fo
3436
- You can test you've installed them right by running `forge --version` and get an output like: `forge 0.2.0 (f016135 2022-07-04T00:15:02.930499Z)`
3537
- To get the latest of each, just run `foundryup`
3638

39+
- [Bulloak](https://github.com/alexfertel/bulloak)
40+
- This is required to generate test stub from `.tree` spec files.
41+
3742
## Usage
3843

3944
The usage of this extension is straightforward.
@@ -76,6 +81,19 @@ The usage of this extension is straightforward.
7681
https://github.com/PraneshASP/vscode-solidity-inspector/assets/42379522/e4906ad3-69e6-4cea-b986-7712ec342fca
7782

7883

84+
---
85+
86+
#### Generate foundry deployment report:
87+
88+
https://github.com/PraneshASP/vscode-solidity-inspector/assets/42379522/cfaf987e-ad91-4927-9042-7562bc8684dc
89+
90+
---
91+
92+
#### Support for `.tree` files and test stub generation:
93+
94+
https://github.com/PraneshASP/vscode-solidity-inspector/assets/42379522/2a3d591b-bc80-46cc-88c9-7e4faa0bb043
95+
96+
7997
---
8098

8199
<!-- CONTRIBUTING -->

package.json

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-solidity-inspector",
33
"displayName": "Solidity Inspector",
44
"description": "A vscode extension used to inspect Solidity files",
5-
"version": "1.1.0",
5+
"version": "1.2.0",
66
"engines": {
77
"vscode": "^1.72.0"
88
},
@@ -28,7 +28,8 @@
2828
"main": "./src/extension.js",
2929
"activationEvents": [
3030
"onLanguage:solidity",
31-
"onLanguage:json"
31+
"onLanguage:json",
32+
"onLanguage:tree"
3233
],
3334
"contributes": {
3435
"commands": [
@@ -86,6 +87,16 @@
8687
"command": "vscode-solidity-inspector.contextMenu.generateDeploymentReport",
8788
"title": "SolidityInspector: generate deployment report",
8889
"category": "Solidity Inspector"
90+
},
91+
{
92+
"command": "vscode-solidity-inspector.activeFile.scaffold",
93+
"title": "Scaffold",
94+
"category": "Solidity Inspector"
95+
},
96+
{
97+
"command": "vscode-solidity-inspector.contextMenu.scaffold",
98+
"title": "Solidity Inspector: scaffold",
99+
"category": "Solidity Inspector"
89100
}
90101
],
91102
"configuration": {
@@ -119,9 +130,29 @@
119130
"group": "solidity",
120131
"command": "vscode-solidity-inspector.contextMenu.generateDeploymentReport",
121132
"when": "resourceFilename =~ /\\.json/"
133+
},
134+
{
135+
"group": "solidity",
136+
"command": "vscode-solidity-inspector.contextMenu.scaffold",
137+
"when": "resourceFilename =~ /\\.tree/"
122138
}
123139
]
124-
}
140+
},
141+
"grammars": [
142+
{
143+
"language": "tree",
144+
"scopeName": "source.tree",
145+
"path": "./src/syntaxes/tree-syntax.tmLanguage.json"
146+
}
147+
],
148+
"languages": [
149+
{
150+
"id": "tree",
151+
"extensions": [
152+
".tree"
153+
]
154+
}
155+
]
125156
},
126157
"scripts": {},
127158
"devDependencies": {

src/commands/bulloak-scaffold.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
const vscode = require("vscode");
2+
const cp = require("child_process");
3+
const { newWindowBeside } = require("../helpers");
4+
5+
async function scaffoldActiveFile(args) {
6+
let activeDoc = vscode.window.activeTextEditor.document;
7+
let activeFile = activeDoc.fileName;
8+
if (activeFile.endsWith(".tree")) {
9+
const filePathArray = activeFile.split("/");
10+
let fileName = filePathArray[filePathArray.length - 1];
11+
fileName = fileName.substring(0, fileName.length - 4);
12+
filePathArray.pop();
13+
let activeFileDirArray = activeFile.split('/');
14+
activeFileDirArray.pop();
15+
let activeFileDir = activeFileDirArray.join("/");
16+
cp.exec(
17+
`cd ${activeFileDir} && bulloak scaffold ${fileName}tree`,
18+
(err, stdout, stderr) => {
19+
if (err) {
20+
vscode.window.showErrorMessage(
21+
`[Operation failed] \n${err.message}\n\nNOTE: Please make sure to install 'bulloak' before using this command`
22+
);
23+
console.error(err);
24+
}
25+
newWindowBeside(stdout);
26+
}
27+
);
28+
} else {
29+
vscode.window.showErrorMessage(
30+
`[Operation failed] ${activeFile}\n\nOnly .tree files are supported.`
31+
);
32+
}
33+
}
34+
35+
async function scaffoldContextMenu(clickedFile, selectedFiles) {
36+
for (let index = 0; index < selectedFiles.length; index++) {
37+
const activeFile = selectedFiles[index].path;
38+
if (!activeFile.endsWith(".tree")) continue;
39+
const filePathArray = activeFile.split("/");
40+
let fileName = filePathArray[filePathArray.length - 1];
41+
fileName = fileName.substring(0, fileName.length - 4);
42+
43+
filePathArray.pop();
44+
45+
let activeFileDirArray = activeFile.split('/');
46+
activeFileDirArray.pop();
47+
let activeFileDir = activeFileDirArray.join("/");
48+
cp.exec(
49+
`cd ${activeFileDir} && bulloak scaffold ${fileName}tree`,
50+
(err, stdout, stderr) => {
51+
if (err) {
52+
vscode.window.showErrorMessage(
53+
`[Operation failed] \n${err.message}\n\nNOTE: Please make sure to install 'bulloak' before using this command`
54+
);
55+
}
56+
newWindowBeside(stdout);
57+
}
58+
);
59+
}
60+
}
61+
62+
module.exports = { scaffoldActiveFile, scaffoldContextMenu };

src/commands/parse-tree.js

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
const vscode = require("vscode");
2+
3+
// Create a diagnostic collection
4+
const treeFilesDiagnosticCollection = vscode.languages.createDiagnosticCollection('treeNodes');
5+
6+
// Register a Code Action provider
7+
const treeFilesCodeActionProvider = vscode.languages.registerCodeActionsProvider('tree', {
8+
provideCodeActions(document) {
9+
const diagnostics = [];
10+
11+
document.getText().split('\n').forEach((lineText, lineNumber) => {
12+
lineText = lineText.trim();
13+
if (lineNumber == 0 && !lineText.endsWith('.t.sol')) {
14+
const diagnostic = new vscode.Diagnostic(
15+
new vscode.Range(0, 0, 0, lineText.length),
16+
`Should be a valid test name (ending with .t.sol)`,
17+
vscode.DiagnosticSeverity.Error
18+
);
19+
20+
diagnostics.push(diagnostic);
21+
}
22+
if (/^(||)/.test(lineText)) {
23+
const allowedPrefixes = ['it', 'when', 'given'];
24+
lineText = lineText.replace(/^[^a-zA-Z0-9]+/, '');
25+
26+
// Check if the line starts with an allowed prefix
27+
const prefix = lineText.split(' ')[0];
28+
if (!allowedPrefixes.includes(prefix)) {
29+
// Create a diagnostic for the violation
30+
const diagnostic = new vscode.Diagnostic(
31+
new vscode.Range(lineNumber, 0, lineNumber, lineText.length),
32+
`Tree node should start with "it", "when", or "given"`,
33+
vscode.DiagnosticSeverity.Error
34+
);
35+
diagnostics.push(diagnostic);
36+
}
37+
}
38+
39+
});
40+
41+
treeFilesDiagnosticCollection.set(document.uri, diagnostics);
42+
43+
},
44+
});
45+
46+
module.exports = { treeFilesDiagnosticCollection, treeFilesCodeActionProvider };

src/extension.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ const {
3232

3333
const {
3434
generateDeploymentReportActiveFile, generateDeploymentReportContextMenu
35-
} = require("./commands/deployment-report")
35+
} = require("./commands/deployment-report");
3636

37+
const { treeFilesCodeActionProvider, treeFilesDiagnosticCollection } = require("./commands/parse-tree");
38+
39+
40+
const { scaffoldActiveFile, scaffoldContextMenu } = require("./commands/bulloak-scaffold");
3741

3842
/** global vars */
3943
const EXTENSION_PREFIX = "vscode-solidity-inspector";
@@ -94,6 +98,16 @@ const generateDeploymentReportContextMenuSubscription = vscode.commands.register
9498
generateDeploymentReportContextMenu
9599
);
96100

101+
const scaffoldActiveFileSubscription = vscode.commands.registerCommand(
102+
EXTENSION_PREFIX + ".activeFile.scaffold",
103+
scaffoldActiveFile
104+
);
105+
106+
const scaffoldContextMenuSubscription = vscode.commands.registerCommand(
107+
EXTENSION_PREFIX + ".contextMenu.scaffold",
108+
scaffoldContextMenu
109+
);
110+
97111
/** event funcs */
98112
function onActivate(context) {
99113
vscode.window.onDidChangeActiveTextEditor(editor => {
@@ -127,7 +141,12 @@ function onActivate(context) {
127141
context.subscriptions.push(generateDeploymentReportActiveFileSubscription);
128142
context.subscriptions.push(generateDeploymentReportContextMenuSubscription);
129143

144+
// Register the Code Action provider and diagnostic collection to the subscriptions
145+
context.subscriptions.push(treeFilesCodeActionProvider);
146+
context.subscriptions.push(treeFilesDiagnosticCollection);
130147

148+
context.subscriptions.push(scaffoldActiveFileSubscription);
149+
context.subscriptions.push(scaffoldContextMenuSubscription);
131150

132151
vscode.window.visibleTextEditors.map(editor => {
133152
if (editor && editor.document && editor.document.languageId == "solidity") {
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
{
2+
"name": "Tree File",
3+
"scopeName": "source.tree",
4+
"fileTypes": [
5+
".tree"
6+
],
7+
"patterns": [
8+
{
9+
"include": "#tree-characters"
10+
},
11+
{
12+
"match": "\\b[a-zA-Z0-9_.-]+\\.t\\.sol\\b",
13+
"name": "constant.filename"
14+
},
15+
{
16+
"match": "\\b(when|it|given)\\b",
17+
"name": "keyword.when-it-given"
18+
},
19+
{
20+
"begin": "//",
21+
"end": "$",
22+
"name": "comment"
23+
}
24+
],
25+
"repository": {
26+
"tree-characters": {
27+
"patterns": [
28+
{
29+
"match": "(├──|└──|│)",
30+
"name": "string.tree-characters"
31+
}
32+
]
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)