 
 (defun tern-get-type ()
   (interactive)
-  (tern-run-request (lambda (data _offset) (message (or (cdr (assq 'type data)) "Not found")))
-                    "type"
-                    (point)))
+  (tern-run-query (lambda (data _offset) (message (or (cdr (assq 'type data)) "Not found")))
+                  "type"
+                  (point)))
 
 ;; Mode plumbing
 

    (when (and opening-paren (equal (char-after opening-paren) ?\())
      (if (and tern-last-argument-hints (eq (car tern-last-argument-hints) opening-paren))
          (tern-show-argument-hints)
        (tern-run-request (lambda (data _offset)
                            (let ((type (tern-parse-function-type data)))
                              (when type
                                (setf tern-last-argument-hints (cons opening-paren type))
                                (tern-show-argument-hints))))
                          `((type . "type")
                            (preferFunction . t))
                          opening-paren
                          :silent)))))

(defun tern-skip-matching-brackets (end-chars)
  (let ((depth 0) (end (+ (point) 500)))

                  (text . ,(buffer-string))) found))))
    (nreverse found)))

(defun tern-run-request (f doc)
  (let ((buffer (current-buffer))
        (retrying nil))
    (labels ((callback (port)
               (if port
                   (tern-req port doc #'runner)
                 (message "Could not find a Tern server")))
             (runner (err data)
               (with-current-buffer buffer
                 (cond ((and err (eq (cadar err) 'connection-failed) (not retrying))
                        (setf retrying t)
                        (let ((old-port tern-known-port))
                          (setf tern-known-port nil)
                          (tern-find-server #'callback old-port)))
                       (t (funcall f err data))))))
      (tern-find-server #'callback))))

(defun tern-run-query (f query pos &optional mode)
  (when (stringp query) (setf query `((type . ,query))))
  (let ((generation (incf tern-command-generation))
        (doc `((query . ,query)))
        (files (and (eq mode :full-file) (tern-modified-sibling-buffers)))
        file-name
