Skip to content

Commit 2ce7932

Browse files
authored
Merge pull request #11 from tintinweb/autocomplete
Autocomplete for Solidity Built-Ins
2 parents b72804e + b302a52 commit 2ce7932

File tree

10 files changed

+278
-36
lines changed

10 files changed

+278
-36
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
# Change Log
22
All notable changes will be documented in this file.
33

4+
## v0.0.10
5+
- new: update to solc@0.8.11
6+
- new: basic autocomplete for built-ins (configurable via `.config`) - #11
7+
- fix: return value of unit constants (e.g. `2 ether`) - #12
8+
- fix: distinguish between/ autoguess const signed and unsigned int return values - #12
9+
- update: minor refactoring - #11
10+
411
## v0.0.9
512
- new: support the `import` directive - #8
613
- new: experimental support for `https` imports, i.e. `import "https://raw.githubusercontent.com/OpenZeppelin/openzeppelin-contracts/master/contracts/token/ERC721/IERC721.sol"`. This can be disabled by setting ` » .config set resolveHttpImports false`.

bin/main.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@ const path = require('path');
1212

1313
const { InteractiveSolidityShell, SolidityStatement } = require('../src/handler');
1414
const { convert, multilineInput } = require('../src/cli/utils');
15+
const { builtIns } = require('../src/compiler/autogenerated/builtIns');
1516

17+
/** GLobals */
1618
const CONFIG_HOME = path.join(os.homedir(), '.solidity-shell');
1719
const CONFIG_FILE = '.config';
1820

19-
const REX_PLACEHOLDER = /(^|\s)(\$_)(\s|$)/ig /* LAST_KNOWN_RESULT placeholder */
21+
const REX_PLACEHOLDER = /(\$_)/ig /* LAST_KNOWN_RESULT placeholder */
2022

2123
var LAST_KNOWN_RESULT = 'ss';
2224
var SESSION = 'previous.session';
@@ -82,7 +84,7 @@ vorpal
8284
let command = multilineInput(input);
8385

8486
/* substitute placeholder: $_ */
85-
command = command.replace(REX_PLACEHOLDER, ' ' + LAST_KNOWN_RESULT + ' ');
87+
command = command.replace(REX_PLACEHOLDER, ' (' + LAST_KNOWN_RESULT + ') ');
8688

8789
if (command.startsWith('.')) {
8890
let commandParts = command.split(' ');
@@ -226,6 +228,15 @@ vorpal
226228
vorpal
227229
.command("$_")
228230

231+
/** autocomplate built-ins (not context sensitive) */
232+
if(config.enableAutoComplete){
233+
for (let builtin of builtIns) {
234+
vorpal //register built-in as command (1st level autocomplete, with 2nd level autocomplete for params)
235+
.command(`${builtin}`)
236+
.autocomplete(builtIns);
237+
}
238+
}
239+
229240
/** start in repl mode */
230241
vorpal.execSync("repl")
231242

package-lock.json

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "solidity-shell",
3-
"version": "0.0.9",
3+
"version": "0.0.10",
44
"description": "",
55
"main": "src/index.js",
66
"bin": {
77
"solidity-shell": "bin/main.js"
88
},
99
"scripts": {
10-
"updateCompilerList": "node scripts/UpdateCompilerList.js > src/compiler/solcVersions.js"
10+
"updateCompilerList": "node scripts/getCompilerList.js > src/compiler/autogenerated/solcVersions.js",
11+
"updateBuiltIns": "node scripts/getBuiltIns.js > src/compiler/autogenerated/builtIns.js"
1112
},
1213
"author": {
1314
"name": "tintinweb",
@@ -28,7 +29,7 @@
2829
"minimist": "^1.2.5",
2930
"readline-sync": "^1.4.10",
3031
"request": "^2.88.2",
31-
"solc": "^0.8.10",
32+
"solc": "^0.8.11",
3233
"sync-request": "^6.1.0",
3334
"vorpal": "^1.12.0",
3435
"web3": "^1.5.2"

scripts/getBuiltIns.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env node
2+
'use strict'
3+
/**
4+
* @author github.com/tintinweb
5+
* @license MIT
6+
* */
7+
const request = require('request');
8+
9+
const rexQuoted = /'(.*?)'/g;
10+
const rexValid = /^[a-z0-9]{3,}$/i;
11+
12+
function getBuiltInsFromAntlrGrammar() {
13+
return new Promise((resolve, reject) => {
14+
request.get('https://raw.githubusercontent.com/solidity-parser/antlr/master/Solidity.g4', (err, res, body) => {
15+
if (err) {
16+
return reject(err)
17+
} else {
18+
const array = Array.from(new Set([...body.matchAll(rexQuoted)].map(m => m[1].trim()))).filter(fi => rexValid.test(fi) );
19+
return resolve(array);
20+
}
21+
})
22+
});
23+
}
24+
25+
26+
getBuiltInsFromAntlrGrammar().then(b => {
27+
console.log(`'use strict'
28+
/**
29+
* @author github.com/tintinweb
30+
* @license MIT
31+
* */
32+
33+
//autogenerated with # npm run updateBuiltIns
34+
module.exports.builtIns = ${JSON.stringify(b, null, 4)}`);
35+
})
36+
Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
'use strict'
2+
/**
3+
* @author github.com/tintinweb
4+
* @license MIT
5+
* */
6+
7+
//autogenerated with # npm run updateBuiltIns
8+
module.exports.builtIns = [
9+
"pragma",
10+
"import",
11+
"from",
12+
"abstract",
13+
"contract",
14+
"interface",
15+
"library",
16+
"error",
17+
"type",
18+
"using",
19+
"for",
20+
"struct",
21+
"modifier",
22+
"function",
23+
"returns",
24+
"event",
25+
"enum",
26+
"address",
27+
"payable",
28+
"mapping",
29+
"memory",
30+
"storage",
31+
"calldata",
32+
"else",
33+
"try",
34+
"catch",
35+
"while",
36+
"unchecked",
37+
"assembly",
38+
"continue",
39+
"break",
40+
"return",
41+
"throw",
42+
"emit",
43+
"revert",
44+
"var",
45+
"bool",
46+
"string",
47+
"byte",
48+
"int",
49+
"int8",
50+
"int16",
51+
"int24",
52+
"int32",
53+
"int40",
54+
"int48",
55+
"int56",
56+
"int64",
57+
"int72",
58+
"int80",
59+
"int88",
60+
"int96",
61+
"int104",
62+
"int112",
63+
"int120",
64+
"int128",
65+
"int136",
66+
"int144",
67+
"int152",
68+
"int160",
69+
"int168",
70+
"int176",
71+
"int184",
72+
"int192",
73+
"int200",
74+
"int208",
75+
"int216",
76+
"int224",
77+
"int232",
78+
"int240",
79+
"int248",
80+
"int256",
81+
"uint",
82+
"uint8",
83+
"uint16",
84+
"uint24",
85+
"uint32",
86+
"uint40",
87+
"uint48",
88+
"uint56",
89+
"uint64",
90+
"uint72",
91+
"uint80",
92+
"uint88",
93+
"uint96",
94+
"uint104",
95+
"uint112",
96+
"uint120",
97+
"uint128",
98+
"uint136",
99+
"uint144",
100+
"uint152",
101+
"uint160",
102+
"uint168",
103+
"uint176",
104+
"uint184",
105+
"uint192",
106+
"uint200",
107+
"uint208",
108+
"uint216",
109+
"uint224",
110+
"uint232",
111+
"uint240",
112+
"uint248",
113+
"uint256",
114+
"bytes",
115+
"bytes1",
116+
"bytes2",
117+
"bytes3",
118+
"bytes4",
119+
"bytes5",
120+
"bytes6",
121+
"bytes7",
122+
"bytes8",
123+
"bytes9",
124+
"bytes10",
125+
"bytes11",
126+
"bytes12",
127+
"bytes13",
128+
"bytes14",
129+
"bytes15",
130+
"bytes16",
131+
"bytes17",
132+
"bytes18",
133+
"bytes19",
134+
"bytes20",
135+
"bytes21",
136+
"bytes22",
137+
"bytes23",
138+
"bytes24",
139+
"bytes25",
140+
"bytes26",
141+
"bytes27",
142+
"bytes28",
143+
"bytes29",
144+
"bytes30",
145+
"bytes31",
146+
"bytes32",
147+
"fixed",
148+
"ufixed",
149+
"new",
150+
"after",
151+
"delete",
152+
"let",
153+
"switch",
154+
"case",
155+
"default",
156+
"receive",
157+
"callback",
158+
"true",
159+
"false",
160+
"wei",
161+
"gwei",
162+
"szabo",
163+
"finney",
164+
"ether",
165+
"seconds",
166+
"minutes",
167+
"hours",
168+
"days",
169+
"weeks",
170+
"years",
171+
"hex",
172+
"final",
173+
"inline",
174+
"match",
175+
"null",
176+
"relocatable",
177+
"static",
178+
"typeof",
179+
"anonymous",
180+
"constant",
181+
"immutable",
182+
"leave",
183+
"external",
184+
"indexed",
185+
"internal",
186+
"private",
187+
"public",
188+
"virtual",
189+
"pure",
190+
"view",
191+
"constructor",
192+
"fallback",
193+
"override",
194+
"unicode"
195+
]
File renamed without changes.

src/compiler/remoteCompiler.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @license MIT
55
* */
66
/** IMPORT */
7-
const { solcVersions } = require('./solcVersions.js')
7+
const { solcVersions } = require('./autogenerated/solcVersions.js')
88
const request = require('request');
99

1010
function normalizeSolcVersion(version) {

0 commit comments

Comments
 (0)