ternjs / tern_for_vim

Tern plugin for Vim
MIT License
1.83k stars 100 forks source link

Tern throws a stack trace when jumping to matches in comments #28

Closed AndrewRayCode closed 11 years ago

AndrewRayCode commented 11 years ago

When I do /varName and hit enter, then n, and the match is inside a comment, I see the tern server get unhappy:

Error: No expression at the given position.
    at exports.findQueryExpr (.vim/bundle/tern_for_vim/node_modules/tern/lib/tern.js:577:13)
    at Object.findTypeAt [as run] (.vim/bundle/tern_for_vim/node_modules/tern/lib/tern.js:582:16)
    at .vim/bundle/tern_for_vim/node_modules/tern/lib/tern.js:189:30
    at Object.exports.withContext (.vim/bundle/tern_for_vim/node_modules/tern/lib/infer.js:612:18)
    at .vim/bundle/tern_for_vim/node_modules/tern/lib/tern.js:186:13
    at analyzeAll (.vim/bundle/tern_for_vim/node_modules/tern/lib/tern.js:289:15)
    at doRequest (.vim/bundle/tern_for_vim/node_modules/tern/lib/tern.js:180:5)
    at Object.signal.mixin.request (.vim/bundle/tern_for_vim/node_modules/tern/lib/tern.js:124:7)
    at respond (.vim/bundle/tern_for_vim/node_modules/tern/bin/tern:179:10)
    at IncomingMessage.<anonymous> (.vim/bundle/tern_for_vim/node_modules/tern/bin/tern:145:32)
Response: 400 Error: No expression at the given position.
AndrewRayCode commented 11 years ago

I also see this stack trace when switching between tabs :frowning: :confused:

AndrewRayCode commented 11 years ago

Dupe of #16

clausreinke commented 11 years ago

Isn't this more likely something to do with an autocommand, like the one for lookupArgumentHints? Probably needs some error handling when the cursor is not on something it can handle.

marijnh commented 11 years ago

This is by design -- the server will complain when you try to perform a query that expects an expression at a point where there is no expression. Don't be worried by the error output.

What stack trace do you see when switching between tabs?

AndrewRayCode commented 11 years ago

I see the same stack trace when switching between tabs

marijnh commented 11 years ago

That's really odd. There is a BufLeave handler that sends the buffer over to the server if it is dirty, but the "No expression at the given position." error can't be fired for a request that simply sends an updated version of a buffer. The stack trace contains findTypeAt, which indicates that somehow a "type" query was done. Probably, the LookupArgumentHints function is somehow running. What is your tern_show_argument_hints setting? Could it be that a hold or move event fires when leaving the buffer? (@clausreinke maybe you know more?)

clausreinke commented 11 years ago

CursorMoved fires on buffer switch, CursorHold will fire in the new buffer, after delay.

marijnh commented 11 years ago

Okay. That seems harmless. I've changed Tern in patch 1 to only spit out stack traces for errors that actually are bugs, not errors that it intentionally raised itself. That should reduce the noise.