feat: add context for solidity (#347)

* feat: add context for solidity

* add test file for solidity, update readme
This commit is contained in:
Meet Mangukiya 2023-10-15 14:38:10 +05:30 committed by GitHub
parent 4cf64264c0
commit 82c6959516
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 139 additions and 1 deletions

View file

@ -160,7 +160,7 @@ Note: if you need support for Neovim 0.6.x please use the tag `compat/0.6`.
- [ ] `scheme`
- [ ] `slint`
- [ ] `smithy`
- [ ] `solidity`
- [x] `solidity`
- [ ] `sparql`
- [ ] `sql`
- [ ] `starlark`

View file

@ -0,0 +1,24 @@
(contract_declaration) @context
(library_declaration) @context
(interface_declaration) @context
(event_definition) @context
(constructor_definition) @context
(function_definition) @context
(modifier_definition) @context
(fallback_receive_definition) @context
(block_statement) @context
(if_statement) @context
(emit_statement) @context
(revert_statement) @context
(try_statement) @context
(catch_clause) @context
(for_statement) @context
(while_statement) @context
(do_while_statement) @context
(call_expression) @context
(error_declaration) @context
(struct_declaration) @context
(enum_declaration) @context

114
test/test.sol Normal file
View file

@ -0,0 +1,114 @@
interface SomeInterface {
function someFunction(uint a, uint b) external returns (uint c);
function testFunction(uint) external returns (uint);
}
contract Contract {
event SomeEvent(
uint a,
uint b,
uint c,
uint d
);
error SomeError(
uint a,
uint b,
uint c,
uint d
);
struct SomeStruct {
uint a;
uint b;
uint c;
uint d;
}
enum SomeEnum {
Entry1,
Entry2,
Entry3,
Entry4
}
constructor() {
// do some construction
}
fallback() external payable {
// this is
// fallback
}
receive() external payable {
// this is
// receive
// function
}
function someFunction(uint a, uint b) external pure returns (uint _c) {
_c = a + b;
if (true) {
// do
// something
// in if statement
emit SomeEvent(1, 2,
3, 4);
} else {
// do
// something
// in else statement
revert SomeError(
1,
2,
3, 4
);
}
for (uint i = 0; i < 10; i++) {
// something
// in loop
uint j = 0;
while (j < 5) {
j++;
// something
// something
try {
// will error
// need to catch
} catch (bytes memory reason) {
// catch
// do some cleanup
}
}
do {
// this is do
// while
unchecked {
j++;
}
} while (j < 5);
}
}
modifier withSomething(uint a) {
// modifier logic
_;
}
}
library SomeLibrary {
function libraryFunction(uint a, uint b, uint c, uint d) internal pure {
a = 1;
b = 2;
c = 3;
d = 4;
}
}