Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple TernDef calls from within script: jumplist #162

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

davidsu
Copy link

@davidsu davidsu commented Mar 31, 2017

we are using requirejs and many times tern jumps into the return of the function ( which is correct since this is where the variable was defined ) but we want to further jump and get to the initial definition of what we were looking for. I've added a piece of code that does just that, based on our codestyle a simple regex may inform us that this is not the place we wanted to see... but we are getting additional stop on our way back with ctrl+o. we would like to ask tern for additional jumps without adding to the jump list.
following the piece of code in my .vimrc ( still need improvement but it's good enough for now )

function! GoToDeclaration()
    let l:pos = getpos('.')
    let l:currFileName = expand('%')
    let l:lineFromCursorPosition = strpart(getline('.'), getpos('.')[2])
    let l:wordUnderCursor = expand('<cword>')
    let l:isFunction = match(l:lineFromCursorPosition , '^\(\w\|\s\)*(') + 1
    silent TernDef
    if join(l:pos) == join(getpos('.'))
        "can't jump to definition with tern, do a search with ag + fzf
        if l:isFunction
            FindNoTestFunction(l:wordUnderCursor)
        else
            call fzf#vim#ag(expand('<cword>'), s:defaultPreview ) 
        endif
        call feedkeys(l:wordUnderCursor)
    else
        let l:newCursorLine = getline('.')
        let l:newCurrFileName = expand('%')
        let l:regex = '^\s*' . l:wordUnderCursor . '\s*\(,\?\|\(:\s*' . l:wordUnderCursor . ',\?\)\)\s*$'
        echom l:regex
        if l:newCurrFileName != l:currFileName && match(l:newCursorLine, '\((\|=\)') < 0 && match(getline('.'), regex ) + 1
            "we are inside a module.exports, maybe we can get to the line where the function is declared
            echom 'the line: ' . getline('.')
            call search(l:wordUnderCursor . '\s*\((\|=\)')
            " note that i changed this function in python to allow `add_jump_position` argument
            py3 tern_lookupDefinition("edit", add_jump_position=False)
        endif
        normal zz
        call CursorPing()
    endif
endfunction

   we are using requirejs and many times tern jumps into the `return` of the function ( which is correct since this is
   where the variable was defined ) but we want to further jump and get to the initial definition of what we were
   looking for. I've added a piece of code that does just that, based on our codestyle a simple regex may inform us that
   this is not the place we wanted to see... but we are getting additional stop on our way back with ctrl+o. we would
   like to ask tern for additional jumps without addind to the jump list.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants