Skip to content

Instantly share code, notes, and snippets.

@shuangjj
Last active November 12, 2023 13:57
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save shuangjj/ae816cacffce3a27e256de7c21312c50 to your computer and use it in GitHub Desktop.
Save shuangjj/ae816cacffce3a27e256de7c21312c50 to your computer and use it in GitHub Desktop.
vim ~/.ctags
--langdef=Solidity
--langmap=Solidity:.sol
--regex-Solidity=/^contract[ \t]+([a-zA-Z0-9_]+)/\1/c,contract/
--regex-Solidity=/[ \t]*function[ \t]+([a-zA-Z0-9_]+)/\1/f,function/
--regex-Solidity=/[ \t]*event[ \t]+([a-zA-Z0-9_]+)/\1/e,event/
--regex-Solidity=/[ \t]*(struct[ \t]+[a-zA-Z0-9_]+)([ \t]*\{)/\1/v,variable/
--regex-Solidity=/[ \t]*(enum[ \t]+[a-zA-Z0-9_]+)([ \t]*\{)/\1/v,variable/
--regex-Solidity=/[ \t]*mapping[ \t]+\(([a-zA-Z0-9_]+)[ \t]*=>[ \t]*([a-zA-Z0-9_]+)\)[ \t]+([a-zA-Z0-9_]+)/\3 (\1=>\2)/m,mapping/
vim ~/.vimrc
let g:tagbar_type_solidity = {
\ 'ctagstype': 'solidity',
\ 'kinds' : [
\ 'c:contracts',
\ 'e:events',
\ 'f:functions',
\ 'm:mappings',
\ 'v:varialbes',
\ ]
\ }
@shalzz
Copy link

shalzz commented Apr 8, 2021

Hi,

This works great but also picks up function and event keywords from comments.
Updating to these should fix it:

--regex-Solidity=/[ \t]*function[ \t]+([a-zA-Z0-9_]+)*\(/\1/f,function/
--regex-Solidity=/[ \t]*event[ \t]+([a-zA-Z0-9_]+)*\(/\1/e,event/

@Coppelian
Copy link

Hi,

I found that this definition could miss functions in a specific format.
I have a demo that could be used to test it:

enum PARAMETER { VESTING, PAYOUT, FEE, DEBT }


function setBondTerms ( PARAMETER _parameter, uint _input ) external onlyPolicy() {

    if ( _parameter == PARAMETER.VESTING ) { // 0

        require( _input >= 10000, "Vesting must be longer than 36 hours" );

        terms.vestingTerm = _input;

    } else if ( _parameter == PARAMETER.PAYOUT ) { // 1

        require( _input <= 1000, "Payout cannot be above 1 percent" );

        terms.maxPayout = _input;

    } else if ( _parameter == PARAMETER.FEE ) { // 2

        require( _input <= 10000, "DAO fee cannot exceed payout" );

        terms.fee = _input;

    } else if ( _parameter == PARAMETER.DEBT ) { // 3

        terms.maxDebt = _input;

    }

}





function setAdjustment ( 

    bool _addition,

    uint _increment, 

    uint _target,

    uint _buffer 

) external onlyPolicy() {

    require( _increment <= terms.controlVariable.mul( 25 ).div( 1000 ), "Increment too large" );



    adjustment = Adjust({

        add: _addition,

        rate: _increment,

        target: _target,

        buffer: _buffer,

        lastBlock: block.number

    });

}




function setStaking( address _staking, bool _helper ) external onlyPolicy() {

    require( _staking != address(0) );

    if ( _helper ) {

        useHelper = true;

        stakingHelper = _staking;

    } else {

        useHelper = false;

        staking = _staking;

    }

}

Two of the function cannot be identified correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment