ternjs / tern_for_vim

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

Give a way to configure the timeout in the .vimrc file #14

Closed fflorent closed 11 years ago

fflorent commented 11 years ago

See this comment: https://github.com/marijnh/tern_for_vim/commit/21912a8954428721d9655f66f7134c30343b147d#commitcomment-3170219

FWIW (I don't know python and I am far from being an expert of vim), here is a patch I made:

diff --git a/autoload/tern.vim b/autoload/tern.vim
index 37da607..354e315 100644
--- a/autoload/tern.vim
+++ b/autoload/tern.vim
@@ -14,7 +14,8 @@ def tern_displayError(err):

 def tern_makeRequest(port, doc):
   try:
-    req = urllib2.urlopen("http://localhost:" + str(port) + "/", json.dumps(doc), 1)
+    timeout = tern_serverTimeout()
+    req = urllib2.urlopen("http://localhost:" + str(port) + "/", json.dumps(doc), timeout)
     return json.loads(req.read())
   except urllib2.HTTPError, error:
     tern_displayError(error.read())
@@ -346,6 +347,11 @@ def tern_rename(newName):
     tern_sendBuffer(external)
   vim.command("call setloclist(0," + json.dumps(changes) + ") | lopen")

+def tern_serverTimeout():
+  timeout = int(vim.eval("g:ternServerTimeout"))
+  if timeout: return timeout
+  return 1
+
 endpy

 if !exists('g:tern#command')

Florent

marijnh commented 11 years ago

See attached patch. I used tern_request_timeout as variable name, and float instead int, since the Python interface takes any floating point number of seconds.